Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Internal Table

Former Member
0 Kudos

hi,

The below program was taken from the <b>SDN</b> forum, but as a beginner in abap it is difficult for me to understand the assignment of Field Symbols in this program even though the steps are clearly explained here.

So can anyone explain me ,where the internal table is dynamically created also how field symbols are actually helpful in creating the dynamic internal table in this program?.

*Data definitions

      • Tables

DATA: LT_DATA type ref to DATA.

DATA: LT_FIELDCATALOG type LVC_T_FCAT.

      • Structure

DATA: LS_FIELDCATALOG type LVC_S_FCAT.

      • Data References

DATA: NEW_LINE type ref to data,

FS_DATA type ref to data.

      • Field Symbols

FIELD-SYMBOLS: <FS_DATA> type ref to DATA,

<FS_1> type any table,

<FS_2>,

<FS_3>.

*Populating the internal table with fieldnames required for our dynamic

*internal table

LS_FIELDCATALOG-FIELDNAME = 'MANDT'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname

LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CONNID'.

LS_FIELDCATALOG-INTTYPE = 'N'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.

LS_FIELDCATALOG-INTTYPE = 'D'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'PRICE'.

LS_FIELDCATALOG-INTTYPE = 'P'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.

LS_FIELDCATALOG-INTTYPE = 'C'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

*Calling the method CREATE_DYNAMIC_TABLE

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = LT_FIELDCATALOG

importing

ep_table = FS_DATA

exceptions

generate_subpool_dir_full = 1

others = 2

.

if sy-subrc <> 0.

endif.

*Assigning Field-Symbol to our dynamic internal table

assign LT_DATA to <FS_DATA>.

*Internal Table is ready, now to put data in that table

      • So <FS_1> now points to our dynamic internal table.

assign FS_DATA->* to <FS_1>.

      • Next step is to create a work area for our dynamic internal table.

create data NEW_LINE like line of <FS_1>.

      • A field-symbol to access that work area

assign NEW_LINE->* to <FS_2>.

      • And to put the data in the internal table

select

MANDT

CARRID

CONNID

FLDATE

PRICE

CURRENCY

from SFLIGHT

into corresponding fields of table <FS_1>.

      • Access contents of internal table

loop at <FS_1> assigning <FS_2>.

do 5 times.

assign component sy-index of structure <FS_2> to <FS_3>.

write: <FS_3>.

enddo.

skip 1.

endloop.

TOP-OF-PAGE.

WRITE:/5 'FUJITSU CONSULTING COMPANY' INVERSE COLOR 6,

50 SY-DATUM INVERSE COLOR 6,

70 SY-PAGNO INVERSE COLOR 6.

ULINE.

ganesh

1 REPLY 1

Former Member
0 Kudos

Hi

see the doc of field symbols

Syntax

FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.

Extras:

1. ... typing

2. ... STRUCTURE struc DEFAULT dobj

Effect

The FIELD-SYMBOLS statement declares a field symbol <fs>. The naming conventions apply to the name fs. The angle brackets of the field symbols indicate the difference to data objects and are obligatory. You can declare field symbols in any procedure and in the global declaration section of an ABAP program, but not in the declaration section of a class or an interface. You can use a field symbol in any operand position in which it is visible and which match the typing defined using typing.

After its declaration, a field symbol is initial - that is, it does not reference a memory area. You have to assign a memory area to it (normally using the ASSIGN statement) before you can use it as an operand. Otherwise an exception will be triggered.

Addition 1

... typing

Effect

You can use the addition typing to type the field symbol. The syntax of typing is described under Syntax of Typing. The typing specifies which memory areas can be assigned to the field symbol (see Checking the Typing) and in which operand positions it can be used.

Note

You can omit the addition typing outside of methods. In this case, the field symbol has the complete generic type any and is implicitly assigned the predefined constant space during the declaration.

Addition 2

... STRUCTURE struc DEFAULT dobj

Effect

If you specify the addition STRUCTURE instead of typing for a field symbol, and struc is a local program structure (a data object, not a data type) or a flat structure from the ABAP Dictionary, this structure is cast for the field symbol <fs>. You have to specify a data object dobj that is initially assigned to the field symbol.

The field symbol copies the technical attributes of structure struc as if it were completely typed. When you assign a data object using the addition DEFAULT, or later using ASSIGN, its complete data type is not checked in non- Unicode programs. Instead, the system merely checks whether it has at least the length of the structure and its alignment.

In Unicode programs, we differentiate between structured and elementary data objects. For a structured data object dobj, its Unicode fragment view has to match the one of struc. In the case of an elementary data object, the object must be character-type and flat, and struc must be purely character-type. The same applies to assignments of data objects to field symbols typed using STRUCTURE when using the ASSIGN statement.

Note

Field symbols declared using the addition STRUCTURE are a mixture of typed field symbols and a utility for casting structured data types. You should use the additions TYPE or LIKE for the FIELD-SYMBOLS statement to type field symbols, while the addition CASTING of the ASSIGN statement is used for casting.

Example

The first example shows the obsolete usage of the addition STRUCTURE.

DATA wa1 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr1> STRUCTURE scarr DEFAULT wa1.

<scarr1>-carrid = '...'.

The second example shows the replacement of STRUCTURE with the additions TYPE and CASTING.

DATA wa2 TYPE c LENGTH 512.

FIELD-SYMBOLS <scarr2> TYPE scarr.

ASSIGN wa2 TO <scarr2> CASTING.

<scarr2>-carrid = '...'.

Dynamic Internal tables

Dynamic internal table is internal table that we create on the fly with flexible column numbers.

For sample code, please look at this code tutorial. Hopefully it can help you

Check this link:

http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm

<b>Reward points for useful Answers</b>

Regards

Anji