SAP ABAP - Custom MRP Report
Main Program
*&---------------------------------------------------------------------*
*& Report ZRPP003
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zrpp003.
TABLES : marc, mara, mdlv.
INCLUDE zrpp003_01. "Structure & Selection
INCLUDE zrpp003_02. "Logic
INCLUDE zrpp003_03. "Alv
START-OF-SELECTION.
IF p_toper < p_bulan.
MESSAGE 'Invalid period' TYPE 'I' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM setfieldcat.
PERFORM generate_structure.
PERFORM get_data2.
PERFORM to_alv_slis_event_exit.
Include ZRPP003_01
*&---------------------------------------------------------------------*
*& Include ZRPP003_01
*&---------------------------------------------------------------------*
TYPES :
BEGIN OF T_DATA,
MATNR TYPE MATNR,
MAKTX TYPE MAKTX,
MEINS TYPE MEINS,
UUQTY TYPE MNG01,
QIQTY TYPE MNG01,
TOQTY TYPE MNG01,
END OF T_DATA.
*data : it_print type standard table of zsrpp003.
*data: it_data type table of zsrpp003 with header line.
DATA: WA_EVENT_EXIT TYPE SLIS_EVENT_EXIT,
IT_EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
IS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FLDCAT TYPE LVC_T_FCAT,
IT_FLDCAT2 TYPE LVC_T_FCAT,
WA_FLNAME(20) TYPE C,
WA_LAYOUT TYPE LVC_S_LAYO,
WA_IT_FLDCAT TYPE LVC_S_FCAT,
V_BULAN TYPE CHAR50.
DATA : ZUUQTY TYPE MENGE_D,
ZQIQTY TYPE MENGE_D,
ZTOQTY TYPE MENGE_D,
ZPOQTY TYPE MENGE_D,
ZPRQTY TYPE MENGE_D,
ZRSQTY TYPE MENGE_D,
ZBALAN TYPE MENGE_D.
FIELD-SYMBOLS: <IT_GRID> TYPE STANDARD TABLE,
<WA_GRID>,
<WA_MATNR> TYPE ANY,
<WA_MRPAR> TYPE ANY,
<WA_UUQTY> TYPE ANY,
<WA_QIQTY> TYPE ANY,
<WA_TOQTY> TYPE ANY,
<WA_QTYPO> TYPE ANY,
<WA_QTYPR> TYPE ANY,
<WA_QTREQ> TYPE ANY,
<WA_QBALN> TYPE ANY,
<WA_QBLBK> TYPE ANY,
<WA_MEINS> TYPE ANY,
<WA_WERKS> TYPE ANY.
DATA: NEW_IT TYPE REF TO DATA,
NEW_LINE TYPE REF TO DATA.
"BAPI Parameters
DATA : MATERIAL TYPE BAPI_MRP_MAT_PARAM-MATERIAL,
PLANT TYPE BAPI_MRP_MAT_PARAM-PLANT,
MRP_AREA TYPE BAPI_MRP_MAT_PARAM-MRP_AREA,
MRP_ITEMS TYPE TABLE OF BAPI_MRP_ITEMS WITH HEADER LINE,
MRP_IND_LINES TYPE TABLE OF BAPI_MRP_IND_LINES WITH HEADER LINE,
LINES TYPE TABLE OF BAPI_MRP_IND_LINES WITH HEADER LINE,
MRP_TOTAL_LINES TYPE TABLE OF BAPI_MRP_TOTAL_LINES WITH HEADER LINE,
IT_MDLV TYPE HASHED TABLE OF MDLV WITH UNIQUE KEY BERID WITH HEADER LINE.
DATA V_PERIOD1(2) TYPE N.
DATA V_PERIOD2(2) TYPE N.
DATA Z_PERIOD(2) TYPE N.
DATA V_COUNT(2) TYPE N.
DATA V_FIELD TYPE CHAR10.
DATA V_TAHUN1(4) TYPE N.
DATA Z_TAHUN(4) TYPE N.
DATA V_TAHUN2(4) TYPE N.
DATA V_TAHUN3(4) TYPE N.
DATA V_SELISIH(2) TYPE N.
DATA B_PERIOD(2) TYPE N.
DATA :SORT_1 TYPE FIELDNAME,
SORT_2 TYPE FIELDNAME.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS :
P_WERKS TYPE WERKS_D OBLIGATORY DEFAULT '1710',
P_BULAN TYPE SPMON OBLIGATORY DEFAULT SY-DATUM(6),
* p_bulan type kpla_perbl obligatory default sy-datum+4(2),
* p_toper type kpla_perbl obligatory default sy-datum+4(2),
P_TOPER TYPE SPMON OBLIGATORY DEFAULT SY-DATUM(6).
* p_tahun type SPMON obligatory default sy-datum(6).
SELECT-OPTIONS :
S_BERID FOR MDLV-BERID OBLIGATORY DEFAULT '1710',
S_MATNR FOR MARC-MATNR,
S_DISPO FOR MARC-DISPO,
S_MTART FOR MARA-MTART.
SELECTION-SCREEN END OF BLOCK B1.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-NAME = 'P_BULAN'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
EXIT.
ENDIF.
ENDLOOP.
INITIALIZATION.
LOOP AT SCREEN.
IF SCREEN-NAME = 'P_BULAN'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
EXIT.
ENDIF.
ENDLOOP.
Include ZRPP003_02
*&---------------------------------------------------------------------*
*& Include ZRPP003_02
*&---------------------------------------------------------------------*
FORM GENERATE_STRUCTURE.
"================================dynamic table display data=====================================================================
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT
IMPORTING
EP_TABLE = NEW_IT.
ASSIGN NEW_IT->* TO <IT_GRID>.
* Create dynamic work area and assign to FS
CREATE DATA NEW_LINE LIKE LINE OF <IT_GRID>.
ASSIGN NEW_LINE->* TO <WA_GRID>.
"================================end of dynamic display data=========================================================================
ENDFORM.
FORM GET_DATA2.
REFRESH : <IT_GRID>.
SELECT * INTO CORRESPONDING FIELDS OF TABLE <IT_GRID>
FROM MARC INNER JOIN MARA ON MARC~MATNR = MARA~MATNR
INNER JOIN MAKT ON MARC~MATNR = MAKT~MATNR
INNER JOIN ZMRPAREA ON MARC~MATNR = ZMRPAREA~MATNR AND MARC~WERKS = ZMRPAREA~WERZG
WHERE MARC~WERKS = P_WERKS AND MARC~MATNR IN S_MATNR AND MARC~DISPO IN S_DISPO AND MARA~MTART IN S_MTART
AND ZMRPAREA~BERID IN S_BERID AND ZMRPAREA~WERZG = P_WERKS AND ZMRPAREA~MATNR IN S_MATNR AND MAKT~SPRAS = 'EN'.
IF <IT_GRID>[] IS NOT INITIAL.
CLEAR PLANT.
PLANT = P_WERKS.
MRP_AREA = P_WERKS.
DATA LENGTH TYPE I.
LENGTH = STRLEN( P_BULAN ).
IF LENGTH = 1.
CONCATENATE '0' P_BULAN INTO P_BULAN.
ENDIF.
LOOP AT <IT_GRID> ASSIGNING <WA_GRID>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <WA_GRID> TO <WA_MATNR>.
ASSIGN COMPONENT 'BERID' OF STRUCTURE <WA_GRID> TO <WA_MRPAR>.
CLEAR : MATERIAL, MRP_AREA.
MATERIAL = <WA_MATNR>.
MRP_AREA = <WA_MRPAR>.
REFRESH : MRP_ITEMS, MRP_IND_LINES, LINES.
CALL FUNCTION 'BAPI_MATERIAL_STOCK_REQ_LIST'
EXPORTING
MATERIAL = MATERIAL
PLANT = PLANT
MRP_AREA = MRP_AREA
GET_ITEM_DETAILS = 'X'
GET_IND_LINES = 'X'
TABLES
MRP_ITEMS = MRP_ITEMS[]
MRP_IND_LINES = MRP_IND_LINES[].
LINES[] = MRP_IND_LINES[].
ASSIGN COMPONENT 'UUQTY' OF STRUCTURE <WA_GRID> TO <WA_UUQTY>.
ASSIGN COMPONENT 'QIQTY' OF STRUCTURE <WA_GRID> TO <WA_QIQTY>.
ASSIGN COMPONENT 'TOQTY' OF STRUCTURE <WA_GRID> TO <WA_TOQTY>.
ASSIGN COMPONENT 'MEINS' OF STRUCTURE <WA_GRID> TO <WA_MEINS>.
CLEAR :ZUUQTY, ZQIQTY, ZTOQTY .
CLEAR LINES.
LOOP AT LINES WHERE MRP_ELEMNT = 'Stock' OR MRP_ELEMNT = 'QM-lot'.
IF LINES-MRP_ELEMNT = 'Stock'.
ZUUQTY = ZUUQTY + LINES-REC_REQD_QTY.
ELSEIF LINES-MRP_ELEMNT = 'QM-lot'.
ZQIQTY = ZQIQTY + LINES-REC_REQD_QTY.
ENDIF.
CLEAR LINES.
ENDLOOP.
<WA_UUQTY> = ZUUQTY.
<WA_QIQTY> = ZQIQTY.
<WA_TOQTY> = ZUUQTY + ZQIQTY.
ZBALAN = <WA_TOQTY>.
CLEAR : V_PERIOD1, V_PERIOD2, V_FIELD, V_TAHUN1, V_TAHUN2.
V_TAHUN1 = P_BULAN(4).
V_TAHUN2 = P_TOPER(4).
V_PERIOD1 = P_BULAN+4(2).
V_PERIOD2 = P_TOPER+4(2).
PERFORM TARIKMUNDUR.
IF V_TAHUN1 = V_TAHUN2.
WHILE V_PERIOD1 <= V_PERIOD2.
CLEAR V_FIELD.
CONCATENATE 'ZTXPO' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPO>.
CLEAR V_FIELD.
CONCATENATE 'ZTXPR' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPR>.
CLEAR V_FIELD.
CONCATENATE 'ZTREQ' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTREQ>.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBALN>.
LOOP AT MRP_IND_LINES WHERE AVAIL_DATE+4(2) = V_PERIOD1 AND AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-AVAIL_DATE+4(2) = V_PERIOD1 AND MRP_IND_LINES-AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-MRP_ELEMNT = 'POitem'.
<WA_QTYPO> = <WA_QTYPO> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'PurRqs'.
<WA_QTYPR> = <WA_QTYPR> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'OrdRes' OR MRP_IND_LINES-MRP_ELEMNT = 'MtlRes' OR MRP_IND_LINES-MRP_ELEMNT = 'DepReq'
OR MRP_IND_LINES-MRP_ELEMNT = 'TrnRes'.
MRP_IND_LINES-REC_REQD_QTY = MRP_IND_LINES-REC_REQD_QTY * -1.
<WA_QTREQ> = <WA_QTREQ> + MRP_IND_LINES-REC_REQD_QTY.
ENDIF.
ENDIF.
CLEAR MRP_IND_LINES.
ENDLOOP.
IF V_PERIOD1 = P_BULAN+4(2).
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
<WA_QBALN> = <WA_TOQTY> + <WA_QTYPO> + <WA_QTYPR> - <WA_QTREQ>.
ELSE.
CLEAR B_PERIOD.
B_PERIOD = V_PERIOD1 - 1.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' B_PERIOD V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
<WA_QBALN> = <WA_QBLBK> + <WA_QTYPO> + <WA_QTYPR> - <WA_QTREQ>.
UNASSIGN <WA_QBLBK>.
ENDIF.
V_PERIOD1 = V_PERIOD1 + 1.
UNASSIGN : <WA_QTYPO>, <WA_QTYPR>, <WA_QTREQ>, <WA_QBALN>.
ENDWHILE.
ELSE.
V_PERIOD1 = P_BULAN+4(2).
V_PERIOD2 = P_TOPER+4(2).
WHILE V_PERIOD1 <= 12.
CLEAR V_FIELD.
CONCATENATE 'ZTXPO' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPO>.
CLEAR V_FIELD.
CONCATENATE 'ZTXPR' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPR>.
CLEAR V_FIELD.
CONCATENATE 'ZTREQ' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTREQ>.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBALN>.
LOOP AT MRP_IND_LINES WHERE AVAIL_DATE+4(2) = V_PERIOD1 AND AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-AVAIL_DATE+4(2) = V_PERIOD1 AND MRP_IND_LINES-AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-MRP_ELEMNT = 'POitem'.
<WA_QTYPO> = <WA_QTYPO> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'PurRqs'.
<WA_QTYPR> = <WA_QTYPR> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'OrdRes' OR MRP_IND_LINES-MRP_ELEMNT = 'MtlRes' OR MRP_IND_LINES-MRP_ELEMNT = 'DepReq'
OR MRP_IND_LINES-MRP_ELEMNT = 'TrnRes'.
MRP_IND_LINES-REC_REQD_QTY = MRP_IND_LINES-REC_REQD_QTY * -1.
<WA_QTREQ> = <WA_QTREQ> + MRP_IND_LINES-REC_REQD_QTY.
ENDIF.
ENDIF.
CLEAR MRP_IND_LINES.
ENDLOOP.
IF V_PERIOD1 = P_BULAN+4(2).
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
<WA_QBALN> = <WA_TOQTY> + <WA_QTYPO> + <WA_QTYPR> - <WA_QTREQ>.
ELSE.
CLEAR B_PERIOD.
B_PERIOD = V_PERIOD1 - 1.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' B_PERIOD V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
<WA_QBALN> = <WA_QBLBK> + <WA_QTYPO> + <WA_QTYPR> - <WA_QTREQ>.
UNASSIGN <WA_QBLBK>.
ENDIF.
V_PERIOD1 = V_PERIOD1 + 1.
UNASSIGN : <WA_QTYPO>, <WA_QTYPR>, <WA_QTREQ>, <WA_QBALN>.
ENDWHILE.
CLEAR : V_SELISIH, Z_TAHUN.
V_SELISIH = V_TAHUN2 - V_TAHUN1.
Z_TAHUN = V_TAHUN1.
DATA ICOUNT TYPE I.
CLEAR ICOUNT.
DO V_SELISIH TIMES.
ICOUNT = ICOUNT + 1.
CLEAR Z_PERIOD.
IF ICOUNT = V_SELISIH.
Z_PERIOD = V_PERIOD2.
ELSEIF ICOUNT < V_SELISIH.
Z_PERIOD = 12.
ENDIF.
Z_TAHUN = Z_TAHUN + 1.
CLEAR V_COUNT.
V_COUNT = 1.
WHILE V_COUNT <= Z_PERIOD.
V_PERIOD1 = V_COUNT.
CLEAR V_FIELD.
CONCATENATE 'ZTXPO' V_COUNT Z_TAHUN+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPO>.
CLEAR V_FIELD.
CONCATENATE 'ZTXPR' V_COUNT Z_TAHUN+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPR>.
CLEAR V_FIELD.
CONCATENATE 'ZTREQ' V_COUNT Z_TAHUN+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTREQ>.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_COUNT Z_TAHUN+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBALN>.
LOOP AT MRP_IND_LINES WHERE AVAIL_DATE+4(2) = V_COUNT AND AVAIL_DATE(4) = Z_TAHUN.
IF MRP_IND_LINES-AVAIL_DATE+4(2) = V_COUNT AND MRP_IND_LINES-AVAIL_DATE(4) = Z_TAHUN.
IF MRP_IND_LINES-MRP_ELEMNT = 'POitem'.
<WA_QTYPO> = <WA_QTYPO> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'PurRqs'.
<WA_QTYPR> = <WA_QTYPR> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'OrdRes' OR MRP_IND_LINES-MRP_ELEMNT = 'MtlRes' OR MRP_IND_LINES-MRP_ELEMNT = 'DepReq'
OR MRP_IND_LINES-MRP_ELEMNT = 'TrnRes'.
MRP_IND_LINES-REC_REQD_QTY = MRP_IND_LINES-REC_REQD_QTY * -1.
<WA_QTREQ> = <WA_QTREQ> + MRP_IND_LINES-REC_REQD_QTY.
ENDIF.
ENDIF.
CLEAR MRP_IND_LINES.
ENDLOOP.
CLEAR B_PERIOD.
IF V_PERIOD1 = 1.
B_PERIOD = 12.
CLEAR : V_FIELD, V_TAHUN3.
V_TAHUN3 = Z_TAHUN.
V_TAHUN3+2(2) = V_TAHUN3+2(2) - 1.
CONCATENATE 'ZBALN' B_PERIOD V_TAHUN3+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
* v_period1 = v_period1 + 1.
ELSE.
B_PERIOD = V_PERIOD1 - 1.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' B_PERIOD Z_TAHUN+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBLBK>.
* v_period1 = v_period2.
ENDIF.
IF <WA_QTYPO> <> 0 OR <WA_QTYPR> <> 0 OR <WA_QTREQ> <> 0.
<WA_QBALN> = <WA_QBLBK> + <WA_QTYPO> + <WA_QTYPR> - <WA_QTREQ>.
ELSE.
<WA_QBALN> = <WA_QBLBK>.
ENDIF.
UNASSIGN <WA_QBLBK>.
UNASSIGN : <WA_QTYPO>, <WA_QTYPR>, <WA_QTREQ>, <WA_QBALN>.
V_COUNT = V_COUNT + 1.
ENDWHILE.
ENDDO.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
INPUT = <WA_MEINS>
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = <WA_MEINS>.
UNASSIGN : <WA_MATNR>, <WA_UUQTY>, <WA_QIQTY>, <WA_TOQTY>, <WA_MEINS>, <WA_MRPAR>.
ENDLOOP.
SORT_1 = 'MATNR'.
SORT_2 = 'BERID'.
SORT <IT_GRID> BY (SORT_1) (SORT_2).
PERFORM DISPLAY_ALV.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TARIKMUNDUR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM TARIKMUNDUR .
CLEAR V_FIELD.
CONCATENATE 'ZTXPO' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPO>.
CLEAR V_FIELD.
CONCATENATE 'ZTXPR' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTYPR>.
CLEAR V_FIELD.
CONCATENATE 'ZTREQ' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QTREQ>.
CLEAR V_FIELD.
CONCATENATE 'ZBALN' V_PERIOD1 V_TAHUN1+2(2) INTO V_FIELD.
ASSIGN COMPONENT V_FIELD OF STRUCTURE <WA_GRID> TO <WA_QBALN>.
LOOP AT MRP_IND_LINES WHERE AVAIL_DATE+4(2) < V_PERIOD1 AND AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-AVAIL_DATE+4(2) < V_PERIOD1 AND MRP_IND_LINES-AVAIL_DATE(4) = V_TAHUN1.
IF MRP_IND_LINES-MRP_ELEMNT = 'POitem'.
<WA_QTYPO> = <WA_QTYPO> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'PurRqs'.
<WA_QTYPR> = <WA_QTYPR> + MRP_IND_LINES-REC_REQD_QTY.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'OrdRes' OR MRP_IND_LINES-MRP_ELEMNT = 'MtlRes' OR MRP_IND_LINES-MRP_ELEMNT = 'DepReq'
OR MRP_IND_LINES-MRP_ELEMNT = 'TrnRes'.
MRP_IND_LINES-REC_REQD_QTY = MRP_IND_LINES-REC_REQD_QTY * -1.
<WA_QTREQ> = <WA_QTREQ> + MRP_IND_LINES-REC_REQD_QTY.
ENDIF.
ENDIF.
CLEAR MRP_IND_LINES.
ENDLOOP.
UNASSIGN : <WA_QTYPO>, <WA_QTYPR>, <WA_QTREQ>, <WA_QBALN>.
ENDFORM.
Include ZRPP003_03
*&---------------------------------------------------------------------*
*& Include ZRPP003_03
*&---------------------------------------------------------------------*
FORM TO_ALV_SLIS_EVENT_EXIT .
CLEAR WA_EVENT_EXIT.
WA_EVENT_EXIT-UCOMM = '&IC1'.
WA_EVENT_EXIT-AFTER = 'X'.
APPEND WA_EVENT_EXIT TO IT_EVENT_EXIT.
WA_EVENT_EXIT-UCOMM = '%_GC 121 2'.
WA_EVENT_EXIT-AFTER = 'X'.
APPEND WA_EVENT_EXIT TO IT_EVENT_EXIT.
ENDFORM.
FORM DISPLAY_ALV.
WA_LAYOUT-STYLEFNAME = 'FIELD_STYLE'.
WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-CWIDTH_OPT = 'X'.
* refresh it_print.
* it_print[] = it_data.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* i_callback_pf_status_set = 'SET_PF_STATUS'
* i_callback_top_of_page = 'TOP_OF_PAGE'
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_FLDCAT[]
I_SAVE = 'X'
TABLES
T_OUTTAB = <IT_GRID>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.
FORM SETFIELDCAT.
* BERID
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 1.
WA_IT_FLDCAT-FIELDNAME = 'BERID'.
* wa_it_fldcat-datatype = 'CHAR'.
WA_IT_FLDCAT-SCRTEXT_L = 'MRP Area'.
WA_IT_FLDCAT-REF_TABLE = 'MDLV'.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-NO_OUT = 'X'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 1.
WA_IT_FLDCAT-FIELDNAME = 'BERTX'.
* wa_it_fldcat-datatype = 'CHAR'.
WA_IT_FLDCAT-SCRTEXT_L = 'MRP Area Desc'.
WA_IT_FLDCAT-REF_TABLE = 'MDLV'.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-KEY = 'X'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 1.
WA_IT_FLDCAT-FIELDNAME = 'MATNR'.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SCRTEXT_L = 'Material'.
WA_IT_FLDCAT-REF_TABLE = 'MARA'.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-KEY = 'X'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 2.
WA_IT_FLDCAT-FIELDNAME = 'MAKTX'.
WA_IT_FLDCAT-DATATYPE = 'CHAR'. "it_ztmme125b-atfor.
WA_IT_FLDCAT-SCRTEXT_L = 'Material Description'.
WA_IT_FLDCAT-INTLEN = 40.
WA_IT_FLDCAT-OUTPUTLEN = 40.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 3.
WA_IT_FLDCAT-FIELDNAME = 'MEINS'.
WA_IT_FLDCAT-DATATYPE = 'UNIT'.
* wa_it_fldcat-edit = 'X'.
WA_IT_FLDCAT-SCRTEXT_L = 'UoM'.
WA_IT_FLDCAT-INTLEN = 10.
WA_IT_FLDCAT-OUTPUTLEN = 10.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 4.
WA_IT_FLDCAT-FIELDNAME = 'UUQTY'.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
WA_IT_FLDCAT-SCRTEXT_L = 'UU Stock'.
WA_IT_FLDCAT-INTLEN = 30.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 5.
WA_IT_FLDCAT-FIELDNAME = 'QIQTY'.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
WA_IT_FLDCAT-SCRTEXT_L = 'QI Stock'.
WA_IT_FLDCAT-INTLEN = 30.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
* CLEAR WA_IT_FLDCAT.
* WA_IT_FLDCAT-FIELDNAME = 'POQTY'.
* WA_IT_FLDCAT-DATATYPE = 'QUAN'.
* WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
* WA_IT_FLDCAT-SCRTEXT_L = 'PO Qty'.
* WA_IT_FLDCAT-INTLEN = 30.
* WA_IT_FLDCAT-OUTPUTLEN = 20.
* WA_IT_FLDCAT-DECIMALS = 3.
* APPEND WA_IT_FLDCAT TO IT_FLDCAT .
*
* CLEAR WA_IT_FLDCAT.
* WA_IT_FLDCAT-FIELDNAME = 'PRQTY'.
* WA_IT_FLDCAT-DATATYPE = 'QUAN'.
* WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
* WA_IT_FLDCAT-SCRTEXT_L = 'PR Qty'.
* WA_IT_FLDCAT-INTLEN = 30.
* WA_IT_FLDCAT-OUTPUTLEN = 20.
* WA_IT_FLDCAT-DECIMALS = 3.
* APPEND WA_IT_FLDCAT TO IT_FLDCAT .
*
* CLEAR WA_IT_FLDCAT.
* WA_IT_FLDCAT-FIELDNAME = 'RSQTY'.
* WA_IT_FLDCAT-DATATYPE = 'QUAN'.
* WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
* WA_IT_FLDCAT-SCRTEXT_L = 'Reservation'.
* WA_IT_FLDCAT-INTLEN = 30.
* WA_IT_FLDCAT-OUTPUTLEN = 20.
* WA_IT_FLDCAT-DECIMALS = 3.
* APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 6.
WA_IT_FLDCAT-FIELDNAME = 'TOQTY'.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
WA_IT_FLDCAT-SCRTEXT_L = 'Total Stock'.
WA_IT_FLDCAT-INTLEN = 30.
WA_IT_FLDCAT-OUTPUTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR : V_PERIOD1, V_PERIOD2, V_COUNT, V_TAHUN1, V_TAHUN2.
V_TAHUN1 = P_BULAN(4).
V_TAHUN2 = P_TOPER(4).
IF V_TAHUN1 = V_TAHUN2.
V_PERIOD1 = P_BULAN+4(2).
V_PERIOD2 = P_TOPER+4(2).
WHILE V_PERIOD1 <= V_PERIOD2.
CLEAR V_COUNT.
V_COUNT = V_PERIOD1.
PERFORM BULAN_BINTANG USING V_PERIOD1 V_TAHUN1.
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 7.
CONCATENATE 'ZTXPO' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
* wa_it_fldcat-fieldname = 'ZTXPO'.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PO' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
* wa_it_fldcat-col_pos = 8.
* wa_it_fldcat-fieldname = 'ZTXPR'.
CONCATENATE 'ZTXPR' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PR' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTREQ' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Req' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZBALN' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Balance' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
V_PERIOD1 = V_PERIOD1 + 1.
ENDWHILE.
ELSEIF V_TAHUN2 > V_TAHUN1.
V_PERIOD1 = P_BULAN+4(2).
V_PERIOD2 = P_TOPER+4(2).
CLEAR : V_SELISIH, Z_TAHUN.
V_SELISIH = V_TAHUN2 - V_TAHUN1.
WHILE V_PERIOD1 <= 12.
CLEAR V_COUNT.
V_COUNT = V_PERIOD1.
PERFORM BULAN_BINTANG USING V_PERIOD1 V_TAHUN1.
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTXPO' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PO' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTXPR' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PR' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTREQ' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Req' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZBALN' V_COUNT V_TAHUN1+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Balance' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
V_PERIOD1 = V_PERIOD1 + 1.
ENDWHILE.
* else.
Z_TAHUN = V_TAHUN1.
DATA ICOUNT TYPE I.
CLEAR ICOUNT.
DO V_SELISIH TIMES.
ICOUNT = ICOUNT + 1.
CLEAR Z_PERIOD.
IF ICOUNT = V_SELISIH.
Z_PERIOD = V_PERIOD2.
ELSEIF ICOUNT < V_SELISIH.
Z_PERIOD = 12.
ENDIF.
Z_TAHUN = Z_TAHUN + 1.
CLEAR V_COUNT.
V_COUNT = 1.
WHILE V_COUNT <= Z_PERIOD.
PERFORM BULAN_BINTANG USING V_COUNT Z_TAHUN.
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTXPO' V_COUNT Z_TAHUN+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PO' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTXPR' V_COUNT Z_TAHUN+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'PR' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZTREQ' V_COUNT Z_TAHUN+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Req' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_IT_FLDCAT.
CONCATENATE 'ZBALN' V_COUNT Z_TAHUN+2(2) INTO WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'QUAN'.
WA_IT_FLDCAT-QFIELDNAME = 'MEINS'.
CONCATENATE 'Balance' V_BULAN INTO WA_IT_FLDCAT-SCRTEXT_L SEPARATED BY SPACE.
WA_IT_FLDCAT-INTLEN = 20.
WA_IT_FLDCAT-DECIMALS = 3.
WA_IT_FLDCAT-OUTPUTLEN = 20.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
V_COUNT = V_COUNT + 1.
ENDWHILE.
ENDDO.
ENDIF.
ENDFORM.
FORM BULAN_BINTANG USING P_PARAM P_TAHUN.
V_BULAN = P_TAHUN.
CONDENSE V_BULAN.
IF P_PARAM = '1' OR P_PARAM = '01'.
CONCATENATE '01.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '2' OR P_PARAM = '02'.
CONCATENATE '02.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '3' OR P_PARAM = '03'.
CONCATENATE '03.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '4' OR P_PARAM = '04'.
CONCATENATE '04.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '5' OR P_PARAM = '05'.
CONCATENATE '05.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '6' OR P_PARAM = '06'.
CONCATENATE '06.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '7' OR P_PARAM = '07'.
CONCATENATE '07.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '8' OR P_PARAM = '08'.
CONCATENATE '08.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '9' OR P_PARAM = '09'.
CONCATENATE '09.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '10'.
CONCATENATE '10.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '11' .
CONCATENATE '11.' V_BULAN INTO V_BULAN.
ELSEIF P_PARAM = '12'.
CONCATENATE '12.' V_BULAN INTO V_BULAN.
ENDIF.
ENDFORM.
Terimakasih,
ReplyDeletesangat membantu report ini ditempat saya.
Sukses selalu