Beruflich Dokumente
Kultur Dokumente
This example shows how to declare local elementary data types within a program. REPORT demo_types_statement. TYPES mytext(10) TYPE c. TYPES myamount TYPE p DECIMALS 2. DATA text TYPE mytext. DATA amount TYPE myamount. text = ' 4 / 3 = '. amount = 4 / 3 . WRITE: text, amount.
Reading Data
Clause
SELECT <result>
Description
The SELECT clause defines the structure of the data you want to read, that is, whether one line or several, which columns you want to read, and whether identical entries are acceptable or not. The INTO clause determines the target area <target> into which the selected data is to be read.
INTO <target>
FROM <source>
The FROM clause specifies the database table or view <source> from which the data is to be selected. It can also be placed before the INTO clause.
The WHERE clause specifies which lines are to be read by specifying conditions for the selection. The GROUP-BY clause produces a single line of results from groups of several lines. A group is a set of lines with identical values for each column listed in <fields>. The HAVING clause sets logical conditions for the lines combined using GROUP BY. The ORDER-BY clause defines a sequence <fields> for the lines resulting from the selection.
Reading certain columns of a single line: DATA WA TYPE SPFLI. SELECT SINGLE CARRID CONNID CITYFROM CITYTO INTO CORRESPONDING FIELDS OF WA FROM SPFLI WHERE CARRID EQ 'LH' AND CONNID EQ '0400'. IF SY-SUBRC EQ 0. WRITE: / WA-CARRID, WA-CONNID, WACITYFROM, WA-CITYTO. ENDIF.
Reading particular columns of more than one line: DATA: ITAB TYPE STANDARD TABLE OF SPFLI, WA LIKE LINE OF ITAB. SELECT CARRID CONNID CITYFROM CITYTO INTO CORRESPONDING FIELDS OF TABLE ITAB FROM SPFLI WHERE CARRID EQ 'LH'. IF SY-SUBRC EQ 0. LOOP AT ITAB INTO WA. WRITE: / WA-CARRID, WA-CONNID, WACITYFROM, WA-CITYTO. ENDLOOP. ENDIF.
Reading all columns of more than one line: DATA WA TYPE SPFLI. SELECT * INTO CORRESPONDING FIELDS OF WA FROM SPFLI WHERE CARRID EQ 'LH'. WRITE: / SY-DBCNT, WA-CARRID, WA-CONNID, WACITYFROM, WA-CITYTO. ENDSELECT.
The same applies to the line type of <itab>, the way in which the data for a line of the database table are assigned to a table line, and the CORRESPONDING FIELDS addition as for flat work areas (see above). The internal table is filled with all of the lines of the selection. When you use INTO, all existing lines in the table are deleted. When you use APPENDING; the new lines are added to the existing internal table <itab>. With APPENDING, the system adds the lines to the internal table appropriately for the table type. Fields in the internal table not affected by the selection are filled with initial values.
Flat structure as target area DATA WA TYPE SPFLI. SELECT * INTO WA FROM SPFLI. WRITE: / WA-CARRID ... ENDSELECT.
This example uses a flat structure with the same data type as the database table SPFLI as the target area in a SELECT loop. Within the loop, it is possible to address the contents of the individual columns. DATA SPFLI TYPE SPFLI. SELECT * FROM SPFLI. WRITE: / SPFLI-CARRID ... ENDSELECT.
Reading packets into an internal table DATA: WA TYPE SPFLI, ITAB TYPE SORTED TABLE OF SPFLI WITH UNIQUE KEY CARRID CONNID. SELECT CARRID CONNID FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE ITAB PACKAGE SIZE 3. LOOP AT ITAB INTO WA. WRITE: / WA-CARRID, WA-CONNID. ENDLOOP. SKIP 1. ENDSELECT.
DATA:
AVERAGE TYPE P DECIMALS 2, SUM TYPE P DECIMALS 2. SELECT AVG( LUGGWEIGHT ) SUM( LUGGWEIGHT ) INTO (AVERAGE, SUM) FROM SBOOK. WRITE: / 'Average:', AVERAGE, / 'Sum :', SUM.
Using aliases: DATA: BEGIN OF LUGGAGE, AVERAGE TYPE P DECIMALS 2, SUM TYPE P DECIMALS 2, END OF LUGGAGE. SELECT AVG( LUGGWEIGHT ) AS AVERAGE SUM( LUGGWEIGHT ) AS SUM INTO CORRESPONDING FIELDS OF LUGGAGE FROM SBOOK. WRITE: / 'Average:', LUGGAGE-AVERAGE, / 'Sum :', LUGGAGE-SUM.
Udpating Data TABLES SPFLI. DATA WA TYPE SPFLI. MOVE 'AA' TO WA-CARRID. MOVE '0064' TO WA-CONNID. MOVE 'WASHINGTON' TO WA-CITYFROM. ... UPDATE SPFLI FROM WA. MOVE 'LH' TO SPFLI-CARRID. MOVE '0017' TO SPFLI-CONNID. MOVE 'BERLIN' TO SPFLI-CITYFROM. ... UPDATE SPFLI.