Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Production Order and Internal Order for each item of the sales order

Hi

I am developing Make To Order Report where I have to display the MTO Line Items and non MTO Line Items. For non MTO Line Items I have to display Internal order with Planned and Actual Costs and also Production Order with Planned and Actual Costs. Could anybody tell how to get the Internal order no and production order with Planned and Actual costs for each line item for a sales order.

Thanks

Naga

Tags:
replied

Hi,

You can get the Production orders, Planned orders, Internal orders generated for Sales order item from AFPO table (use fields KDAUF-Sales order number & KDPOS-Sales order item). Then to identify the order type use order category (AUTYP) from table AUFK.

Once you have the Production/internal order, you can ge the cost from COSS and COSP table. Use the object number from AUFK to get the cost entries from COSS & COSP.

You can use the following sample code as reference.

Hope this is helps.. (Don't forget to mark it... )

-


----


  • Form GET_COSTS *

----


  • Get the material cost, labour hours and the labour cost for the *

  • sales order material. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM GET_COSTS.

DATA V_OBJNR LIKE AUFK-OBJNR.

  • DATA v_menge LIKE vbap-kwmeng.

SELECT SINGLE OBJNR

INTO V_OBJNR

FROM AUFK

WHERE AUFNR EQ AFPO-AUFNR.

SELECT * FROM COSS

WHERE OBJNR EQ V_OBJNR

AND WRTTP IN ('01', '04'). " p_wrttp. "Labour Cost ( Plan, Actual)

PERFORM GET_VALUES_FROM_COSS.

ENDSELECT.

SELECT * FROM COSP

WHERE OBJNR EQ V_OBJNR

AND WRTTP IN ('01', '04') " p_wrttp

AND KSTAR NE '0000510033'. " EQ p_kstar2. "Material Cost

PERFORM GET_VALUE_FROM_COSP.

ENDSELECT.

  • Get the unit cost of the production order by dividing the production

  • cost by the order quantity. The result will be multiplied by the

  • GL posting qunatity (Delivery quantity) to get the production cost

  • for the quantity being deluivered.

IF NOT AFPO-PSMNG IS INITIAL.

OUT_REC-LABOUR_HOURS_ACT = OUT_REC-LABOUR_HOURS_ACT / AFPO-PSMNG.

OUT_REC-ADDNL_LABOUR_HOURS_ACT =

OUT_REC-ADDNL_LABOUR_HOURS_ACT / AFPO-PSMNG.

OUT_REC-LABOUR_HOURS_PLN = OUT_REC-LABOUR_HOURS_PLN / AFPO-PSMNG.

OUT_REC-ADDNL_LABOUR_HOURS_PLN =

OUT_REC-ADDNL_LABOUR_HOURS_PLN / AFPO-PSMNG.

OUT_REC-LABOUR_COST_ACT = OUT_REC-LABOUR_COST_ACT / AFPO-PSMNG.

OUT_REC-ADDNL_LABOUR_COST_ACT =

OUT_REC-ADDNL_LABOUR_COST_ACT / AFPO-PSMNG.

OUT_REC-LABOUR_COST_PLN = OUT_REC-LABOUR_COST_PLN / AFPO-PSMNG.

OUT_REC-ADDNL_LABOUR_COST_PLN =

OUT_REC-ADDNL_LABOUR_COST_PLN / AFPO-PSMNG.

OUT_REC-MATERIAL_COST_ACT = OUT_REC-MATERIAL_COST_ACT / AFPO-PSMNG.

OUT_REC-ADDNL_MATERIAL_COST_ACT =

OUT_REC-ADDNL_MATERIAL_COST_ACT / AFPO-PSMNG.

OUT_REC-MATERIAL_COST_PLN = OUT_REC-MATERIAL_COST_PLN / AFPO-PSMNG.

OUT_REC-ADDNL_MATERIAL_COST_PLN =

OUT_REC-ADDNL_MATERIAL_COST_PLN / AFPO-PSMNG.

ENDIF.

  • Multiply the calculated Unit Production costs with the GL quantity to

  • get the actual production cost of the quantity delivered.

  • Calculation for Labour Hours

OUT_REC-LABOUR_HOURS_ACT = OUT_REC-LABOUR_HOURS_ACT *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_LABOUR_HOURS_ACT = OUT_REC-ADDNL_LABOUR_HOURS_ACT *

OUT_REC-QUANTITY.

OUT_REC-LABOUR_HOURS_PLN = OUT_REC-LABOUR_HOURS_PLN *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_LABOUR_HOURS_PLN = OUT_REC-ADDNL_LABOUR_HOURS_PLN *

OUT_REC-QUANTITY.

  • Calculation for Material Cost

OUT_REC-MATERIAL_COST_ACT = OUT_REC-MATERIAL_COST_ACT *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_MATERIAL_COST_ACT =

OUT_REC-ADDNL_MATERIAL_COST_ACT * OUT_REC-QUANTITY.

OUT_REC-MATERIAL_COST_PLN = OUT_REC-MATERIAL_COST_PLN *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_MATERIAL_COST_PLN =

OUT_REC-ADDNL_MATERIAL_COST_PLN * OUT_REC-QUANTITY.

  • Calculation for Labour cost

OUT_REC-LABOUR_COST_ACT = OUT_REC-LABOUR_COST_ACT *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_LABOUR_COST_ACT = OUT_REC-ADDNL_LABOUR_COST_ACT *

OUT_REC-QUANTITY.

OUT_REC-LABOUR_COST_PLN = OUT_REC-LABOUR_COST_PLN *

OUT_REC-QUANTITY.

OUT_REC-ADDNL_LABOUR_COST_PLN = OUT_REC-ADDNL_LABOUR_COST_PLN *

OUT_REC-QUANTITY.

  • Get the planned material cost from the total of the planned cost of

  • the component materials in the production order confirmations.

SELECT BWART MENGE MATNR SHKZG FROM AUFM

INTO (AUFM-BWART, AUFM-MENGE, AUFM-MATNR, AUFM-SHKZG)

WHERE AUFNR EQ AFPO-AUFNR.

CHECK AUFM-BWART NE '101'.

READ TABLE I_MBEW WITH KEY MATNR = AUFM-MATNR

BWKEY = AFPO-DWERK.

IF SY-SUBRC NE 0.

SELECT MATNR BWKEY ZPLPR LPLPR PEINH

FROM MBEW

INTO I_MBEW

WHERE MATNR EQ AUFM-MATNR

AND BWKEY EQ AFPO-DWERK.

APPEND I_MBEW.

ENDSELECT.

ENDIF.

IF SY-SUBRC EQ 0.

IF I_MBEW-ZPLPR NE 0.

IF AUFM-SHKZG EQ 'H'.

OUT_REC-PLANNED_MATERIAL_COST =

OUT_REC-PLANNED_MATERIAL_COST +

( I_MBEW-ZPLPR * AUFM-MENGE / I_MBEW-PEINH ).

ELSE.

OUT_REC-PLANNED_MATERIAL_COST =

OUT_REC-PLANNED_MATERIAL_COST -

( I_MBEW-ZPLPR * AUFM-MENGE / I_MBEW-PEINH ).

ENDIF.

ELSEIF I_MBEW-LPLPR NE 0.

IF AUFM-SHKZG EQ 'H'.

OUT_REC-CURRENT_MATERIAL_COST =

OUT_REC-CURRENT_MATERIAL_COST +

( I_MBEW-LPLPR * AUFM-MENGE / I_MBEW-PEINH ).

ELSE.

OUT_REC-CURRENT_MATERIAL_COST =

OUT_REC-CURRENT_MATERIAL_COST -

( I_MBEW-LPLPR * AUFM-MENGE / I_MBEW-PEINH ).

ENDIF.

ENDIF.

ENDIF.

ENDSELECT.

  • Get the Future material cost per Unit by deviding the calculated

  • Future material cost above with the goods reciept quantity to, then

  • multiply the unit cost with the GL quantity to get the Future material

  • Cost for the Quantity delivered. (Quantity in the entery from GLPCA

  • Table).

IF NOT AFPO-WEMNG IS INITIAL.

OUT_REC-PLANNED_MATERIAL_COST =

OUT_REC-PLANNED_MATERIAL_COST / AFPO-WEMNG * OUT_REC-QUANTITY.

OUT_REC-CURRENT_MATERIAL_COST =

OUT_REC-CURRENT_MATERIAL_COST / AFPO-WEMNG * OUT_REC-QUANTITY.

ENDIF.

ENDFORM. " GET_COSTS

----


  • Form GET_VALUE_FROM_COSP *

----


  • Get the Material cost from COSP table. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM GET_VALUE_FROM_COSP.

FIELD-SYMBOLS: <FS> TYPE ANY.

DATA: V_COMPONENT TYPE I.

  • Cummulate the posting values of all the 16 period buckets as to get

  • total production order cost. This is to handle the aprtial posting of

  • prodction order values in diffrent periods.

V_COMPONENT = 15.

DO 16 TIMES.

ADD 1 TO V_COMPONENT.

ASSIGN COMPONENT V_COMPONENT OF STRUCTURE COSP TO <FS>.

IF COSP-WRTTP EQ '04' AND COSP-KSTAR EQ P_KSTAR2.

ADD <FS> TO OUT_REC-MATERIAL_COST_ACT.

ELSEIF COSP-WRTTP EQ '04'.

ADD <FS> TO OUT_REC-ADDNL_MATERIAL_COST_ACT.

ELSEIF COSP-WRTTP EQ '01' AND COSP-KSTAR EQ P_KSTAR2.

ADD <FS> TO OUT_REC-MATERIAL_COST_PLN.

ELSEIF COSP-WRTTP EQ '01'.

ADD <FS> TO OUT_REC-ADDNL_MATERIAL_COST_PLN.

ENDIF.

ENDDO.

ENDFORM. " GET_VALUE_FROM_COSP

----


  • Form GET_VALUES_FROM_COSS *

----


  • Get the Labour cost and Labour hours from the COSS table. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM GET_VALUES_FROM_COSS.

FIELD-SYMBOLS: <FS1> TYPE ANY,

<FS2> TYPE ANY.

DATA: V_COMPONENT1 TYPE I,

V_COMPONENT2 TYPE I.

  • Cummulate the posting values of all the 16 period buckets as to get

  • total production order cost. This is to handle the aprtial posting of

  • prodction order values in diffrent periods.

V_COMPONENT1 = 15.

V_COMPONENT2 = 111.

DO 16 TIMES.

ADD 1 TO: V_COMPONENT1, V_COMPONENT2.

ASSIGN COMPONENT V_COMPONENT1 OF STRUCTURE COSS TO <FS1>.

ASSIGN COMPONENT V_COMPONENT2 OF STRUCTURE COSS TO <FS2>.

IF COSS-WRTTP EQ '04' AND COSS-KSTAR EQ P_KSTAR1.

ADD <FS1> TO OUT_REC-LABOUR_COST_ACT.

ADD <FS2> TO OUT_REC-LABOUR_HOURS_ACT.

ELSEIF COSS-WRTTP EQ '04'.

ADD <FS1> TO OUT_REC-ADDNL_LABOUR_COST_ACT.

ADD <FS2> TO OUT_REC-ADDNL_LABOUR_HOURS_ACT.

ELSEIF COSS-WRTTP EQ '01' AND COSS-KSTAR EQ P_KSTAR1.

ADD <FS1> TO OUT_REC-LABOUR_COST_PLN.

ADD <FS2> TO OUT_REC-LABOUR_HOURS_PLN.

ELSEIF COSS-WRTTP EQ '01'.

ADD <FS1> TO OUT_REC-ADDNL_LABOUR_COST_PLN.

ADD <FS2> TO OUT_REC-ADDNL_LABOUR_HOURS_PLN.

ENDIF.

ENDDO.

ENDFORM. " GET_VALUES_FROM_COSS

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question