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: 

Issue to modify dynamic field symbol

former_member212148
Participant
0 Kudos

Hello Experts,

I am getting issue while modifying dynamic field symbol.

My scenario is i have three internal table and field symbol.

two field symbol has record and want to append both field symbol record in third(final) field symbol.

my code is here.

LOOP AT <DYN_TABLE> ASSIGNING <DYN_WA>.
     ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
     ASSIGN COMPONENT SY-INDEX  OF STRUCTURE <DYN_MAINWA> TO <DYN_FIELD2>.
     <DYN_MAINWA> = <DYN_FIELD>.
     APPEND <DYN_MAINWA> TO <DYN_MAINTABLE>.   " Its successfully appended
   ENDLOOP.

   LOOP AT <DYN_TABLE1> ASSIGNING <DYN_WA1>.
     DATA: V_COUNT(4) TYPE C.
     V_COUNT = 1 + V_COUNT.
     ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYN_WA1> TO <DYN_FIELD1>.
     ASSIGN COMPONENT SY-INDEX  OF STRUCTURE <DYN_MAINWA> TO <DYN_FIELD2>.
     DATA: V_VALUE TYPE STRING.

     APPEND INITIAL LINE TO <DYN_MAINTABLE> ASSIGNING <DYN_MAINWA>.
     IF SY-SUBRC = 0.
       MOVE-CORRESPONDING <DYN_WA1> TO <DYN_MAINWA>.
       MODIFY <DYN_MAINTABLE> INDEX V_COUNT FROM <DYN_MAINWA>." TRANSPORTING (KFIELD).
       CLEAR <DYN_MAINWA>.
     ENDIF.
   ENDLOOP.

first field symbol recodes are successfully appended in final field symbol.

line          matnr     mart     meins     maktx

1              1000      HALB    NOS

2              1001       HALB   NOS  

but when i modify record with second field symbol record it remove the field value that is not maintained in second field symbol.

line          matnr     mart     meins     maktx

1              1000                                 TEST MATERIAL

2              1001                                 TEST MATERIAL2

How to over come from this problem.

Your support is appreciated.


1 ACCEPTED SOLUTION

former_member184569
Active Contributor
0 Kudos

Dear Ranjit,

Its not that complicated. Try it this way.

loop at <dyn_table> ASSIGNING <dyn_wa>.

* Here ensure <dyn_mainwa> is assigned to work area of final main table 

   MOVE-CORRESPONDING <dyn_wa> to <dyn_mainwa>.

   append <dyn_mainwa> to <dyn_maintable>.
endloop.


loop at <dyn_maintable> ASSIGNING <dyn_mainwa>.
   ASSIGN COMPONENT 'MATNR' OF STRUCTURE <dyn_mainwa> TO <dyn_field>.  

   READ TABLE <dyn_table1> ASSIGNING <dyn_wa1> WITH KEY ('MATNR') = <dyn_field>.

   MOVE-CORRESPONDING <dyn_wa1> to <dyn_mainwa>.
endloop.

loop at <dyn_maintable> ASSIGNING <dyn_mainwa>.
write 😕 <dyn_mainwa>.
endloop.


6 REPLIES 6

Former Member
0 Kudos

Your logic does not make sense.

Post example data of internal tables and expected output so that logic can be corrected.

Former Member
0 Kudos

Hi Ranjit,

i your tables got the same line spec you wanna go with:

append lines of tab1 to maintab.

append lines of tab2 to maintab.

Your "Assign Component" doesn't make any sense, because the LOOP AT -Statement sets sy-tabix so sy-index will be not be changed.

If you use APPEND INITIAL LINE... ASSIGNING <fs_line>, you already got an assigned field Symbol (<fs_line>) where you can change the content of this new created line. Therefore  your MODIFY doesn't make any sense.

I hope this will help you.

regards

Jan Martin Müller

former_member206395
Participant
0 Kudos

The piece of code written is very confusing. Kindly change it to.

  LOOP AT <DYN_TABLE> ASSIGNING <DYN_WA>.
     MOVE-CORRESPONDING <DYN_WA> TO <DYN_MAINWA>.
     APPEND <DYN_MAINWA> TO <DYN_MAINTABLE>.   " Its successfully appended
   ENDLOOP.

  UNASSIGN <DYN_MAINWA>.

   LOOP AT <DYN_TABLE1> ASSIGNING <DYN_WA1>.

     READ TABLE<DYN_MAINTABLE> ASSIGNING <DYN_MAINWA> INDEX V_COUNT.
     IF SY-SUBRC = 0.
       MOVE-CORRESPONDING <DYN_WA1> TO <DYN_MAINWA>.
*       CLEAR <DYN_MAINWA>.
     ENDIF.
   ENDLOOP.

Kindly check this.

0 Kudos

I am getting dump because <DYN_WA1> AND <DYN_MAINWA> has different structure.

former_member184569
Active Contributor
0 Kudos

Dear Ranjit,

Its not that complicated. Try it this way.

loop at <dyn_table> ASSIGNING <dyn_wa>.

* Here ensure <dyn_mainwa> is assigned to work area of final main table 

   MOVE-CORRESPONDING <dyn_wa> to <dyn_mainwa>.

   append <dyn_mainwa> to <dyn_maintable>.
endloop.


loop at <dyn_maintable> ASSIGNING <dyn_mainwa>.
   ASSIGN COMPONENT 'MATNR' OF STRUCTURE <dyn_mainwa> TO <dyn_field>.  

   READ TABLE <dyn_table1> ASSIGNING <dyn_wa1> WITH KEY ('MATNR') = <dyn_field>.

   MOVE-CORRESPONDING <dyn_wa1> to <dyn_mainwa>.
endloop.

loop at <dyn_maintable> ASSIGNING <dyn_mainwa>.
write 😕 <dyn_mainwa>.
endloop.


0 Kudos

Dear Susmitha,

My Problem is solved.

Thanks to all for support.