*&---------------------------------------------------------------------*
*& Report ZPPR012
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2020-03-05
*& Program Type : Report
*& Description : 删除重复的成品需求
*&---------------------------------------------------------------------*
REPORT ZPPR012.
*&---------------------------------------------------------------------*
*& 包含 YN_TEST02_TOP
*&---------------------------------------------------------------------*
TABLES:MARC,MARA,ZTMJCP,ZTMJZD,ZTZBRAN.
TYPE-POOLS:SLIS,T001W.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_MATNR FOR MARC-MATNR MODIF ID C1 . "磨具编码
SELECT-OPTIONS: S_WERKS FOR MARC-WERKS MODIF ID C1 . "产品物料编码
SELECTION-SCREEN END OF BLOCK B1.
DATA:GT_DATA TYPE TABLE OF MARC WITH HEADER LINE.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
DATA:MRP_ITEMS LIKE BAPI_MRP_ITEMS OCCURS 0 WITH HEADER LINE .
DATA:MRP_IND_LINES LIKE BAPI_MRP_IND_LINES OCCURS 0 WITH HEADER LINE .
DATA:GT_EBAN TYPE TABLE OF EBAN WITH HEADER LINE .
DATA:GT_CDHDR TYPE TABLE OF CDHDR WITH HEADER LINE .
DATA:GT_EKKO TYPE TABLE OF EKKO WITH HEADER LINE .
DATA:GT_EKPO TYPE TABLE OF EKPO WITH HEADER LINE .
DATA:GT_EKBE TYPE TABLE OF EKBE WITH HEADER LINE .
DATA:NUMBER LIKE BAPIMEREQHEADER-PREQ_NO.
DATA:PRITEM LIKE BAPIMEREQITEMIMP OCCURS 0 WITH HEADER LINE .
DATA:PRITEMX LIKE BAPIMEREQITEMX OCCURS 0 WITH HEADER LINE .
DATA:RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE .
DATA:MESSAGE TYPE BAPI_MSG.
DATA:GT_PP01 TYPE TABLE OF ZTPP01 WITH HEADER LINE.
DATA:FLAG TYPE C.
CLEAR GT_DATA[] .
SELECT MATNR WERKS INTO CORRESPONDING FIELDS OF TABLE GT_DATA[] FROM MARC
WHERE WERKS IN S_WERKS
AND MATNR IN S_MATNR
.
LOOP AT GT_DATA.
CLEAR MRP_ITEMS[].
CLEAR MRP_IND_LINES[].
CALL FUNCTION 'BAPI_MATERIAL_STOCK_REQ_LIST'
EXPORTING
MATERIAL_LONG = GT_DATA-MATNR
PLANT = GT_DATA-WERKS
GET_ITEM_DETAILS = 'X'
TABLES
MRP_ITEMS = MRP_ITEMS[]
MRP_IND_LINES = MRP_IND_LINES[].
LOOP AT MRP_IND_LINES WHERE EXCMESSAGE = '20' .
IF MRP_IND_LINES-MRP_ELEMNT = 'PurRqs'.
CLEAR GT_EBAN.
SPLIT MRP_IND_LINES-ELEMNT_DATA AT '/' INTO GT_EBAN-BANFN GT_EBAN-BNFPO .
SELECT SINGLE * INTO CORRESPONDING FIELDS OF GT_EBAN FROM EBAN
WHERE BANFN = GT_EBAN-BANFN
AND BNFPO = GT_EBAN-BNFPO
.
*1.对打了固定标记的请购单 、修改用户名为CS*、请购单类型为NB、供应工厂不为空、
*请购单例外信息为20(多余需求,系统建议删除)的请购单,程序自动删除
IF GT_EBAN-FIXKZ IS NOT INITIAL
AND GT_EBAN-BSART = 'NB'
* AND GT_EBAN-ERNAM CS 'CS'
AND GT_EBAN-RESWK IS NOT INITIAL
.
CLEAR GT_CDHDR.
GT_CDHDR-OBJECTID = GT_EBAN-BANFN .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_CDHDR-OBJECTID
IMPORTING
OUTPUT = GT_CDHDR-OBJECTID.
GT_CDHDR-USERNAME = 'CS%' .
SELECT SINGLE * INTO CORRESPONDING FIELDS OF GT_CDHDR FROM CDHDR
WHERE OBJECTCLAS = 'BANF'
AND OBJECTID = GT_CDHDR-OBJECTID
AND USERNAME LIKE GT_CDHDR-USERNAME
.
IF SY-SUBRC = 0.
* PERFORM FOM_PRITDE USING GT_EBAN CHANGING GT_PP01.
NUMBER = GT_EBAN-BANFN .
CLEAR PRITEM[].
PRITEM-PREQ_ITEM = GT_EBAN-BNFPO .
PRITEM-DELETE_IND = 'X' .
APPEND PRITEM.
CLEAR PRITEMX[].
PRITEMX-PREQ_ITEM = GT_EBAN-BNFPO .
PRITEMX-PREQ_ITEMX = 'X' .
PRITEMX-DELETE_IND = 'X' .
APPEND PRITEMX.
CLEAR RETURN[].
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
NUMBER = NUMBER
TABLES
RETURN = RETURN
PRITEM = PRITEM
PRITEMX = PRITEMX.
CLEAR MESSAGE .
SORT RETURN BY MESSAGE .
DELETE ADJACENT DUPLICATES FROM RETURN[] COMPARING MESSAGE.
LOOP AT RETURN WHERE TYPE = 'E'.
MESSAGE = MESSAGE && '/' && RETURN-MESSAGE .
ENDLOOP.
IF SY-SUBRC = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
GT_PP01-DATUM = SY-DATUM .
GT_PP01-MRP_ELEMNT = MRP_IND_LINES-MRP_ELEMNT .
GT_PP01-ELEMNT_DATA = MRP_IND_LINES-ELEMNT_DATA .
GT_PP01-STAND = 'E' .
GT_PP01-MESSAGE = MESSAGE .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
GT_PP01-DATUM = SY-DATUM .
GT_PP01-MRP_ELEMNT = MRP_IND_LINES-MRP_ELEMNT .
GT_PP01-ELEMNT_DATA = MRP_IND_LINES-ELEMNT_DATA .
GT_PP01-STAND = 'S' .
GT_PP01-MESSAGE = '执行成功!' .
ENDIF.
MODIFY ZTPP01 FROM GT_PP01 .
COMMIT WORK .
ENDIF.
ENDIF.
ELSEIF MRP_IND_LINES-MRP_ELEMNT = 'POitem'.
CLEAR GT_EKKO .
CLEAR GT_EKPO .
SPLIT MRP_IND_LINES-ELEMNT_DATA AT '/' INTO GT_EKPO-EBELN GT_EKPO-EBELP .
SELECT SINGLE * INTO CORRESPONDING FIELDS OF GT_EKKO FROM EKKO
* WHERE BSART = 'Z002'
WHERE BSART = 'Z001'
AND EBELN = GT_EKPO-EBELN
.
IF SY-SUBRC = 0.
IF GT_EKKO-ERNAM CS 'CS' OR GT_EKKO-ERNAM CS 'WH'.
CLEAR GT_EKBE[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_EKBE[] FROM EKBE
WHERE EBELN = GT_EKPO-EBELN
AND EBELP = GT_EKPO-EBELP
.
IF SY-SUBRC <> 0.
PERFORM FOM_POITDE USING GT_EKPO CHANGING GT_PP01.
MODIFY ZTPP01 FROM GT_PP01 .
COMMIT WORK .
ELSE.
LOOP AT GT_EKBE WHERE BEWTP <> 'L'.
ENDLOOP.
IF SY-SUBRC <> 0.
SORT GT_EKBE[] BY BELNR BUZEI .
DELETE ADJACENT DUPLICATES FROM GT_EKBE[] COMPARING BELNR BUZEI.
CLEAR FLAG .
LOOP AT GT_EKBE WHERE BELNR IS NOT INITIAL AND BUZEI IS NOT INITIAL.
PERFORM FOM_DNITDE USING GT_EKBE CHANGING GT_PP01 FLAG.
IF FLAG IS NOT INITIAL.
MODIFY ZTPP01 FROM GT_PP01 .
COMMIT WORK .
EXIT.
ENDIF.
CLEAR GT_EKBE .
ENDLOOP.
IF FLAG IS INITIAL.
PERFORM FOM_POITDE USING GT_EKPO CHANGING GT_PP01.
MODIFY ZTPP01 FROM GT_PP01 .
COMMIT WORK .
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR MRP_IND_LINES .
CLEAR GT_PP01 .
ENDLOOP.
CLEAR GT_DATA .
ENDLOOP.
ENDFORM.
INITIALIZATION .
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA .
*&---------------------------------------------------------------------*
*& Form FOM_POITDE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GT_EKPO
*& <-- GT_PP01
*&---------------------------------------------------------------------*
FORM FOM_POITDE USING P_GT_EKPO TYPE EKPO
CHANGING P_GT_PP01 TYPE ZTPP01.
DATA: T_POITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE.
DATA: T_POITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE.
DATA: T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: MESSAGE TYPE BAPI_MSG.
CLEAR T_POITEM[].
T_POITEM-PO_ITEM = P_GT_EKPO-EBELP.
T_POITEM-DELETE_IND = 'L'.
APPEND T_POITEM.
CLEAR T_POITEMX[].
T_POITEMX-PO_ITEM = P_GT_EKPO-EBELP.
T_POITEMX-PO_ITEMX = 'X'.
T_POITEMX-DELETE_IND = 'X'.
APPEND T_POITEMX.
CLEAR T_RETURN[].
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = P_GT_EKPO-EBELN
TABLES
RETURN = T_RETURN
POITEM = T_POITEM
POITEMX = T_POITEMX.
CLEAR MESSAGE .
SORT T_RETURN BY MESSAGE .
DELETE ADJACENT DUPLICATES FROM T_RETURN[] COMPARING MESSAGE.
LOOP AT T_RETURN WHERE TYPE = 'E'.
MESSAGE = MESSAGE && '/' && T_RETURN-MESSAGE .
ENDLOOP.
IF SY-SUBRC = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
P_GT_PP01-DATUM = SY-DATUM .
P_GT_PP01-MRP_ELEMNT = 'POitem' .
P_GT_PP01-ELEMNT_DATA = P_GT_EKPO-EBELN && '/' && P_GT_EKPO-EBELP.
P_GT_PP01-STAND = 'E' .
P_GT_PP01-MESSAGE = MESSAGE .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
P_GT_PP01-DATUM = SY-DATUM .
P_GT_PP01-MRP_ELEMNT = 'POitem' .
P_GT_PP01-ELEMNT_DATA = P_GT_EKPO-EBELN && '/' && P_GT_EKPO-EBELP.
P_GT_PP01-STAND = 'S' .
P_GT_PP01-MESSAGE = '执行成功!' .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_DNITDE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GT_EKBE
*& <-- GT_PP01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FOM_DNITDE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GT_EKBE
*& <-- GT_PP01
*& <-- FLAG
*&---------------------------------------------------------------------*
FORM FOM_DNITDE USING P_GT_EKBE TYPE EKBE
CHANGING P_GT_PP01 TYPE ZTPP01
P_FLAG TYPE C.
DATA: STR_HEADER_DATA LIKE BAPIOBDLVHDRCHG,
STR_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCHG.
DATA: ITEM_DATA LIKE BAPIOBDLVITEMCHG OCCURS 0 WITH HEADER LINE.
DATA: ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCHG OCCURS 0 WITH HEADER LINE.
DATA: T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: MESSAGE TYPE BAPI_MSG.
DATA V_DEL LIKE BAPIOBDLVHDRCHG-DELIV_NUMB.
DATA V_LIPS LIKE LIPS.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF V_LIPS FROM LIPS
WHERE VBELN = P_GT_EKBE-BELNR
AND POSNR = P_GT_EKBE-BUZEI
.
V_DEL = V_LIPS-VBELN.
CLEAR STR_HEADER_DATA .
STR_HEADER_DATA-DELIV_NUMB = V_LIPS-VBELN.
CLEAR STR_HEADER_CONTROL .
STR_HEADER_CONTROL-DELIV_NUMB = V_LIPS-VBELN.
CLEAR ITEM_DATA[] .
ITEM_DATA-DELIV_NUMB = V_LIPS-VBELN.
ITEM_DATA-DELIV_ITEM = V_LIPS-POSNR.
ITEM_DATA-MATERIAL = V_LIPS-MATNR.
ITEM_DATA-DLV_QTY = V_LIPS-LFIMG.
ITEM_DATA-DLV_QTY_IMUNIT = V_LIPS-LFIMG.
ITEM_DATA-FACT_UNIT_NOM = V_LIPS-UMVKZ.
ITEM_DATA-FACT_UNIT_DENOM = V_LIPS-UMVKN.
ITEM_DATA-BATCH = V_LIPS-CHARG.
ITEM_DATA-DELIV_NUMB = V_LIPS-VBELN.
ITEM_DATA-DELIV_ITEM = V_LIPS-POSNR.
APPEND ITEM_DATA .
CLEAR ITEM_CONTROL[] .
ITEM_CONTROL-DELIV_NUMB = V_LIPS-VBELN.
ITEM_CONTROL-DELIV_ITEM = V_LIPS-POSNR.
ITEM_CONTROL-DEL_ITEM = 'X'.
APPEND ITEM_CONTROL .
CLEAR T_RETURN[].
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
HEADER_DATA = STR_HEADER_DATA
HEADER_CONTROL = STR_HEADER_CONTROL
DELIVERY = V_DEL
TABLES
ITEM_DATA = ITEM_DATA
ITEM_CONTROL = ITEM_CONTROL
RETURN = T_RETURN.
CLEAR MESSAGE .
SORT T_RETURN BY MESSAGE .
DELETE ADJACENT DUPLICATES FROM T_RETURN[] COMPARING MESSAGE.
LOOP AT T_RETURN WHERE TYPE = 'E'.
MESSAGE = MESSAGE && '/' && T_RETURN-MESSAGE .
ENDLOOP.
IF SY-SUBRC = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
P_GT_PP01-DATUM = SY-DATUM .
P_GT_PP01-MRP_ELEMNT = 'POitem' .
P_GT_PP01-ELEMNT_DATA = P_GT_EKBE-BELNR && '/' && P_GT_EKBE-BUZEI.
P_GT_PP01-STAND = 'E' .
P_GT_PP01-MESSAGE = MESSAGE .
P_FLAG = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ENDFORM.
PP-自动删除MD04中重复的成品需求(开发笔记)
最新推荐文章于 2024-03-11 10:16:59 发布