‎2007 Apr 18 4:32 AM
Hi,
I have one query regarding internal table.
Suppose I have two internal tables X,Y. Table X having fields F1,F2 & F3. Table Y having fields F1,M1,M2.
Both the tables having data. Now my requirement is to make one new internal table Z having fields F1, F2 & M1.
Now I wanted to populate the corresponding records in table Z i.e. F1, F2 & M1.
I will write the code like
loop at X.
move x-f1 to z-f1.
move x-f2 to z-f2.
append z.
clear z.
endloop.
Now I wanted to populate the M1 field in Z table based on corresponding enteries for F1 field.
Anybody will pls suggest me how to do it??
‎2007 Apr 18 5:17 AM
Hi Neha,
Check out the following lines of code...
<b>loop at x.
read table y with key f1 = x-f1.
if sy-subrc eq 0.
z-f1 = y-f1.
z-f2 = x-f2.
z-m1 = y-m1.
append z.
clear z.
endif.
endloop.</b>
hope this solves your purpose.
regards,
Navneeth.K
‎2007 Apr 18 4:44 AM
Hi ,
U can use this:
select pF1 pF2 qM1 into corresponding fields of table Z from (X as p inner join Y as q on pF1 = q~F1).
‎2007 Apr 18 4:44 AM
Hi Neha,
Data var1 type sy-tabix.
sort y by f1.
loop at x.
move x-f1 to z-f1.
move x-f2 to z-f2.
append z.
read table y with key f1 = x-f1.
var1 = sy-tabix.
loop at y from var1.
if y-f1 <> x-f1.
exit.
else.
move y-m1 to z-m1.
modify z transporting m1.
endloop
clear z.
endloop.
‎2007 Apr 18 4:45 AM
Hi,
TRy this...
loop at X.
<b>num = sy-index.
READ TABLE Y INDEX num WITH KEY M1 = X-M1.
if sy-subrc eq 0.
move X-m1 to Z-m1.
endif.</b>
move x-f1 to z-f1.
move x-f2 to z-f2.
append z.
clear z.
endloop.
As per my knowledge..
Kishore.
‎2007 Apr 18 4:47 AM
if the field in both the tables is a key field then join the two tables with join condition (hope u know inner join) and tranfer the necessary fields into another table z with ur required fields.. then u can populate ur m1 vales corresponding to f1..
regards..
‎2007 Apr 18 4:52 AM
hi
assuming x and y have same values for F1, you can try this
data sytabix like sy-tabix.
loop at x.
move x-f1 to z-f1.
move x-f2 to z-f2.
append z.
endloop.
loop at z.
sytabix = sy-tabix.
read table y with key f1 eq z-f1.
if sy-subrc eq 0.
move y-m1 to z-m1.
modify z index sytabix.
else.
continue.
endif.
endloop.
if helpful, reward
Sathish. R
Message was edited by:
Sathish R
‎2007 Apr 18 5:07 AM
Neha,
1. If you have F1 values multiples in X internal table & Yinternal table,then you have to take one more internal table
Ex : internal table "K" like X
K[] = X[].
SORT : K by F1,
Y by F1.
Delete Adjacent duplicates from K comparing F1.
LOOP AT K.
Loop AT Y WHERE F1 = K-F1.
MOVE :K-F1 TO Z-F1,
K-F2 TO Z-F2,
Y-M1 TO Z-M1.
APPEND Z.
CLEAR Z.
endloop.
ENDLOOP.
2.Suppose if ur X and Y internal tables are having no duplicate F1 values.Thenn
SORT : X by F1,
Y BY F1.
loop at X.
READ TABLE Y WITH KEY F1 = X-F1 BINARY SEARCH.
IF SY-SUBRC EQ 0.
MOVE :X-F1 TO Z-F1,
X-F2 TO Z-F2,
Y-M1 TO Z-M1.
APPEND Z.
CLEAR Z.
ENDIF.
ENDLOOP.
3.SUPPOSE IF YOUR X INTERNAL TABLE IS HAVING NODUPLICATESVALUES FO f1 AND y IS HAVING dUPLICAT OF f1.
SORT : X by F1,
Y by F1.
LOOP AT X.
Loop AT Y WHERE F1 = X-F1.
MOVE :X-F1 TO Z-F1,
X-F2 TO Z-F2,
Y-M1 TO Z-M1.
APPEND Z.
CLEAR Z.
endloop.
ENDLOOP.
Don't forget to reward if useful
‎2007 Apr 18 5:17 AM
Hi Neha,
Check out the following lines of code...
<b>loop at x.
read table y with key f1 = x-f1.
if sy-subrc eq 0.
z-f1 = y-f1.
z-f2 = x-f2.
z-m1 = y-m1.
append z.
clear z.
endif.
endloop.</b>
hope this solves your purpose.
regards,
Navneeth.K
‎2007 Apr 18 5:48 AM
‎2007 Apr 19 8:31 AM
Hi Navneeth,
Yup, My query has been resolved.
Thanks for your valuable help.
Regards,
Neha