04-16-2009 1:20 PM
plz help me to implement the following code.its not working.
LOOP AT ITAB_OUTTAB INTO WA_OUTTAB.
MOVE:WA_OUTTAB-BISMT TO WA_CONSUMPTION-BISMT.
AT NEW WERKS.
MOVE WA_OUTTAB-WERKS TO WA_CONSUMPTION-WERKS.
AT NEW MATNR.
MOVE WA_OUTTAB-MATNR TO WA_CONSUMPTION-MATNR.
IF WA_OUTTAB-SHKZG = 'H'.
QUANTITY_H = WA_OUTTAB-MENGE.
QUANTITY_H_SUM = QUANTITY_H_SUM + QUANTITY_H.
ELSE.
QUANTITY_S = WA_OUTTAB-MENGE.
QUANTITY_S_SUM = QUANTITY_S_SUM + QUANTITY_S.
ENDIF.
QUANTITY_NET = QUANTITY_S_SUM - QUANTITY_H_SUM.
MOVE QUANTITY_H_SUM TO WA_CONSUMPTION-QUANTITY_H_SUM.
MOVE QUANTITY_S_SUM TO WA_CONSUMPTION-QUANTITY_S_SUM.
MOVE QUANTITY_NET TO WA_CONSUMPTION-QUANTITY_NET.
APPEND WA_CONSUMPTION TO FINAL_CONSUMPTION.
CLEAR WA_CONSUMPTION.
ENDAT.
ENDAT.
ENDLOOP.
04-16-2009 1:24 PM
04-16-2009 1:27 PM
Hi,
LOOP AT ITAB_OUTTAB INTO WA_OUTTAB.
MOVE:WA_OUTTAB-BISMT TO WA_CONSUMPTION-BISMT.
AT NEW WERKS.
read table itab_outtab into wa_outtab with key werks = wa_outtab-werks. " added
MOVE WA_OUTTAB-WERKS TO WA_CONSUMPTION-WERKS.
AT NEW MATNR.
read table itab_outtab into wa_outtab with key werks = wa_outtab-matnr. " Added
MOVE WA_OUTTAB-MATNR TO WA_CONSUMPTION-MATNR.
IF WA_OUTTAB-SHKZG = 'H'.
QUANTITY_H = WA_OUTTAB-MENGE.
QUANTITY_H_SUM = QUANTITY_H_SUM + QUANTITY_H.
ELSE.
QUANTITY_S = WA_OUTTAB-MENGE.
QUANTITY_S_SUM = QUANTITY_S_SUM + QUANTITY_S.
ENDIF.
QUANTITY_NET = QUANTITY_S_SUM - QUANTITY_H_SUM.
MOVE QUANTITY_H_SUM TO WA_CONSUMPTION-QUANTITY_H_SUM.
MOVE QUANTITY_S_SUM TO WA_CONSUMPTION-QUANTITY_S_SUM.
MOVE QUANTITY_NET TO WA_CONSUMPTION-QUANTITY_NET.
APPEND WA_CONSUMPTION TO FINAL_CONSUMPTION.
CLEAR WA_CONSUMPTION.
ENDAT.
ENDAT.
ENDLOOP.
Edited by: Krishna Gowrneni on Apr 16, 2009 5:58 PM
04-16-2009 1:25 PM
hi,
use the control staements which is best fit for you r program
Control level reporting
Overview
When using control levels with an internal table, remember to sort the internal table in accordance with the control levels, and the fields in the table must occur in the same order as you sort the table.
In the example below, carrid must be the first field in the table
Se also Working with subtotals in internal tables using AT/ENDAT
When you use control levels the SUM statement can be used to generate totals.
Every control level statement end with ENDAT
Important: The fields in the internal table must be in the same order as the sort order.
Remember to place the control levels in the following order:
at new xxxx
write detail line
at end of xxxx
Control levels
AT NEW xxx
AT END OF xxx
AT FIRST
AT LAST
Example
sort itab by bukrs.
loop at itab.
* Heading for every bukrs
at new bukrs.
write: / itab-bukrs.
endat.
* Detail line
write: / itab-bukrs.
* Totals per bukrs
at end of bukrs
* Sum all variables of type P and I
sum.
uline.
write: / 'Total bukrs', itab-bukrs.
uline.
endat.
* Grand totals
at last.
sum.
write: / 'Grand total', itab-bukrs.
endat.
endloop.
Regards,
Prabhduas
04-16-2009 1:33 PM
HI,
Try this way..
LOOP AT itab_outtab INTO wa_outtab.
MOVE:wa_outtab-bismt TO wa_consumption-bismt.
MOVE wa_outtab-werks TO wa_consumption-werks.
AT NEW matnr.
MOVE wa_outtab-matnr TO wa_consumption-matnr.
IF wa_outtab-shkzg = 'H'.
quantity_h = wa_outtab-menge.
quantity_h_sum = quantity_h_sum + quantity_h.
ELSE.
quantity_s = wa_outtab-menge.
quantity_s_sum = quantity_s_sum + quantity_s.
ENDIF.
quantity_net = quantity_s_sum - quantity_h_sum.
MOVE quantity_h_sum TO wa_consumption-quantity_h_sum.
MOVE quantity_s_sum TO wa_consumption-quantity_s_sum.
MOVE quantity_net TO wa_consumption-quantity_net.
APPEND wa_consumption TO final_consumption.
CLEAR wa_consumption.
ENDAT.
ENDLOOP.
04-16-2009 1:45 PM
Hi,
Two things to be taken care of :
1. You are using AT NEW...ENDAT is fine. However, have you ensured that the table hierarchy is also built having the first field as WERKS and the second field as MATNR ? And the table is sorted by WERKS and MATNR. If not then your code will never work.
2. Secondly, when using these control level statments, all the fields to the right hand side of the field that is used in the control statement have a astericks in it, so just after the loop, copy the data WA_OUTTAB into a WA_OUTTAB_tmp. And use the temporary work area to move the fields to the target work area.
SORT ITAB_OUTTAB by WERKS MATNR.
LOOP AT ITAB_OUTTAB INTO WA_OUTTAB.
move WA_OUTTAB to WA_OUTTAB_tmp.
....
regards,
Advait
04-16-2009 1:51 PM
Hi,
What I understand in your internal table you are moving data at new werks if this condition fulfill than it will see that if the material is new than again you are moving the data into another internal table.
What I understand If this is the scenario than this should work fine. If this is not write the exact requirement.
Regards,
Himanshu
04-16-2009 2:02 PM
I understood that you are trying to consolidate debit, credi and difference amount at plant and mateial wise.
Please check code.
SORT ITAB_OUTTAB BY WERKS MATNR.
LOOP AT ITAB_OUTTAB INTO WA_OUTTAB.
MOVE:WA_OUTTAB-BISMT TO WA_CONSUMPTION-BISMT.
MOVE WA_OUTTAB-WERKS TO WA_CONSUMPTION-WERKS.
AT NEW MATNR.
MOVE WA_OUTTAB-MATNR TO WA_CONSUMPTION-MATNR.
IF WA_OUTTAB-SHKZG = 'H'.
*QUANTITY_H = WA_OUTTAB-MENGE.
QUANTITY_H_SUM = QUANTITY_H_SUM + QUANTITY_H.
WA_CONSUMPTION-QUANTITY_H_SUM = WA_OUTTAB-MENGE.
ELSE.
*QUANTITY_S = WA_OUTTAB-MENGE.
QUANTITY_S_SUM = QUANTITY_S_SUM + QUANTITY_S.
WA_CONSUMPTION-QUANTITY_S_SUM = = WA_OUTTAB-MENGE.
ENDIF.
QUANTITY_NET = QUANTITY_S_SUM - QUANTITY_H_SUM.
WA_CONSUMPTION-QUANTITY_NET = WA_CONSUMPTION-QUANTITY_S_SUM - WA_CONSUMPTION-QUANTITY_H_SUM.
MOVE QUANTITY_H_SUM TO WA_CONSUMPTION-QUANTITY_H_SUM.
MOVE QUANTITY_S_SUM TO WA_CONSUMPTION-QUANTITY_S_SUM.
MOVE QUANTITY_NET TO WA_CONSUMPTION-QUANTITY_NET.
APPEND WA_CONSUMPTION TO FINAL_CONSUMPTION.
*Below collect statemet adds total for same plant and material number.
COLLECT WA_CONSUMPTION INTO FINAL_CONSUMPTION.
CLEAR WA_CONSUMPTION.
ENDAT.
ENDAT.
ENDLOOP.
04-16-2009 3:48 PM
I guess using AT new statements are not helping you much over here.
You are not using it for some calculations .
You can achieve this without using those statements.
It can be directly appended to the consumption internal table.
Just sort using matnr and werks.
delete adjacent duplicates matnr and werks.
If this is not the case specify your requirement precisely
Regards,
Lalit Mohan Gupta.