REPORT 102.
TABLES: VBAP,MSKA,MAKT,VBAK.
DATA: BEGIN OF ITAB OCCURS 0,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
KWMENG LIKE VBAP-KWMENG,
VBELN LIKE VBAP-VBELN,
WERKS LIKE VBAP-WERKS,
LGORT LIKE MARD-LGORT,
MAKTX LIKE MAKT-MAKTX,
OPENQ LIKE VBAP-KWMENG,
SHIPQ LIKE VBAP-KWMENG,
ZMENG LIKE VBAP-ZMENG,
MTPOS LIKE MVKE-MTPOS,
BMENG LIKE VBEP-BMENG,
EDATU LIKE VBEP-EDATU,
WEBAZ LIKE MARC-WEBAZ,
PLIFZ LIKE MARC-PLIFZ,
LABST LIKE MARD-LABST,
OPEN_POQTY LIKE EKET-MENGE,
END OF ITAB.
DATA : ITAB_UNITE LIKE ITAB OCCURS 0 WITH HEADER LINE .
DATA: L_TOTAL LIKE VBAP-KWMENG.
DATA: L_SHIPPED TYPE P DECIMALS 2,
L_OPEN TYPE P DECIMALS 2,
L_FLAG TYPE I VALUE 0.
DATA: BEGIN OF ITAB_PO OCCURS 0,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MENGE LIKE EKET-MENGE,
WEMNG LIKE EKET-WEMNG,
OPEN_POQTY LIKE EKET-MENGE,
MATNR LIKE EKPO-MATNR,
END OF ITAB_PO.
DATA : ITAB_EKET LIKE ITAB_PO OCCURS 0 WITH HEADER LINE .
DATA : ITAB_POTOTAL LIKE ITAB_PO OCCURS 0 WITH HEADER LINE .
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME. TITLE TEXT-001.
PARAMETERS: P_WERKS LIKE MSKA-WERKS.
SELECT-OPTIONS:S_MATNR FOR MSKA-MATNR MEMORY ID UD.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM. GET_DATA_SO.
PERFORM. GET_DATA_PO.
PERFORM. GET_DATA_UNITE.
END-OF-SELECTION.
IF L_FLAG <> 1.
PERFORM. OUTPUT.
ENDIF.
*&--------------------------------------------------------------------*
*& Form GET_DATA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM. GET_DATA_SO.
***For SO
SELECT VBAP~VBELN VBAP~MATNR VBAP~KWMENG VBAP~WERKS VBUP~LFSTA VBAP~ZMENG
VBAP~POSNR FROM VBAP INNER JOIN VBUP
ON VBAP~VBELN = VBUP~VBELN
AND VBAP~POSNR = VBUP~POSNR
INTO CORRESPONDING FIELDS OF TABLE ITAB
WHERE MATNR IN S_MATNR
AND WERKS = P_WERKS
AND LFSTA <> 'C'.
IF SY-SUBRC <> 0.
L_FLAG = 1.
MESSAGE 'The data is not exist' TYPE 'S'.
EXIT.
ENDIF.
LOOP AT ITAB.
PERFORM. ORDER_QTY USING ITAB-VBELN ITAB-POSNR
CHANGING L_SHIPPED.
IF ITAB-KWMENG <> 0.
L_OPEN = ITAB-KWMENG.
ELSE.
L_OPEN = ITAB-ZMENG.
ITAB-KWMENG = ITAB-ZMENG.
ENDIF.
SUBTRACT L_SHIPPED FROM L_OPEN.
IF L_OPEN <= 0.
DELETE ITAB. CONTINUE.
ENDIF.
ITAB-SHIPQ = L_SHIPPED.
ITAB-OPENQ = L_OPEN.
SELECT SINGLE MAKTX FROM MAKT INTO ITAB-MAKTX
WHERE MATNR = ITAB-MATNR.
SELECT SINGLE BMENG FROM VBEP INTO ITAB-BMENG
WHERE VBELN = ITAB-VBELN
AND POSNR = ITAB-POSNR.
IF ITAB-BMENG = ITAB-KWMENG.
SELECT MAX( EDATU ) FROM VBEP INTO ITAB-EDATU
WHERE VBELN = ITAB-VBELN
AND POSNR = ITAB-POSNR.
ELSEIF ITAB-KWMENG > ITAB-BMENG .
SELECT MAX( EDATU ) FROM VBEP INTO ITAB-EDATU
WHERE VBELN = ITAB-VBELN
AND POSNR = ITAB-POSNR.
SELECT SINGLE WEBAZ PLIFZ FROM MARC INTO (ITAB-WEBAZ,ITAB-PLIFZ)
WHERE MATNR = ITAB-MATNR.
ITAB-EDATU = ITAB-EDATU + ITAB-WEBAZ + ITAB-PLIFZ.
ENDIF.
MODIFY ITAB .
CLEAR ITAB .
ENDLOOP.
LOOP AT ITAB.
ITAB_UNITE-MATNR = ITAB-MATNR.
ITAB_UNITE-MAKTX = ITAB-MAKTX.
ITAB_UNITE-MTPOS = ITAB-MTPOS.
ITAB_UNITE-KWMENG = ITAB-KWMENG.
ITAB_UNITE-OPENQ = ITAB-OPENQ.
COLLECT ITAB_UNITE.
ENDLOOP.
LOOP AT ITAB_UNITE.
SELECT SINGLE MTPOS FROM MVKE INTO ITAB_UNITE-MTPOS
WHERE MATNR = ITAB_UNITE-MATNR.
SELECT SINGLE LGORT LABST FROM MARD INTO (ITAB_UNITE-LGORT,ITAB_UNITE-LABST)
WHERE MATNR = ITAB_UNITE-MATNR.
MODIFY ITAB_UNITE.
CLEAR ITAB_UNITE.
ENDLOOP.
ENDFORM. "GET_DATA
*&--------------------------------------------------------------------*
*& Form GET_DATA_PO
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM. GET_DATA_PO.
****For PO
SELECT EKPO~MATNR EKPO~EBELN EKPO~EBELP FROM EKPO INNER JOIN EKKO
ON EKKO~EBELN = EKPO~EBELN
INTO CORRESPONDING FIELDS OF TABLE ITAB_PO
WHERE EKPO~MATNR IN S_MATNR
AND EKPO~WERKS = P_WERKS
AND EKKO~BSTYP = 'F'
AND EKKO~BSART = 'NB'.
SELECT EBELN EBELP MENGE WEMNG INTO TABLE ITAB_EKET FROM EKET
FOR ALL ENTRIES IN ITAB_PO
WHERE EBELN = ITAB_PO-EBELN
AND EBELP = ITAB_PO-EBELP.
LOOP AT ITAB_EKET.
SELECT SINGLE MATNR FROM EKPO INTO ITAB_EKET-MATNR
WHERE WERKS = P_WERKS
AND EBELN = ITAB_EKET-EBELN
AND EBELP = ITAB_EKET-EBELP.
ITAB_EKET-OPEN_POQTY = ITAB_EKET-MENGE - ITAB_EKET-WEMNG.
MODIFY ITAB_EKET.
CLEAR ITAB_EKET.
ENDLOOP.
DELETE ITAB_EKET WHERE OPEN_POQTY =< 0.
LOOP AT ITAB_EKET.
ITAB_POTOTAL-MATNR = ITAB_EKET-MATNR.
ITAB_POTOTAL-OPEN_POQTY = ITAB_EKET-OPEN_POQTY.
COLLECT ITAB_POTOTAL.
CLEAR ITAB_POTOTAL.
ENDLOOP .
ENDFORM. "GET_DATA_PO
*&--------------------------------------------------------------------*
*& Form GET_DATA_UNITE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM. GET_DATA_UNITE.
LOOP AT ITAB_UNITE.
READ TABLE ITAB_POTOTAL WITH KEY MATNR = ITAB_UNITE-MATNR.
IF SY-SUBRC = 0.
ITAB_UNITE-OPEN_POQTY = ITAB_POTOTAL-OPEN_POQTY.
ENDIF.
MODIFY ITAB_UNITE.
CLEAR ITAB_UNITE.
ENDLOOP.
ENDFORM. "GET_DATA_UNITE
*&--------------------------------------------------------------------*
*& Form get_order_quantity
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->P_VBELN text
* -->P_POSNR text
* -->P_TOTAL_SHItext
*---------------------------------------------------------------------*
FORM. ORDER_QTY USING P_VBELN P_POSNR
CHANGING P_TOTAL_SHIPINV.
DATA: IT_VBFA LIKE VBFAVB OCCURS 0 WITH HEADER LINE.
DATA: L_SHIPP_TOT LIKE VBAP-KWMENG,
L_TOTAL_INVOICED LIKE VBAP-KWMENG.
CLEAR: P_TOTAL_SHIPINV.
SELECT RFMNG VBTYP_N FROM VBFA
INTO CORRESPONDING FIELDS OF TABLE IT_VBFA
WHERE VBELV = P_VBELN
AND POSNV = P_POSNR.
LOOP AT IT_VBFA WHERE RFMNG <> 0 AND
( VBTYP_N = 'R' OR VBTYP_N = 'H' OR
VBTYP_N = 'M' OR VBTYP_N = 'N' ).
IF IT_VBFA-VBTYP_N = 'R' .
ADD IT_VBFA-RFMNG TO L_SHIPP_TOT.
ELSEIF IT_VBFA-VBTYP_N = 'H' .
SUBTRACT IT_VBFA-RFMNG FROM L_SHIPP_TOT.
ELSEIF IT_VBFA-VBTYP_N = 'M'.
ADD IT_VBFA-RFMNG TO L_TOTAL_INVOICED.
ELSEIF IT_VBFA-VBTYP_N = 'N'.
SUBTRACT IT_VBFA-RFMNG FROM L_TOTAL_INVOICED.
ENDIF.
ENDLOOP.
IF L_SHIPP_TOT <> 0.
P_TOTAL_SHIPINV = L_SHIPP_TOT.
ELSE.
P_TOTAL_SHIPINV = L_TOTAL_INVOICED.
ENDIF.
ENDFORM. "ORDER_QTY
*&--------------------------------------------------------------------*
*& Form OUTPUT
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM. OUTPUT.
TYPE-POOLS: SLIS.
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
COL_POS TYPE I VALUE 0.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'MATNR'.
FIELDCAT_LN-SELTEXT_L = 'Material'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'MAKTX'.
FIELDCAT_LN-SELTEXT_L = 'Material Des'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'MTPOS'.
FIELDCAT_LN-SELTEXT_L = 'MTPOS'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'KWMENG'.
FIELDCAT_LN-SELTEXT_L = 'SO Qty'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'OPENQ'.
FIELDCAT_LN-SELTEXT_L = 'Have not receipt SO Qty'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'LGORT'.
FIELDCAT_LN-SELTEXT_L = 'Locator'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'LABST'.
FIELDCAT_LN-SELTEXT_L = 'Material Stock'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
***For PO
ADD 1 TO COL_POS.
FIELDCAT_LN-TABNAME = 'ITAB_UNITE'.
FIELDCAT_LN-FIELDNAME = 'OPEN_POQTY'.
FIELDCAT_LN-SELTEXT_L = 'Have not receipt PO Qty'.
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_BACKGROUND_ID = 'ALV_BACKGROUND'
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = FIELDCAT
TABLES
T_OUTTAB = ITAB_UNITE.
ENDFORM. "OUTPUT
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9309631/viewspace-624996/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9309631/viewspace-624996/