2009 Jan 06 8:30 AM
example:
material no stat
1111 2 H
1111 3 H
2222 2 H
2222 1 S
perform the addition process based on same material number and stat (addtion process for H and substration for S) the answer to be in internal table B:
material count
1111 5 (2 + 3)
2222 1 (2 - 1)
any suggestion?
is it possible to use together the COLLECT statement?
2009 Jan 06 8:38 AM
Hi
use another internal table to store material and count only.
but before storing , put a condition that
if it is S , multiply count by -1 .
after that usee collect statement.
EXAMPLe.
Loop at itab1.
itab2-mat = itab1-mat.
if itab1-stat = 'S'.
itab2-count = itab1-count * -1.
else.
itab2-count = itab1-count .
endif.
collect itab2.
clear itab2.
endloop.
this will definitely solve ur prob.
reg
Ramya
Hi
use another internal table to store material and count only.
but before storing , put a condition that
if it is S , multiply count by -1 .
after that usee collect statement.
EXAMPLe.
Loop at itab1.
itab2-mat = itab1-mat.
if itab1-stat = 'S'.
itab2-count = itab1-count * -1.
else.
itab2-count = itab1-count .
endif.
collect itab2.
clear itab2.
endloop.
this will definitely solve ur prob.
reg
Ramya
2009 Jan 06 8:36 AM
Hi,
Yes, you can use COLLECT and another way is in the LOOP use CONTROL BREAK EVENTS.
actually , i ve done the same type req..
LOOP AT itab.
READ TABLE it_ekbe1 INTO wa_ekbe WITH KEY ebeln = wa_ekpo-ebeln ebelp = wa_ekpo-ebelp
shkzg = 'S' BINARY SEARCH.
IF sy-subrc EQ 0.
l_menge_s = wa_ekbe-menge.
l_wrbtr_s = wa_ekbe-wrbtr.
CLEAR wa_ekbe.
ENDIF.
READ TABLE it_ekbe1 INTO wa_ekbe WITH KEY ebeln = wa_ekpo-ebeln ebelp = wa_ekpo-ebelp
shkzg = 'H' BINARY SEARCH.
IF sy-subrc EQ 0.
l_menge_h = wa_ekbe-menge.
l_wrbtr_h = wa_ekbe-wrbtr.
ENDIF.
ENDLOOP.
Hope it helps!!
Regards,
Pavan
Edited by: vishnu Pavan on Jan 6, 2009 9:40 AM
2009 Jan 06 8:38 AM
Hi
use another internal table to store material and count only.
but before storing , put a condition that
if it is S , multiply count by -1 .
after that usee collect statement.
EXAMPLe.
Loop at itab1.
itab2-mat = itab1-mat.
if itab1-stat = 'S'.
itab2-count = itab1-count * -1.
else.
itab2-count = itab1-count .
endif.
collect itab2.
clear itab2.
endloop.
this will definitely solve ur prob.
reg
Ramya
2009 Jan 06 8:41 AM
Hi,
I think it is not possible in collect statement....
But this can be done in coding... If you want i can give you the coding.
2009 Jan 06 8:43 AM
Hi,
if u use collect the output will be
1111 5 H
2222 2 H
2222 1 S .
for ur purpose, u can use code like,
loop at itab.
if <field> = H.
var = var + amount( the number field).
else.
if var > amount.
var = var - amount.
else.
var = amount - var.
endif.
endif.
at end of <field(1111 ,2222)>.
append itab2.
clear var.
endat.
endloop.
thanks,
2009 Jan 06 8:44 AM
Hi
Up to my knowledge collect stmt is works for addition not for subtraction.
Thanks,
Tulasi
2009 Jan 06 8:44 AM
Let us take internal table A is having following records,
material no stat
1111 2 H
1111 3 H
2222 2 H
2222 1 S
In the internal table B you need to populate the records,
DATA : BEGIN OF B OCCURS 0,
materil,
no,
END OF B.
Follow this procedure
LOOP AT A.
B-MATERIL = A-MATERIAL.
B-NO = A-NO.
COLLECT B
ENDLOOP.
It will work.
Regards,
Madan Mohan.
2009 Jan 06 9:11 AM
thanx guys , i also already find the solution ...
by using 2 internal table which first table (it_reserv ) have original value and 2nd table (it_wbs) copy the
unique number and answer.
LOOP AT it_reserv INTO wa_reserv.
READ TABLE it_wbs INTO wa_wbs WITH KEY rsnum = wa_reserv-rsnum.
tp_tabix = sy-tabix.
IF sy-subrc = 0.
IF wa_reserv-shkzg = 'H'.
wa_wbs-a = wa_wbs-a + wa_reserv-menge.
ELSEIF wa_reserv-shkzg = 'S'.
wa_wbs-a = wa_wbs-a - wa_reserv3-menge.
ENDIF.
MODIFY it_wbs INDEX tp_tabix FROM wa_wbs.
ELSE.
wa_wbs-rsnum = wa_reserv-rsnum.
wa_wbs-a = wa_reserv-menge.
APPEND wa_wbs TO it_wbs.
ENDIF.
ENDLOOP.
i'll try others approach to find the best solution !!
2009 Jan 06 9:14 AM
hi firdaus,
appreciate good answers for theeir valuable time.
reg
Ramya
2009 Jan 06 9:29 AM
Hi Hashim,
Try to do it in this way:
Sort itab by material.
Loop at itab into wa.
If wa-stat eq 'H'.
w_add = w_add_no + wa-no.
Elseif wa-stat eq 'S'.
w_add = w-add - wa-no.
Endif.
At end of material.
wa_final-material = wa-material.
wa_final-no = w_add.
Append wa_final into itab_final.
Clear wa_final.
Endat.
Endloop.With luck,
Pritam.
2009 Jan 07 1:40 AM
finally i used solution from Ramy_s ..
>
> Loop at itab1.
> itab2-mat = itab1-mat.
> if itab1-stat = 'S'.
> itab2-count = itab1-count * -1.
> else.
> itab2-count = itab1-count .
> endif.
> collect itab2.
> clear itab2.
> endloop.
thanks guys for all your quick replies !!
Edited by: firdaus hashim on Jan 7, 2009 2:44 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |