‎2009 Mar 19 12:12 PM
Hi all,
I have got two tables zdata_sec and zdata_hold ... I need to get the field zsec from the first table and zhold from the second and need to insert in an internal table ztest_sec_hold... Now I have got another internal table called ztest_final (which has got all the records). Now I need to get all the valid records from table ztest_final that should have the valid combination of zsec and zhold.
So can you please tell me how can I do that.
Thanks,
Rajeev
‎2009 Mar 19 12:24 PM
Try this code : assuming key1 is a primary field in all tables.
select key1 zsec
from zdata_sec
into table itab_sec.
select key1 zhold
from zdata_hold
into table itab_hold.
loop at itab_sec.
read table itab_hold with key key1 = itab_sec-key1.
if sy-subrc eq 0.
itab_sec_hold-key1 = itab_sec-key1.
itab_sec_hold-sec = itab_sec-sec.
itab_sec_hold-hold = itab_hold-hold.
append itab_sec_hold.
clear: itab_sec_hold.
endif.
endloop.
loop itab_sec_hold.
read table itab_final with key key1 = itab_sec_hold-key1
sec = itab_sec_hold-sec
hold = itab_sec_hold-hold.
if sy-subrc = 0.
delete table itab_final from itab_final.
endif.
endloop.
‎2009 Mar 19 12:16 PM
Hi,
Put ineer join on zdata_sec and zdata_hold and stors it in ztest_sec_hold.
Now put loop on ztest_sec_hold.table inside that loop read table ztest_final.
Hope this will solve your problem.
Thanks & Regards,
Anagha Deshmukh
‎2009 Mar 19 12:18 PM
Hi Rajeev,
Try using FOR ALL ENTRIES in select query.
Regards,
Lakshman.
‎2009 Mar 19 12:19 PM
HI.
Try this way..
Loop the zdata_sec.
Read or loop the zdata_hold on the common field
if found then
append the sec and hold in internal table ztest_sec_hold
else d
onot append to ztest_sec_hold table.
endif.
EnDloop.
Loop AT ztest_final .
Check the entry in ztest_sec_hold for sec and hold combination key.
if found then
keep the record in ztest_final
else
Delete from ztest_final
endif.endloop.
‎2009 Mar 19 12:20 PM
What is the relation between zdata_sec and zdata_hold table?
I assume zdata_sec is master
1. select data including ZSEC field from 1st table into itab1.
2. select data from 2nd table including ZHOLD into itab2 where fieldn = key field from 1st table. You need to use FOR ALL ENTRIES IN ...
3.
loop at itab1
read itab2 with key fieldn = itab1-field1.
check sy-subrc = 0.
append the details into ztest_sec_hold.
endloop.
4.
LOOP AT ztest_final .
READ TABLE ( ztest_sec_hold) with required keys. ( zsec & zhold ).
check sy-subrc = 0.
append ztest_final with required fields of ztest_final & ztest_sec_hold
endloop.
You need to refine the logic as per your data declaration.
‎2009 Mar 19 12:21 PM
Would you please provide some sample data for both the Itab and what output you are looking for, from that?
‎2009 Mar 19 12:24 PM
Try this code : assuming key1 is a primary field in all tables.
select key1 zsec
from zdata_sec
into table itab_sec.
select key1 zhold
from zdata_hold
into table itab_hold.
loop at itab_sec.
read table itab_hold with key key1 = itab_sec-key1.
if sy-subrc eq 0.
itab_sec_hold-key1 = itab_sec-key1.
itab_sec_hold-sec = itab_sec-sec.
itab_sec_hold-hold = itab_hold-hold.
append itab_sec_hold.
clear: itab_sec_hold.
endif.
endloop.
loop itab_sec_hold.
read table itab_final with key key1 = itab_sec_hold-key1
sec = itab_sec_hold-sec
hold = itab_sec_hold-hold.
if sy-subrc = 0.
delete table itab_final from itab_final.
endif.
endloop.