‎2008 May 26 9:23 AM
hello all,
my query to get subtotal of all production order
prod no: qty
101 10
101 20
103 20
103 20
how to get
prod no: qty
101 30
103 40.
i dont want to write the subtotal value just store in itab.
‎2008 May 26 9:27 AM
Hi
You can do the following way.
data: beign of itab occurs 0,
prod type char10,
qty type i,
end of itab.
data: it_out like itab occurs 0.
loop at itab.
collect itab into it_out.
endloop.
You can get the sum based on yr production code.
Reward points if it is helpful.
Regards
Raja.
‎2008 May 26 9:25 AM
Hi,
U can use COLLECT statement if u want the total on the basis of production number and if the data is already in internal table.
Thanks
‎2008 May 26 9:25 AM
Hi,
just use At end and store in a new table.
For eg.
loop at itab.
at end of product.
sum.
move : itab-product to itab2-product.
itab-qty to itab2-qty.
append itab2.
endat.
endloop.
-->after this itab2 will have the values you need.
‎2008 May 26 9:27 AM
Hi
You can do the following way.
data: beign of itab occurs 0,
prod type char10,
qty type i,
end of itab.
data: it_out like itab occurs 0.
loop at itab.
collect itab into it_out.
endloop.
You can get the sum based on yr production code.
Reward points if it is helpful.
Regards
Raja.
‎2008 May 26 9:31 AM
Hi,
you can use collect ,check the sample code.
REPORT demo_int_tables_COLLECT .
DATA: BEGIN OF line,
col1(3) TYPE c,
col2(2) TYPE n,
col3 TYPE i,
END OF line.
DATA itab LIKE SORTED TABLE OF line
WITH NON-UNIQUE KEY col1 col2.
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 3.
COLLECT line INTO itab.
WRITE / sy-tabix.
line-col1 = 'def'. line-col2 = '34'. line-col3 = 5.
COLLECT line INTO itab.
WRITE / sy-tabix.
line-col1 = 'abc'. line-col2 = '12'. line-col3 = 7.
COLLECT line INTO itab.
WRITE / sy-tabix.
LOOP AT itab INTO line.
WRITE: / line-col1, line-col2, line-col3.
ENDLOOP.
The list output is:
1
2
1
abc 12 10
def 34 5
The example fills a sorted table. The first two COLLECT statements work like normal insertion statements. In the third COLLECTstatement, the first line of itab is modified.
Regards,
RAj.
‎2008 May 26 10:09 AM
in my case prod no is not key field.. and if i code with at new not working with this..
‎2008 May 26 10:41 AM
Hi,
Just copy and paste the below code and check :
types : begin of tp_itab,
prod type char10,
qty type i,
end of tp_itab.
data: ig_itab type standard table of tp_itab,
wg_itab type tp_itab.
data: ig_out type standard table of tp_itab,
wg_out type tp_itab.
wg_itab-prod = '101'.
wg_itab-qty = 10.
append wg_itab to ig_itab.
wg_itab-prod = '101'.
wg_itab-qty = 20.
append wg_itab to ig_itab.
wg_itab-prod = '103'.
wg_itab-qty = 20.
append wg_itab to ig_itab.
wg_itab-prod = '103'.
wg_itab-qty = 20.
append wg_itab to ig_itab.
loop at ig_itab into wg_itab.
collect wg_itab into ig_out.
clear wg_itab.
endloop.
loop at ig_out into wg_out.
write : / wg_out-prod, wg_out-qty.
clear wg_out.
endloop.Regards,
Raghu
‎2008 May 26 10:14 AM
Hi,
You can use collect statement as the production order is of char datatype.
Thanks,
Sriram Ponna.
‎2008 May 26 10:45 AM
HI,
first sort the entries based on prodcution order and use the control break at new to get the subtotal.
Regards,
Bharathi.
‎2008 May 26 11:11 AM
Hi gs_p,
i've tried the example with collect it is working fine.
see the below code
DATA : BEGIN OF itab OCCURS 0,
col1(3),
col2 type i,
END OF itab.
itab-col1 = 101.
itab-col2 = 10.
COLLECT itab.
itab-col1 = 103.
itab-col2 = 20.
COLLECT itab.
itab-col1 = 101.
itab-col2 = 30.
COLLECT itab.
itab-col1 = 103.
itab-col2 = 50.
COLLECT itab.
SORT itab BY col1.
LOOP AT itab.
WRITE 😕 itab-col1,
itab-col2.
ENDLOOP.
plz rewards points if helpful,
Ganesh.