‎2013 Feb 08 4:45 AM
Hello,
I created a 3-level deep table, i.e., one column of table1 is table2 which contains a column named table3. Table1, table2, and table3 are all internal tables. I tried to populate the table but met some errors such as 'At a loop over an internal table, CLEAR is not allowded.' Can any expert provide hints on populating the table?
Thanx.
Bestregards,
ts
‎2013 Feb 08 5:05 AM
Here's a crude demo program that declares nested internal tables,
assigns some data to them, and reports the contents.
Hope this helps.
REPORT ZDEMO.
* Declare type lev1 having a 'field' that is an internal table ita
* with rows of type lev2, and so on.
TYPES:
BEGIN OF LEV3,
FIELD1(8) TYPE C,
FIELD2(8) TYPE C,
END OF LEV3,
BEGIN OF LEV2,
FIELD1(8) TYPE C,
FIELD2(8) TYPE C,
ITA TYPE LEV3 OCCURS 0,
END OF LEV2,
BEGIN OF LEV1,
FIELD1(8) TYPE C,
FIELD2(8) TYPE C,
ITA TYPE LEV2 OCCURS 0,
END OF LEV1.
DATA:
IST TYPE LEV1 OCCURS 0, "internal table
LEVEL1 LIKE LINE OF IST, "row thereof
LEVEL2 LIKE LINE OF LEVEL1-ITA, "row of the int. table in the above
LEVEL3 LIKE LINE OF LEVEL2-ITA. "row of the int. table in the above
* assign level-3 data to level-2 internal table
REFRESH LEVEL2-ITA.
LEVEL3-FIELD1 = 'ABCDEFGH'.
LEVEL3-FIELD2 = 'caps'.
APPEND LEVEL3 TO LEVEL2-ITA.
LEVEL3-FIELD1 = 'abcdefgh'.
LEVEL3-FIELD2 = 'smalls'.
APPEND LEVEL3 TO LEVEL2-ITA.
* assign level-2 data to level-1 internal table
REFRESH LEVEL1-ITA.
LEVEL2-FIELD1 = '12345678'.
LEVEL2-FIELD2 = 'numbers'.
APPEND LEVEL2 TO LEVEL1-ITA.
APPEND LEVEL2 TO LEVEL1-ITA. "let's have this twice
REFRESH LEVEL2-ITA. "[wipe the level3 data for demo purposes]
APPEND LEVEL2 TO LEVEL1-ITA. "and a third time, but without level3
* assign remaining level-1 data and write to internal table
LEVEL1-FIELD1 = 'TOP'.
LEVEL1-FIELD2 = 'LEVEL'.
APPEND LEVEL1 TO IST.
REFRESH LEVEL1-ITA.
APPEND LEVEL1 TO IST.
* some more data for demo purposes
REFRESH LEVEL2-ITA.
LEVEL3-FIELD1 = '!#£$%^&*'.
LEVEL3-FIELD2 = 'symbols'.
APPEND LEVEL3 TO LEVEL2-ITA.
LEVEL3-FIELD1 = 'hgfedcba'.
LEVEL3-FIELD2 = 'smalls'.
APPEND LEVEL3 TO LEVEL2-ITA.
REFRESH LEVEL1-ITA.
LEVEL2-FIELD1 = '87654321'.
LEVEL2-FIELD2 = 'numbers'.
APPEND LEVEL2 TO LEVEL1-ITA.
REFRESH LEVEL2-ITA. "[wipe the level3 data for demo purposes]
LEVEL2-FIELD1 = '98765432'.
LEVEL2-FIELD2 = 'backnos'.
APPEND LEVEL2 TO LEVEL1-ITA.
LEVEL1-FIELD1 = 'top'.
LEVEL1-FIELD2 = 'level'.
APPEND LEVEL1 TO IST.
APPEND LEVEL1 TO IST. "let's have this twice.
* read & display the data
LOOP AT IST INTO LEVEL1.
WRITE: /, /4 'level1:', LEVEL1-FIELD1, LEVEL1-FIELD2.
LOOP AT LEVEL1-ITA INTO LEVEL2.
WRITE: /, /12 'level2:', LEVEL2-FIELD1, LEVEL2-FIELD2.
LOOP AT LEVEL2-ITA INTO LEVEL3.
WRITE: /, /20 'level3:', LEVEL3-FIELD1, LEVEL3-FIELD2.
ENDLOOP.
ENDLOOP.
ENDLOOP.
* The assignments to the internal table(s) are bottom-up.
* Processing the internal table(s) is top-down.
Katrice