INTO clause
Variants
1. ... INTO wa
2. ... INTO CORRESPONDING FIELDS OF wa
3. ... INTO (f1, ..., fn)
4. ... INTO TABLE itab
5. ... INTO CORRESPONDING FIELDS OF TABLE itab
6. ... APPENDING TABLE itab
7. ... APPENDING CORRESPONDING FIELDS OF TABLE itab
Effect
With SELECT or
FETCH , this statement determines the
target area into which the data is to be read. If no data is read, the
target area remains unchanged.
The result set is transported to the target area field by field. This
means that the ABAP/4 Dictionary data types must correspond to
the ABAP/4 data types of the target fields as follows:
Result field | Target field |
Dict. data type | ABAP/4 data type |
ACCP | -> C or N |
CHAR | -> C |
CLNT | -> C |
CUKY | -> C |
CURR | -> I, P or F |
DEC | -> I, P or F |
DATS | -> D |
FLTP | -> I or F |
INT1 | -> I, P or F |
INT2 | -> I, P or F |
INT4 | -> I, P or F |
LCHR | -> C |
LRAW | -> X |
LANG | -> C |
NUMC | -> C or N |
PREC | -> X |
QUAN | -> I, P or F |
RAW | -> X |
TIMS | -> T |
UNIT | -> C |
VARC | -> C |
If the ABAP/4 data type of the target field is C ,
N or X , the contents of the result field are placed
left-justified in the target field. If the target field is too short,
the result value is truncated.
If the ABAP/4 of the target field is numeric, the target field
must be long enough to hold the contents of the result field. When
transporting the contents of a result field of type FLTP ot a
target field of type I , the whole number part is copied.
If a field in the result set contains a NULL value, the
initial value of the ABAP/4 data type corresponding to the field
type is placed in the target area (see
TABLES ).
Depending on the database system, any violation of the correspondence
rules can lead to a runtime error.
Variant 1
... INTO wa
Effect
Places the result set in the target area wa line
by line. The fields are transported to the corresponding components of
the wa from left to right.
If you specify a "*" in the SELECT clause
, the selected data is placed left-justified in
wa according to the structure of the table work area
dbtab (see TABLES ). Therefore,
the structure of wa does not have to correspond to the structure
of the result set. However, to access the columns of the results line
symbolically, the structures of wa and dbtab must be
compatible. In each case, the work area wa must be at least as
wide as the table work area dbtab . If wa is wider, the
contents of the remaining area on the right are undefined.
If you specify a list of fields in the
SELECT clause , the selected
data is placed field by field in wa according to the
structure of the work area . If wa has fewer components than
the SELECT list, a runtime error occurs. If it has more, the
contents of the excess components of wa remain undefined.
If the result of a selection is a table, the data is retrieved in a
processing loop introduced by SELECT
and concluded by ENDSELECT . The
processing passes through the loop once for each line read. If the
result is a single record, the closing ENDSELECT is omitted.
Examples
Output a list of all airlines (with short description
and name):
-
TABLES SCARR.
DATA WA LIKE SCARR.
SELECT * INTO WA FROM SCARR.
WRITE: / WA-CARRID, WA-CARRNAME.
ENDSELECT.
Output a list of all airlines (with short description and name):
-
TABLES SCARR.
DATA TABNAME(10).
DATA BEGIN OF WA1,
CARRID LIKE SCARR-CARRID,
CARRNAME LIKE SCARR-CARRNAME,
REST(100),
END OF WA1.
TABNAME = 'SCARR'.
SELECT * INTO WA1 FROM (TABNAME).
WRITE: / WA1-CARRID, WA1-CARRNAME.
ENDSELECT.
Output a list of all airlines (with short description and name):
-
DATA BEGIN OF WA2,
CARRID LIKE SCARR-CARRID,
CARRNAME LIKE SCARR-CARRNAME,
REST(100),
END OF WA2.
SELECT CARRID CARRNAME
INTO WA2
FROM SCARR.
WRITE: / WA2-CARRID, WA2-CARRNAME.
ENDSELECT.
Variant 2
... INTO CORRESPONDING FIELDS OF wa
Effect
Places the result set in the target area wa line
by line. Each field of the result set is transported to the field of
the same name in wa . If no such field exists, a runtime error
occurs.
If the result of a selection is a table, the data is retrieved in a
processing loop introduced by SELECT
and concluded by ENDSELECT . The
processing passes through the loop once for each line read. If the
result is a single record, the closing ENDSELECT is omitted.
Example
Output a list of all airlines (with short description
and name):
-
TABLES SCARR.
SELECT CARRID CARRNAME
INTO CORRESPONDING FIELDS OF SCARR
FROM SCARR.
WRITE: / SCARR-CARRID, SCARR-CARRNAME.
ENDSELECT.
Variant 3
... INTO (f1, ..., fn)
Effect
Places the result set in the target area (f1, ...,
fn) . The fields of the result set are transported to the target
fields fi from left to right. INTO (f1, ..., fn) is
allowed only if a list with n elements is also specified in the
SELECT clause.
If the result of a selection is a table, the data is retrieved in a
processing loop introduced by SELECT
and concluded by ENDSELECT . The
processing passes through the loop once for each line read. If the
result is a single record, the closing ENDSELECT is omitted.
Example
Output a list of all airlines (with short description
and name):
-
TABLES SCARR.
DATA: CARRID LIKE SCARR-CARRID,
CARRNAME LIKE SCARR-CARRNAME,
SELECT CARRID CARRNAME
INTO (CARRID, CARRNAME)
FROM SCARR.
WRITE: / CARRID, CARRNAME.
ENDSELECT
Variant 4
... INTO TABLE itab
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO wa , except that the selected
data is not assigned to the internal table itab line by line,
but in one single operation. In this case,
SELECT does not introduce a processing
loop, so there can be no ENDSELECT
statement. The old contents of itab are overwritten.
Example
Output a list of all airlines (with short description
and name):
-
TABLES SCARR.
DATA ITAB LIKE SCARR OCCURS 100 WITH HEADER LINE.
SELECT * INTO TABLE ITAB FROM SCARR.
LOOP AT ITAB.
WRITE: / ITAB-CARRID, ITAB-CARRNAME.
ENDLOOP.
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO wa , except that the selected
data is not assigned to the internal table
-
If n = 0, all lines selected by the WHERE condition are
returned in one single operation.
-
n < 0 causes a runtime error.
-
Internally, n is placed in a type I field. Here, the usual
conversion rules apply (see MOVE ).
-
After leaving the processing loop, the contents of the internal table
itab are undefined.
If the result of a selection is a table, the data is retrieved in a
processing loop introduced by SELECT
and concluded by ENDSELECT . The
processing passes through the loop once for each line read. If the
result is a single record, the closing ENDSELECT is omitted.
Example
Output a list of all airlines (with short description
and name):
-
TABLES SCARR.
DATA ITAB LIKE SCARR OCCURS 100 WITH HEADER LINE.
SELECT * INTO TABLE ITAB PACKAGE SIZE 20 FROM SCARR.
LOOP AT ITAB.
WRITE: / ITAB-CARRID, ITAB-CARRNAME.
ENDLOOP.
ENDSELECT.
Variant 5
... INTO CORRESPONDING FIELDS OF TABLE itab
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO CORRESPONDING FIELDS OF wa ,
except that the selected data is not assigned to the internal table
SELECT does not introduce a processing
loop, so there can be no ENDSELECT
statement. The old contents of itab are overwritten.
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO TABLE itab .
Variant 6
... APPENDING TABLE itab
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO TABLE itab , except that the
read lines are appended to the old contents of the internal table
itab .
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO TABLE itab .
Variant 7
... APPENDING CORRESPONDING FIELDS OF TABLE
itab
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO CORRESPONDING FIELDS OF TABLE
itab , except that the read lines are appended to the old contents of
the internal table itab .
Addition
... PACKAGE SIZE n
Effect
Works like ... INTO TABLE itab .
Notes
Performance
If you only want to evaluate the selected data once, you should read
it into a work area. Reading it into an internal table would incur
additional costs for the handling of internal tables and also use more
memory space.
If you want to read the data into an internal table, it is better to
do this in a single operation than to read it line-by-line in a
SELECT loop and then use APPEND to append it to an
internal table.
You should only use the variant ... INTO CORRESPONDING FIELDS
... with large volumes of data because otherwise the time required
to compare the field names in the name table is too high.
Index
© SAP AG 1996