‎2007 May 23 9:49 PM
Hi Experts,
I have to move data from one internal table itab_1 to itab_2 if a field by name posnr is empty in itab_1. posnr is of type c.
I did
loop itab_1.
if itab_1-posnr ne ' '.
move-corresponding itab_1 to itab_2.
endif.
endloop.
please check if this code is correct.
Thank you.
Regards,
Admir.
Points will be rewarded.
‎2007 May 24 4:45 AM
Hi,
Instead of checking the condition inside the loop you can write like this
loop at itab_1 where posnr ne ' '.
itab_2 = itab_1.
append itab_2.
clear itab_2.
endloop.
performance wise it is good.
reward points if it is helpful
regards,
sangeetha.a
‎2007 May 23 9:50 PM
field names should be matching in 2 tables.
By itab1-posnr ne '', you are checking if it is not empty.
Is that wat you wanna do?
If you want to check whether posnr is empty then,
you can use the condition <b>itab1-posnr is initial</b>
‎2007 May 23 9:52 PM
Hi,
Try this code...Check NOT INITIAL instead of <> ' '.
loop itab_1.
if NOT itab_1-posnr IS INITIAL.
move-corresponding itab_1 to itab_2.
endif.
endloop.
Thanks,
Naren
‎2007 May 23 10:04 PM
you can also do like...
also its safe to move the fields field by field if the internal table is big rather than move-corresponding.
also instead of if condition you can include it in where clause of the loop statement itself.
‎2007 May 23 10:10 PM
Are itab_1 and itab_2 similar in structure? If so simply do this.
itab_2[] = itab_1[].
DELETE itab_2 WHERE posnr = SPACE.
‎2007 May 24 4:45 AM
Hi,
Instead of checking the condition inside the loop you can write like this
loop at itab_1 where posnr ne ' '.
itab_2 = itab_1.
append itab_2.
clear itab_2.
endloop.
performance wise it is good.
reward points if it is helpful
regards,
sangeetha.a
‎2007 May 24 4:49 AM
Hi,
Put append statement.
loop at itab_1.
if itab_1-posnr ne ' '.
move-corresponding itab_1 to itab_2.
append itab2.
endif.
clear: itab2, itab1.
endloop.
Thnaks
Sandeep
Reward if helpful
‎2007 May 24 4:58 AM
Hi Admir,
The code for your requirement is as follows:
data: itab1 type table of <...>,
itab2 type table of <....>.
data: wa_itab1 type <...>
start-of-selection.
loop at itab1 into wa_itab1.
if wa_itab1-posnr is INITIAL.
wa_itab2-<fieldname> = wa_itab1-<fieldname>
"Copy all the required fields in the above manner.
Append wa_itab2 to itab2.
endif.
endloop.
Note: Do not use move-coresponding, as it not considered efficient/good coding
Plz Reward Points if Helpful.
‎2007 May 24 5:42 AM
hi admir,
loop itab_1.
if itab_1-posnr is not initial.
move itab_1-posnr to itab_2-posnr.
modify itab_2.
endif.
endloop.
if helpful reward some points.
with regards,
suresh babu aluri.