Hello,
I am looking to write an ABAP field routine (stock value - ZSTK_VAL) for a BW transformation and need some help on this issue.
The logic should be :
- Capture the source material coming from SAP to BW.
- Perform a check against the material master (0MAT_PLANT) in BW - if the source material exists; in any of the plants G10 , G20 , G11.
- If it exists in any of listed plants, the 'price' against that plant should be considered for calculation of ZSTK_VAL = price * source quantity and the local currency should be set to this plant currency.
- If the material does not exist in any of these three plants; then it should consider the 'price * source quantity' against other plant (could be F10/U10/D10 etc) against that material for ZSTK_VAL calculation.
I have written the code using if..elseif but it doesn't seem to work. It picks the F10 or U10 price even thought this material is present in plant G10/G20/G11.
Appreciate any help I could get on this. Thanks!
LOOP AT GT_PMAT_PLANT INTO GS_PMAT_PLANT WHERE MAT_PLANT =
SOURCE_FIELDS-MATERIAL.
IF GS_PMAT_PLANT-PLANT = 'G10'.
ZSTK_VAL = GS_PMAT_PLANT-PRICE_MAT * SOURCE_FIELDS-CML_OR_QTY.
RESULT = ZSTK_VAL.
CURRENCY = GS_PMAT_PLANT-CURRENCY.
EXIT.
ELSEIF GS_PMAT_PLANT-PLANT = 'G20'.
ZSTK_VAL = GS_PMAT_PLANT-PRICE_MAT * SOURCE_FIELDS-CML_OR_QTY.
RESULT = ZSTK_VAL.
CURRENCY = GS_PMAT_PLANT-CURRENCY.
EXIT.
ELSEIF GS_PMAT_PLANT-PLANT = 'G11'.
ZSTK_VAL = GS_PMAT_PLANT-PRICE_MAT *
SOURCE_FIELDS-CML_OR_QTY.
RESULT = ZSTK_VAL.
CURRENCY = GS_PMAT_PLANT-CURRENCY.
EXIT.
ELSEIF GS_PMAT_PLANT-PLANT = SOURCE_FIELDS-PLANT.
ZSTK_VAL = GS_PMAT_PLANT-PRICE_MAT * SOURCE_FIELDS-CML_OR_QTY.
RESULT = ZSTK_VAL.
CURRENCY = GS_PMAT_PLANT-CURRENCY.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
Regards,
Aboli