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: 

Updating internal table

Former Member
0 Kudos

Hi,

I have a requirement as follows:

Internal table 1 <ITAB1> contains following data (5 rows)

KDKG

__ (blank)

EB

EC

EA

__ (blank)

Internal table 2 <ITAB2> contains following data (5 rows)

KDKG

EA

EB

ED

__ (blank)

__ (blank)

I want to update <ITAB1> from data in <ITAB2> only if the entries in <ITAB1> are different from the one in <ITAB2> i.e.

in the above example, only field ED should be updated in <ITAB1> at postion 1 (which is a blank). fields EA and EB should not be updated in <ITAB1> since they are already present in <ITAB1>.

Also, use of loops should be avoided as far as possible since this logic is a part of a loop already.

Can any one please suggest a good way of doing this???

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

you can do so

loop at itab1

read itab2 using key xxx

if sy-subrc = 0.

itab1-ED = itab2-ed.

modify itab1 transporting ED.

endif.

endloop.

regards,

siva chalasani

5 REPLIES 5

Former Member
0 Kudos

Hi,

you can do so

loop at itab1

read itab2 using key xxx

if sy-subrc = 0.

itab1-ED = itab2-ed.

modify itab1 transporting ED.

endif.

endloop.

regards,

siva chalasani

Former Member
0 Kudos

Hi,

Try as follows:

Sort itab2.

sort itab1.

loop at itab2.

read itab1 with key kdkg = itab2-val.

if sy-subrc <> 0.

read itab2 with key kdkg is initial.

if sy-subrc = 0.

l_f_index = sy-tabix. (index of itab2 after read statement)

itab1-kdkg = itab2-kdkg.

modify itab1 transporting kdkg index l_f_index.

else.

exit.

endif.

endif.

endloop.

Former Member
0 Kudos

hi,

Try the following logic.

REPORT zstemp_qty2_ LINE-SIZE 255 .

DATA:BEGIN OF itab1 OCCURS 0,

kdkg(4),

f(2),

END OF itab1.

DATA:itab2 LIKE itab1 OCCURS 0 WITH HEADER LINE.

itab1-kdkg = ''. itab1-f = 'X'.

APPEND itab1. CLEAR itab1.

itab1-kdkg = 'EB'.itab1-f = 'Y'.

APPEND itab1. CLEAR itab1.

itab1-kdkg = 'EC'.itab1-f = 'Z'.

APPEND itab1. CLEAR itab1.

itab1-kdkg = 'EA'.itab1-f = 'XX'.

APPEND itab1. CLEAR itab1.

itab1-kdkg = ''.itab1-f = 'YY'.

APPEND itab1. CLEAR itab1.

itab2-kdkg = 'EA'.itab2-f = 'XX'.

APPEND itab2. CLEAR itab2.

itab2-kdkg = 'EB'.itab2-f = 'Y'.

APPEND itab2. CLEAR itab2.

itab2-kdkg = 'ED'.itab2-f = 'ZZ'.

APPEND itab2. CLEAR itab2.

itab2-kdkg = ''.itab2-f = 'X'.

APPEND itab2. CLEAR itab2.

itab2-kdkg = ''.itab2-f = 'YY'.

APPEND itab2. CLEAR itab2.

SORT itab1 BY kdkg.SORT itab2 BY kdkg descending.

LOOP AT itab2 where kdkg NE ''.

READ TABLE itab1 WITH KEY kdkg = itab2-kdkg.

IF sy-subrc NE 0.

itab1-kdkg = itab2-kdkg.

itab1-f = itab2-f.

APPEND itab1.CLEAR itab1.

ENDIF.

ENDLOOP.

LOOP AT itab1.

WRITE:/ itab1-kdkg,itab1-f.

ENDLOOP.

Output::::

X

YY

EA XX

EB Y

EC Z

ED ZZ

___________________________________

If you want in otherway please reply.

Regds

Sivaparvathi

Please reward points if helpful...

Former Member
0 Kudos

Hi,

reffer the below code.

loop at itab1.

read table itab2 with key KDKG = itab1-kdkg

EA = itab1-ea

EB = itab1-eb.

if sy-subrc = 0.

itab1-ED = itab2-ed.

modify table itab1 transaporting ED.

endif.

clear: itab1,

itab2.

endloop.

reward if useful.

Thanks,

Sreeram.

former_member402443
Contributor
0 Kudos

Hi Raghavendra,

Check this code.

TYPES : BEGIN OF x_tab,

name(30) TYPE c,

END OF x_tab.

DATA : itab1 TYPE STANDARD TABLE OF x_tab,

wa_itab1 TYPE x_tab,

itab2 TYPE STANDARD TABLE OF x_tab,

wa_itab2 TYPE x_tab.

MOVE 'KDKG' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE ' ' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE 'EB' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE 'EC' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE 'EA' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE ' ' TO wa_itab1-name.

APPEND wa_itab1 TO itab1.

MOVE 'KDKG' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

MOVE 'EA' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

MOVE 'EB' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

MOVE 'ED' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

MOVE ' ' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

MOVE ' ' TO wa_itab2-name.

APPEND wa_itab2 TO itab2.

SORT itab2 BY name.

LOOP AT itab2 INTO wa_itab2. " WHERE name = ' '.

READ TABLE itab1 into wa_itab1 WITH KEY name = wa_itab2-name.

IF sy-subrc NE 0.

wa_itab1-name = wa_itab2-name.

APPEND wa_itab1 TO itab1.

ENDIF.

ENDLOOP.

LOOP AT itab1 INTO wa_itab1.

WRITE 😕 sy-tabix,wa_itab1-name.

ENDLOOP.

Reward Points, if useful.

Regards,

Manoj Kumar