*&———————————————————————*
*& Report ZMMI0003
*&———————————————————————*
*&
*&———————————————————————*
REPORT ZMMI0003.
INCLUDE: ZPUB_LVC_FUNC.
TABLES: T001,MSEG,ZMMT04.
DATA: BEGIN OF IT_ALV OCCURS 0,
ZORDER TYPE CHAR10, “blank
BELNR LIKE EKBE-BELNR,
EBELN LIKE EKBE-EBELN,
RELNB TYPE CHAR3, “blank
EBELP LIKE EKBE-EBELP,
ETENR LIKE EKET-ETENR,
MATNR LIKE EKBE-MATNR,
MAKTX LIKE MAKT-MAKTX,
MEINS LIKE EKPO-MEINS,
ZNAME TYPE CHAR50,
LIFN2 LIKE EKPA-LIFN2,
ZDATE TYPE CHAR40,
WAERS LIKE EKBE-WAERS,
NETPR LIKE EKPO-NETPR,
MENGE LIKE EKBE-MENGE,
BKTXT LIKE MKPF-BKTXT,
NTTVD TYPE CHAR50,
ZSUBI TYPE CHAR5,
CDATE LIKE EKBE-CPUDT,
GJAHR LIKE EKBE-GJAHR,
BUDAT LIKE EKBE-BUDAT,
WERKS LIKE EKBE-WERKS,
LGORT LIKE MSEG-LGORT,
CPUDT LIKE EKBE-CPUDT,
CPUTM LIKE EKBE-CPUTM,
SHKZG LIKE EKBE-SHKZG,
END OF IT_ALV,
IT_OUT LIKE STANDARD TABLE OF IT_ALV,
BEGIN OF IT_EKKO OCCURS 0,
EBELN LIKE EKKO-EBELN,
LIFNR LIKE EKKO-LIFNR,
NAME1 LIKE LFA1-NAME1,
NAME2 LIKE LFA1-NAME2,
END OF IT_EKKO.
DATA: IT_EKBE LIKE STANDARD TABLE OF EKBE WITH HEADER LINE,
IT_EKET LIKE STANDARD TABLE OF EKET WITH HEADER LINE,
IT_MAKT LIKE STANDARD TABLE OF MAKT WITH HEADER LINE,
IT_LFA1 LIKE STANDARD TABLE OF LFA1 WITH HEADER LINE,
IT_EKPA LIKE STANDARD TABLE OF EKPA WITH HEADER LINE,
IT_MKPF LIKE STANDARD TABLE OF MKPF WITH HEADER LINE,
IT_MSEG LIKE STANDARD TABLE OF MSEG WITH HEADER LINE,
IT_ZMMT LIKE STANDARD TABLE OF ZMMT04 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_WERKS FOR T001-BUKRS OBLIGATORY,
S_DATE FOR SY-DATUM,
S_LGORT FOR MSEG-LGORT.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-002.
PARAMETERS: R_ALV RADIOBUTTON GROUP G2 USER-COMMAND UC DEFAULT ‘X’.
PARAMETERS: R_PI RADIOBUTTON GROUP G2 .
PARAMETERS: R_HS RADIOBUTTON GROUP G2 .
SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN END OF BLOCK B1.
INITIALIZATION.
S_DATE-SIGN = ‘I’.
S_DATE-OPTION = ‘BT’.
S_DATE-LOW = SY-DATUM – 3.
S_DATE-HIGH = SY-DATUM.
APPEND S_DATE.
S_WERKS-SIGN = ‘I’.
S_WERKS-OPTION = ‘EQ’.
S_WERKS-LOW = ‘MX11’.
APPEND S_WERKS.
S_WERKS-LOW = ‘MX21’.
APPEND S_WERKS.
START-OF-SELECTION.
IF R_ALV = ‘X’. “选择展示数据,取数–>展示
PERFORM GET_DATA.
PERFORM DIS_DATA.
“PERFORM DEL_DATA.
ELSEIF R_HS = ‘X’. “选择发送历史数据到PI,从自建表取数–>展示–>发送到PI
PERFORM HIS_DATA.
PERFORM PI_DATA.
ELSE. “选择发送数据到PI,取数并检查是否是历史数据–>发送到PI–>保存到自建表
PERFORM GET_DATA.
PERFORM PI_DATA.
PERFORM SAVE_DATA.
ENDIF.
FORM GET_DATA.
SELECT EKBE~BELNR EKBE~EBELN EKBE~EBELP EKBE~MATNR EKBE~CPUDT
EKBE~CPUTM EKBE~WAERS EKBE~MENGE EKPO~MEINS EKPO~NETPR
EKBE~GJAHR EKBE~SHKZG EKBE~WERKS EKBE~BUDAT
INTO CORRESPONDING FIELDS OF TABLE IT_OUT
FROM EKBE JOIN EKPO ON EKBE~EBELN = EKPO~EBELN AND EKBE~EBELP
= EKPO~EBELP
WHERE EKBE~WERKS IN S_WERKS
AND EKBE~BUDAT IN S_DATE
AND EKBE~VGABE = ‘1’.
IF IT_OUT[] IS NOT INITIAL.
SELECT * INTO TABLE IT_EKET
FROM EKET
FOR ALL ENTRIES IN IT_OUT
WHERE EBELN = IT_OUT-EBELN
AND EBELP = IT_OUT-EBELP.
SORT IT_EKBE BY EBELN EBELP.
SELECT * INTO TABLE IT_MAKT
FROM MAKT
FOR ALL ENTRIES IN IT_OUT
WHERE MATNR = IT_OUT-MATNR
AND SPRAS = ‘EN’.
SORT IT_MAKT BY MATNR.
SELECT EBELN EKKO~LIFNR AS LIFNR NAME1 NAME2 INTO TABLE IT_EKKO
FROM EKKO JOIN LFA1 ON EKKO~LIFNR = LFA1~LIFNR.
SORT IT_EKKO BY EBELN.
SELECT * INTO TABLE IT_EKPA
FROM EKPA
FOR ALL ENTRIES IN IT_OUT
WHERE EBELN = IT_OUT-EBELN
AND PARVW = ‘BA’.
SORT IT_EKPA BY EBELN EBELP.
SELECT * INTO TABLE IT_MKPF
FROM MKPF
FOR ALL ENTRIES IN IT_OUT
WHERE MBLNR = IT_OUT-BELNR.
SORT IT_MKPF BY MBLNR.
SELECT * INTO TABLE IT_MSEG
FROM MSEG
FOR ALL ENTRIES IN IT_OUT
WHERE EBELN = IT_OUT-EBELN
AND EBELP = IT_OUT-EBELP
AND LGORT IN S_LGORT.
SORT IT_MSEG BY MBLNR EBELN EBELP.
ENDIF.
LOOP AT IT_OUT INTO IT_ALV WHERE MATNR IS NOT INITIAL.
IF IT_ALV-SHKZG = ‘H’.
IT_ALV-MENGE = – IT_ALV-MENGE.
ENDIF.
“日期格式转换
DATA: IT_DATE TYPE STRING,
IT_TIME TYPE STRING,
IT_DAY(2),
IT_MONTH(2),
IT_YEAR(4),
IT_H(2),
IT_M(2),
IT_S(2).
CALL FUNCTION ‘CONVERT_DATE_TO_INTERNAL’
EXPORTING
DATE_EXTERNAL = IT_ALV-BUDAT
IMPORTING
DATE_INTERNAL = IT_ALV-BUDAT
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2.
IT_YEAR = IT_ALV-BUDAT(4).
IT_MONTH = IT_ALV-BUDAT+4(2).
IT_DAY = IT_ALV-BUDAT+6(2).
IT_H = IT_ALV-CPUTM(2).
IT_M = IT_ALV-CPUTM+2(2).
IT_S = IT_ALV-CPUTM+4(2).
IT_DATE = |{ IT_YEAR }-{ IT_MONTH }-{ IT_DAY }|.
IT_TIME = | { IT_H }:{ IT_M }:{ IT_S }|.
IT_ALV-ZDATE = IT_DATE && IT_TIME.
IT_ALV-CDATE = SY-DATUM.
CLEAR:IT_DATE,IT_TIME,IT_YEAR,IT_MONTH,IT_DAY,IT_H,IT_M,IT_S.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_OUTPUT’
EXPORTING
INPUT = IT_ALV-MEINS
IMPORTING
OUTPUT = IT_ALV-MEINS
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
READ TABLE IT_EKET WITH KEY EBELN = IT_ALV-EBELN EBELP = IT_ALV-EBELP.
IF SY-SUBRC = 0.
IT_ALV-ETENR = IT_EKET-ETENR.
ENDIF.
READ TABLE IT_MAKT WITH KEY MATNR = IT_ALV-MATNR.
IF SY-SUBRC = 0.
IT_ALV-MAKTX = IT_MAKT-MAKTX.
ENDIF.
READ TABLE IT_EKKO WITH KEY EBELN = IT_ALV-EBELN.
IF SY-SUBRC = 0.
IT_ALV-ZNAME = IT_EKKO-NAME1 && IT_EKKO-NAME2.
ENDIF.
READ TABLE IT_EKPA WITH KEY EBELN = IT_ALV-EBELN.
IF SY-SUBRC = 0.
IT_ALV-LIFN2 = IT_EKPA-LIFN2.
ENDIF.
READ TABLE IT_MKPF WITH KEY MBLNR = IT_ALV-BELNR.
IF SY-SUBRC = 0.
IT_ALV-BKTXT = IT_MKPF-BKTXT.
ENDIF.
READ TABLE IT_MSEG WITH KEY EBELN = IT_ALV-EBELN EBELP = IT_ALV-EBELP.
IT_ALV-LGORT = IT_MSEG-LGORT.
IT_ALV-ZSUBI = IT_MSEG-LGORT.
* IF SY-SUBRC = 0 AND IT_MSEG-LGORT = ‘MW01’.
* IT_ALV-LGORT = IT_MSEG-LGORT.
* IT_ALV-ZSUBI = ‘6DOCK’.
* ELSEIF SY-SUBRC = 0 AND IT_MSEG-LGORT = ‘MW02’.
* IT_ALV-LGORT = IT_MSEG-LGORT.
* IT_ALV-ZSUBI = ‘DOCK’.
* ENDIF.
DATA:L_LINES TYPE TABLE OF TLINE WITH HEADER LINE,
W_LINES TYPE TLINE,
L_NAME TYPE THEAD-TDNAME.
L_NAME = IT_ALV-EBELN.
CALL FUNCTION ‘READ_TEXT’
EXPORTING
ID = ‘F02’
LANGUAGE = SY-LANGU
NAME = L_NAME
OBJECT = ‘EKKO’
TABLES
LINES = L_LINES[]
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
LOOP AT L_LINES INTO W_LINES.
IT_ALV-NTTVD = W_LINES-TDLINE.
CLEAR W_LINES.
ENDLOOP.
APPEND IT_ALV.
CLEAR: IT_ALV,L_LINES[].
ENDLOOP.
“检查自建表是否有记录,只发送没有发送过的数据。
IF R_PI = ‘X’.
DATA: BEGIN OF IT_CHECK OCCURS 0,
BELNR LIKE EKBE-BELNR,
GJAHR LIKE EKBE-GJAHR,
END OF IT_CHECK.
SELECT BELNR GJAHR INTO TABLE IT_CHECK
FROM ZMMT04.
LOOP AT IT_CHECK.
DELETE IT_ALV WHERE BELNR = IT_CHECK-BELNR
AND GJAHR = IT_CHECK-GJAHR.
ENDLOOP.
ENDIF.
SORT IT_ALV BY BELNR EBELN EBELP.
ENDFORM.
FORM HIS_DATA.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_ALV FROM ZMMT04
WHERE WERKS IN S_WERKS AND LGORT IN S_LGORT AND BUDAT IN S_DATE.
ENDFORM.
FORM PI_DATA.
DATA: LR_DATA_OUT TYPE REF TO ZCO_SI_ERP2DMR_GR_OUT.
DATA: LV_OUTPUT TYPE ZMT_ERP_GR_REQ.
DATA: IT_ITEMS TYPE ZDT_GR_ITEMS_TAB,
WA_ITEM TYPE ZDT_GR_ITEMS,
LO_SYS_EXCEPTION TYPE REF TO CX_AI_SYSTEM_FAULT,
LO_APP_EXCEPTION TYPE REF TO CX_AI_APPLICATION_FAULT,
WA_HEADER TYPE ZDT_HEADER.
WA_ITEM-ODR_NBR = ‘How_Many_Orders’.
WA_ITEM-GRNBR = ‘Receipt_Nbr’.
WA_ITEM-PONBR = ‘PO_Nbr’.
WA_ITEM-RLS_NBR = ‘Release_Nbr’.
WA_ITEM-ODR_LIN_NBR = ‘Order_Line_Nbr’.
WA_ITEM-SHP_NBR = ‘Shipment_Nbr’.
WA_ITEM-ITEM_NBR = ‘Item_Nbr’.
WA_ITEM-ITEM_DESC = ‘Item_Desc’.
WA_ITEM-UOM = ‘Unit_Of_Measure’.
WA_ITEM-VDR_NAME = ‘Vendor_Name’.
WA_ITEM-SITE_CODE = ‘Site_Code’.
WA_ITEM-CRT_DATE = ‘Creation_Date’.
WA_ITEM-NOTE2RECVR = ‘Note_to_Receiver’.
WA_ITEM-UNIT_PRICE_FCUR = ‘Unit_Price_F_cur’.
WA_ITEM-QTY = ‘Qty’.
WA_ITEM-FULL_NAME = ‘Full_Name’.
WA_ITEM-NOTE2VDR = ‘Note_to_Vendor’.
WA_ITEM-SUB_INV = ‘Sub_Inventory’.
APPEND WA_ITEM TO IT_ITEMS.
CLEAR WA_ITEM.
SORT IT_ALV BY BELNR.
LOOP AT IT_ALV.
WA_ITEM-ODR_NBR = IT_ALV-ZORDER.
WA_ITEM-GRNBR = IT_ALV-BELNR.
WA_ITEM-PONBR = IT_ALV-EBELN.
WA_ITEM-RLS_NBR = IT_ALV-RELNB.
WA_ITEM-ODR_LIN_NBR = IT_ALV-EBELP.
WA_ITEM-SHP_NBR = IT_ALV-ETENR.
WA_ITEM-ITEM_NBR = IT_ALV-MATNR.
WA_ITEM-ITEM_DESC = IT_ALV-MAKTX.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_OUTPUT’
EXPORTING
INPUT = IT_ALV-MEINS
IMPORTING
OUTPUT = IT_ALV-MEINS
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
WA_ITEM-UOM = IT_ALV-MEINS.
WA_ITEM-VDR_NAME = IT_ALV-ZNAME.
WA_ITEM-SITE_CODE = IT_ALV-LIFN2.
WA_ITEM-CRT_DATE = IT_ALV-ZDATE.
WA_ITEM-NOTE2RECVR = IT_ALV-WAERS.
WA_ITEM-UNIT_PRICE_FCUR = IT_ALV-NETPR.
WA_ITEM-QTY = IT_ALV-MENGE.
WA_ITEM-FULL_NAME = IT_ALV-BKTXT.
WA_ITEM-NOTE2VDR = IT_ALV-NTTVD.
WA_ITEM-SUB_INV = IT_ALV-ZSUBI.
APPEND WA_ITEM TO IT_ITEMS.
CLEAR: WA_ITEM,IT_ALV.
ENDLOOP.
CHECK IT_ITEMS[] IS NOT INITIAL.
LV_OUTPUT-MT_ERP_GR_REQ-ITEMS = IT_ITEMS.
CREATE OBJECT LR_DATA_OUT.
TRY.
CALL METHOD LR_DATA_OUT->SI_ERP2DMR_GR_OUT
EXPORTING
OUTPUT = LV_OUTPUT.
COMMIT WORK AND WAIT.
MESSAGE ‘Done!’ TYPE ‘S’.
CATCH CX_AI_SYSTEM_FAULT INTO LO_SYS_EXCEPTION .
CATCH CX_AI_APPLICATION_FAULT INTO LO_APP_EXCEPTION .
ENDTRY.
ENDFORM.
FORM SAVE_DATA.
LOOP AT IT_ALV.
IT_ZMMT-ZORDER = IT_ALV-ZORDER.
IT_ZMMT-BELNR = IT_ALV-BELNR.
IT_ZMMT-EBELN = IT_ALV-EBELN.
IT_ZMMT-RELNB = IT_ALV-RELNB.
IT_ZMMT-EBELP = IT_ALV-EBELP.
IT_ZMMT-ETENR = IT_ALV-ETENR.
IT_ZMMT-MATNR = IT_ALV-MATNR.
IT_ZMMT-MAKTX = IT_ALV-MAKTX.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT’
EXPORTING
INPUT = IT_ALV-MEINS
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = IT_ALV-MEINS
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
IT_ZMMT-MEINS = IT_ALV-MEINS.
IT_ZMMT-ZNAME = IT_ALV-ZNAME.
IT_ZMMT-LIFN2 = IT_ALV-LIFN2.
IT_ZMMT-ZDATE = IT_ALV-ZDATE.
IT_ZMMT-WAERS = IT_ALV-WAERS.
IT_ZMMT-NETPR = IT_ALV-NETPR.
IT_ZMMT-MENGE = IT_ALV-MENGE.
IT_ZMMT-BKTXT = IT_ALV-BKTXT.
IT_ZMMT-NTTVD = IT_ALV-NTTVD.
IT_ZMMT-ZSUBI = IT_ALV-ZSUBI.
IT_ZMMT-CDATE = IT_ALV-CDATE.
IT_ZMMT-GJAHR = IT_ALV-GJAHR.
IT_ZMMT-BUDAT = IT_ALV-BUDAT.
IT_ZMMT-WERKS = IT_ALV-WERKS.
IT_ZMMT-LGORT = IT_ALV-LGORT.
IT_ZMMT-CPUDT = IT_ALV-CPUDT.
IT_ZMMT-CPUTM = IT_ALV-CPUTM.
INSERT ZMMT04 FROM IT_ZMMT.
APPEND IT_ZMMT.
CLEAR:IT_ALV,IT_ZMMT.
ENDLOOP.
CLEAR IT_ZMMT[].
ENDFORM.
FORM DIS_DATA.
ALV_CLEAR_DATA.
ALV_ADD_DATA: ‘IT_ALV’ ” ” ” ” ” ” ‘ZORDER’ ‘How_Many_Orders’,
‘IT_ALV’ ” ” ” ” ” ” ‘BELNR’ ‘Receipt_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘EBELN’ ‘PO_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘RELNB’ ‘Release_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘EBELP’ ‘Order_Line_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘ETENR’ ‘Shipment_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘MATNR’ ‘Item_Nbr’,
‘IT_ALV’ ” ” ” ” ” ” ‘MAKTX’ ‘Item_Desc’,
‘IT_ALV’ ” ” ” ” ” ” ‘MEINS’ ‘Unit_Of_Measure’,
‘IT_ALV’ ” ” ” ” ” ” ‘ZNAME’ ‘Vendor_Name’,
‘IT_ALV’ ” ” ” ” ” ” ‘LIFN2’ ‘Site_Code’,
‘IT_ALV’ ” ” ” ” ” ” ‘ZDATE’ ‘Creation_Date’,
‘IT_ALV’ ” ” ” ” ” ” ‘WAERS’ ‘Note_to_Receiver’,
‘IT_ALV’ ” ” ” ” ” ” ‘NETPR’ ‘Unit_Price_F_cur’,
‘IT_ALV’ ” ” ” ” ” ” ‘MENGE’ ‘Qty’,
‘IT_ALV’ ” ” ” ” ” ” ‘BKTXT’ ‘Full_Name’,
‘IT_ALV’ ” ” ” ” ” ” ‘NTTVD’ ‘Note_to_Vendor’,
‘IT_ALV’ ” ” ” ” ” ” ‘ZSUBI’ ‘Sub_Inventory’.
ALV_SHOW_DATA IT_ALV.
ENDFORM.
FORM DEL_DATA.
DELETE FROM ZMMT04.
ENDFORM.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19572.html