Description : Cost Report (Tcode-ck11n) with Material Weight & Time (Routing)
**********************************************************
REPORT ZFI_COST_DETAILS.
TABLES: MARA,CKIS.
TYPE-POOLS:SLIS.
TYPES: BEGIN OF FINAL,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
VGW03 TYPE PLPO-VGW03,
END OF FINAL.
DATA: BEGIN OF ITAB OCCURS 0,
COUNT TYPE I,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
STLAL TYPE MAST-STLAL,
STLNR TYPE MAST-STLNR,
C1 TYPE MARA-MATNR,
C2 TYPE MARA-MATNR,
C3 TYPE MARA-MATNR,
C4 TYPE MARA-MATNR,
C5 TYPE MARA-MATNR,
C6 TYPE MARA-MATNR,
C7 TYPE MARA-MATNR,
C8 TYPE MARA-MATNR,
D1 TYPE MAKT-MAKTX,
D2 TYPE MAKT-MAKTX,
D3 TYPE MAKT-MAKTX,
D4 TYPE MAKT-MAKTX,
D5 TYPE MAKT-MAKTX,
D6 TYPE MAKT-MAKTX,
D7 TYPE MAKT-MAKTX,
D8 TYPE MAKT-MAKTX,
TOTVAL TYPE CKCOSTLINE-GK,
TOTVAL1 TYPE CKCOSTLINE-GK,
VERPR TYPE MBEW-VERPR,
VERPR1 TYPE MBEW-VERPR,
MENGE LIKE STPO-MENGE,
MEINS LIKE STPO-MEINS,
MENGE1 LIKE STPO-MENGE,
MEINS1 LIKE STPO-MEINS,
TOT_QTY TYPE STPO-MENGE,
TOT_VAL TYPE CKCOSTLINE-GK,
VGW03 TYPE ASVRG,
VGW031 TYPE ASVRG,
TOT_TIME TYPE ASVRG,
END OF ITAB.
DATA : IT_MAKT LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA ITAB2 LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA : IT_MARA LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: LN TYPE I.
DATA: HEADING TYPE SLIS_T_LISTHEADER WITH HEADER LINE.
DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECT-OPTIONS: MATNR1 FOR MARA-MATNR.
*&------------------------------------------------------*&
DATA: BEGIN OF IT_MAPL OCCURS 0,
PLNNR LIKE MAPL-PLNNR,
PLNAL LIKE MAPL-PLNAL,
PLNKN LIKE PLAS-PLNKN,
PLNFL LIKE PLAS-PLNFL,
ZAEHL LIKE PLAS-ZAEHL,
MATNR LIKE MAPL-MATNR,
MAKTX LIKE MAKT-MAKTX,
VORNR LIKE PLPO-VORNR,
STEUS LIKE PLPO-STEUS,
MAXVOR LIKE PLPO-VORNR,
LTXA1 LIKE PLPO-LTXA1,
LOSVN LIKE PLKO-LOSVN,
LOSBS LIKE PLKO-LOSBS,
STATU LIKE PLKO-STATU,
VGW02 LIKE PLPO-VGW02,
VGW03 TYPE ASVRG,
* VGW03 LIKE PLPO-VGW03,
ARBPL LIKE CRHD-ARBPL,
ARBID LIKE PLPO-ARBID,
ARBPL1 LIKE CRHD-ARBPL,
ARBID1 LIKE PLPO-ARBID,
* FEVOR LIKE MARC-FEVOR,
* DISPO LIKE MARC-DISPO,
RECORDS TYPE SYST-DBCNT,
LTIME LIKE PLPO-VGW02,
MSTAE LIKE MARA-MSTAE, "Cross-Plant Material Status (03) - Blocked Material
MTART LIKE MARA-MTART,
FERTH LIKE MARA-FERTH,
SRNO TYPE I,
END OF IT_MAPL.
** SELECT-OPTIONS: S_DATE FOR CKIS-KADKY.
DATA: BEGIN OF IPLAS OCCURS 0,
PLNNR LIKE MAPL-PLNNR,
PLNAL LIKE MAPL-PLNAL,
PLNKN LIKE PLAS-PLNKN,
PLNFL LIKE PLAS-PLNFL,
ZAEHL LIKE PLAS-ZAEHL,
ARBID LIKE PLPO-ARBID,
VGW02 LIKE PLPO-VGW02,
VGW03 LIKE PLPO-VGW03,
LTIME LIKE PLPO-VGW02,
STEUS LIKE PLPO-STEUS,
LTXA1 LIKE PLPO-LTXA1,
VORNR LIKE PLPO-VORNR,
RECORDS TYPE SYST-DBCNT,
END OF IPLAS.
DATA CNT2 TYPE I.
DATA : PP TYPE PLNKN.
DATA : TEMP TYPE PLNKN.
** DATA: BEGIN OF IPLAS3 OCCURS 0,
** PLNNR LIKE AFKO-PLNNR,
** PLNAL LIKE PLAS-PLNAL,
** PLNKN LIKE PLAS-PLNKN,
** VORNR LIKE PLPO-VORNR,
** STEUS LIKE PLPO-STEUS,
** RECORDS LIKE SYST-DBCNT,
** END OF IPLAS3.
*&-----------------------------------------------------------------*&
START-OF-SELECTION.
SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA
WHERE MATNR IN MATNR1
AND MTART = 'ZFIN'.
SORT IT_MARA BY MATNR.
CHECK IT_MARA[] IS NOT INITIAL.
SELECT * FROM MAKT INTO CORRESPONDING FIELDS OF TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.
SORT IT_MAKT BY MATNR.
LOOP AT IT_MARA.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '01'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC <> 0.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '02'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC <> 0.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '03'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC = 0.
MODIFY IT_MARA.
ELSE.
ENDIF.
ELSE.
MODIFY IT_MARA.
ENDIF.
ELSE.
MODIFY IT_MARA.
ENDIF.
ENDLOOP.
LOOP AT IT_MARA.
ITAB-MATNR = IT_MARA-MATNR.
ITAB-MTART = IT_MARA-MTART.
ITAB-MATKL = IT_MARA-MATKL.
ITAB-STLAL = IT_MARA-STLAL.
ITAB-STLNR = IT_MARA-STLNR.
READ TABLE IT_MAKT WITH KEY MATNR = IT_MARA-MATNR BINARY SEARCH.
ITAB-MAKTX = IT_MAKT-MAKTX.
APPEND ITAB.
ENDLOOP.
SORT BY ITAB-MATNR.
DATA: BOM_TAB TYPE TABLE OF STPO_API02 WITH HEADER LINE.
DATA: STPU_TAB TYPE TABLE OF STPU_API01 WITH HEADER LINE.
DATA : DE(18) TYPE C,
DE1(1) TYPE C.
**BREAK-POINT.
LOOP AT ITAB.
DATA: CNT TYPE I.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-MATNR
PLANT = 'HIP'
BOM_USAGE = '1'
ALTERNATIVE = ITAB-STLAL
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
DE = ITAB-MATNR.
SHIFT DE BY 8 PLACES.
DE1 = DE.
IF DE1 = 'D'.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C1 = BOM_TAB-COMPONENT .
IF ITAB-C1+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0020'.
IF BOM_TAB-COMPONENT <> ' ' AND BOM_TAB-ITEM_NO = '0020'.
ITAB-C5 = BOM_TAB-COMPONENT.
ENDIF.
IF ITAB-C1 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C1.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C1
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C2 = BOM_TAB-COMPONENT .
IF ITAB-C2+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C2 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C2.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C2
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C3 = BOM_TAB-COMPONENT .
IF ITAB-C3+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C3 <> ' '.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C3.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C3
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C4 = BOM_TAB-COMPONENT .
IF ITAB-C4+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C4.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
SELECT MAKTX INTO ITAB-D4 FROM MAKT
WHERE MATNR = ITAB-C4.
ENDSELECT.
ENDIF.
ENDIF.
ENDIF.
IF ITAB-C5 <> ' '.
SELECT MAKTX INTO ITAB-D5 FROM MAKT
WHERE MATNR = ITAB-C5.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C5
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C6 = BOM_TAB-COMPONENT .
IF ITAB-C6+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C6 <> ' '.
SELECT MAKTX INTO ITAB-D6 FROM MAKT
WHERE MATNR = ITAB-C6.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C6
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C7 = BOM_TAB-COMPONENT .
IF ITAB-C7+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C7 <> ' '.
SELECT MAKTX INTO ITAB-D7 FROM MAKT
WHERE MATNR = ITAB-C7.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C7
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C8 = BOM_TAB-COMPONENT .
IF ITAB-C8+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS1 = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR1
WHERE MATNR = ITAB-C8.
ITAB-TOTVAL1 = ITAB-VERPR1 * ITAB-MENGE1.
ENDIF.
SELECT MAKTX INTO ITAB-D8 FROM MAKT
WHERE MATNR = ITAB-C8.
ENDSELECT.
ENDIF.
ENDIF.
ENDIF.
MODIFY ITAB.
ELSEIF DE1 = 'G'.
*====================== For Single End Only =======================
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C1 = BOM_TAB-COMPONENT .
IF ITAB-C1+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C2.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
IF ITAB-C1 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C1.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C1
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C2 = BOM_TAB-COMPONENT .
IF ITAB-C2+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C2.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
ENDIF.
IF ITAB-C2 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C2.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C2
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C3 = BOM_TAB-COMPONENT .
IF ITAB-C3+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C3.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C3.
ENDSELECT.
ENDIF.
MODIFY ITAB.
ELSE.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C5 = BOM_TAB-COMPONENT .
IF ITAB-C5+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C6.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
IF ITAB-C5 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C5.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C5
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C6 = BOM_TAB-COMPONENT .
IF ITAB-C6+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C6.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
ENDIF.
IF ITAB-C6 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C6.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C6
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C7 = BOM_TAB-COMPONENT .
IF ITAB-C7+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C7.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C7.
ENDSELECT.
ENDIF.
MODIFY ITAB.
ENDIF.
ENDLOOP.
**BREAK-POINT.
LOOP AT ITAB.
IF ITAB-C1+8(1) = 'G' AND ITAB-MATNR+8(1) = 'D'.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C1 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW03 = IPLAS-VGW03 .
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
IF ITAB-C1+8(1) = 'N' AND ITAB-MATNR+8(1) = 'D'.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C1 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03 .
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
IF ITAB-C5+8(1) = 'N' AND ITAB-MATNR+8(1) = 'D'.
CLEAR : IT_MAPL[],IPLAS.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C5 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03.
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ELSEIF ITAB-MATNR+8(1) = 'G' OR ITAB-MATNR+8(1) = 'N'.
CLEAR : IT_MAPL[],IPLAS.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-MATNR AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03.
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
*&------------------------------------------------------------------
LOOP AT ITAB.
ITAB-TOT_QTY = ITAB-MENGE + ITAB-MENGE1.
ITAB-TOT_VAL = ITAB-TOTVAL + ITAB-TOTVAL1.
ITAB-TOT_TIME = ITAB-VGW03 + ITAB-VGW031.
MODIFY ITAB.
ENDLOOP.
DESCRIBE TABLE ITAB LINES LN.
PERFORM F_CAT.
**LS_LAYOUT-BOX_FIELDNAME = 'SEL'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = ITAB.
FORM F_CAT.
DATA CNT TYPE I.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MATNR'.
IT_FIELDCAT-SELTEXT_M = 'MATERIAL'.
IT_FIELDCAT-OUTPUTLEN = 21.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MAKTX'.
IT_FIELDCAT-SELTEXT_M = 'DESC.'.
IT_FIELDCAT-OUTPUTLEN = 22.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MENGE'.
IT_FIELDCAT-SELTEXT_M = 'GO_WT'.
IT_FIELDCAT-OUTPUTLEN = 8.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOTVAL'.
IT_FIELDCAT-SELTEXT_M = 'GO.MAT.COST'.
IT_FIELDCAT-OUTPUTLEN = 12.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MENGE1'.
IT_FIELDCAT-SELTEXT_M = 'NOTGO_WT'.
IT_FIELDCAT-OUTPUTLEN = 10.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOTVAL1'.
IT_FIELDCAT-SELTEXT_M = 'NOTGO MAT.COST'.
IT_FIELDCAT-OUTPUTLEN = 16.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOT_QTY'.
IT_FIELDCAT-SELTEXT_M = 'TOTAL WT'.
IT_FIELDCAT-OUTPUTLEN = 10.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'TOT.MAT.COST'.
IT_FIELDCAT-FIELDNAME = 'TOT_VAL'.
IT_FIELDCAT-OUTPUTLEN = 14.
IT_FIELDCAT-DO_SUM = 'X'.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.GO.TIME'.
IT_FIELDCAT-FIELDNAME = 'VGW03'.
IT_FIELDCAT-OUTPUTLEN = 12.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.NOTGO.TIME'.
IT_FIELDCAT-FIELDNAME = 'VGW031'.
IT_FIELDCAT-OUTPUTLEN = 15.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.TOT.TIME'.
IT_FIELDCAT-FIELDNAME = 'TOT_TIME'.
IT_FIELDCAT-OUTPUTLEN = 13.
IT_FIELDCAT-DO_SUM = 'X'.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
LS_LAYOUT-BOX_FIELDNAME = 'SEL'.
ENDFORM.
FORM TOP_OF_PAGE.
CLEAR : HEADING,HEADING[].
HEADING-TYP = 'H'.
HEADING-INFO = 'Material Cost Estimate with Qty & Value Report'.
APPEND HEADING.
CLEAR HEADING.
HEADING-TYP = 'S'.
HEADING-KEY = 'Hit Entries:'.
HEADING-INFO = LN.
APPEND HEADING.
CLEAR HEADING.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADING[].
ENDFORM.
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
BREAK-POINT.
CASE R_UCOMM.
IF RS_SELFIELD-FIELDNAME = 'MATNR'.
READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID : 'MAT' FIELD ITAB-MATNR.
CALL TRANSACTION 'CK13N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
****************************************************************
**********************************************************
REPORT ZFI_COST_DETAILS.
TABLES: MARA,CKIS.
TYPE-POOLS:SLIS.
TYPES: BEGIN OF FINAL,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
VGW03 TYPE PLPO-VGW03,
END OF FINAL.
DATA: BEGIN OF ITAB OCCURS 0,
COUNT TYPE I,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
STLAL TYPE MAST-STLAL,
STLNR TYPE MAST-STLNR,
C1 TYPE MARA-MATNR,
C2 TYPE MARA-MATNR,
C3 TYPE MARA-MATNR,
C4 TYPE MARA-MATNR,
C5 TYPE MARA-MATNR,
C6 TYPE MARA-MATNR,
C7 TYPE MARA-MATNR,
C8 TYPE MARA-MATNR,
D1 TYPE MAKT-MAKTX,
D2 TYPE MAKT-MAKTX,
D3 TYPE MAKT-MAKTX,
D4 TYPE MAKT-MAKTX,
D5 TYPE MAKT-MAKTX,
D6 TYPE MAKT-MAKTX,
D7 TYPE MAKT-MAKTX,
D8 TYPE MAKT-MAKTX,
TOTVAL TYPE CKCOSTLINE-GK,
TOTVAL1 TYPE CKCOSTLINE-GK,
VERPR TYPE MBEW-VERPR,
VERPR1 TYPE MBEW-VERPR,
MENGE LIKE STPO-MENGE,
MEINS LIKE STPO-MEINS,
MENGE1 LIKE STPO-MENGE,
MEINS1 LIKE STPO-MEINS,
TOT_QTY TYPE STPO-MENGE,
TOT_VAL TYPE CKCOSTLINE-GK,
VGW03 TYPE ASVRG,
VGW031 TYPE ASVRG,
TOT_TIME TYPE ASVRG,
END OF ITAB.
DATA : IT_MAKT LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA ITAB2 LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA : IT_MARA LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: LN TYPE I.
DATA: HEADING TYPE SLIS_T_LISTHEADER WITH HEADER LINE.
DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECT-OPTIONS: MATNR1 FOR MARA-MATNR.
*&------------------------------------------------------*&
DATA: BEGIN OF IT_MAPL OCCURS 0,
PLNNR LIKE MAPL-PLNNR,
PLNAL LIKE MAPL-PLNAL,
PLNKN LIKE PLAS-PLNKN,
PLNFL LIKE PLAS-PLNFL,
ZAEHL LIKE PLAS-ZAEHL,
MATNR LIKE MAPL-MATNR,
MAKTX LIKE MAKT-MAKTX,
VORNR LIKE PLPO-VORNR,
STEUS LIKE PLPO-STEUS,
MAXVOR LIKE PLPO-VORNR,
LTXA1 LIKE PLPO-LTXA1,
LOSVN LIKE PLKO-LOSVN,
LOSBS LIKE PLKO-LOSBS,
STATU LIKE PLKO-STATU,
VGW02 LIKE PLPO-VGW02,
VGW03 TYPE ASVRG,
* VGW03 LIKE PLPO-VGW03,
ARBPL LIKE CRHD-ARBPL,
ARBID LIKE PLPO-ARBID,
ARBPL1 LIKE CRHD-ARBPL,
ARBID1 LIKE PLPO-ARBID,
* FEVOR LIKE MARC-FEVOR,
* DISPO LIKE MARC-DISPO,
RECORDS TYPE SYST-DBCNT,
LTIME LIKE PLPO-VGW02,
MSTAE LIKE MARA-MSTAE, "Cross-Plant Material Status (03) - Blocked Material
MTART LIKE MARA-MTART,
FERTH LIKE MARA-FERTH,
SRNO TYPE I,
END OF IT_MAPL.
** SELECT-OPTIONS: S_DATE FOR CKIS-KADKY.
DATA: BEGIN OF IPLAS OCCURS 0,
PLNNR LIKE MAPL-PLNNR,
PLNAL LIKE MAPL-PLNAL,
PLNKN LIKE PLAS-PLNKN,
PLNFL LIKE PLAS-PLNFL,
ZAEHL LIKE PLAS-ZAEHL,
ARBID LIKE PLPO-ARBID,
VGW02 LIKE PLPO-VGW02,
VGW03 LIKE PLPO-VGW03,
LTIME LIKE PLPO-VGW02,
STEUS LIKE PLPO-STEUS,
LTXA1 LIKE PLPO-LTXA1,
VORNR LIKE PLPO-VORNR,
RECORDS TYPE SYST-DBCNT,
END OF IPLAS.
DATA CNT2 TYPE I.
DATA : PP TYPE PLNKN.
DATA : TEMP TYPE PLNKN.
** DATA: BEGIN OF IPLAS3 OCCURS 0,
** PLNNR LIKE AFKO-PLNNR,
** PLNAL LIKE PLAS-PLNAL,
** PLNKN LIKE PLAS-PLNKN,
** VORNR LIKE PLPO-VORNR,
** STEUS LIKE PLPO-STEUS,
** RECORDS LIKE SYST-DBCNT,
** END OF IPLAS3.
*&-----------------------------------------------------------------*&
START-OF-SELECTION.
SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA
WHERE MATNR IN MATNR1
AND MTART = 'ZFIN'.
SORT IT_MARA BY MATNR.
CHECK IT_MARA[] IS NOT INITIAL.
SELECT * FROM MAKT INTO CORRESPONDING FIELDS OF TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.
SORT IT_MAKT BY MATNR.
LOOP AT IT_MARA.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '01'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC <> 0.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '02'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC <> 0.
SELECT SINGLE STLAL STLNR FROM MAST
INTO CORRESPONDING FIELDS OF IT_MARA
WHERE WERKS = 'HIP' AND STLAL = '03'
AND MATNR = IT_MARA-MATNR AND STLAN = '1'.
IF SY-SUBRC = 0.
MODIFY IT_MARA.
ELSE.
ENDIF.
ELSE.
MODIFY IT_MARA.
ENDIF.
ELSE.
MODIFY IT_MARA.
ENDIF.
ENDLOOP.
LOOP AT IT_MARA.
ITAB-MATNR = IT_MARA-MATNR.
ITAB-MTART = IT_MARA-MTART.
ITAB-MATKL = IT_MARA-MATKL.
ITAB-STLAL = IT_MARA-STLAL.
ITAB-STLNR = IT_MARA-STLNR.
READ TABLE IT_MAKT WITH KEY MATNR = IT_MARA-MATNR BINARY SEARCH.
ITAB-MAKTX = IT_MAKT-MAKTX.
APPEND ITAB.
ENDLOOP.
SORT BY ITAB-MATNR.
DATA: BOM_TAB TYPE TABLE OF STPO_API02 WITH HEADER LINE.
DATA: STPU_TAB TYPE TABLE OF STPU_API01 WITH HEADER LINE.
DATA : DE(18) TYPE C,
DE1(1) TYPE C.
**BREAK-POINT.
LOOP AT ITAB.
DATA: CNT TYPE I.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-MATNR
PLANT = 'HIP'
BOM_USAGE = '1'
ALTERNATIVE = ITAB-STLAL
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
DE = ITAB-MATNR.
SHIFT DE BY 8 PLACES.
DE1 = DE.
IF DE1 = 'D'.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C1 = BOM_TAB-COMPONENT .
IF ITAB-C1+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0020'.
IF BOM_TAB-COMPONENT <> ' ' AND BOM_TAB-ITEM_NO = '0020'.
ITAB-C5 = BOM_TAB-COMPONENT.
ENDIF.
IF ITAB-C1 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C1.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C1
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C2 = BOM_TAB-COMPONENT .
IF ITAB-C2+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C2 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C2.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C2
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C3 = BOM_TAB-COMPONENT .
IF ITAB-C3+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C3 <> ' '.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C3.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C3
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C4 = BOM_TAB-COMPONENT .
IF ITAB-C4+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C4.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
SELECT MAKTX INTO ITAB-D4 FROM MAKT
WHERE MATNR = ITAB-C4.
ENDSELECT.
ENDIF.
ENDIF.
ENDIF.
IF ITAB-C5 <> ' '.
SELECT MAKTX INTO ITAB-D5 FROM MAKT
WHERE MATNR = ITAB-C5.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C5
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C6 = BOM_TAB-COMPONENT .
IF ITAB-C6+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C6 <> ' '.
SELECT MAKTX INTO ITAB-D6 FROM MAKT
WHERE MATNR = ITAB-C6.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C6
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C7 = BOM_TAB-COMPONENT .
IF ITAB-C7+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
ENDIF.
IF ITAB-C7 <> ' '.
SELECT MAKTX INTO ITAB-D7 FROM MAKT
WHERE MATNR = ITAB-C7.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C7
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C8 = BOM_TAB-COMPONENT .
IF ITAB-C8+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS1 = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR1
WHERE MATNR = ITAB-C8.
ITAB-TOTVAL1 = ITAB-VERPR1 * ITAB-MENGE1.
ENDIF.
SELECT MAKTX INTO ITAB-D8 FROM MAKT
WHERE MATNR = ITAB-C8.
ENDSELECT.
ENDIF.
ENDIF.
ENDIF.
MODIFY ITAB.
ELSEIF DE1 = 'G'.
*====================== For Single End Only =======================
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C1 = BOM_TAB-COMPONENT .
IF ITAB-C1+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C2.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
IF ITAB-C1 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C1.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C1
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C2 = BOM_TAB-COMPONENT .
IF ITAB-C2+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C2.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
ENDIF.
IF ITAB-C2 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C2.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C2
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C3 = BOM_TAB-COMPONENT .
IF ITAB-C3+0(3) = 'RST'.
ITAB-MENGE = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C3.
ITAB-TOTVAL = ITAB-VERPR * ITAB-MENGE.
ENDIF.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C3.
ENDSELECT.
ENDIF.
MODIFY ITAB.
ELSE.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C5 = BOM_TAB-COMPONENT .
IF ITAB-C5+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C6.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
IF ITAB-C5 <> ' '.
SELECT MAKTX INTO ITAB-D1 FROM MAKT
WHERE MATNR = ITAB-C5.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C5
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C6 = BOM_TAB-COMPONENT .
IF ITAB-C6+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C6.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
ENDIF.
IF ITAB-C6 <> ' '.
SELECT MAKTX INTO ITAB-D2 FROM MAKT
WHERE MATNR = ITAB-C6.
ENDSELECT.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
MATERIAL = ITAB-C6
PLANT = 'HIP'
BOM_USAGE = '1'
TABLES
T_STPO = BOM_TAB
EXCEPTIONS
ERROR = 1
OTHERS = 2.
READ TABLE BOM_TAB WITH KEY ITEM_NO = '0010'.
ITAB-C7 = BOM_TAB-COMPONENT .
IF ITAB-C7+0(3) = 'RST'.
ITAB-MENGE1 = BOM_TAB-COMP_QTY.
ITAB-MEINS = BOM_TAB-COMP_UNIT.
SELECT SINGLE VERPR FROM MBEW INTO ITAB-VERPR
WHERE MATNR = ITAB-C7.
ITAB-TOTVAL1 = ITAB-VERPR * ITAB-MENGE1.
ENDIF.
SELECT MAKTX INTO ITAB-D3 FROM MAKT
WHERE MATNR = ITAB-C7.
ENDSELECT.
ENDIF.
MODIFY ITAB.
ENDIF.
ENDLOOP.
**BREAK-POINT.
LOOP AT ITAB.
IF ITAB-C1+8(1) = 'G' AND ITAB-MATNR+8(1) = 'D'.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C1 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW03 = IPLAS-VGW03 .
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
IF ITAB-C1+8(1) = 'N' AND ITAB-MATNR+8(1) = 'D'.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C1 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03 .
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
IF ITAB-C5+8(1) = 'N' AND ITAB-MATNR+8(1) = 'D'.
CLEAR : IT_MAPL[],IPLAS.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-C5 AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03.
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ELSEIF ITAB-MATNR+8(1) = 'G' OR ITAB-MATNR+8(1) = 'N'.
CLEAR : IT_MAPL[],IPLAS.
SELECT * FROM MAPL INTO CORRESPONDING FIELDS OF TABLE IT_MAPL
WHERE WERKS = 'HIP' AND
MATNR = ITAB-MATNR AND
PLNAL = '01' AND
LOEKZ <> 'X' AND
PLNTY = 'N' .
SORT IT_MAPL BY PLNNR PLNAL .
IF IT_MAPL[] IS NOT INITIAL.
SELECT * FROM PLAS INTO CORRESPONDING FIELDS OF TABLE IPLAS
FOR ALL ENTRIES IN IT_MAPL
WHERE PLNTY = 'N'
AND PLNNR = IT_MAPL-PLNNR
AND PLNAL = IT_MAPL-PLNAL
AND LOEKZ <> 'X'
AND PLNFL = '000000'.
SORT IPLAS BY PLNNR PLNAL PLNKN.
LOOP AT IPLAS.
TEMP = IPLAS-PLNKN.
CNT2 = CNT2 + 1.
AT NEW PLNNR.
PP = TEMP.
ENDAT.
SELECT SINGLE VORNR VGW03 FROM PLPO
INTO (IPLAS-VORNR , IPLAS-VGW03)
WHERE PLNNR = IPLAS-PLNNR
AND PLNKN = IPLAS-PLNKN
AND PLNTY = 'N'.
MODIFY IPLAS TRANSPORTING VORNR VGW03.
ENDLOOP.
SORT IPLAS BY PLNNR PLNAL VORNR DESCENDING.
LOOP AT IT_MAPL.
READ TABLE IPLAS WITH KEY PLNNR = IT_MAPL-PLNNR
PLNAL = IT_MAPL-PLNAL BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB-VGW031 = IPLAS-VGW03.
ENDIF.
MODIFY ITAB.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
*&------------------------------------------------------------------
LOOP AT ITAB.
ITAB-TOT_QTY = ITAB-MENGE + ITAB-MENGE1.
ITAB-TOT_VAL = ITAB-TOTVAL + ITAB-TOTVAL1.
ITAB-TOT_TIME = ITAB-VGW03 + ITAB-VGW031.
MODIFY ITAB.
ENDLOOP.
DESCRIBE TABLE ITAB LINES LN.
PERFORM F_CAT.
**LS_LAYOUT-BOX_FIELDNAME = 'SEL'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = ITAB.
FORM F_CAT.
DATA CNT TYPE I.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MATNR'.
IT_FIELDCAT-SELTEXT_M = 'MATERIAL'.
IT_FIELDCAT-OUTPUTLEN = 21.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MAKTX'.
IT_FIELDCAT-SELTEXT_M = 'DESC.'.
IT_FIELDCAT-OUTPUTLEN = 22.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MENGE'.
IT_FIELDCAT-SELTEXT_M = 'GO_WT'.
IT_FIELDCAT-OUTPUTLEN = 8.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOTVAL'.
IT_FIELDCAT-SELTEXT_M = 'GO.MAT.COST'.
IT_FIELDCAT-OUTPUTLEN = 12.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'MENGE1'.
IT_FIELDCAT-SELTEXT_M = 'NOTGO_WT'.
IT_FIELDCAT-OUTPUTLEN = 10.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOTVAL1'.
IT_FIELDCAT-SELTEXT_M = 'NOTGO MAT.COST'.
IT_FIELDCAT-OUTPUTLEN = 16.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-FIELDNAME = 'TOT_QTY'.
IT_FIELDCAT-SELTEXT_M = 'TOTAL WT'.
IT_FIELDCAT-OUTPUTLEN = 10.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'TOT.MAT.COST'.
IT_FIELDCAT-FIELDNAME = 'TOT_VAL'.
IT_FIELDCAT-OUTPUTLEN = 14.
IT_FIELDCAT-DO_SUM = 'X'.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.GO.TIME'.
IT_FIELDCAT-FIELDNAME = 'VGW03'.
IT_FIELDCAT-OUTPUTLEN = 12.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.NOTGO.TIME'.
IT_FIELDCAT-FIELDNAME = 'VGW031'.
IT_FIELDCAT-OUTPUTLEN = 15.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
CNT = CNT + 1.
IT_FIELDCAT-COL_POS = CNT.
IT_FIELDCAT-SELTEXT_M = 'LAB.TOT.TIME'.
IT_FIELDCAT-FIELDNAME = 'TOT_TIME'.
IT_FIELDCAT-OUTPUTLEN = 13.
IT_FIELDCAT-DO_SUM = 'X'.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
LS_LAYOUT-BOX_FIELDNAME = 'SEL'.
ENDFORM.
FORM TOP_OF_PAGE.
CLEAR : HEADING,HEADING[].
HEADING-TYP = 'H'.
HEADING-INFO = 'Material Cost Estimate with Qty & Value Report'.
APPEND HEADING.
CLEAR HEADING.
HEADING-TYP = 'S'.
HEADING-KEY = 'Hit Entries:'.
HEADING-INFO = LN.
APPEND HEADING.
CLEAR HEADING.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADING[].
ENDFORM.
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
BREAK-POINT.
CASE R_UCOMM.
IF RS_SELFIELD-FIELDNAME = 'MATNR'.
READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID : 'MAT' FIELD ITAB-MATNR.
CALL TRANSACTION 'CK13N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
****************************************************************
No comments:
Post a Comment