FUNCTION ZRFC_PPORDER_GET.
*"----------------------------------------------------------------------
*"*"局部接口:
*" EXPORTING
*" VALUE(STATUS) TYPE CHAR1
*" VALUE(RETMSG) TYPE CHAR70
*" TABLES
*" S_WERKS STRUCTURE BAPI_ITOB_SEL_DESCRIPT OPTIONAL
*" S_ARBPL STRUCTURE BAPI_ITOB_SEL_DESCRIPT OPTIONAL
*" S_ERDAT STRUCTURE BAPI_ITOB_SEL_DESCRIPT OPTIONAL
*" S_STAT STRUCTURE BAPI_ITOB_SEL_DESCRIPT OPTIONAL
*" S_AUFNR STRUCTURE BAPI_ITOB_SEL_DESCRIPT OPTIONAL
*" RETITEM STRUCTURE ZSTRU_PPORDER OPTIONAL
*"----------------------------------------------------------------------
DATA:LAUFNR LIKE CAUFV-AUFNR.
data:s_wsobjid like BAPI_ITOB_SEL_DESCRIPT OCCURS 0 WITH HEADER LINE.
data:cnt TYPE i.
"$. Region 预处理
FIELD-SYMBOLS <FS> TYPE BAPI_ITOB_SEL_DESCRIPT.
LOOP AT S_AUFNR ASSIGNING <FS>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = S_AUFNR-LOW
IMPORTING
OUTPUT = LAUFNR.
<FS>-LOW = LAUFNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = S_AUFNR-HIGH
IMPORTING
OUTPUT = LAUFNR.
<FS>-HIGH = LAUFNR.
ENDLOOP.
"$. Endregion 预处理
data:LCRHD like crhd OCCURS 0 WITH HEADER LINE.
"$. Region 工作中心集合 s_wsobjid
"获取工作中心对象号
SELECT * INTO TABLE LCRHD
FROM CRHD WHERE OBJTY = 'A' and ARBPL IN S_ARBPL AND WERKS IN S_WERKS.
CLEAR S_WSOBJID[].
LOOP AT LCRHD.
S_WSOBJID-LOW = LCRHD-OBJID.
S_WSOBJID-SIGN = 'I'.
S_WSOBJID-OPTION = 'EQ'.
APPEND S_WSOBJID.
ENDLOOP.
"$. Endregion 工作中心集合 s_wsobjid
DATA:BEGIN OF WITAB OCCURS 0,
AUFNR LIKE CAUFV-AUFNR,
AUART LIKE CAUFV-AUART,
AUTYP LIKE CAUFV-AUTYP,
ERDAT LIKE CAUFV-ERDAT,
AEDAT LIKE CAUFV-AEDAT,
PLNBEZ LIKE CAUFV-PLNBEZ,
MAKTXZ LIKE MAKT-MAKTX,
GAMNG LIKE CAUFV-GAMNG,
GMEIN LIKE CAUFV-GMEIN,
OBJNR LIKE CAUFV-OBJNR,"获取订单状态 排除 CNF需要
RSNUM LIKE RESB-RSNUM,
RSPOS LIKE RESB-RSPOS,
MATNR LIKE RESB-MATNR,
BDMNG LIKE RESB-BDMNG,
MEINS LIKE RESB-MEINS,
AUFPL LIKE AFVC-AUFPL,
ARBID LIKE AFVC-ARBID,
END OF WITAB.
"$. Region 生产订单状态处理
DATA:LTJ02T LIKE TJ02T OCCURS 0 WITH HEADER LINE.
DATA:S_STATS LIKE BAPI_ITOB_SEL_DESCRIPT OCCURS 0 WITH HEADER LINE.
SELECT * INTO TABLE LTJ02T FROM TJ02T
WHERE TXT04 IN S_STAT AND SPRAS = 1.
CLEAR S_STATS.
LOOP AT LTJ02T.
S_STATS-SIGN = 'I'.
S_STATS-OPTION = 'EQ'.
S_STATS-LOW = LTJ02T-ISTAT.
APPEND S_STATS.
ENDLOOP.
"$. Endregion 生产订单状态处理
SELECT CAUFV~AUFNR CAUFV~AUART CAUFV~AUTYP ERDAT AEDAT PLNBEZ maktx as maktxz
GAMNG GMEIN CAUFV~OBJNR CAUFV~RSNUM RESB~RSPOS RESB~MATNR RESB~BDMNG RESB~MEINS CAUFV~AUFPL AFVC~ARBID
INTO CORRESPONDING FIELDS OF TABLE WITAB
FROM CAUFV
JOIN RESB ON RESB~RSNUM = CAUFV~RSNUM
JOIN MAKT ON MAKT~MATNR = CAUFV~PLNBEZ AND MAKT~SPRAS = 1
JOIN AFVC ON AFVC~AUFPL = CAUFV~AUFPL
WHERE CAUFV~AUFNR IN S_AUFNR AND CAUFV~WERKS IN S_WERKS AND AFVC~ARBID IN S_WSOBJID AND
( CAUFV~ERDAT IN S_ERDAT OR CAUFV~AEDAT IN S_ERDAT ) AND RESB~DUMPS <> 'X' and resb~XLOEK <> 'X'
and CAUFV~OBJNR not in ( select JEST~OBJNR from JEST where JEST~OBJNR = CAUFV~OBJNR and STAT IN S_STATS )."删除 虚拟键
"状态为 CNF 等的排除在外
LOOP AT WITAB.
MOVE-CORRESPONDING WITAB TO RETITEM.
SELECT SINGLE MAKTX INTO RETITEM-MAKTX
FROM MAKT
WHERE MAKT~MATNR = RETITEM-MATNR AND SPRAS = 1.
SHIFT RETITEM-MATNR LEFT DELETING LEADING '0'.
SHIFT RETITEM-PLNBEZ LEFT DELETING LEADING '0'.
SHIFT RETITEM-AUFNR LEFT DELETING LEADING '0'.
APPEND RETITEM.
ENDLOOP.
DESCRIBE TABLE RETITEM LINES cnt.
IF CNT > 0.
STATUS = 'S'.
RETMSG = '获取到' && CNT && '条记录'.
ELSE.
STATUS = 'E'.
RETMSG = '未获取到记录,请核对条件和数据'.
ENDIF.
ENDFUNCTION.
|