Skip to Content
0
May 09, 2008 at 04:57 AM

Can anybody help me with the product costing report... URGENt!!!!!

31 Views

Hi,

Can anybody help me with the logic. teh present logic is given below. But as per the new requirement in the Selection screen when I add Material as Select Options then Logic should "expecting to get the report either in Product Group or (single/multiple/range) Material" . Please reply ASAP.

  • get the list of product groups based on the range entered by the user.

SELECT KSTRG FROM CKPH INTO TABLE I_KSTRG

WHERE KSTRG IN SO_KSTRG.

  • for each product explode the hierarchy get all sub product groups

LOOP AT I_KSTRG.

CLEAR I_CKPH. REFRESH I_CKPH.

CALL FUNCTION 'K_CKPH_GET_HIERARCHY'

EXPORTING

DATBI = '99991231'

KSTRG = I_KSTRG-KSTRG

TABLES

CKPH_I = I_CKPH

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC EQ 0.

  • save all unique product groups within the hierarchy.

LOOP AT I_CKPH.

MOVE 'EQ' TO F_KSTRG-OPTION.

MOVE 'I' TO F_KSTRG-SIGN.

MOVE I_CKPH-KSTRG TO F_KSTRG-LOW.

COLLECT F_KSTRG.

MOVE I_CKPH-KSTRG TO KSTRG-LEVEL2.

MOVE I_CKPH-UEKTR TO KSTRG-LEVEL1.

COLLECT KSTRG. CLEAR KSTRG.

ENDLOOP.

ENDIF.

ENDLOOP.

SORT KSTRG BY LEVEL2 LEVEL1.

  • check if there are product groups extracted.

CLEAR Z_LINES. DESCRIBE TABLE F_KSTRG LINES Z_LINES.

IF Z_LINES GT 0.

  • get the materials attached to each product group.

SELECT KSTRG WERKS MATNR

INTO CORRESPONDING FIELDS OF TABLE I_CKPE

FROM CKPE

WHERE KSTRG IN F_KSTRG

AND WERKS = PA_WERKS.

IF NOT I_CKPE[] IS INITIAL.

  • get the order info order number & object number

SELECT AFPOMATNR AUFKOBJNR

INTO CORRESPONDING FIELDS OF TABLE I_AFPO

FROM AFPO AS AFPO INNER JOIN AUFK AS AUFK

ON AFPOAUFNR = AUFKAUFNR

FOR ALL ENTRIES IN I_CKPE

WHERE AFPO~MATNR = I_CKPE-MATNR.

ENDIF.

SORT I_AFPO BY MATNR.

LOOP AT I_CKPE.

  • get the division for the material.

CLEAR: Z_SPART, MARA.

SELECT SINGLE SPART

INTO Z_SPART

FROM MARA

WHERE MATNR = I_CKPE-MATNR

AND MTART = 'ZTFG'.

MARA-SPART = Z_SPART.

  • only proceed with processing if division is within users selection

IF Z_SPART IN SO_SPART.

LOOP AT I_AFPO WHERE MATNR = I_CKPE-MATNR.

CLEAR: Z_MATERIAL_FLG, Z_EXPENSES_FLG, Z_SCRAP_FLG,

Z_OUTVAR_FLG, Z_ACTIVITY_FLG.

LOOP AT I_COEP WHERE OBJNR = I_AFPO-OBJNR

AND VRGNG NE 'KOAO'. "changed by Kasturi

PERFORM GET_DATA_FOR_REPORT TABLES I_DATA I_DATA_QTY.

ENDLOOP.

ENDLOOP. "afpo

ENDIF. "division check

ENDLOOP. "ckpe

ELSE.

  • no product groups extracted.

  • MESSAGE i011.

ENDIF.