ABAPINTO_CLAUSE - INTO CLAUSE

CPI1466 during Backup   ABAP Short Reference  
This documentation is copyright by SAP AG.

SELECT - target

Short Reference



Syntax

... { INTO
      { {[CORRESPONDING FIELDS OF] wa}|(dobj1, dobj2, ...)} }
  | { INTO|APPENDING
         [CORRESPONDING FIELDS OF] TABLE itab [PACKAGE SIZE n] }
    [ creating ] ...  .

Alternatives:

1. ... INTO [CORRESPONDING FIELDS OF] wa

2. ... INTO (dobj1, dobj2, ... )

3. ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab [PACKAGE SIZE n]

Effect

target specifies to which data objects theresult set ofa SELECT or FETCHstatement is assigned. You can either specify a single work area wa or a list of data objectsdobj1, dobj2, ... after INTO, or you can specify an internal table itab after INTO or APPENDING.

If a LOB of the resulting set is associated with aLOBhandle in the target, you may need to use creating to specify whether you are dealing with adata stream or alocator.

Notes

  • When specifying the data objects, there are no dynamic variants that correspond to the other additions.Instead you can work with dynamically created data objects (see the example for CREATE DATA).
  • The statement SELECT also has an obsolete short form, in which you can omit INTO or APPENDING.
  • You cannot currently specify reference variables for LOB handles or LOB handle structures after the statement FETCH (Release 7.1, EhP1).


Alternative 1

... INTO [CORRESPONDING FIELDS OF] wa


Effect

For wa, you can specify a data object that must meet certainprerequisites withoutCORRESPONDING FIELDS OF being specified. If the result set consists of a single row, this rowis assigned to wa. If the result set has multiple rows, SELECT must be followed by anENDSELECT statement; the result set is assigned to the work area wa row-by-row and canbe evaluated in the loop. After ENDSELECT, the work area wa contains the row that wasassigned last. If used in the FETCHstatement, a row is extracted at the current cursor position. If the result is empty, the work area remains unchanged.

The rows of the result set are assigned as follows, based on the column specification after SELECT:

Specification of * without the addition CORRESPONDING FIELDS

If all columns are read using * and CORRESPONDING FIELDS is not specified, SELECT behaves as follows:

  • When specifying a work area that does not contain any reference variables forLOBhandles, the row is assigned to the result set left-aligned and unconverted in accordance with thestructure of the result set. Unaffected parts of wa retain their previous content. To be ableto access the components of the result set according to type, the work area wa must be structured like the result set.
  • When you specify a LOB handle structure, it must be constructed (in accordance with theprerequisites) exactly like the structure of the database table. The contents of the columns of the result set that are not assigned to anyLOB handle components are directly assigned to the corresponding components of the work area. ALOB handle is created for each LOB handle component.

All other combinations

If the result set consists of a single column specified explicitly after SELECT or a singleaggregateexpression, then wa can be an elementary data object or a structure. If the result set consists of multiple columns, it must be a structure and the following rules apply:

  • If the CORRESPONDING FIELDS addition is not specified, wa must contain enough componentsand the contents of the columns are assigned to the components of wa from left to right in the order specified after SELECT.
  • If the CORRESPONDING FIELDS addition is specified, only those contents of columns for which thereare identically-named components in wa are assigned to them; this takes into account any alternativecolumn names. Columns and aggregate expressions that appear multiple times can only be assigned usingalternative column names, if CORRESPONDING FIELDS is specified. If a column name appears multiple times and no alternative column name was specified, the last column listed is assigned.

Assignment rules apply to the individual assignments. If aLOB of a reference variable forLOB handle is assigned, aLOB handle is created.

Notes

  • The addition CORRESPONDING FIELDS ignores names which were only defined using the addition ASname of the statement INCLUDEor when integrating the structures in ABAP Dictionary. However, components that were renamed using the RENAMING WITH SUFFIX addition of the INCLUDE statement or similarly in ABAP Dictionary are not ignored.
  • The addition CORRESPONDING FIELDS determines the assignment of the fields of the same name once for each SELECT statement at runtime.


Example

In this example, four columns of the result set are read into four correspondingly named components of a work area.

DATA wa TYPE spfli.

SELECT carrid connid cityfrom cityto
       FROM spfli
       INTO CORRESPONDING FIELDS OF wa.
  WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDSELECT.

Alternative 2

... INTO (dobj1, dobj2, ... )


Effect

If the result set consists of multiple columns oraggregateexpressions specified explicitly after SELECT, you can specify a list of elementary dataobjects dobj1, dobj2, ... (in parentheses and separated by commas) after INTO. You mustspecify the same number of elementary data objects dobj as there are columns in the result set.The contents of the columns in the result set are assigned to the data objects from left to right, according to the order specified after SELECT.Assignment rules apply to the individual assignments. If aLOB of a reference variable forLOB handle is assigned, aLOB handle is created. If the result set is empty, the data objects remain unchanged.

If the result set consists of one row, the columns are assigned from that row. If the result set containsmultiple rows, SELECT must be followed by an ENDSELECT statement; the columns of the resultset are assigned to the data objects row-by-row and they can be evaluated in a loop. If used in theFETCH statement, the columns of the row are extracted at the current cursor position.

Example

In this example, four columns of the result set are read into four individually specified columns of a structure. Unlike in the previous example, the runtime environment does not compare names here.

DATA wa TYPE spfli.

SELECT carrid connid cityfrom cityto
       FROM spfli
       INTO (wa-carrid, wa-connid, wa-cityfrom, wa-cityto).
  WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDSELECT.

Alternative 3

... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab [PACKAGE SIZE n]


Addition:

... PACKAGE SIZE n

Effect

If the result set consists of multiple rows, an internal table itab of any table type can be specified after INTO or APPENDING. The row type of the internal table must meet theprerequisites.

The result set is inserted into the internal table itab row-by-row; a sorting process is executed in the case of asortedtable. If INTO is used, the internal table is initialized. Previous rows remain intact if APPENDING is used.

Before any assignment of a row of the result set, an initial row of the internal table itab iscreated and the row of the result set is assigned to this row. When assigning a row of the result setto a row of the internal table with or without CORRESPONDING FIELDS, the same rules apply as when assigning to an individual work area wa (see above) with the exception that when inserting into internal tables,LOB handles can becreated aslocators but not asread streams.

If the PACKAGE SIZE addition is not used, all rows of the result set are inserted in the internal table itab and the ENDSELECT statement must not be specified after SELECT.

If the result set is empty, the internal table is initialized when INTO is used, and remains unchanged when APPENDING is used.

Notes

  • When specifying an internal table with a unique primary orsecondarytable key, an exception is raised that cannot be handled if an attempt is made to create a duplicate entry.
  • If the internal table contains more columns than required when using the addition CORRESPONDING FIELDS,then generally too much memory is being used by initial fields and a warning is displayed by the syntax check. In cases where the columns are needed, for example when they are filled with derived values by the program, you can use apragma to suppress the warning.
  • Since the maximum number of data streams that can be assigned to an Open SQL statement is limited to 16, it does not make any sense to create read streams when importing internal tables.


Addition

... PACKAGE SIZE n

Effect

If you specify the PACKAGE SIZE addition, all rows of the result set for SELECT are processedin a loop, which must be closed with ENDSELECT. They are inserted in packages of n rowsin the internal table itab. n expects a data object of type i that contains thenumber of rows. If the value of n is less than 0, an exception is raised that cannot be handled.If n is equal to 0, all rows of the result set are inserted in the internal table itab.If used in the FETCH statement, n rows are extracted from the current cursor position.

If INTO is used, the internal table is initialized before each insertion and, in the SELECTloop, it only contains the rows of the current package. If APPENDING is used, a further packageis added to the existing rows of the internal table for each SELECT loop or for each extraction using FETCH.

After ENDSELECT, the content of itab is not defined if INTO is used. That is, thetable can either contain the rows of the last package or it can be initial. If APPENDING is used, the content of itab retains the state of the last loop pass.

Notes

  • The addition PACKAGE SIZE can be used after INTO to limit the amount of data read in one go. Otherwise a runtime error can occur when reading a data set that is too large into an internal table so that itsmaximum size is exceeded. PACKAGE SIZE cannot prevent this runtime error after APPENDING.
  • If the addition PACKAGE SIZE is specified with the addition FORALL ENTRIES, all selected rows are read initially into an internal system table and the packagesare only created when they are passed from the system table to the actual target table. The addition FOR ALL ENTRIES thereby negates the effect of PACKAGE SIZE in preventing memory overflow.
  • The addition PACKAGE SIZE does not influence the size of thepackages (configured in the profile parameters) used to transport data between the database server and the application server.

Example

In this example, all columns of a result set are read into an internal table, the row type of whichis a nested structure with the same structure as the result set. Note that in practice, the column carridexists twice in the result set with the same content and, after the assignment, this content is stored redundantly in the columns struc1-carrid and struc2-carrid of the internal table.

DATA: BEGIN OF wa,
        struc1 TYPE scarr,
        struc2 TYPE spfli,
      END OF wa.

DATA itab LIKE SORTED TABLE OF wa
          WITH UNIQUE KEY table_line.

SELECT *
       FROM scarr
         INNER JOIN spfli ON scarr~carrid = spfli~carrid
       INTO TABLE itab.

LOOP AT itab INTO wa.
  WRITE: / wa-struc1-carrid,
           wa-struc1-carrname,
           wa-struc2-connid.
ENDLOOP.


CL_GUI_FRONTEND_SERVICES - Frontend Services   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.


Length: 19331 Date: 20120522 Time: 234917     triton ( 417 ms )