Skip to Content
0
Former Member
Apr 01, 2013 at 05:57 AM

hi exports i need a mto process i want to actual material cost and activity and oh

27 Views

Based on below report my client want to the sales order line item wise

sales order number,wbs element,line item, customer name, sales order value(inr),Producion order, material number,order type, order quantity, production order quantity till lost year,prodution order quantity from 1aprial to current month of the this year fiscal year.....actual cost for the period 1st aprial to current month in that material cost, affloading, employee cost, sv activity, smm activity, sf activity, oh and total..based on that closing of the period material cost, affloading, employee cost, sv activity, smm activity, sf activity, oh and total........

based of that my client want the report....

*&---------------------------------------------------------------------*

*& Include YCO_WIP_LEDGER_FF

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Form F4_MONTH

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM F4_MONTH .

TYPES: BEGIN OF LTY_MONTH,

FCMNR TYPE FCMNR,

MONTH TYPE CHAR10,

END OF LTY_MONTH.

DATA: LT_MON TYPE STANDARD TABLE OF LTY_MONTH,

LS_MON TYPE LTY_MONTH.

DATA:LT_RETURN TYPE TABLE OF DDSHRETVAL,

LS_RETURN LIKE LINE OF LT_RETURN.

REFRESH LT_MON.

CLEAR LS_MON.

LS_MON-FCMNR = '01'.

LS_MON-MONTH = 'April'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '02'.

LS_MON-MONTH = 'May'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '03'.

LS_MON-MONTH = 'June'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '04'.

LS_MON-MONTH = 'July'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '05'.

LS_MON-MONTH = 'August'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '06'.

LS_MON-MONTH = 'September'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '07'.

LS_MON-MONTH = 'October'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '08'.

LS_MON-MONTH = 'November'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '09'.

LS_MON-MONTH = 'December'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '10'.

LS_MON-MONTH = 'January'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '11'.

LS_MON-MONTH = 'February'.

APPEND LS_MON TO LT_MON.

LS_MON-FCMNR = '12'.

LS_MON-MONTH = 'March'.

APPEND LS_MON TO LT_MON.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

EXPORTING

RETFIELD = 'FCMNR'

DYNPPROG = SY-REPID

DYNPNR = SY-DYNNR

VALUE_ORG = 'S'

TABLES

VALUE_TAB = LT_MON

RETURN_TAB = LT_RETURN

EXCEPTIONS

PARAMETER_ERROR = 1

NO_VALUES_FOUND = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

READ TABLE LT_RETURN INTO LS_RETURN INDEX 1.

P_MON = LS_RETURN-FIELDVAL.

CLEAR LS_RETURN.

ENDIF.

ENDFORM. " F4_MONTH

*&---------------------------------------------------------------------*

*& Form VALIDATE_SCREEN

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM VALIDATE_SCREEN .

IF P_SO = 'X'.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'SOR'.

SCREEN-INPUT = 1.

SCREEN-INVISIBLE = 0.

MODIFY SCREEN.

ELSEIF SCREEN-GROUP1 = 'WBS'.

SCREEN-INPUT = 0.

SCREEN-INVISIBLE = 1.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'SOR'.

SCREEN-INPUT = 0.

SCREEN-INVISIBLE = 1.

MODIFY SCREEN.

ELSEIF SCREEN-GROUP1 = 'WBS'.

SCREEN-INPUT = 1.

SCREEN-INVISIBLE = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. " VALIDATE_SCREEN

*&---------------------------------------------------------------------*

*& Form GET_POSTING_DATE

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM GET_POSTING_DATE .

DATA: F_DATE TYPE SY-DATUM,

LV_DATE TYPE CHAR8,

LV_YYMM TYPE JVA_PROD_MONTH,

L_DATE TYPE SY-DATUM,

L_YEAR TYPE GJAHR,

L_MON TYPE FCMNR.

*----Get Posting Priod from Fiscal year and month

CLEAR: L_YEAR, L_MON, L_DATE, F_DATE, LV_DATE.

IF P_MON = '01'.

L_YEAR = P_YEAR.

L_MON = '04'.

ELSEIF P_MON = '02'.

L_YEAR = P_YEAR.

L_MON = '05'.

ELSEIF P_MON = '03'.

L_YEAR = P_YEAR.

L_MON = '06'.

ELSEIF P_MON = '04'.

L_YEAR = P_YEAR.

L_MON = '07'.

ELSEIF P_MON = '05'.

L_YEAR = P_YEAR.

L_MON = '08'.

ELSEIF P_MON = '06'.

L_YEAR = P_YEAR.

L_MON = '09'.

ELSEIF P_MON = '07'.

L_YEAR = P_YEAR.

L_MON = '10'.

ELSEIF P_MON = '08'.

L_YEAR = P_YEAR.

L_MON = '11'.

ELSEIF P_MON = '09'.

L_YEAR = P_YEAR.

L_MON = '12'.

ELSEIF P_MON = '10'.

L_YEAR = P_YEAR + 1.

L_MON = '01'.

ELSEIF P_MON = '11'.

L_YEAR = P_YEAR + 1.

L_MON = '02'.

ELSEIF P_MON = '12'.

L_YEAR = P_YEAR + 1.

L_MON = '03'.

ENDIF.

* CONCATENATE L_YEAR L_MON '01' INTO LV_DATE.

* CONCATENATE L_YEAR '04' '01' INTO LV_DATE. " cOMMENT ON 28.02.2012 BY NiLESH PATEL

CONCATENATE P_YEAR '04' '01' INTO LV_DATE. " ADD ON 28.02.2012 BY NILESH PATEL

F_DATE = LV_DATE.

CONCATENATE L_YEAR L_MON INTO LV_YYMM.

CALL FUNCTION 'JVA_LAST_DATE_OF_MONTH'

EXPORTING

YEAR_MONTH = LV_YYMM

IMPORTING

LAST_DATE_OF_MONTH = L_DATE

EXCEPTIONS

INVALIDE_MONTH = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

REFRESH S_DATE.

S_DATE-SIGN = 'I'.

S_DATE-OPTION = 'BT'.

S_DATE-LOW = F_DATE.

S_DATE-HIGH = L_DATE.

APPEND S_DATE.

REFRESH S_MON.

S_MON-SIGN = 'I'.

S_MON-OPTION = 'BT'.

S_MON-LOW = '01'.

S_MON-HIGH = P_MON.

APPEND S_MON.

ENDFORM. " GET_POSTING_DATE

*&---------------------------------------------------------------------*

*& Form GET_DATA

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM GET_DATA .

*-----Get Data according to Sales Order/item

IF P_SO = 'X'.

*----If user gives SO/item, then fetch from AFPO Table

IF S_ORDER[] IS NOT INITIAL.

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

WHERE KDAUF IN S_ORDER

AND KDPOS IN S_ITEM

AND DAUAT IN S_TYPE.

ELSE.

*----If user gives only month & year, then take all orders from COEP table

SELECT KOKRS BELNR BUZEI PERIO GJAHR OBJNR

FROM COEP

INTO TABLE GT_COEP

WHERE PERIO IN S_MON

AND GJAHR = P_YEAR

AND OBJNR LIKE 'OR%'.

IF GT_COEP[] IS NOT INITIAL.

LOOP AT GT_COEP INTO GS_COEP.

GS_COEP-AUFNR = GS_COEP-OBJNR+2(12).

MODIFY GT_COEP FROM GS_COEP TRANSPORTING AUFNR.

ENDLOOP.

SORT GT_COEP BY AUFNR.

DELETE ADJACENT DUPLICATES FROM GT_COEP COMPARING AUFNR.

*-----According to COEP table, fetch SO/item from AFPO Table

IF GT_COEP[] IS NOT INITIAL.

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

FOR ALL ENTRIES IN GT_COEP

WHERE AUFNR = GT_COEP-AUFNR.

ENDIF.

GT_AFPO_C[] = GT_AFPO[].

SORT GT_AFPO_C BY KDAUF KDPOS.

DELETE ADJACENT DUPLICATES FROM GT_AFPO_C COMPARING KDAUF KDPOS.

IF GT_AFPO_C[] IS NOT INITIAL.

REFRESH GT_AFPO.

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

FOR ALL ENTRIES IN GT_AFPO_C

WHERE KDAUF = GT_AFPO_C-KDAUF

AND KDPOS = GT_AFPO_C-KDPOS

AND DAUAT IN S_TYPE.

ENDIF.

ENDIF.

ENDIF.

REFRESH GT_AFPO_C.

GT_AFPO_C[] = GT_AFPO[].

*-----According to AFPO table, fetch SO/item details from VBAP Table

SORT GT_AFPO BY KDAUF KDPOS.

DELETE ADJACENT DUPLICATES FROM GT_AFPO COMPARING KDAUF KDPOS.

IF GT_AFPO[] IS NOT INITIAL.

SELECT VBELN POSNR PS_PSP_PNR MATNR ARKTX

KWMENG AS ZMENG

KZWI1

FROM VBAP

INTO TABLE GT_VBAP

FOR ALL ENTRIES IN GT_AFPO

WHERE VBELN = GT_AFPO-KDAUF

AND POSNR = GT_AFPO-KDPOS.

*** START Edition By Nilesh Patel on 03.03.2012 **********************************************

*-----According to Sales Oredr ,Header Material, Fetch Sales price

IF GT_VBAP[] IS NOT INITIAL.

SELECT VBELN KNUMV FROM VBAK

INTO TABLE GT_VBAK

FOR ALL ENTRIES IN GT_VBAP

WHERE VBELN = GT_VBAP-VBELN.

IF GT_VBAK[] IS NOT INITIAL.

DATA: IDX TYPE SY-TABIX.

LOOP AT GT_VBAP INTO GS_VBAP.

IDX = SY-TABIX.

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

GS_VBAP-KNUMV = GS_VBAK-KNUMV.

ENDIF.

MODIFY GT_VBAP FROM GS_VBAP INDEX IDX TRANSPORTING KNUMV.

CLEAR GS_VBAP.

ENDLOOP.

SELECT KNUMV KPOSN KSCHL KBETR KWERT

FROM KONV

INTO TABLE GT_KONV

FOR ALL ENTRIES IN GT_VBAP

WHERE KNUMV = GT_VBAP-KNUMV

AND KPOSN = GT_VBAP-POSNR

AND KSCHL IN ('TPR1', 'TPR2', 'TPR3').

ENDIF.

ENDIF.

*********** END Addotion by Nilesh Patel on 03.03.2012*****************************************

ENDIF.

*-----Get Data according to WBS Element

ELSE.

*----If user gives WBS, then fetch from AFPO Table

IF S_WBS[] IS NOT INITIAL.

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

WHERE PROJN IN S_WBS

AND DAUAT IN S_TYPE.

ELSE.

*----If user gives only month & year, then take all orders from COEP table

SELECT KOKRS BELNR BUZEI PERIO GJAHR OBJNR

FROM COEP

INTO TABLE GT_COEP

WHERE PERIO IN S_MON

AND GJAHR = P_YEAR

AND OBJNR LIKE 'OR%'.

IF GT_COEP[] IS NOT INITIAL.

LOOP AT GT_COEP INTO GS_COEP.

GS_COEP-AUFNR = GS_COEP-OBJNR+2(12).

MODIFY GT_COEP FROM GS_COEP TRANSPORTING AUFNR.

ENDLOOP.

SORT GT_COEP BY AUFNR.

DELETE ADJACENT DUPLICATES FROM GT_COEP COMPARING AUFNR.

*-----According to COEP table, fetch WBS from AFPO Table

IF GT_COEP[] IS NOT INITIAL.

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

FOR ALL ENTRIES IN GT_COEP

WHERE AUFNR = GT_COEP-AUFNR.

ENDIF.

GT_AFPO_C[] = GT_AFPO[].

SORT GT_AFPO_C BY PROJN.

DELETE ADJACENT DUPLICATES FROM GT_AFPO_C COMPARING PROJN.

IF GT_AFPO_C[] IS NOT INITIAL.

REFRESH GT_AFPO. " Added 13.08.2011

SELECT AUFNR POSNR KDAUF KDPOS PROJN DAUAT MATNR

FROM AFPO

INTO TABLE GT_AFPO

FOR ALL ENTRIES IN GT_AFPO_C

WHERE PROJN = GT_AFPO_C-PROJN

AND DAUAT IN S_TYPE.

ENDIF.

ENDIF.

ENDIF.

GT_AFPO_C[] = GT_AFPO[].

SORT GT_AFPO BY PROJN.

DELETE ADJACENT DUPLICATES FROM GT_AFPO COMPARING PROJN.

*-----According to AFPO table, fetch WBS details from VBAP Table

IF GT_AFPO[] IS NOT INITIAL.

SELECT VBELN POSNR PS_PSP_PNR MATNR ARKTX

KWMENG AS ZMENG KZWI1

FROM VBAP

INTO TABLE GT_VBAP

FOR ALL ENTRIES IN GT_AFPO

WHERE PS_PSP_PNR = GT_AFPO-PROJN.

* and PS_PSP_PNR is NOT NULL.

DELETE GT_VBAP WHERE PS_PSP_PNR IS INITIAL.

*-----According to Header Material, Fetch Agreed price only for WBS element

IF GT_VBAP[] IS NOT INITIAL.

SELECT VBELN KNUMV FROM VBAK

INTO TABLE GT_VBAK

FOR ALL ENTRIES IN GT_VBAP

WHERE VBELN = GT_VBAP-VBELN.

IF GT_VBAK[] IS NOT INITIAL.

* DATA: IDX TYPE SY-TABIX.

LOOP AT GT_VBAP INTO GS_VBAP.

IDX = SY-TABIX.

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

GS_VBAP-KNUMV = GS_VBAK-KNUMV.

ENDIF.

MODIFY GT_VBAP FROM GS_VBAP INDEX IDX TRANSPORTING KNUMV.

CLEAR GS_VBAP.

ENDLOOP.

SELECT KNUMV KPOSN KSCHL KBETR KWERT

FROM KONV

INTO TABLE GT_KONV

FOR ALL ENTRIES IN GT_VBAP

WHERE KNUMV = GT_VBAP-KNUMV

AND KPOSN = GT_VBAP-POSNR

AND KSCHL IN ('TPA1', 'TPA2', 'TPA3').

ENDIF.

ENDIF.

ENDIF.

ENDIF.

*----Fetch Current month opening inventory from Ztable

SELECT * FROM YCO_RECON_OPEN INTO TABLE GT_OPEN

WHERE ZYEAR = P_YEAR

AND VBELN IN S_ORDER

AND POSNR IN S_ITEM

AND PROJN IN S_WBS

AND AUART IN S_TYPE.

*----Prepare Final SO/item or WBS with is in WIP

PERFORM GET_GR_DETAILS.

SORT GT_AFPO_C BY AUFNR.

DELETE ADJACENT DUPLICATES FROM GT_AFPO_C COMPARING AUFNR.

*----Fetch Standard material Cost

PERFORM FETCH_STD_MAT_COST.

*----Fetch Booked Cost

PERFORM FETCH_COST_BOOK.

*----Fetch Standard Time

PERFORM GET_STANDARD_TIME.

*----Fetch Actual Time

PERFORM GET_ACTUAL_TIME.

ENDFORM. " GET_DATA

*&---------------------------------------------------------------------*

*& Form GET_GR_DETAILS

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM GET_GR_DETAILS .

DATA: GS_MSEG1 TYPE GTY_MSEG.

*----Fetch GR Data of this month according to SO/item or WBS

IF GT_VBAP[] IS NOT INITIAL.

IF P_SO = 'X'.

SELECT MBLNR_I MJAHR_I ZEILE_I BUDAT BWART_I KDAUF_I KDPOS_I PS_PSP_PNR_I SMBLN_I SMBLP_I AUFNR_I MENGE_I MEINS_I

FROM WB2_V_MKPF_MSEG2

INTO TABLE GT_MSEG

FOR ALL ENTRIES IN GT_VBAP

WHERE KDAUF_I = GT_VBAP-VBELN

AND KDPOS_I = GT_VBAP-POSNR

AND BWART_I IN ('321', '322')

AND AUFNR_I NE ' '

AND XAUTO_I = ' '

AND BUDAT IN S_DATE.

ELSE.

SELECT MBLNR_I MJAHR_I ZEILE_I BUDAT BWART_I KDAUF_I KDPOS_I PS_PSP_PNR_I SMBLN_I SMBLP_I AUFNR_I MENGE_I MEINS_I

FROM WB2_V_MKPF_MSEG2

INTO TABLE GT_MSEG

FOR ALL ENTRIES IN GT_VBAP

WHERE PS_PSP_PNR_I = GT_VBAP-PS_PSP_PNR

AND BWART_I IN ('321', '322')

AND AUFNR_I NE ' '

AND XAUTO_I = ' '

AND BUDAT IN S_DATE.

ENDIF.

ENDIF.

*----Calculate GR qty excluding reversal of 321 mvt

LOOP AT GT_MSEG INTO GS_MSEG WHERE BWART_I = '321'.

READ TABLE GT_MSEG INTO GS_MSEG1 WITH KEY SMBLN_I = GS_MSEG-MBLNR_I

SMBLP_I = GS_MSEG-ZEILE_I

BWART_I = '322'.

IF SY-SUBRC = 0.

GS_GR-MENGE_I = GS_MSEG-MENGE_I - GS_MSEG1-MENGE_I.

ELSE.

GS_GR-MENGE_I = GS_MSEG-MENGE_I.

ENDIF.

GS_GR-KDAUF_I = GS_MSEG-KDAUF_I.

GS_GR-KDPOS_I = GS_MSEG-KDPOS_I.

GS_GR-PS_PSP_PNR_I = GS_MSEG-PS_PSP_PNR_I.

IF GS_GR-MENGE_I IS NOT INITIAL.

GS_GR-MEINS_I = GS_MSEG-MEINS_I. " Add By Nilesh Patel on 22.12.2011

COLLECT GS_GR INTO GT_GR.

ENDIF.

CLEAR: GS_GR, GS_MSEG, GS_MSEG1.

ENDLOOP.

REFRESH GT_CLOSE.

IF P_SO = 'X'.

LOOP AT GT_GR INTO GS_GR.

READ TABLE GT_OPEN INTO GS_OPEN WITH KEY VBELN = GS_GR-KDAUF_I

POSNR = GS_GR-KDPOS_I.

IF SY-SUBRC = 0.

IF GS_OPEN-CLOSEINV = GS_GR-MENGE_I.

GS_CLOSE-KDAUF = GS_GR-KDAUF_I.

GS_CLOSE-KDPOS = GS_GR-KDPOS_I.

GS_CLOSE-PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

GS_CLOSE-MENGE = GS_GR-MENGE_I.

APPEND GS_CLOSE TO GT_CLOSE.

* DELETE GT_VBAP WHERE VBELN = GS_GR-KDAUF_I AND POSNR = GS_GR-KDPOS_I.

* DELETE GT_AFPO WHERE KDAUF = GS_GR-KDAUF_I AND KDPOS = GS_GR-KDPOS_I.

* DELETE GT_GR WHERE KDAUF_I = GS_GR-KDAUF_I AND KDPOS_I = GS_GR-KDPOS_I.

* DELETE GT_AFPO_C WHERE KDAUF = GS_GR-KDAUF_I AND KDPOS = GS_GR-KDPOS_I.

ENDIF.

ELSE.

READ TABLE GT_VBAP INTO GS_VBAP WITH KEY VBELN = GS_GR-KDAUF_I

POSNR = GS_GR-KDPOS_I.

IF SY-SUBRC = 0.

IF GS_VBAP-ZMENG = GS_GR-MENGE_I.

GS_CLOSE-KDAUF = GS_GR-KDAUF_I.

GS_CLOSE-KDPOS = GS_GR-KDPOS_I.

GS_CLOSE-MENGE = GS_GR-MENGE_I.

APPEND GS_CLOSE TO GT_CLOSE.

* DELETE GT_VBAP WHERE VBELN = GS_GR-KDAUF_I AND POSNR = GS_GR-KDPOS_I.

* DELETE GT_AFPO WHERE KDAUF = GS_GR-KDAUF_I AND KDPOS = GS_GR-KDPOS_I.

* DELETE GT_GR WHERE KDAUF_I = GS_GR-KDAUF_I AND KDPOS_I = GS_GR-KDPOS_I.

* DELETE GT_AFPO_C WHERE KDAUF = GS_GR-KDAUF_I AND KDPOS = GS_GR-KDPOS_I.

ENDIF.

ENDIF.

ENDIF.

CLEAR: GS_GR, GS_CLOSE.

ENDLOOP.

ELSE.

LOOP AT GT_GR INTO GS_GR.

READ TABLE GT_OPEN INTO GS_OPEN WITH KEY PROJN = GS_GR-PS_PSP_PNR_I.

IF SY-SUBRC = 0.

IF GS_OPEN-CLOSEINV = GS_GR-MENGE_I.

GS_CLOSE-PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

GS_CLOSE-MENGE = GS_GR-MENGE_I.

APPEND GS_CLOSE TO GT_CLOSE.

* DELETE GT_VBAP WHERE PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

* DELETE GT_AFPO WHERE PROJN = GS_GR-PS_PSP_PNR_I.

* DELETE GT_GR WHERE PS_PSP_PNR_I = GS_GR-PS_PSP_PNR_I.

* DELETE GT_AFPO_C WHERE PROJN = GS_GR-PS_PSP_PNR_I.

ENDIF.

ELSE.

READ TABLE GT_VBAP INTO GS_VBAP WITH KEY PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

IF SY-SUBRC = 0.

IF GS_VBAP-ZMENG = GS_GR-MENGE_I.

GS_CLOSE-PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

GS_CLOSE-MENGE = GS_GR-MENGE_I.

APPEND GS_CLOSE TO GT_CLOSE.

* DELETE GT_VBAP WHERE PS_PSP_PNR = GS_GR-PS_PSP_PNR_I.

* DELETE GT_AFPO WHERE PROJN = GS_GR-PS_PSP_PNR_I.

* DELETE GT_GR WHERE PS_PSP_PNR_I = GS_GR-PS_PSP_PNR_I.

* DELETE GT_AFPO_C WHERE PROJN = GS_GR-PS_PSP_PNR_I.

ENDIF.

ENDIF.

ENDIF.

CLEAR: GS_GR, GS_CLOSE.

ENDLOOP.

ENDIF.

ENDFORM. " GET_GR_DETAILS

*&---------------------------------------------------------------------*

*& Form FETCH_STD_MAT_COST

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM FETCH_STD_MAT_COST .

IF GT_VBAP[] IS NOT INITIAL.

IF P_SO = 'X'.

SELECT KALNR KALKA KADKY MATNR VBELN POSNR

FROM KEKO

INTO TABLE GT_KEKO

FOR ALL ENTRIES IN GT_VBAP

WHERE VBELN = GT_VBAP-VBELN

AND POSNR = GT_VBAP-POSNR

AND MATNR = GT_VBAP-MATNR

AND KALKA = '18'.

IF SY-SUBRC = 0.

SELECT KALNR KALKA KADKY KKZST KST001 KST002 KST004 KST005 KST007

FROM KEPH

INTO TABLE GT_KEPH

FOR ALL ENTRIES IN GT_KEKO

WHERE KALNR = GT_KEKO-KALNR

AND KKZST = ' '.

ENDIF.

ELSE.

SELECT KALNR KALKA KADKY MATNR VBELN POSNR

FROM KEKO

INTO TABLE GT_KEKO

FOR ALL ENTRIES IN GT_VBAP

WHERE MATNR = GT_VBAP-MATNR

AND KADKY IN S_DATE

AND KALKA = '01'.

IF SY-SUBRC = 0.

SELECT KALNR KALKA KADKY KKZST KST001 KST002 KST004 KST005 KST007

FROM KEPH

INTO TABLE GT_KEPH

FOR ALL ENTRIES IN GT_KEKO

WHERE KALNR = GT_KEKO-KALNR

AND KKZST = ' '.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " FETCH_STD_MAT_COST

*&---------------------------------------------------------------------*

*& Form FETCH_COST_BOOK

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM FETCH_COST_BOOK .

DATA: LV_OBJNR TYPE COEP-OBJNR.

REFRESH GT_MSEG.

* IF GT_VBAP[] IS NOT INITIAL. "" COmment START on 29.08.2011 By Nilesh Patel ***************

* refresh s_matnr.

* s_matnr-sign = 'I'.

* s_matnr-option = 'BT'.

* s_matnr-low = '000000007000000000'.

* CALL FUNCTION 'CONVERSION_EXIT_CCMAT_INPUT'

* EXPORTING

* INPUT = s_matnr-low

* IMPORTING

* OUTPUT = s_matnr-low.

*

* s_matnr-high = '000000007999999999'.

* CALL FUNCTION 'CONVERSION_EXIT_CCMAT_INPUT'

* EXPORTING

* INPUT = s_matnr-high

* IMPORTING

* OUTPUT = s_matnr-high.

* append s_matnr.

" COmment START on 29.08.2011 By Nilesh Patel ***************

* IF P_SO = 'X'.

* SELECT MBLNR_I MJAHR_I ZEILE_I BUDAT BWART_I KDAUF_I KDPOS_I PS_PSP_PNR_I

* SMBLN_I SMBLP_I AUFNR_I MENGE_I LGORT_I MATNR_I MAT_KDAUF_I MAT_KDPOS_I MAT_PSPNR_I

* FROM WB2_V_MKPF_MSEG2

* INTO TABLE GT_MSEG

* FOR ALL ENTRIES IN GT_VBAP

* WHERE MAT_KDAUF_I = GT_VBAP-VBELN

* AND MAT_KDPOS_I = GT_VBAP-POSNR

* AND AUFNR_I EQ ''

* AND SHKZG_I = 'S'

* AND BWART_I IN ('101', '102', '413', '415', '561', '301', '309', '412', '413', '414', '415', '416', '221', '222', '281', '282').

** AND MATNR_I in s_matnr "LIKE '000000007%'

** AND BUDAT IN S_DATE.

* ELSE.

* SELECT MBLNR_I MJAHR_I ZEILE_I BUDAT BWART_I KDAUF_I KDPOS_I PS_PSP_PNR_I

* SMBLN_I SMBLP_I AUFNR_I MENGE_I LGORT_I MATNR_I MAT_KDAUF_I MAT_KDPOS_I MAT_PSPNR_I

* FROM WB2_V_MKPF_MSEG2

* INTO TABLE GT_MSEG

* FOR ALL ENTRIES IN GT_VBAP

* WHERE MAT_PSPNR_I = GT_VBAP-PS_PSP_PNR

* AND AUFNR_I = ''

* AND SHKZG_I = 'S'

* AND BWART_I IN ('101', '102', '413', '415', '561', '301', '309', '412', '413', '414', '415', '416', '221', '222', '281', '282').

** AND MATNR_I not LIKE '000000007%'

** AND BUDAT IN S_DATE.

* ENDIF.

* ENDIF.

* DELETE GT_MSEG WHERE LGORT_I = 'SF01'.

* DELETE GT_MSEG WHERE LGORT_I = 'FG01'.

* SORT GT_MSEG BY MATNR_I.

* DELETE ADJACENT DUPLICATES FROM GT_MSEG COMPARING MATNR_I.

******* Comment END on 29.08.2011 By Nilesh Patel **********************

REFRESH GT_COEP.

BREAK HPABAP.

IF GT_AFPO_C[] IS NOT INITIAL.

LOOP AT GT_AFPO_C INTO GS_AFPO_C.

CONCATENATE 'OR' GS_AFPO_C-AUFNR INTO LV_OBJNR.

GS_AFPO_C-OBJNR = LV_OBJNR.

MODIFY GT_AFPO_C FROM GS_AFPO_C TRANSPORTING OBJNR.

CLEAR: GS_AFPO_C, LV_OBJNR.

ENDLOOP.

SELECT KOKRS BELNR BUZEI PERIO GJAHR OBJNR KSTAR MATNR WRTTP BEKNZ WTGBTR MEGBTR

FROM COEP

INTO TABLE GT_COEP

FOR ALL ENTRIES IN GT_AFPO_C

WHERE PERIO IN S_MON

AND GJAHR = P_YEAR

AND OBJNR = GT_AFPO_C-OBJNR

AND WRTTP = '04'

AND BEKNZ IN ('S', 'H').

IF SY-SUBRC = 0.

SORT GT_AFPO_C BY OBJNR MATNR.

SORT GT_COEP BY OBJNR MATNR.

LOOP AT GT_COEP INTO GS_COEP." where beknz = 'D' or beknz = 'C'.

IF GS_COEP-BEKNZ = 'H'.

* GS_COEP-WTGBTR = GS_COEP-WTGBTR * ( -1 ). " Comment on 29.08.2011 By Nilesh Patel

GS_COEP-WTGBTR = GS_COEP-WTGBTR . " Add on 29.08.2011 By Nilesh Patel

ENDIF.

READ TABLE GT_AFPO_C INTO GS_AFPO_C WITH KEY OBJNR = GS_COEP-OBJNR.

IF SY-SUBRC = 0.

GS_BOOK-VBELN = GS_AFPO_C-KDAUF.

GS_BOOK-POSNR = GS_AFPO_C-KDPOS.

GS_BOOK-PS_PSP_PNR = GS_AFPO_C-PROJN.

* ENDIF.

IF GS_COEP-KSTAR = '0003002003'. "Offloading

GS_BOOK-BK_OFF = GS_COEP-WTGBTR.

ELSEIF GS_COEP-KSTAR = '0007430000'. "SVM

GS_BOOK-BK_SVM = GS_COEP-WTGBTR.

ELSEIF GS_COEP-KSTAR = '0007430001'. "SFM

GS_BOOK-BK_SFM = GS_COEP-WTGBTR.

ELSEIF GS_COEP-KSTAR = '0007430010'. "SMM

GS_BOOK-BK_SMM = GS_COEP-WTGBTR.

ELSEIF GS_COEP-KSTAR = '0009410000'. "COH

GS_BOOK-BK_COH = GS_COEP-WTGBTR.

ELSE.

" Remove Comment STRAT By Nilesh Patel

* READ TABLE GT_AFPO_C INTO GS_AFPO_C WITH KEY MATNR = GS_COEP-MATNR. " Comment on 20.12.2011

* IF SY-SUBRC NE 0.

* GS_BOOK-BK_MATC = GS_COEP-WTGBTR.

************* STRAT Addition on 20.12.2011 By Nilesh Patel ***************************

READ TABLE GT_AFPO_C INTO GS_AFPO_C WITH KEY OBJNR = GS_COEP-OBJNR.

IF SY-SUBRC = 0.

IF P_SO = 'X'.

READ TABLE GT_AFPO_C INTO GS_AFPO WITH KEY KDAUF = GS_AFPO_C-KDAUF

KDPOS = GS_AFPO_C-KDPOS

MATNR = GS_COEP-MATNR.

IF SY-SUBRC NE 0.

GS_BOOK-BK_MATC = GS_COEP-WTGBTR.

ELSE.

CLEAR: GS_BOOK, GS_COEP, GS_AFPO_C,GS_AFPO,GS_VBAP.

CONTINUE.

ENDIF.

ELSE.

READ TABLE GT_AFPO_C INTO GS_AFPO WITH KEY PROJN = GS_AFPO_C-PROJN

MATNR = GS_COEP-MATNR.

IF SY-SUBRC NE 0.

GS_BOOK-BK_MATC = GS_COEP-WTGBTR.

ELSE.

CLEAR: GS_BOOK, GS_COEP,GS_AFPO_C,GS_AFPO,GS_VBAP.

CONTINUE.

ENDIF.

ENDIF.

************* END Addition on 20.12.2011 By Nilesh Patel

ELSE.

CLEAR: GS_BOOK, GS_COEP, GS_AFPO_C.

CONTINUE.

ENDIF.

* if gs_coep-matnr+8(1) = '7'.

" Comment START By Nilesh Patel

* IF P_SO = 'X'.

* READ TABLE GT_MSEG INTO GS_MSEG WITH KEY MAT_KDAUF_I = GS_AFPO_C-KDAUF

* MAT_KDPOS_I = GS_AFPO_C-KDPOS

* MATNR_I = GS_COEP-MATNR.

* IF SY-SUBRC EQ 0.

* GS_BOOK-BK_MATC = GS_COEP-WTGBTR.

* ELSE.

* CLEAR: GS_BOOK, GS_COEP, GS_AFPO_C.

* CONTINUE.

* ENDIF.

* ELSE.

* READ TABLE GT_MSEG INTO GS_MSEG WITH KEY MAT_PSPNR_I = GS_AFPO_C-PROJN

* MATNR_I = GS_COEP-MATNR.

* IF SY-SUBRC EQ 0.

* GS_BOOK-BK_MATC = GS_COEP-WTGBTR.

* ELSE.

* CLEAR: GS_BOOK, GS_COEP, GS_AFPO_C.

* CONTINUE.

* ENDIF.

* ENDIF.

" Comment END By Nilesh Patel

ENDIF.

GS_BOOK-BK_TOTAL = GS_BOOK-BK_MATC + GS_BOOK-BK_SMM + GS_BOOK-BK_SVM

+ GS_BOOK-BK_SFM + GS_BOOK-BK_COH + GS_BOOK-BK_OFF.

COLLECT GS_BOOK INTO GT_BOOK.

ENDIF.

CLEAR: GS_BOOK, GS_COEP, GS_AFPO_C.

ENDLOOP.

DELETE GT_BOOK WHERE VBELN IS INITIAL AND PS_PSP_PNR IS INITIAL.

ENDIF.

ENDIF.

ENDFORM. " FETCH_COST_BOOK

*&---------------------------------------------------------------------*

*& Form GET_STANDARD_TIME

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM GET_STANDARD_TIME .

IF P_SO = 'X'.

IF GT_VBAP[] IS NOT INITIAL.

SELECT AUFNR AUFPL KDAUF KDPOS PSPEL

FROM CAUFV

INTO TABLE GT_CAUFV

FOR ALL ENTRIES IN GT_VBAP

WHERE KDAUF = GT_VBAP-VBELN

AND KDPOS = GT_VBAP-POSNR.

IF SY-SUBRC = 0.

SELECT AUFPL BMSCH VGW01 VGW02 VGW03

FROM AFVV

INTO TABLE GT_AFVV

FOR ALL ENTRIES IN GT_CAUFV

WHERE AUFPL = GT_CAUFV-AUFPL.

SELECT AUFNR PROJN PGMNG

FROM AFPO

INTO TABLE GT_AFPO_Q

FOR ALL ENTRIES IN GT_CAUFV

WHERE AUFNR = GT_CAUFV-AUFNR.

ENDIF.

ENDIF.

LOOP AT GT_CAUFV INTO GS_CAUFV.

GS_STIME-KDAUF = GS_CAUFV-KDAUF.

GS_STIME-KDPOS = GS_CAUFV-KDPOS.

READ TABLE GT_AFVV INTO GS_AFVV WITH KEY AUFPL = GS_CAUFV-AUFPL.

IF SY-SUBRC = 0.

READ TABLE GT_AFPO_Q INTO GS_AFPO_Q WITH KEY AUFNR = GS_CAUFV-AUFNR.

IF SY-SUBRC = 0 .

GS_STIME-STIME = ( GS_AFVV-VGW01 * GS_AFPO_Q-PGMNG ) / 60.

* GS_STIME-STIME = ( ( GS_AFVV-VGW01 + GS_AFVV-VGW02 + GS_AFVV-VGW03 ) * GS_AFPO_Q-PGMNG ) / 60.

ENDIF.

ENDIF.

COLLECT GS_STIME INTO GT_STIME.

CLEAR: GS_STIME, GS_CAUFV.

ENDLOOP.

ELSE.

* IF GT_VBAP[] IS NOT INITIAL.

* SELECT AUFNR AUFPL KDAUF KDPOS PSPEL

* FROM CAUFV

* INTO TABLE GT_CAUFV

* FOR ALL ENTRIES IN GT_VBAP

* WHERE PSPEL = GT_VBAP-PS_PSP_PNR.

* IF SY-SUBRC = 0.

* SELECT AUFPL BMSCH VGW01 VGW02 VGW03

* FROM AFVV

* INTO TABLE GT_AFVV

* FOR ALL ENTRIES IN GT_CAUFV

* WHERE AUFPL = GT_CAUFV-AUFPL.

* SELECT AUFNR PGMNG

* FROM AFPO

* INTO TABLE GT_AFPO_Q

* FOR ALL ENTRIES IN GT_CAUFV

* WHERE AUFNR = GT_CAUFV-AUFNR.

* ENDIF.

* ENDIF.

IF GT_VBAP[] IS NOT INITIAL.

SELECT AUFNR PROJN PGMNG

FROM AFPO

INTO TABLE GT_AFPO_Q

FOR ALL ENTRIES IN GT_VBAP

WHERE PROJN = GT_VBAP-PS_PSP_PNR

AND DAUTY = '10'.

IF SY-SUBRC = 0.

SELECT AUFNR AUFPL

FROM AFKO

INTO TABLE GT_AFKO

FOR ALL ENTRIES IN GT_AFPO_Q

WHERE AUFNR = GT_AFPO_Q-AUFNR.

IF SY-SUBRC = 0.

SELECT AUFPL BMSCH VGW01 VGW02 VGW03

FROM AFVV

INTO TABLE GT_AFVV

FOR ALL ENTRIES IN GT_AFKO

WHERE AUFPL = GT_AFKO-AUFPL.

ENDIF.

ENDIF.

ENDIF.

* LOOP AT GT_CAUFV INTO GS_CAUFV.

* GS_STIME-PSPEL = GS_CAUFV-PSPEL.

* READ TABLE GT_AFVV INTO GS_AFVV WITH KEY AUFPL = GS_CAUFV-AUFPL.

* IF SY-SUBRC = 0.

* READ TABLE GT_AFPO_Q INTO GS_AFPO_Q WITH KEY AUFNR = GS_CAUFV-AUFNR.

* IF SY-SUBRC = 0 .

** GS_STIME-STIME = ( ( GS_AFVV-VGW01 + GS_AFVV-VGW02 + GS_AFVV-VGW03 ) * GS_AFPO_Q-PGMNG ) / 60.

* GS_STIME-STIME = ( GS_AFVV-VGW01 * GS_AFPO_Q-PGMNG ) / 60.

* ENDIF.

* ENDIF.

* COLLECT GS_STIME INTO GT_STIME.

* CLEAR: GS_STIME, GS_CAUFV.

* ENDLOOP.

LOOP AT GT_AFVV INTO GS_AFVV.

READ TABLE GT_AFKO INTO GS_AFKO WITH KEY AUFPL = GS_AFVV-AUFPL.

IF SY-SUBRC = 0.

READ TABLE GT_AFPO_Q INTO GS_AFPO_Q WITH KEY AUFNR = GS_AFKO-AUFNR.

IF SY-SUBRC = 0 .

GS_STIME-PSPEL = GS_AFPO_Q-PROJN.

GS_STIME-STIME = ( GS_AFVV-VGW01 * GS_AFPO_Q-PGMNG ) / 60.

ENDIF.

ENDIF.

COLLECT GS_STIME INTO GT_STIME.

CLEAR: GS_STIME, GS_AFVV.

ENDLOOP.

ENDIF.

ENDFORM. " GET_STANDARD_TIME

*&---------------------------------------------------------------------*

*& Form GET_ACTUAL_TIME

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM GET_ACTUAL_TIME .

IF P_SO = 'X'.

LOOP AT GT_COEP INTO GS_COEP WHERE KSTAR = '0007430010'.

* OR KSTAR = '0007430001'

* OR KSTAR = '0007430000'.

READ TABLE GT_AFPO_C INTO GS_AFPO_C WITH KEY OBJNR = GS_COEP-OBJNR.

IF SY-SUBRC = 0.

GS_ATIME-KDAUF = GS_AFPO_C-KDAUF.

GS_ATIME-KDPOS = GS_AFPO_C-KDPOS.

GS_ATIME-MEGBTR = GS_COEP-MEGBTR .

COLLECT GS_ATIME INTO GT_ATIME.

ENDIF.

CLEAR: GS_ATIME, GS_COEP, GS_AFPO_C.

ENDLOOP.

ELSE.

LOOP AT GT_COEP INTO GS_COEP WHERE KSTAR = '0007430010'.

* OR KSTAR = '0007430001'

* OR KSTAR = '0007430000'.

READ TABLE GT_AFPO_C INTO GS_AFPO_C WITH KEY OBJNR = GS_COEP-OBJNR.

IF SY-SUBRC = 0.

GS_ATIME-PROJN = GS_AFPO_C-PROJN.

GS_ATIME-MEGBTR = GS_COEP-MEGBTR .

COLLECT GS_ATIME INTO GT_ATIME.

ENDIF.

CLEAR: GS_ATIME, GS_COEP, GS_AFPO_C.

ENDLOOP.

ENDIF.

ENDFORM. " GET_ACTUAL_TIME

*&---------------------------------------------------------------------*

*& Form PROCESS_DATA

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM PROCESS_DATA .

DATA: LV_SALES TYPE KZWI1,

LV_LINE TYPE I.

LOOP AT GT_VBAP INTO GS_VBAP.

CLEAR LV_LINE.

GS_FINAL-VBELN = GS_VBAP-VBELN. "Sales Order

GS_FINAL-POSNR = GS_VBAP-POSNR. "SO Item

GS_FINAL-PS_PSP_PNR = GS_VBAP-PS_PSP_PNR. "WBS Element

GS_FINAL-MATNR = GS_VBAP-MATNR. "Header material

GS_FINAL-ARKTX = GS_VBAP-ARKTX. "Material Description

GS_FINAL-ZMENG = GS_VBAP-ZMENG. "Quantity

GS_FINAL-KZWI1 = GS_VBAP-KZWI1. "Value

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

READ TABLE GT_KONV INTO GS_KONV WITH KEY KNUMV = GS_VBAP-KNUMV

KPOSN = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

IF P_SO NE 'X'. " Add By Nilesh Patel;

GS_FINAL-KWERT = GS_KONV-KWERT. "Agreed Price

ENDIF.

* GS_FINAL-KWERT = GS_KONV-KWERT. "Agreed Price

ENDIF.

ENDIF.

*---For Sales order/item-----

IF P_SO = 'X'.

MOVE-CORRESPONDING GS_FINAL TO GS_FINAL1.

CLEAR: GS_FINAL1-ZMENG, GS_FINAL1-KZWI1, GS_FINAL1-KWERT.

LOOP AT GT_AFPO_C INTO GS_AFPO_C WHERE KDAUF = GS_VBAP-VBELN

AND KDPOS = GS_VBAP-POSNR

AND MATNR = GS_VBAP-MATNR.

LV_LINE = LV_LINE + 1.

IF LV_LINE = 1.

GS_FINAL-AUFNR = GS_AFPO_C-AUFNR. "Production Order

GS_FINAL-DAUAT = GS_AFPO_C-DAUAT. "Order Type

READ TABLE GT_OPEN INTO GS_OPEN WITH KEY VBELN = GS_VBAP-VBELN

POSNR = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-CLOSEINV = GS_OPEN-CLOSEINV.

GS_FINAL-MEINS = GS_OPEN-MEINS.

GS_FINAL-OP_MATC = GS_OPEN-MATCOST.

GS_FINAL-OP_SMM = GS_OPEN-SMM.

GS_FINAL-OP_SVM = GS_OPEN-SVM.

GS_FINAL-OP_SFM = GS_OPEN-SFM.

GS_FINAL-OP_COH = GS_OPEN-COH.

GS_FINAL-OP_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-OP_TOTAL = GS_OPEN-TOTAL.

DELETE GT_OPEN INDEX SY-TABIX.

ENDIF.

READ TABLE GT_BOOK INTO GS_BOOK WITH KEY VBELN = GS_VBAP-VBELN

POSNR = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-BK_MATC = GS_BOOK-BK_MATC.

GS_FINAL-BK_SMM = GS_BOOK-BK_SMM.

GS_FINAL-BK_SVM = GS_BOOK-BK_SVM.

GS_FINAL-BK_SFM = GS_BOOK-BK_SFM.

GS_FINAL-BK_COH = GS_BOOK-BK_COH.

GS_FINAL-BK_OFF = GS_BOOK-BK_OFF.

GS_FINAL-BK_TOTAL = GS_BOOK-BK_TOTAL.

ENDIF.

READ TABLE GT_GR INTO GS_GR WITH KEY KDAUF_I = GS_VBAP-VBELN

KDPOS_I = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-CP_QTY = GS_GR-MENGE_I.

GS_FINAL-CP_UNIT = GS_GR-MEINS_I.

IF GS_FINAL-CP_QTY IS NOT INITIAL.

GS_FINAL-CP_AGRVAL = GS_FINAL-CP_QTY * GS_KONV-KBETR.

ENDIF.

READ TABLE GT_KEKO INTO GS_KEKO WITH KEY VBELN = GS_VBAP-VBELN

POSNR = GS_VBAP-POSNR

MATNR = GS_VBAP-MATNR.

IF SY-SUBRC = 0.

READ TABLE GT_KEPH INTO GS_KEPH WITH KEY KALNR = GS_KEKO-KALNR.

IF SY-SUBRC = 0.

IF GS_VBAP-ZMENG IS NOT INITIAL. " Addition by nilesh patel on 26.06.2012

GS_FINAL-CP_MATC = ( GS_KEPH-KST001 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

GS_FINAL-CP_SMM = ( GS_KEPH-KST002 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

GS_FINAL-CP_SVM = ( GS_KEPH-KST004 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

GS_FINAL-CP_SFM = ( GS_KEPH-KST005 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

GS_FINAL-CP_COH = ( GS_KEPH-KST007 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

IF NOT GS_FINAL-BK_OFF IS INITIAL.

GS_FINAL-CP_OFF = ( GS_FINAL-OP_OFF + GS_FINAL-BK_OFF ).

ENDIF.

* GS_FINAL-CP_OFF = ( GS_KEPH-KST001 / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

GS_FINAL-CP_TOTAL = ( ( GS_KEPH-KST001 + GS_KEPH-KST002 + GS_KEPH-KST004 + GS_KEPH-KST005

+ GS_KEPH-KST007 ) / GS_VBAP-ZMENG ) * GS_GR-MENGE_I.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

READ TABLE GT_KEKO INTO GS_KEKO WITH KEY VBELN = GS_VBAP-VBELN

POSNR = GS_VBAP-POSNR

MATNR = GS_VBAP-MATNR.

IF SY-SUBRC = 0.

READ TABLE GT_KEPH INTO GS_KEPH WITH KEY KALNR = GS_KEKO-KALNR.

IF SY-SUBRC = 0.

GS_FINAL-STDMAT = ( GS_KEPH-KST001 + GS_KEPH-KST002 + GS_KEPH-KST004 + GS_KEPH-KST005

+ GS_KEPH-KST007 ).

ENDIF.

ENDIF.

READ TABLE GT_STIME INTO GS_STIME WITH KEY KDAUF = GS_VBAP-VBELN

KDPOS = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-STIME = GS_STIME-STIME.

ENDIF.

READ TABLE GT_ATIME INTO GS_ATIME WITH KEY KDAUF = GS_VBAP-VBELN

KDPOS = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-ATIME = GS_ATIME-MEGBTR.

ENDIF.

IF GS_FINAL-CLOSEINV IS NOT INITIAL.

GS_FINAL-CL_QTY = GS_FINAL-CLOSEINV - GS_FINAL-CP_QTY.

ELSE.

GS_FINAL-CL_QTY = GS_FINAL-ZMENG - GS_FINAL-CP_QTY.

ENDIF.

READ TABLE GT_CLOSE INTO GS_CLOSE WITH KEY KDAUF = GS_VBAP-VBELN

KDPOS = GS_VBAP-POSNR.

IF SY-SUBRC NE 0.

GS_FINAL-CL_MATC = ( GS_FINAL-OP_MATC + GS_FINAL-BK_MATC ) - GS_FINAL-CP_MATC.

GS_FINAL-CL_SMM = ( GS_FINAL-OP_SMM + GS_FINAL-BK_SMM ) - GS_FINAL-CP_SMM.

GS_FINAL-CL_SVM = ( GS_FINAL-OP_SVM + GS_FINAL-BK_SVM ) - GS_FINAL-CP_SVM.

GS_FINAL-CL_SFM = ( GS_FINAL-OP_SFM + GS_FINAL-BK_SFM ) - GS_FINAL-CP_SFM.

GS_FINAL-CL_COH = ( GS_FINAL-OP_COH + GS_FINAL-BK_COH ) - GS_FINAL-CP_COH.

GS_FINAL-CL_OFF = ( GS_FINAL-OP_OFF + GS_FINAL-BK_OFF ) - GS_FINAL-CP_OFF.

GS_FINAL-CL_TOTAL = ( GS_FINAL-OP_TOTAL + GS_FINAL-BK_TOTAL ) - GS_FINAL-CP_TOTAL.

ELSE.

GS_FINAL-CP_MATC = GS_FINAL-BK_MATC.

GS_FINAL-CP_SMM = GS_FINAL-BK_SMM.

GS_FINAL-CP_SVM = GS_FINAL-BK_SVM.

GS_FINAL-CP_SFM = GS_FINAL-BK_SFM.

GS_FINAL-CP_COH = GS_FINAL-BK_COH.

GS_FINAL-CP_OFF = GS_FINAL-BK_OFF.

GS_FINAL-CP_TOTAL = GS_FINAL-BK_TOTAL.

ENDIF.

IF GS_FINAL-ZMENG IS NOT INITIAL.

LV_SALES = ( GS_FINAL-KZWI1 / GS_FINAL-ZMENG ) * GS_FINAL-CP_QTY.

ENDIF.

GS_FINAL-CONTR = LV_SALES - ( GS_FINAL-CP_MATC + GS_FINAL-CP_SVM ).

IF LV_SALES IS NOT INITIAL.

GS_FINAL-PERC = ( GS_FINAL-CONTR / LV_SALES ) * 100.

ENDIF.

ELSE.

MOVE-CORRESPONDING GS_FINAL1 TO GS_FINAL.

GS_FINAL-AUFNR = GS_AFPO_C-AUFNR. "Production Order

GS_FINAL-DAUAT = GS_AFPO_C-DAUAT. "Order Type

ENDIF.

APPEND GS_FINAL TO GT_FINAL.

CLEAR: GS_VBAP, GS_GR, GS_BOOK, GS_OPEN, GS_STIME, GS_ATIME, LV_SALES, GS_FINAL.

ENDLOOP.

*----for WBS element

ELSE.

MOVE-CORRESPONDING GS_FINAL TO GS_FINAL1.

CLEAR: GS_FINAL1-ZMENG, GS_FINAL1-KZWI1, GS_FINAL1-KWERT.

LOOP AT GT_AFPO_C INTO GS_AFPO_C WHERE PROJN = GS_VBAP-PS_PSP_PNR

AND MATNR = GS_VBAP-MATNR.

LV_LINE = LV_LINE + 1.

IF LV_LINE = 1.

GS_FINAL-AUFNR = GS_AFPO_C-AUFNR. "Production Order

GS_FINAL-DAUAT = GS_AFPO_C-DAUAT. "Order Type

READ TABLE GT_OPEN INTO GS_OPEN WITH KEY PROJN = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC = 0.

GS_FINAL-CLOSEINV = GS_OPEN-CLOSEINV.

GS_FINAL-MEINS = GS_OPEN-MEINS.

GS_FINAL-OP_MATC = GS_OPEN-MATCOST.

GS_FINAL-OP_SMM = GS_OPEN-SMM.

GS_FINAL-OP_SVM = GS_OPEN-SVM.

GS_FINAL-OP_SFM = GS_OPEN-SFM.

GS_FINAL-OP_COH = GS_OPEN-COH.

GS_FINAL-OP_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-OP_TOTAL = GS_OPEN-TOTAL.

DELETE GT_OPEN INDEX SY-TABIX.

ENDIF.

READ TABLE GT_BOOK INTO GS_BOOK WITH KEY PS_PSP_PNR = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC = 0.

GS_FINAL-BK_MATC = GS_BOOK-BK_MATC.

GS_FINAL-BK_SMM = GS_BOOK-BK_SMM.

GS_FINAL-BK_SVM = GS_BOOK-BK_SVM.

GS_FINAL-BK_SFM = GS_BOOK-BK_SFM.

GS_FINAL-BK_COH = GS_BOOK-BK_COH.

GS_FINAL-BK_OFF = GS_BOOK-BK_OFF.

GS_FINAL-BK_TOTAL = GS_BOOK-BK_TOTAL.

ENDIF.

READ TABLE GT_GR INTO GS_GR WITH KEY PS_PSP_PNR_I = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC = 0.

GS_FINAL-CP_QTY = GS_GR-MENGE_I.

GS_FINAL-CP_UNIT = GS_GR-MEINS_I.

IF GS_FINAL-CP_QTY IS NOT INITIAL.

GS_FINAL-CP_AGRVAL = GS_FINAL-CP_QTY * GS_KONV-KBETR.

ENDIF.

READ TABLE GT_KEKO INTO GS_KEKO WITH KEY MATNR = GS_VBAP-MATNR.

IF SY-SUBRC = 0.

READ TABLE GT_KEPH INTO GS_KEPH WITH KEY KALNR = GS_KEKO-KALNR.

IF SY-SUBRC = 0.

GS_FINAL-CP_MATC = GS_KEPH-KST001 * GS_GR-MENGE_I.

GS_FINAL-CP_SMM = GS_KEPH-KST002 * GS_GR-MENGE_I.

GS_FINAL-CP_SVM = GS_KEPH-KST004 * GS_GR-MENGE_I.

GS_FINAL-CP_SFM = GS_KEPH-KST005 * GS_GR-MENGE_I.

GS_FINAL-CP_COH = GS_KEPH-KST007 * GS_GR-MENGE_I.

GS_FINAL-CP_OFF = GS_KEPH-KST001 * GS_GR-MENGE_I.

GS_FINAL-CP_TOTAL = ( GS_KEPH-KST001 + GS_KEPH-KST002 + GS_KEPH-KST004 + GS_KEPH-KST005

+ GS_KEPH-KST007 ) * GS_GR-MENGE_I.

ENDIF.

ENDIF.

ENDIF.

****Added For Standard Material Cost

SORT GT_KEPH BY KADKY DESCENDING.

******End

READ TABLE GT_KEKO INTO GS_KEKO WITH KEY MATNR = GS_VBAP-MATNR.

IF SY-SUBRC = 0.

READ TABLE GT_KEPH INTO GS_KEPH WITH KEY KALNR = GS_KEKO-KALNR.

IF SY-SUBRC = 0.

GS_FINAL-STDMAT = ( GS_KEPH-KST001 + GS_KEPH-KST002 + GS_KEPH-KST004 + GS_KEPH-KST005

+ GS_KEPH-KST007 ) * GS_VBAP-ZMENG.

ENDIF.

ENDIF.

READ TABLE GT_STIME INTO GS_STIME WITH KEY PSPEL = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC = 0.

GS_FINAL-STIME = GS_STIME-STIME.

ENDIF.

READ TABLE GT_ATIME INTO GS_ATIME WITH KEY PROJN = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC = 0.

GS_FINAL-ATIME = GS_ATIME-MEGBTR.

ENDIF.

IF GS_FINAL-CLOSEINV IS NOT INITIAL.

GS_FINAL-CL_QTY = GS_FINAL-CLOSEINV - GS_FINAL-CP_QTY.

ELSE.

GS_FINAL-CL_QTY = GS_FINAL-ZMENG - GS_FINAL-CP_QTY.

ENDIF.

READ TABLE GT_CLOSE INTO GS_CLOSE WITH KEY PS_PSP_PNR = GS_VBAP-PS_PSP_PNR.

IF SY-SUBRC NE 0.

GS_FINAL-CL_MATC = ( GS_FINAL-OP_MATC + GS_FINAL-BK_MATC ) - GS_FINAL-CP_MATC.

GS_FINAL-CL_SMM = ( GS_FINAL-OP_SMM + GS_FINAL-BK_SMM ) - GS_FINAL-CP_SMM.

GS_FINAL-CL_SVM = ( GS_FINAL-OP_SVM + GS_FINAL-BK_SVM ) - GS_FINAL-CP_SVM.

GS_FINAL-CL_SFM = ( GS_FINAL-OP_SFM + GS_FINAL-BK_SFM ) - GS_FINAL-CP_SFM.

GS_FINAL-CL_COH = ( GS_FINAL-OP_COH + GS_FINAL-BK_COH ) - GS_FINAL-CP_COH.

GS_FINAL-CL_OFF = ( GS_FINAL-OP_OFF + GS_FINAL-BK_OFF ) - GS_FINAL-CP_OFF.

GS_FINAL-CL_TOTAL = ( GS_FINAL-OP_TOTAL + GS_FINAL-BK_TOTAL ) - GS_FINAL-CP_TOTAL.

ELSE.

GS_FINAL-CP_MATC = GS_FINAL-BK_MATC.

GS_FINAL-CP_SMM = GS_FINAL-BK_SMM.

GS_FINAL-CP_SVM = GS_FINAL-BK_SVM.

GS_FINAL-CP_SFM = GS_FINAL-BK_SFM.

GS_FINAL-CP_COH = GS_FINAL-BK_COH.

GS_FINAL-CP_OFF = GS_FINAL-BK_OFF.

GS_FINAL-CP_TOTAL = GS_FINAL-BK_TOTAL.

ENDIF.

IF GS_FINAL-ZMENG IS NOT INITIAL.

LV_SALES = ( GS_FINAL-KZWI1 / GS_FINAL-ZMENG ) * GS_FINAL-CP_QTY.

ENDIF.

GS_FINAL-CONTR = LV_SALES - ( GS_FINAL-CP_MATC + GS_FINAL-CP_SVM ).

IF LV_SALES IS NOT INITIAL.

GS_FINAL-PERC = ( GS_FINAL-CONTR / LV_SALES ) * 100.

ENDIF.

ELSE.

MOVE-CORRESPONDING GS_FINAL1 TO GS_FINAL.

GS_FINAL-AUFNR = GS_AFPO_C-AUFNR. "Production Order

GS_FINAL-DAUAT = GS_AFPO_C-DAUAT. "Order Type

ENDIF.

APPEND GS_FINAL TO GT_FINAL.

CLEAR: GS_VBAP, GS_GR, GS_BOOK, GS_OPEN, GS_FINAL, GS_STIME, GS_ATIME, LV_SALES.

ENDLOOP.

ENDIF.

CLEAR: GS_FINAL1, GS_FINAL.

ENDLOOP.

DATA: IDX TYPE SY-TABIX.

IF P_SO = 'X'.

DELETE GT_OPEN WHERE PROJN IS NOT INITIAL.

IF GT_OPEN[] IS NOT INITIAL.

REFRESH GT_VBAP.

SELECT VBELN POSNR PS_PSP_PNR MATNR ARKTX

KWMENG AS ZMENG

KZWI1

FROM VBAP

INTO TABLE GT_VBAP

FOR ALL ENTRIES IN GT_OPEN

WHERE VBELN = GT_OPEN-VBELN

AND POSNR = GT_OPEN-POSNR.

*-----According to Header Material, Fetch Agreed price only for WBS element

IF GT_VBAP[] IS NOT INITIAL.

SELECT VBELN KNUMV FROM VBAK

INTO TABLE GT_VBAK

FOR ALL ENTRIES IN GT_VBAP

WHERE VBELN = GT_VBAP-VBELN.

IF GT_VBAK[] IS NOT INITIAL.

LOOP AT GT_VBAP INTO GS_VBAP.

IDX = SY-TABIX.

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

GS_VBAP-KNUMV = GS_VBAK-KNUMV.

ENDIF.

MODIFY GT_VBAP FROM GS_VBAP INDEX IDX TRANSPORTING KNUMV.

CLEAR GS_VBAP.

ENDLOOP.

SELECT KNUMV KPOSN KSCHL KBETR KWERT

FROM KONV

INTO TABLE GT_KONV

FOR ALL ENTRIES IN GT_VBAP

WHERE KNUMV = GT_VBAP-KNUMV

AND KPOSN = GT_VBAP-POSNR

AND KSCHL IN ('TPA1', 'TPA2', 'TPA3').

ENDIF.

ENDIF.

LOOP AT GT_OPEN INTO GS_OPEN.

READ TABLE GT_FINAL INTO GS_FINAL WITH KEY VBELN = GS_OPEN-VBELN "Sales Order

POSNR = GS_OPEN-POSNR. "SO Item

IF SY-SUBRC NE 0.

GS_FINAL-VBELN = GS_OPEN-VBELN.

GS_FINAL-POSNR = GS_OPEN-POSNR.

GS_FINAL-AUFNR = GS_OPEN-AUFNR. "Prod Order No Added on 18.08.2011

GS_FINAL-DAUAT = GS_OPEN-AUART. "Order Type

READ TABLE GT_VBAP INTO GS_VBAP WITH KEY VBELN = GS_OPEN-VBELN "Sales Order

POSNR = GS_OPEN-POSNR. "SO Item

IF SY-SUBRC EQ 0.

* GS_FINAL-PS_PSP_PNR = GS_VBAP-PS_PSP_PNR. "WBS Element

GS_FINAL-MATNR = GS_VBAP-MATNR. "Header material

GS_FINAL-ARKTX = GS_VBAP-ARKTX. "Material Description

GS_FINAL-ZMENG = GS_VBAP-ZMENG. "Quantity

GS_FINAL-KZWI1 = GS_VBAP-KZWI1. "Value

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

READ TABLE GT_KONV INTO GS_KONV WITH KEY KNUMV = GS_VBAP-KNUMV

KPOSN = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-KWERT = GS_KONV-KWERT. "Agreed Price

ENDIF.

ENDIF.

ENDIF.

GS_FINAL-CLOSEINV = GS_OPEN-CLOSEINV.

GS_FINAL-MEINS = GS_OPEN-MEINS.

GS_FINAL-OP_MATC = GS_OPEN-MATCOST.

GS_FINAL-OP_SMM = GS_OPEN-SMM.

GS_FINAL-OP_SVM = GS_OPEN-SVM.

GS_FINAL-OP_SFM = GS_OPEN-SFM.

GS_FINAL-OP_COH = GS_OPEN-COH.

GS_FINAL-OP_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-OP_TOTAL = GS_OPEN-TOTAL.

GS_FINAL-CL_QTY = GS_OPEN-CLOSEINV.

GS_FINAL-CL_MATC = GS_OPEN-MATCOST.

GS_FINAL-CL_SMM = GS_OPEN-SMM.

GS_FINAL-CL_SVM = GS_OPEN-SVM.

GS_FINAL-CL_SFM = GS_OPEN-SFM.

GS_FINAL-CL_COH = GS_OPEN-COH.

GS_FINAL-CL_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-CL_TOTAL = GS_OPEN-TOTAL.

APPEND GS_FINAL TO GT_FINAL.

ENDIF.

CLEAR: GS_FINAL, GS_OPEN.

ENDLOOP.

ENDIF.

ELSE.

DELETE GT_OPEN WHERE PROJN IS INITIAL.

IF GT_OPEN[] IS NOT INITIAL.

REFRESH GT_VBAP.

SELECT VBELN POSNR PS_PSP_PNR MATNR ARKTX

KWMENG AS ZMENG

KZWI1

FROM VBAP

INTO TABLE GT_VBAP

FOR ALL ENTRIES IN GT_OPEN

WHERE PS_PSP_PNR = GT_OPEN-PROJN.

*-----According to Header Material, Fetch Agreed price only for WBS element

IF GT_VBAP[] IS NOT INITIAL.

SELECT VBELN KNUMV FROM VBAK

INTO TABLE GT_VBAK

FOR ALL ENTRIES IN GT_VBAP

WHERE VBELN = GT_VBAP-VBELN.

IF GT_VBAK[] IS NOT INITIAL.

LOOP AT GT_VBAP INTO GS_VBAP.

IDX = SY-TABIX.

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

GS_VBAP-KNUMV = GS_VBAK-KNUMV.

ENDIF.

MODIFY GT_VBAP FROM GS_VBAP INDEX IDX TRANSPORTING KNUMV.

CLEAR GS_VBAP.

ENDLOOP.

SELECT KNUMV KPOSN KSCHL KBETR KWERT

FROM KONV

INTO TABLE GT_KONV

FOR ALL ENTRIES IN GT_VBAP

WHERE KNUMV = GT_VBAP-KNUMV

AND KPOSN = GT_VBAP-POSNR

AND KSCHL IN ('TPA1', 'TPA2', 'TPA3').

ENDIF.

ENDIF.

LOOP AT GT_OPEN INTO GS_OPEN.

READ TABLE GT_FINAL INTO GS_FINAL WITH KEY PS_PSP_PNR = GS_OPEN-PROJN. "WBS Element

IF SY-SUBRC NE 0.

GS_FINAL-PS_PSP_PNR = GS_OPEN-PROJN. "WBS Element

GS_FINAL-AUFNR = GS_OPEN-AUFNR. "Prod Order No Added on 18.08.2011

GS_FINAL-DAUAT = GS_OPEN-AUART. "Order Type

READ TABLE GT_VBAP INTO GS_VBAP WITH KEY PS_PSP_PNR = GS_OPEN-PROJN.

IF SY-SUBRC EQ 0.

GS_FINAL-VBELN = GS_OPEN-VBELN.

GS_FINAL-POSNR = GS_OPEN-POSNR.

GS_FINAL-MATNR = GS_VBAP-MATNR. "Header material

GS_FINAL-ARKTX = GS_VBAP-ARKTX. "Material Description

GS_FINAL-ZMENG = GS_VBAP-ZMENG. "Quantity

GS_FINAL-KZWI1 = GS_VBAP-KZWI1. "Value

READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN.

IF SY-SUBRC = 0.

READ TABLE GT_KONV INTO GS_KONV WITH KEY KNUMV = GS_VBAP-KNUMV

KPOSN = GS_VBAP-POSNR.

IF SY-SUBRC = 0.

GS_FINAL-KWERT = GS_KONV-KWERT. "Agreed Price

ENDIF.

ENDIF.

ENDIF.

GS_FINAL-CLOSEINV = GS_OPEN-CLOSEINV.

GS_FINAL-MEINS = GS_OPEN-MEINS.

GS_FINAL-OP_MATC = GS_OPEN-MATCOST.

GS_FINAL-OP_SMM = GS_OPEN-SMM.

GS_FINAL-OP_SVM = GS_OPEN-SVM.

GS_FINAL-OP_SFM = GS_OPEN-SFM.

GS_FINAL-OP_COH = GS_OPEN-COH.

GS_FINAL-OP_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-OP_TOTAL = GS_OPEN-TOTAL.

GS_FINAL-CL_QTY = GS_OPEN-CLOSEINV.

GS_FINAL-CL_MATC = GS_OPEN-MATCOST.

GS_FINAL-CL_SMM = GS_OPEN-SMM.

GS_FINAL-CL_SVM = GS_OPEN-SVM.

GS_FINAL-CL_SFM = GS_OPEN-SFM.

GS_FINAL-CL_COH = GS_OPEN-COH.

GS_FINAL-CL_OFF = GS_OPEN-OFFLOAD.

GS_FINAL-CL_TOTAL = GS_OPEN-TOTAL.

APPEND GS_FINAL TO GT_FINAL.

ENDIF.

CLEAR: GS_FINAL, GS_OPEN.

ENDLOOP.

ENDIF.

ENDIF.

ENDFORM. " PROCESS_DATA

*&---------------------------------------------------------------------*

*& Form ALV_FIELDCAT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM ALV_FIELDCAT .

REFRESH: GT_FIELDCAT.

CLEAR: GS_FIELDCAT.

PERFORM FIELDCAT USING 'VBELN' 'Sales Order' '' 'X' '' 'C110' ''.

PERFORM FIELDCAT USING 'POSNR' 'Item' '' 'X' '' 'C110' ''.

PERFORM FIELDCAT USING 'ZMENG' 'SO Quantity' '' 'X' 'X' '' ''.

PERFORM FIELDCAT USING 'KZWI1' 'SODS Value' '' 'X' 'X' '' ''.

PERFORM FIELDCAT USING 'PS_PSP_PNR' 'WBS Element' '' 'X' '' 'C110' ''.

PERFORM FIELDCAT USING 'KWERT' 'Agreed Price' '' 'X' 'X' '' ''.

PERFORM FIELDCAT USING 'AUFNR' 'Prod. Order' '' 'X' '' '' ''.

PERFORM FIELDCAT USING 'MATNR' 'Material' '18' 'X' '' '' ''.

PERFORM FIELDCAT USING 'ARKTX' 'Mat. Descriptin' '' '' '' '' ''.

PERFORM FIELDCAT USING 'DAUAT' 'Order Type' '' '' '' '' ''.

*----Opening Inventory Details

PERFORM FIELDCAT USING 'CLOSEINV' 'OP Qty' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_MATC' 'OP Mat. Cost' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_SMM' 'OP SMM' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_SVM' 'OP SVM' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_SFM' 'OP SFM' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_COH' 'OP COH' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_OFF' 'OP OFF' '' 'X' 'X' 'C510' ''.

PERFORM FIELDCAT USING 'OP_TOTAL' 'OP Total' '' 'X' 'X' 'C510' ''.

*----Cost Booked Details

PERFORM FIELDCAT USING 'BK_MATC' 'BK Mat. Cost' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_SMM' 'BK SMM' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_SVM' 'BK SVM' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_SFM' 'BK SFM' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_COH' 'BK COH' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_OFF' 'BK OFF' '' 'X' 'X' 'C310' ''.

PERFORM FIELDCAT USING 'BK_TOTAL' 'BK Total' '' 'X' 'X' 'C310' ''.

*----Cost of production Details

PERFORM FIELDCAT USING 'CP_QTY' 'CP Qty' '' 'X' 'X' 'C710' 'CP_UNIT'.

PERFORM FIELDCAT USING 'CP_UNIT' 'CP Unit' '' '' '' 'C710' ''. " Add By Nilesh Patel on 22.12.2011

PERFORM FIELDCAT USING 'CP_AGRVAL' 'CP Agreed Price' '' 'X' 'X' '' ''. " Add By Nilesh Patel on 26.12.2011

PERFORM FIELDCAT USING 'CP_MATC' 'CP Mat. Cost' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_SMM' 'CP SMM' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_SVM' 'CP SVM' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_SFM' 'CP SFM' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_COH' 'CP COH' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_OFF' 'CP OFF' '' 'X' 'X' 'C710' ''.

PERFORM FIELDCAT USING 'CP_TOTAL' 'CP Total' '' 'X' 'X' 'C710' ''.

*----Closing Inventory Details

PERFORM FIELDCAT USING 'CL_QTY' 'CL Qty' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_MATC' 'CL Mat. Cost' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_SMM' 'CL SMM' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_SVM' 'CL SVM' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_SFM' 'CL SFM' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_COH' 'CL COH' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_OFF' 'CL OFF' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CL_TOTAL' 'CL Total' '' 'X' 'X' 'C410' ''.

PERFORM FIELDCAT USING 'CONTR' 'Contr' '' 'X' '' '' ''.

PERFORM FIELDCAT USING 'PERC' 'Contr %' '' 'X' '' '' ''.

PERFORM FIELDCAT USING 'STDMAT' 'SO/Std Cost' '' 'X' '' '' ''.

PERFORM FIELDCAT USING 'STIME' 'Standard Time(Hr)' '' 'X' '' '' ''.

PERFORM FIELDCAT USING 'ATIME' 'Actual Time(Hr)' '' 'X' '' '' ''.

ENDFORM. " ALV_FIELDCAT

*&---------------------------------------------------------------------*

*& Form FIELDCAT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_3083 text

* -->P_3084 text

* -->P_3085 text

* -->P_3086 text

* -->P_3087 text

* -->P_3088 text

*----------------------------------------------------------------------*

FORM FIELDCAT USING P_FILENAME

P_TEXT

P_OUT

P_ZERO

P_SUM

P_COLOR

P_QFIELDNAME.

CLEAR : GS_FIELDCAT.

GS_FIELDCAT-FIELDNAME = P_FILENAME.

GS_FIELDCAT-OUTPUTLEN = P_OUT.

GS_FIELDCAT-SELTEXT_L = P_TEXT.

GS_FIELDCAT-NO_ZERO = P_ZERO.

GS_FIELDCAT-DO_SUM = P_SUM.

GS_FIELDCAT-EMPHASIZE = P_COLOR.

GS_FIELDCAT-QFIELDNAME = P_QFIELDNAME .

APPEND GS_FIELDCAT TO GT_FIELDCAT.

ENDFORM. " FIELDCAT

*&---------------------------------------------------------------------*

*& Form ALV_LAYOUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM ALV_LAYOUT .

CLEAR GS_LAYOUT.

GS_LAYOUT-ZEBRA = 'X'.

GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

ENDFORM. " ALV_LAYOUT

*&---------------------------------------------------------------------*

*& Form ALV_EVENT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM ALV_EVENT .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = GT_EVENT

EXCEPTIONS

LIST_TYPE_WRONG = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

READ TABLE GT_EVENT INTO GS_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.

IF SY-SUBRC = 0.

GS_EVENT-FORM = 'TOP_OF_PAGE'.

MODIFY GT_EVENT FROM GS_EVENT INDEX SY-TABIX.

ENDIF.

ENDFORM. " ALV_EVENT

*&---------------------------------------------------------------------*

*& Form top_of_page

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM TOP_OF_PAGE.

DATA:LT_HEADER TYPE TABLE OF SLIS_LISTHEADER,

LS_HEADER TYPE SLIS_LISTHEADER,

T_LINE LIKE LS_HEADER-INFO,

LD_LINES TYPE I,

LD_LINESC(10) TYPE C,

LD_VALUE(20) TYPE C,

LV_PLANT(40) TYPE C.

REFRESH LT_HEADER.

CLEAR LS_HEADER.

LS_HEADER-TYP = 'H'.

LS_HEADER-INFO = 'WIP Ledger'.

APPEND LS_HEADER TO LT_HEADER.

LS_HEADER-TYP = 'S'.

LS_HEADER-KEY = 'Period ending on:'.

CONCATENATE P_MON '/' P_YEAR INTO LS_HEADER-INFO.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER.

DESCRIBE TABLE GT_FINAL LINES LD_LINES.

LD_LINESC = LD_LINES.

CONDENSE LD_LINESC.

T_LINE = LD_LINESC.

LS_HEADER-TYP = 'S'.

LS_HEADER-KEY = 'Total Order: '.

LS_HEADER-INFO = T_LINE.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER, T_LINE.

LS_HEADER-TYP = 'A'.

LS_HEADER-INFO = 'OP = Opening Inventory(WIP)'.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER.

LS_HEADER-TYP = 'A'.

LS_HEADER-INFO = 'BK = Cost Booked'.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER.

LS_HEADER-TYP = 'A'.

LS_HEADER-INFO = 'CP = Cost of Production'.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER.

LS_HEADER-TYP = 'A'.

LS_HEADER-INFO = 'CL = Closing Inventory(WIP)'.

APPEND LS_HEADER TO LT_HEADER.

CLEAR: LS_HEADER.

* LS_HEADER-TYP = 'A'.

* LS_HEADER-INFO = 'CONTR = Contribution'.

* APPEND LS_HEADER TO LT_HEADER.

* CLEAR: LS_HEADER.

*

* LS_HEADER-TYP = 'A'.

* LS_HEADER-INFO = 'STDMAT = Standard Material Cost'.

* APPEND LS_HEADER TO LT_HEADER.

* CLEAR: LS_HEADER.

* LS_HEADER-TYP = 'A'.

* LS_HEADER-INFO = 'CP = Cost of Production'.

* APPEND LS_HEADER TO LT_HEADER.

* CLEAR: LS_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = LT_HEADER.

* I_LOGO =

* I_END_OF_LIST_GRID =

* I_ALV_FORM =

.

ENDFORM. "'TOP_OF_PAGE'

*&---------------------------------------------------------------------*

*& Form ALV_DISPLAY

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM ALV_DISPLAY .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

* I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'Order Details'

IS_LAYOUT = GS_LAYOUT

IT_FIELDCAT = GT_FIELDCAT

IT_SORT = GT_SORT_INFO

I_DEFAULT = 'X'

I_SAVE = G_SAVE

IS_VARIANT = GD_VARIANT

IT_EVENTS = GT_EVENT[]

TABLES

T_OUTTAB = GT_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " ALV_DISPLAY

*&---------------------------------------------------------------------*

*& Form SET_PF_STATUS

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->UT_EXTAB text

*----------------------------------------------------------------------*

FORM SET_PF_STATUS USING UT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'MAIN'.

ENDFORM. " SET_PF_STATUS

*&---------------------------------------------------------------------*

*& Form user_command

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->V_UCOMM text

* -->RS_SELFIELD text

*----------------------------------------------------------------------*

FORM USER_COMMAND USING V_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

CASE V_UCOMM.

WHEN 'CLOSE'.

PERFORM DISPLAY_CLOSE_DATA.

ENDCASE.

ENDFORM. "USER_COMMAND

*&---------------------------------------------------------------------*

*& Form DISPLAY_CLOSE_DATA

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM DISPLAY_CLOSE_DATA .

REFRESH GT_FCAT1.

PERFORM ADD_FIELDCAT USING 'KDAUF' 'Sales Order' 'GT_CLOSE' CHANGING GT_FCAT1.

PERFORM ADD_FIELDCAT USING 'KDPOS' 'Item' 'GT_CLOSE' CHANGING GT_FCAT1.

PERFORM ADD_FIELDCAT USING 'PS_PSP_PNR' 'WBS Elemnt' 'GT_CLOSE' CHANGING GT_FCAT1.

PERFORM ADD_FIELDCAT USING 'MENGE' 'Qty-Dlvd' 'GT_CLOSE' CHANGING GT_FCAT1.

CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

EXPORTING

I_TITLE = TEXT-014

I_SELECTION = ' '

I_ZEBRA = 'X'

I_SCREEN_START_COLUMN = 10

I_SCREEN_START_LINE = 3

I_SCREEN_END_COLUMN = 140

I_SCREEN_END_LINE = 25

I_TABNAME = 'GT_CLOSE'

I_STRUCTURE_NAME = 'GTY_CLOSE'

IT_FIELDCAT = GT_FCAT1

TABLES

T_OUTTAB = GT_CLOSE

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

ENDIF.

ENDFORM. " DISPLAY_CLOSE_DATA

*&---------------------------------------------------------------------*

*& Form ADD_FIELDCAT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_3620 text

* -->P_3621 text

* -->P_3622 text

* <--P_GT_FCAT1 text

*----------------------------------------------------------------------*

FORM ADD_FIELDCAT USING P_FIELDNAME

P_HEADING

P_TAB

CHANGING T_FCAT LIKE GT_FCAT1.

CLEAR GS_FCAT1.

GS_FCAT1-FIELDNAME = P_FIELDNAME.

GS_FCAT1-TABNAME = P_TAB.

GS_FCAT1-SELTEXT_L = P_HEADING.

APPEND GS_FCAT1 TO GT_FCAT1.

CLEAR GS_FCAT1 .

ENDFORM. " ADD_FIELDCAT

*&---------------------------------------------------------------------*

*& Form ALV_SORT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM ALV_SORT .

REFRESH GT_SORT_INFO.

IF P_SO = 'X'.

GS_SORT_INFO-SPOS = '1'.

GS_SORT_INFO-FIELDNAME = 'VBELN'.

GS_SORT_INFO-TABNAME = 'GT_FINAL'.

APPEND GS_SORT_INFO TO GT_SORT_INFO.

GS_SORT_INFO-SPOS = '2'.

GS_SORT_INFO-FIELDNAME = 'POSNR'.

GS_SORT_INFO-SUBTOT = 'X'.

APPEND GS_SORT_INFO TO GT_SORT_INFO.

ELSE.

GS_SORT_INFO-SPOS = '1'.

GS_SORT_INFO-FIELDNAME = 'PS_PSP_PNR'.

GS_SORT_INFO-TABNAME = 'GT_FINAL'.

APPEND GS_SORT_INFO TO GT_SORT_INFO.

ENDIF.

ENDFORM. " ALV_SORT