‎2014 Feb 04 11:02 AM
Hello Experts,
I have the following requirement.
I have a internal table with 10 fields of which am displaying only 6 fields in my maintable of smartform. Now in my internal table structure i have the last two fields as MATNR and MATKL.
Now the 6 fields am displaying on main table are
1) Item no
2)description
3)QTY
4)some integer value1
5)some integer value2
6)some integer value3
Now based on the combination of matnr and matkl i must add the line items in the item table.
Conditions,
Item no, description can be taken from the first line item, rest all fields must be added.
Can you help me on acheiving this requirement.
Am very thankful to your immediate response
Thanks
Loki
‎2014 Feb 07 3:33 AM
Hi Lokeshwari,
I hope you got the answer
If not you can try this code below, it will work i have checked
Do the following steps before you use the code,
Make the field matnr (Whichever field you want to use as a condition for summarization) as first field in your structure,
Also create one extra internal table as final which will hold your summarized value and use that table to display.
Define other data as we used in the code,
after that use the code below,
LOOP AT it_item1 INTO wa_item1.
AT NEW matnr.
G_flag1 = 1.
ENDAT.
IF G_flag1 is NOT INITIAL.
wa_final-item = wa_item1-item.
wa_final-desc = wa_item1-item.
CLEAR G_flag1.
ENDIF.
wa_final-qty = wa_final-qty+ wa_item1-qty.
wa_final-intvalue1 = gwa_final-intvalue1+ gwa_item1-intvalue1.
wa_final-intvalue2 = gwa_final-intvalue2+ gwa_item1-intvalue2.
wa_final-intvalue3 = gwa_final-intvalue3+ gwa_item1-intvalue3.
at END OF matnr.
G_flag2 = 1.
ENDAT.
IF G_flag2 is NOT INITIAL.
APPEND wa_final TO it_final.
CLEAR wa_final.
CLEAR G_flag2.
ENDIF.
ENDLOOP.
" Am using Flag value inside "at new" and "at end of" because variables will be holding only junk value inside these control break statements.
Hope you got this logic, Please get back if you have any issues in understanding the code
Thanks,
Satish
‎2014 Feb 04 11:06 AM
Hi Lokeswari,
Why dont you try using At new, At last functionalities
Thanks,
Satishi
‎2014 Feb 04 11:10 AM
Hi Mohan,
You can use COLLECT Statement.
LOOP HEAD_TAB.
WA_ITEM = WA_HEAD. "(required fields)
COLLECT WA_ITEM TO ITEM_TAB.
ENDLOOP.
Here except 4,5,6 and 7 remaining all are Char fields. So, these fields will be simulated with respect to non numeric fields.
Hope you understand.
regards,
Vijay
‎2014 Feb 04 12:59 PM
Hi Lokeshwari,
with help of your collect statements we can achieve your requirements.
here data type of field should be specified below type.
data: begin of wa,
matnr(20) type c,
matkl(20) type c,
Item_no(6) type c ,
description(40) type c
QTY type n,
some integer value1 type n,
some integer value2 type n,
some integer value3 type n,
end of wa.
data : itab like wa occurs 0.
loop at itab into wa.
collect wa to itab.
endloop.
Regards,
Thangam.P
‎2014 Feb 04 3:20 PM
Hello All Please understand the condition that i have to maintain,
For every line item having same material number and material group i have to sum up the fields.
Hope i explained my requirement clearly
Thanks,
loki
‎2014 Feb 04 4:07 PM
Hi,
Have you tried COLLECT?
If you are having data as below,
MAT1 MATGRP1 20 50 10
MAT1 MATGRP1 10 10 20
MAT1 MATGRP1 30 20 40
MAT1 MATGRP1 40 50 50
Collect makes this as
MAT1 MATGRP1 100 130 120. I think, this is what you required.
-Vijay
‎2014 Feb 04 5:01 PM
yes you are right, but i may also have MAT2MATGRP2, MAT3MATGRP3 will it work for all conditions?
Can you please also specify the syntax for collect ?
‎2014 Feb 04 5:37 PM
Hi Mohan,
Yes it will workout for all materials and groups.
Already I mentioned the syntax and sample in my first reply. Generally when we are moving data from one table to another we use APPEND WA TO ITAB at the end of loop, instead of APPEND use COLLECT WA INTO ITAB.
And also go through this link for clear syntax and example code.
-Vijay
‎2014 Feb 05 4:31 AM
Hi Lokeshwari,
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
let me know know still facing the problem.
Regards,
Thangam.P
‎2014 Feb 07 3:33 AM
Hi Lokeshwari,
I hope you got the answer
If not you can try this code below, it will work i have checked
Do the following steps before you use the code,
Make the field matnr (Whichever field you want to use as a condition for summarization) as first field in your structure,
Also create one extra internal table as final which will hold your summarized value and use that table to display.
Define other data as we used in the code,
after that use the code below,
LOOP AT it_item1 INTO wa_item1.
AT NEW matnr.
G_flag1 = 1.
ENDAT.
IF G_flag1 is NOT INITIAL.
wa_final-item = wa_item1-item.
wa_final-desc = wa_item1-item.
CLEAR G_flag1.
ENDIF.
wa_final-qty = wa_final-qty+ wa_item1-qty.
wa_final-intvalue1 = gwa_final-intvalue1+ gwa_item1-intvalue1.
wa_final-intvalue2 = gwa_final-intvalue2+ gwa_item1-intvalue2.
wa_final-intvalue3 = gwa_final-intvalue3+ gwa_item1-intvalue3.
at END OF matnr.
G_flag2 = 1.
ENDAT.
IF G_flag2 is NOT INITIAL.
APPEND wa_final TO it_final.
CLEAR wa_final.
CLEAR G_flag2.
ENDIF.
ENDLOOP.
" Am using Flag value inside "at new" and "at end of" because variables will be holding only junk value inside these control break statements.
Hope you got this logic, Please get back if you have any issues in understanding the code
Thanks,
Satish
‎2014 Feb 07 8:29 AM
Hi Satish,
Thanks for the reply, Your code worked
Also i thank all others who contributed for my query.
Thanks,
lokeshwari
‎2014 Feb 07 8:33 AM
‎2014 Jun 30 8:56 AM
hiiii alll,
if i have 1 field which i dnt want to collect like rate whos value must b same throughout...
for eg..
total_diamnd_stn discription no_of_stn diamnd_rate total_val
.22 round 22 120 = 120*.22
.32 crt_round 12 150 =150*.32
.45 round 2 120 =120*.45
.85 crt_round 8 150 =150*.85
now i want to club all the columns, but the diamnd_rate column also gets clubed, which i want only 120 and 150 correspondly...
output like below...
total_diamnd_stn discription no_of_stn diamnd_rate total_val
.67 round 24 120 120*.67
1.17 crt_round 20 150 150*1.17
plz help......
thank u..
‎2014 Jun 30 9:36 AM
Hi Priyanka,
Make DIAMND_RATE column type as C (CHAR) and try.
Regards,
Vijay