12-05-2009 1:28 PM
Hi All,
Please resolve the following quiery:
The internal table itab1 is as follows;
A B C
1 X 12
2 X 11
3 X 9
4 Y 1
5 Y 3
6 Y 5
7 Z 22
8 Z 4
9 Z 7
10 Z 8
The totals of all values corresponding to x,y and z are sotred as follows in itab2:
A B c
X 32
Y 9
Z 41
Now the above two tables has to be combined and display the output in below format:
That is the total correspnding to X should come first before the X vaues are started.
That is the total correspnding to Y should come first before the Y vaues are started.
That is the total correspnding to Z should come first before the Z vaues are started.
The final output ih itab3 is as follows:
A B C
X 32
1 X 12
2 X 11
3 X 9
Y 9
4 Y 1
5 Y 3
6 Y 5
Z 41
7 Z 22
8 Z 4
9 Z 7
10 Z 8
Please do the needful at the earliest.
Regards,
A.Srinivas
12-05-2009 1:43 PM
12-05-2009 1:43 PM
12-05-2009 2:02 PM
Hi,
Please try this:-
SORT itab1 BY B.
Loop at itab1 into wa_itab1.
AT NEW B.
READ TABLE itab2 into wa_itab2 with key A = wa_itab1-B.
IF sy-subrc = 0.
wa_itab3-A = WA_ITAB2-A.
wa_itab3-B = wa_itab2-B.
ENDIF.
ENDAT.
wa_itab3-A = wa_itab1-A.
wa_itab3-B = wa_itab1-B.
wa_itab3-C = wa_itab1-C.
append wa_itab3 to t_itab3.
endloop.
Regards,
Subhashini
12-06-2009 4:19 AM
You need to loop on first table, then read records from second table, not fill the third internal table as desired.
Press F1 to AT New to fill the first row.
Hope you understand it.
12-06-2009 11:06 PM
Hi,
I feel the code which Subhasini K has given is almost correct. Just one thing I would like to add.
In the AT..ENDAT. you have to add another line
append wa_itab3 to t_itab3.
So the revised AT..ENDAT should look like -
AT NEW B.
READ TABLE itab2 into wa_itab2 with key A = wa_itab1-B.
IF sy-subrc = 0.
wa_itab3-A = WA_ITAB2-A.
wa_itab3-B = wa_itab2-B.
append wa_itab3 to t_itab3.
ENDIF.
ENDAT.
Rest should be same.
Please let me know if you problem is not resolved.
Thanks,
Mainak
12-08-2009 2:55 AM
Hi,
Thanks for your quick and prospective reply.
The actual issues as follows:
The internal table itab1 is as follows;
A B C
1 X 12
2 X 11
3 X 9
4 Y 1
5 Y 3
6 Y 5
7 Z 22
8 Z 4
9 Z 7
10 Z 8
The totals of all values corresponding to x,y and z are sotred as follows in itab2:
A B c
X 32
Y 9
Z 41
Now the above two tables has to be combined and display the output in below format:
That is the total correspnding to X should come first before the X vaues are started.
That is the total correspnding to Y should come first before the Y vaues are started.
That is the total correspnding to Z should come first before the Z vaues are started.
The final output ih itab3 is as follows:
A B C
X 32
1 X 12
2 X 11
3 X 9
Y 9
4 Y 1
5 Y 3
6 Y 5
Z 41
7 Z 22
8 Z 4
9 Z 7
10 Z 8
***********************************************************************************************************
Now my above same issue is extended as follows:
The new internal table is as follows:
The internal table itab1 is as follows;
A B B1 C
1 X cas 12
2 X IBI 11
3 X IBI 9
4 Y cas 1
5 Y cas 3
6 Y cas 5
7 Z cas 22
8 Z cas 4
9 Z cas 7
10 Z cas 8
The totals of all values corresponding to x,y and z are sotred as follows in itab2 using along collect function along with new field B1:
A B B1 C
X 12 cas
X 20 IBI
Y 9 cas
Z 41 cas
Now the above two tables has to be combined and display the output in below format:
That is the total correspnding to X and cas should come first before the X values(corresponding to cas) are started.
That is the total correspnding to X and IBI should come first before the X values(corresponding to IBI) are started.
That is the total correspnding to Y should come first before the Y vaues are started.
That is the total correspnding to Z should come first before the Z vaues are started.
The final output ini itab3 should be as follows:
A B B1 C
X cas 12
1 X IBI 12
X IBI 20
2 X IBI 11
3 X IBI 9
Y cas 9
4 Y cas 1
5 Y cas 3
6 Y cas 5
Z cas 41
7 Z cas 22
8 Z cas 4
9 Z cas 7
10 Z cas 8
12-08-2009 2:57 AM
Hi,
Please do the needful to my extended issue at the earliest.
Regards,
A.Srinivas
12-08-2009 5:52 AM
Hi,
Please do this:-
SORT itab1 BY B B1.
Loop at itab1 into wa_itab1.
AT NEW B B1.
READ TABLE itab2 into wa_itab2 with key A = wa_itab1-B
B1 = wa_itab1-B1.
IF sy-subrc = 0.
wa_itab3-A = WA_ITAB2-A.
wa_itab3-B = wa_itab2-B.
wa_itab3-B1 = wa_itab2-B1.
append wa_itab3 to t_itab3.
ENDIF.
ENDAT.
if sy-subrc <> 0.
wa_itab3-A = wa_itab1-A.
wa_itab3-B = wa_itab1-B.
wa_itab3-B1 = wa_itab1-B1.
wa_itab3-C = wa_itab1-C.
append wa_itab3 to t_itab3.
endif.
endloop.
Regards,
Subhashini
12-09-2009 12:09 PM
12-09-2009 5:03 PM
Hi,
I am just waiting for any further extension of my issue so as to update you the same at once.
Thanks for your reply and solution but there is no possbitility for your second solution as "at new takes" only one field at a time.
Your first solution gave me a lot of inputs for initiation of my issue.
I resolved the same by "on change of b or b1."
Thanks again for all your help.
Regards,
A.Srinivas
12-06-2009 10:58 PM
Hi Srinu,
The following logic should work to meet your requirement:
Assuming all int tables with header line
LOOP AT itab2.
APPEND itab2 to itab3. "This will give you summary line
Then conditionally loop through itab1
LOOP AT itab1 WHERE b = itab2-a.
APPEND itab1 to itab3.
ENDLOOP.
ENDLOOP.
*Now you got your itab3 as required
Regards
Suresh