Application Development and Automation 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: 
Read only

Dynamically updating internal table fields.

Former Member
0 Likes
506

Hi all.

I'm trying to update values from one internal table to another internal table for particular fields. The fields to be updates is specified in CARRIER-FIELD_NAME.

I have to pick particular field value from internal table ITAB1 and update it into corresponding field of internal table ITAB2.

for example: if carrier-field_name has value FROMDATE, then I have to fetch value of ITAB1-FROMDATE and update it into ITAB2-FROMDATE.

Following code sniplet is written by me to do the functionality, but the statement

<fs1> = <fs> , is not puting fetched data into internal table ITAB2.

Can anyone help me out with this ?

FIELD-SYMBOLS: <fs> TYPE ANY,

<fs1> TYPE ANY.

LOOP AT itab1.

LOOP AT carrier.

field = carrier-field_name.

CONCATENATE 'ITAB1-' field INTO val1.

ASSIGN (val1) TO <fs>.

CONCATENATE 'ITAB2-' field INTO val2.

ASSIGN val2 TO <fs1>.

<fs1> = <fs>.

APPEND itab2.

ENDLOOP.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
483

Hi

I believe you should append the record to ITAB2 out of the loop of the CARRIER table.

Try to use ASSIGN COMPONENT in this way

LOOP AT itab1.
   LOOP AT carrier.
      field = carrier-field_name.
      ASSIGN COMPONENT FIELD OF STRUCTURE ITAB1 TO <FS>.
      IF SY-SUBRC = 0.
         ASSIGN COMPONENT FIELD OF STRUCTURE ITAB2 TO <FS1>.
         IF SY-SUBRC = 0.
            <fs1> = <fs>.
         ENDIF.
      ENDIF.
    ENDLOOP.
    IF NOT ITAB2 IS INITIAL.
      APPEND itab2.
    ENDIF
ENDLOOP.

Max

3 REPLIES 3
Read only

Former Member
0 Likes
484

Hi

I believe you should append the record to ITAB2 out of the loop of the CARRIER table.

Try to use ASSIGN COMPONENT in this way

LOOP AT itab1.
   LOOP AT carrier.
      field = carrier-field_name.
      ASSIGN COMPONENT FIELD OF STRUCTURE ITAB1 TO <FS>.
      IF SY-SUBRC = 0.
         ASSIGN COMPONENT FIELD OF STRUCTURE ITAB2 TO <FS1>.
         IF SY-SUBRC = 0.
            <fs1> = <fs>.
         ENDIF.
      ENDIF.
    ENDLOOP.
    IF NOT ITAB2 IS INITIAL.
      APPEND itab2.
    ENDIF
ENDLOOP.

Max

Read only

0 Likes
483

thanks Max.

its working fine now.

Read only

Former Member
0 Likes
483

Hi,

try this code,u'll surely get it.

tables:sflight.

data:begin of itab1 occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of itab1.

data:begin of carrier occurs 0,

field_name like sflight-fldate,

end of carrier.

data:begin of itab2 occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of itab2.

suppose if the field is fldate,then itab2 will be updated by fldate field with data taken from itab1.

carrier-field_name = 'fldate'.

select carrid connid fldate from sflight into table itab1.

case carrier-field_name.

when 'fldate'.

loop at itab1.

itab2-fldate = itab1-fldate.

append itab2.

endloop.

endcase.

Regards,

Sowjanya