Assigning Inline declared table to Field Symbols

Isuru picture Isuru · Jan 19, 2018 · Viewed 24.4k times · Source

There is an inline-declared table generated from a SELECT statement as below:

SELECT *
INTO TABLE @DATA(lt_result)
FROM scarr.

How can lt_result be assigned to a Field Symbol?

I tried the following way:

  FIELD-SYMBOLS: <fs_lt_result> TYPE ANY.

  LOOP AT lt_result ASSIGNING <fs_lt_result>.

But I'm not able to call any components in the field symbol inside the loop like:

WRITE / <fs_lt_result>-carrid.

(syntax error: The data object "<FS_LT_RESULT>" does not have a structure and therefore does not have a component called "CARRID".)

Answer

Isuru picture Isuru · Jan 19, 2018

Inline declaration of a field symbol for an internal table in an ASSIGN statement and inline declaration of a field symbol for the rows of the table in a LOOP.

LOOP AT <lt_result> ASSIGNING FIELD-SYMBOL(<line>).
  ...
ENDLOOP. 

source: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenfield-symbol_inline.htm