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: 

Coding with deep structure

Former Member
0 Kudos

Hi All,

I need help for coding in deep structure.

My code is as follows:

loop at t_header into w_header.

   loop at w_header-curr_items into w_curr_item.

     sort  w_curr_item-invoices by INVNO.

     loop at w_curr_item-invoices into w_invoice.

     loop at t_INV into w_INV where vbeln = w_invoice-INVNO.

      Append w_iNV-name1 to w_curr_item-invoices.

     endloop.

*      Append w_iNV-name1 to t_HEADER-curr_itemS-invoices.    ...*This statement doesnt works

      endloop.

      endloop.

   endloop.

Where t_header is header structure with inner structures defined as follows: t_header-curr_items-invoices.

Above code doesnt update t_header intead w_curr_item is updated.



I will be thankful for guiding how invoices structure can be updated.

3 REPLIES 3

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

You can use field-symbols .

Regards .

Code:


Check price at the BREAK-POINT .

FORM test_01 .

  DATA: it_sflight TYPE TABLE OF sflight .

  FIELD-SYMBOLS: <st_sflight> LIKE LINE OF it_sflight .

  SELECT * FROM sflight INTO TABLE it_sflight UP TO 10 ROWS .

  BREAK-POINT .

  LOOP AT it_sflight ASSIGNING <st_sflight> .
    <st_sflight>-price = <st_sflight>-price * '1.5' .
  ENDLOOP.

  BREAK-POINT .

ENDFORM .           

thanga_prakash
Active Contributor
0 Kudos

Hello San,

Check whether w_iNV-name1 and t_HEADER-curr_itemS-invoices has same structures.

If yes, then try the below logic, You are using 3 levels of deep structure and you are trying to append value directly to level1. Might be you can try by passing the value in the hierarchical manner like, first APPEND the value to level3 and then to level2 and then finally to level1.

Refer the below crude program for example:


* 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.

Regards, Thanga

Former Member
0 Kudos

Either use field-symbols, as suggested by Eitan. Otherwise you will have to modify the work areas from down to up:

Append w_iNV-name1 to w_curr_item-invoices.

append to w_invoice.

append to w_curr_item.


using the modify from statement. But go for the field-symbols, it is much easier.