ABAP 定时刷新ALV (TIMER)
function alv定时刷新,10分钟刷新一次,通过定时器10分钟触发一次自定义的按钮refresh,然后就会refresh按钮的响应事件,进入user command 重新取数,user command里会刷新ALV。下面贴源代码,重点看前面class定义和START-OF-SELECTION、P_USER_COMMAND里的代码。**************************
·
function alv定时刷新,10分钟刷新一次,通过定时器10分钟触发一次自定义的按钮refresh,然后就会refresh按钮的响应事件,进入user command 重新取数,user command里会刷新ALV。
下面贴源代码,重点看前面class定义和START-OF-SELECTION、P_USER_COMMAND里的代码。
*********************************************************************************
* 程序名:ZWMRP005
* 程序名称:拣选任务清单
*-------------------------------------------------
* 创建日期 程序员 SAP版本 程序类型
* 2016-09-06 y RP
*-------------------------------------------------
* 描述:
* 拣选需求:1.仓库领料(预留)2.销售出库、调拨
* 定时刷新
*=================================================
* 修改日期 版本 修改人 修改描述
*
********************************************************************************
REPORT ZWMRP005.
*------------------------------------------------------------------------------*
* GLOBLE-DEFINATION *
*------------------------------------------------------------------------------*
TABLES:LIPS,RESB,ZTA_WMJXRW.
TABLES SSCRFIELDS.
*----ALV变量
TYPE-POOLS slis.
TYPE-POOLS: icon.
DATA: WA_FIELDCAT TYPE LINE OF SLIS_T_FIELDCAT_ALV,
ITAB_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GT_EVENTS TYPE SLIS_T_EVENT,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
ITAB_LAYOUT TYPE SLIS_LAYOUT_ALV,
I_GRID_SETTINGS TYPE LVC_S_GLAY.
*----ALV宏
DEFINE ADD_FIELD.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-TABNAME = &2.
WA_FIELDCAT-SELTEXT_M = &3.
WA_FIELDCAT-CHECKBOX = &4.
WA_FIELDCAT-EDIT = &5.
WA_FIELDCAT-NO_ZERO = 'X'. "无前导0
IF WA_FIELDCAT-TABNAME CO 'LIGHT'.
WA_FIELDCAT-ICON = 'X'.
ENDIF.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.
END-OF-DEFINITION.
TYPES: BEGIN OF TY_TOTAL, "
SEL TYPE C,
ZTANUM TYPE ZTA_WMJXRW-ZTANUM ," 转储单编号
ZTAPOS TYPE ZTA_WMJXRW-ZTAPOS,"转储单项目
ZTBNUM TYPE ZTA_WMJXRW-ZTBNUM ," 转移要求号
ZJXDH TYPE ZTA_WMJXRW-ZJXDH," 拣选单号(仓库号+TO号)
ZTASK_TYPE TYPE ZTA_WMJXRW-ZTASK_TYPE ,"任务类型
ZPICK_LIGHT TYPE ZTA_WMJXRW-ZPICK_LIGHT ,"拣选交通灯
ZDELIVERY_LIGHT TYPE ZTA_WMJXRW-ZDELIVERY_LIGHT ,"配送交通灯
ZLGORT_S TYPE ZTA_WMJXRW-ZLGORT_S ,"源库存地仓库
ZLGORT_S_MS TYPE ZTA_WMJXRW-ZLGORT_S ,"源库存地仓库 -描述
ZLGORT_D TYPE ZTA_WMJXRW-ZLGORT_D ," 目的库存地
ZLGORT_D_MS TYPE ZTA_WMJXRW-ZLGORT_D ," 目的库存地 -描述
ZMATNR TYPE ZTA_WMJXRW-ZMATNR ,"物料编号
ZMENGE TYPE ZTA_WMJXRW-ZMENGE ,"{数量
ZMEINS TYPE ZTA_WMJXRW-ZMEINS ,"基本计量单位
ZDATE TYPE ZTA_WMJXRW-ZDATE , "类型 DATS 的字段
ZTIME TYPE ZTA_WMJXRW-ZTIME ," TIME类型的字段
ZRSNUM TYPE RESB-RSNUM, "预留号
ZRSPOS TYPE RESB-RSPOS,"预留行项目
ZVBELN TYPE LIPS-VBELN,"交货
ZPOSNR TYPE LIPS-POSNR,"项目
ZWERKS TYPE WERKS_D,
ZMAKTX TYPE MAKTX,
FLAG TYPE C," X 来源预留
ZBWART TYPE RESB-BWART,"
ZKOSTA TYPE VBUP-KOSTA, "拣配状态/入库状态
ZPSTYV TYPE LIPS-PSTYV, "交货项目类别
ZCHARG TYPE LIPS-CHARG,"批次
ZKDMAT TYPE LIPS-KDMAT ,"客户物料
ZKOMKZ TYPE LIPS-KOMKZ ,"拣配指示符
ZLGNUM TYPE LIPS-LGNUM ,"仓库号
ZVGBEL TYPE LIPS-VGBEL, "参考单据的单据编号-交货单时 为ub订单
ZVGPOS TYPE LIPS-VGPOS, "参考项目的项目号
ZBRGEW TYPE LIPS-BRGEW ,"毛重
ZBZSL TYPE N LENGTH 4, "包装数量
NAME1 TYPE KNA1-NAME1,"客户名-打印交货单需要
END OF TY_TOTAL.
TYPES: BEGIN OF TY_LIPS, "为了使用AT END OF
ZVBELN TYPE LIPS-VBELN,"交货
ZPOSNR TYPE LIPS-POSNR,"项目
SEL TYPE C,
ZTANUM TYPE ZTA_WMJXRW-ZTANUM ," 转储单编号
ZTAPOS TYPE ZTA_WMJXRW-ZTAPOS,"转储单项目
ZTBNUM TYPE ZTA_WMJXRW-ZTBNUM ," 转移要求号
ZJXDH TYPE ZTA_WMJXRW-ZJXDH," 拣选单号(仓库号+TO号)
ZTASK_TYPE TYPE ZTA_WMJXRW-ZTASK_TYPE ,"任务类型
ZPICK_LIGHT TYPE ZTA_WMJXRW-ZPICK_LIGHT ,"拣选交通灯
ZDELIVERY_LIGHT TYPE ZTA_WMJXRW-ZDELIVERY_LIGHT ,"配送交通灯
ZLGORT_S TYPE ZTA_WMJXRW-ZLGORT_S ,"源库存地仓库
ZLGORT_D TYPE ZTA_WMJXRW-ZLGORT_D ," 目的库存地
ZMATNR TYPE ZTA_WMJXRW-ZMATNR ,"物料编号
ZMENGE TYPE ZTA_WMJXRW-ZMENGE ,"{数量
ZMEINS TYPE ZTA_WMJXRW-ZMEINS ,"基本计量单位
ZDATE TYPE ZTA_WMJXRW-ZDATE , "类型 DATS 的字段
ZTIME TYPE ZTA_WMJXRW-ZTIME ," TIME类型的字段
ZRSNUM TYPE RESB-RSNUM, "预留号
ZRSPOS TYPE RESB-RSPOS,"预留行项目
ZWERKS TYPE WERKS_D,
ZMAKTX TYPE MAKTX,
FLAG TYPE C," X 来源预留
ZBWART TYPE RESB-BWART,"
ZKOSTA TYPE VBUP-KOSTA, "拣配状态/入库状态
ZPSTYV TYPE LIPS-PSTYV, "交货项目类别
ZCHARG TYPE LIPS-CHARG,"批次
ZKDMAT TYPE LIPS-KDMAT ,"客户物料
ZKOMKZ TYPE LIPS-KOMKZ ,"拣配指示符
ZLGNUM TYPE LIPS-LGNUM ,"仓库号
ZVGBEL TYPE LIPS-VGBEL, "参考单据的单据编号-交货单时 为ub订单
ZVGPOS TYPE LIPS-VGPOS, "参考项目的项目号
ZBRGEW TYPE LIPS-BRGEW ,"毛重
ZBZSL TYPE N LENGTH 4, "包装数量
NAME1 TYPE KNA1-NAME1,"客户名-打印交货单需要
END OF TY_LIPS.
TYPES: BEGIN OF TY_RESB, "为了使用AT END OF
ZRSNUM TYPE RESB-RSNUM, "预留号
ZRSPOS TYPE RESB-RSPOS,"预留行项目
SEL TYPE C,
ZTANUM TYPE ZTA_WMJXRW-ZTANUM ," 转储单编号
ZTAPOS TYPE ZTA_WMJXRW-ZTAPOS,"转储单项目
ZTBNUM TYPE ZTA_WMJXRW-ZTBNUM ," 转移要求号
ZJXDH TYPE ZTA_WMJXRW-ZJXDH," 拣选单号(仓库号+TO号)
ZTASK_TYPE TYPE ZTA_WMJXRW-ZTASK_TYPE ,"任务类型
ZPICK_LIGHT TYPE ZTA_WMJXRW-ZPICK_LIGHT ,"拣选交通灯
ZDELIVERY_LIGHT TYPE ZTA_WMJXRW-ZDELIVERY_LIGHT ,"配送交通灯
ZLGORT_S TYPE ZTA_WMJXRW-ZLGORT_S ,"源库存地仓库
ZLGORT_D TYPE ZTA_WMJXRW-ZLGORT_D ," 目的库存地
ZMATNR TYPE ZTA_WMJXRW-ZMATNR ,"物料编号
ZMENGE TYPE ZTA_WMJXRW-ZMENGE ,"{数量
ZMEINS TYPE ZTA_WMJXRW-ZMEINS ,"基本计量单位
ZDATE TYPE ZTA_WMJXRW-ZDATE , "类型 DATS 的字段
ZTIME TYPE ZTA_WMJXRW-ZTIME ," TIME类型的字段
ZVBELN TYPE LIPS-VBELN,"交货
ZPOSNR TYPE LIPS-POSNR,"项目
ZWERKS TYPE WERKS_D,
ZMAKTX TYPE MAKTX,
FLAG TYPE C," X 来源预留
ZBWART TYPE RESB-BWART,"
ZKOSTA TYPE VBUP-KOSTA, "拣配状态/入库状态
ZPSTYV TYPE LIPS-PSTYV, "交货项目类别
ZCHARG TYPE LIPS-CHARG,"批次
ZKDMAT TYPE LIPS-KDMAT ,"客户物料
ZKOMKZ TYPE LIPS-KOMKZ ,"拣配指示符
ZLGNUM TYPE LIPS-LGNUM ,"仓库号
ZVGBEL TYPE LIPS-VGBEL, "参考单据的单据编号-交货单时 为ub订单
ZVGPOS TYPE LIPS-VGPOS, "参考项目的项目号
ZBRGEW TYPE LIPS-BRGEW ,"毛重
ZBZSL TYPE N LENGTH 4, "包装数量
NAME1 TYPE KNA1-NAME1,"客户名-打印交货单需要
END OF TY_RESB.
DATA: ITAB_TOTAL TYPE TABLE OF TY_TOTAL,
WA_TOTAL TYPE TY_TOTAL.
DATA: ITAB_SF TYPE TABLE OF TY_TOTAL, "SMARTFORMS传参
WA_SF TYPE TY_TOTAL.
DATA: ITAB_FROM_RESB TYPE TABLE OF TY_RESB,
WA_FROM_RESB TYPE TY_RESB.
DATA: ITAB_FROM_LIPS TYPE TABLE OF TY_LIPS,
WA_FROM_LIPS TYPE TY_LIPS.
DATA: ICON_GREEN_LIGHT(4) TYPE C VALUE '@08@'," Green light; positive
ICON_YELLOW_LIGHT(4) TYPE C VALUE '@09@'," Yellow light; neutral
ICON_RED_LIGHT(4) TYPE C VALUE '@0A@'." Red light; negative
*------------------------------------------------------------------------------*
* 类定义-定时刷新 *
*------------------------------------------------------------------------------*
CLASS LCL_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_FINISHED FOR EVENT FINISHED OF CL_GUI_TIMER.
ENDCLASS.
DATA: RECEIVER TYPE REF TO LCL_RECEIVER,
TIMER TYPE REF TO CL_GUI_TIMER.
CLASS LCL_RECEIVER IMPLEMENTATION.
METHOD HANDLE_FINISHED.
PERFORM P_GET_DATA.
CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE "触发pai ,usercommand里有刷新alv的代码
EXPORTING
NEW_CODE = 'REFRESH'.
* MESSAGE ID 'MO' TYPE 'S' NUMBER 429 .
CALL METHOD TIMER->RUN.
ENDMETHOD.
endclass.
*------------------------------------------------------------------------------*
* SELECTION-SCREEN *
*------------------------------------------------------------------------------*
PARAMETERS: P_WERKS TYPE LIPS-WERKS DEFAULT '2000' OBLIGATORY. "工厂
SELECT-OPTIONS: S_LGORT FOR LIPS-LGORT, "库存地
S_MATNR FOR LIPS-MATNR, "物料编号
S_DATE FOR LIPS-ERDAT, "日期
S_ZJXDH FOR ZTA_WMJXRW-ZJXDH . "拣货单号
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(8) TEXT-001.
SELECTION-SCREEN POSITION 10.
PARAMETERS : R_RESB RADIOBUTTON GROUP CTR1 DEFAULT 'X'.
SELECTION-SCREEN COMMENT 12(6) TEXT-T01.
SELECTION-SCREEN POSITION 20.
PARAMETERS : R_LIPS RADIOBUTTON GROUP CTR1 .
SELECTION-SCREEN COMMENT 22(18) TEXT-T02.
SELECTION-SCREEN POSITION 42.
* PARAMETERS : R_PRINT RADIOBUTTON GROUP CTR1 .
PARAMETERS : R_PRINT AS CHECKBOX USER-COMMAND RBK .
SELECTION-SCREEN COMMENT 44(18) TEXT-T03.
SELECTION-SCREEN END OF LINE.
*------------------------------------------------------------------------------*
* INITIALIZATION *
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*------------------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
IF R_PRINT = ''.
LOOP AT SCREEN.
IF SCREEN-NAME CP '*S_ZJXDH*'.
SCREEN-ACTIVE = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
*------------------------------------------------------------------------------*
* START-OF-SELECTION *
*------------------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM P_GET_DATA.
CREATE OBJECT TIMER.
CREATE OBJECT RECEIVER.
SET HANDLER RECEIVER->HANDLE_FINISHED FOR TIMER.
TIMER->INTERVAL = 600. "10分钟刷新一次
CALL METHOD TIMER->RUN.
PERFORM P_DISPLAY.
CALL METHOD TIMER->RUN.
*------------------------------------------------------------------------------*
* SUBROUTINES *
*------------------------------------------------------------------------------*
FORM P_USER_COMMAND USING R_UCOMM TYPE SY-UCOMM
R_SEL TYPE SLIS_SELFIELD. "响应ALV点击自定义按钮之后的事件
DATA: LV_ANSWER TYPE C.
DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
DATA : LV_STABLE TYPE LVC_S_STBL.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF.
CALL METHOD REF->CHECK_CHANGED_DATA.
CASE R_UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN '&F12'.
WHEN 'SEL_ALL'.
CLEAR WA_TOTAL.
LOOP AT ITAB_TOTAL INTO WA_TOTAL WHERE SEL = ''.
WA_TOTAL-SEL = 'X'.
MODIFY ITAB_TOTAL FROM WA_TOTAL.
ENDLOOP.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING IS_STABLE = LV_STABLE ..
WHEN 'DESEL_ALL'.
CLEAR WA_TOTAL.
LOOP AT ITAB_TOTAL INTO WA_TOTAL WHERE SEL = 'X'.
WA_TOTAL-SEL = ''.
MODIFY ITAB_TOTAL FROM WA_TOTAL.
ENDLOOP.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING IS_STABLE = LV_STABLE .
WHEN 'CONFIRM'. "下达
* fm里面需检查是否已经下达 ----------------------------待写 09 13
IF R_RESB = 'X'.
PERFORM P_CREATE_TO_BY_RESB.
ELSEIF R_LIPS = 'X'.
PERFORM P_CREATE_TO_BY_LIPS.
ENDIF.
WHEN 'PRINT'.
PERFORM P_PRINT.
* CALL METHOD REF->REFRESH_TABLE_DISPLAY
* EXPORTING IS_STABLE = LV_STABLE .
WHEN 'REFRESH' .
PERFORM P_GET_DATA.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING IS_STABLE = LV_STABLE .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_GET_DATA .
CLEAR: ITAB_TOTAL,WA_TOTAL.
IF R_RESB = 'X'. "resb取转储
SELECT
RSNUM AS ZRSNUM"预留号
RSPOS AS ZRSPOS"预留行项目
WERKS AS ZWERKS"工厂
MATNR AS ZMATNR"物料代码
BDTER AS ZDATE"需求日期
BDMNG AS ZMENGE"数量
MEINS AS ZMEINS"单位
BWART AS ZBWART"移动类型
LGORT AS ZLGORT_S "源库存地
UMLGO AS ZLGORT_D"接收库存地
* XLOEK "项目被删除
* XWAOK "许可的移动
* KZEAR "最后发货
INTO CORRESPONDING FIELDS OF TABLE ITAB_TOTAL
FROM RESB
WHERE WERKS = P_WERKS
AND LGORT IN S_LGORT
AND MATNR IN S_MATNR
AND BDTER IN S_DATE
AND BWART = '311'
AND XLOEK = '' "项目已删除标记
AND XWAOK = 'X'
AND KZEAR = ''.
IF ITAB_TOTAL IS INITIAL.
MESSAGE ID 'MO' TYPE 'S' NUMBER 429 .
STOP.
ENDIF.
SELECT * FROM ZTA_WMJXRW INTO TABLE @DATA(ITAB_JXRW).
LOOP AT ITAB_TOTAL ASSIGNING FIELD-SYMBOL(<FS_TOTAL>).
* <FS_TOTAL>-FLAG = 'X'.
<FS_TOTAL>-ZDELIVERY_LIGHT = ICON_YELLOW_LIGHT."开始默认黄灯
<FS_TOTAL>-ZPICK_LIGHT = ICON_YELLOW_LIGHT.
* ---------------------------------------------------还需匹配存在自建表的数据-待写
READ TABLE ITAB_JXRW INTO DATA(WA_JXRW) WITH KEY ZRSNUM = <FS_TOTAL>-ZRSNUM ZRSPOS = <FS_TOTAL>-ZRSPOS.
IF SY-SUBRC = 0."如果存在已下达的
<FS_TOTAL>-ZDELIVERY_LIGHT = WA_JXRW-ZPICK_LIGHT ."拣选交通灯
<FS_TOTAL>-ZTANUM = WA_JXRW-ZTANUM."转储单编号
<FS_TOTAL>-ZTAPOS = WA_JXRW-ZRSPOS ."转储单项目--和预留一致 bg. flag
<FS_TOTAL>-ZRSNUM = WA_JXRW-ZRSNUM ."预留/相关需求的编号
<FS_TOTAL>-ZRSPOS = WA_JXRW-ZRSPOS ."预留 / 相关需求的项目编号
<FS_TOTAL>-ZJXDH = WA_JXRW-ZJXDH."拣选单号(仓库号-TO号)
<FS_TOTAL>-ZTBNUM = WA_JXRW-ZTBNUM."TR号
<FS_TOTAL>-ZPICK_LIGHT = WA_JXRW-ZPICK_LIGHT."拣选交通灯
<FS_TOTAL>-ZDELIVERY_LIGHT = WA_JXRW-ZDELIVERY_LIGHT."配送交通灯
<FS_TOTAL>-ZDATE = WA_JXRW-ZDATE ."类型 DATS 的字段
<FS_TOTAL>-ZTIME = WA_JXRW-ZTIME ."TIMS 类型的字段
ENDIF.
* READ TABLE ITAB_JXRW
IF <FS_TOTAL>-ZBWART = '311'.
<FS_TOTAL>-ZTASK_TYPE = '转储'.
ENDIF.
*取物料描述
SELECT SINGLE MAKTX
INTO <FS_TOTAL>-ZMAKTX
FROM MAKT
WHERE MATNR = <FS_TOTAL>-ZMATNR.
*取原、目的仓库描述
SELECT SINGLE LGOBE
INTO <FS_TOTAL>-ZLGORT_S_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = <FS_TOTAL>-ZLGORT_S.
SELECT SINGLE LGOBE
INTO <FS_TOTAL>-ZLGORT_D_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = <FS_TOTAL>-ZLGORT_D.
ENDLOOP.
SORT ITAB_TOTAL BY ZRSNUM ZRSPOS.
ENDIF.
*LIPS 调拨出库”、“销售出库
IF R_LIPS = 'X'.
SELECT
LIPS~WERKS AS ZWERKS"工厂
LIPS~MATNR AS ZMATNR"物料代码
LIPS~ERDAT AS ZDATE"记录建立日期
LIPS~ERZET AS ZTIME "输入时间
LIPS~LFIMG AS ZMENGE"数量
LIPS~MEINS AS ZMEINS"单位
LIPS~BWART AS ZBWART"移动类型
LIPS~LGORT AS ZLGORT_S"源库存地
* LIPS~UMLGO AS ZLGORT_D"接收库存地 ----从调拨单取
LIPS~VBELN AS ZVBELN "交货
LIPS~POSNR AS ZPOSNR "项目
LIPS~PSTYV AS ZPSTYV "交货项目类别
LIPS~CHARG AS ZCHARG "批次
LIPS~KDMAT AS ZKDMAT "客户物料
LIPS~KOMKZ AS ZKOMKZ "拣配指示符
LIPS~LGNUM AS ZLGNUM "仓库号
VBUP~KOSTA AS ZKOSTA " 拣配状态/入库状态
LIPS~BRGEW AS ZBRGEW "毛重
LIPS~VGBEL AS ZVGBEL "参考单据的单据编号-交货单时 为ub订单
LIPS~VGPOS AS ZVGPOS "参考项目的项目号
FROM LIPS
INNER JOIN VBUP ON LIPS~VBELN = VBUP~VBELN AND LIPS~POSNR = VBUP~POSNR
INNER JOIN LIKP ON LIPS~VBELN = LIKP~VBELN
INTO CORRESPONDING FIELDS OF TABLE ITAB_TOTAL
WHERE LIPS~WERKS = P_WERKS
AND LIPS~LGORT IN S_LGORT
AND LIPS~MATNR IN S_MATNR
AND LIPS~ERDAT IN S_DATE
AND ( LIKP~LFART = 'ZNL' OR LIKP~LFART = 'ZLF' )
AND VBUP~KOSTA <> 'C' .
IF ITAB_TOTAL IS INITIAL.
MESSAGE ID 'MO' TYPE 'S' NUMBER 429 .
STOP.
ENDIF.
SELECT * FROM ZTA_WMJXRW INTO TABLE @DATA(ITAB_JXRW2).
LOOP AT ITAB_TOTAL INTO WA_TOTAL.
WA_TOTAL-ZDELIVERY_LIGHT = ICON_YELLOW_LIGHT."开始默认黄灯
WA_TOTAL-ZPICK_LIGHT = ICON_YELLOW_LIGHT.
* -------------------------还需匹配存在自建表的数据- ------存在一种情况 如果是前台创建的TO 不会写回自建表-
READ TABLE ITAB_JXRW2 INTO DATA(WA_JXRW2) WITH KEY ZVBELN = WA_TOTAL-ZVBELN ZPOSNR = WA_TOTAL-ZPOSNR.
IF SY-SUBRC = 0."如果存在已下达的
WA_TOTAL-ZDELIVERY_LIGHT = WA_JXRW2-ZPICK_LIGHT ."拣选交通灯
WA_TOTAL-ZTANUM = WA_JXRW2-ZTANUM."转储单编号
WA_TOTAL-ZTAPOS = WA_JXRW2-ZRSPOS ."转储单项目--和预留一致 bg. flag
WA_TOTAL-ZJXDH = WA_JXRW2-ZJXDH."拣选单号(仓库号-TO号)
WA_TOTAL-ZTBNUM = WA_JXRW2-ZTBNUM."TR号
WA_TOTAL-ZPICK_LIGHT = WA_JXRW2-ZPICK_LIGHT."拣选交通灯
WA_TOTAL-ZDELIVERY_LIGHT = WA_JXRW2-ZDELIVERY_LIGHT."配送交通灯
WA_TOTAL-ZDATE = WA_JXRW2-ZDATE ."类型 DATS 的字段
WA_TOTAL-ZTIME = WA_JXRW2-ZTIME ."TIMS 类型的字段
ENDIF.
* READ TABLE ITAB_JXRW
IF WA_TOTAL-ZPSTYV = 'ZNL'.
WA_TOTAL-ZTASK_TYPE = '调拨出库'.
ELSEIF WA_TOTAL-ZPSTYV = 'ZLF'.
WA_TOTAL-ZTASK_TYPE = '销售出库'.
ENDIF.
SELECT SINGLE MAKTX
INTO WA_TOTAL-ZMAKTX
FROM MAKT
WHERE MATNR = WA_TOTAL-ZMATNR.
*取目的库存地
SELECT SINGLE LGORT
INTO WA_TOTAL-ZLGORT_D
FROM EKPO
WHERE EBELN = WA_TOTAL-ZVGBEL
AND EBELP = WA_TOTAL-ZVGPOS.
*取原、目的仓库描述
SELECT SINGLE LGOBE
INTO WA_TOTAL-ZLGORT_S_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = WA_TOTAL-ZLGORT_S.
SELECT SINGLE LGOBE
INTO WA_TOTAL-ZLGORT_D_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = WA_TOTAL-ZLGORT_D.
MODIFY ITAB_TOTAL FROM WA_TOTAL.
ENDLOOP.
SORT ITAB_TOTAL BY ZVBELN ZPOSNR.
ENDIF.
* 打印 重打 --只取自建表数据-即取已经下达的数据
IF R_PRINT = 'X'.
DATA S TYPE ZTA_WMJXRW-ZTASK_TYPE.
IF R_RESB = 'X'. "
SELECT *
FROM ZTA_WMJXRW
INTO CORRESPONDING FIELDS OF TABLE ITAB_TOTAL
WHERE ZWERKS = P_WERKS
AND ( ZLGORT_S IN S_LGORT OR ZLGORT_D IN S_LGORT )
AND ZMATNR IN S_MATNR
AND ZDATE IN S_DATE
AND ZJXDH IN S_ZJXDH
AND ZTASK_TYPE = '转储'.
ELSEIF R_LIPS = 'X'.
SELECT *
FROM ZTA_WMJXRW
INTO CORRESPONDING FIELDS OF TABLE ITAB_TOTAL
WHERE ZWERKS = P_WERKS
AND ( ZLGORT_S IN S_LGORT OR ZLGORT_D IN S_LGORT )
AND ZMATNR IN S_MATNR
AND ZDATE IN S_DATE
AND ZJXDH IN S_ZJXDH
AND ( ZTASK_TYPE = '调拨出库' OR ZTASK_TYPE = '销售出库' ).
ENDIF.
IF ITAB_TOTAL IS INITIAL.
MESSAGE ID 'MO' TYPE 'S' NUMBER 429 .
STOP.
ENDIF.
LOOP AT ITAB_TOTAL INTO WA_TOTAL.
SELECT SINGLE MAKTX
INTO WA_TOTAL-ZMAKTX
FROM MAKT
WHERE MATNR = WA_TOTAL-ZMATNR.
*取原、目的仓库描述
SELECT SINGLE LGOBE
INTO WA_TOTAL-ZLGORT_S_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = WA_TOTAL-ZLGORT_S.
SELECT SINGLE LGOBE
INTO WA_TOTAL-ZLGORT_D_MS
FROM T001L
WHERE WERKS = P_WERKS
AND LGORT = WA_TOTAL-ZLGORT_D.
*取仓库号等
SELECT SINGLE
LGNUM AS ZLGNUM "仓库号
BRGEW AS ZBRGEW "毛重
FROM LIPS
INTO ( WA_TOTAL-ZLGNUM , WA_TOTAL-ZBRGEW )
WHERE LIPS~WERKS = WA_TOTAL-ZWERKS
AND VBELN = WA_TOTAL-ZVBELN
AND POSNR = WA_TOTAL-ZPOSNR.
MODIFY ITAB_TOTAL FROM WA_TOTAL.
ENDLOOP.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_DISPLAY .
ADD_FIELD 'SEL' 'ITAB_TOTAL' '选择' 'X' 'X' .
ADD_FIELD 'ZPICK_LIGHT' 'ITAB_TOTAL' '拣配交通灯' SPACE SPACE .
ADD_FIELD 'ZDELIVERY_LIGHT' 'ITAB_TOTAL' '配送交通灯' SPACE SPACE .
IF R_RESB = 'X' . "resb取转储 、打印取自建表
ADD_FIELD 'ZRSNUM' 'ITAB_TOTAL' '预留号' SPACE SPACE .
ADD_FIELD 'ZRSPOS ' 'ITAB_TOTAL' '预留行项目' SPACE SPACE .
ENDIF.
IF R_LIPS = 'X' . "resb取交货单、打印取自建表
ADD_FIELD 'ZVBELN' 'ITAB_TOTAL' '交货单号' SPACE SPACE .
ADD_FIELD 'ZPOSNR ' 'ITAB_TOTAL' '交货单行项目' SPACE SPACE .
ENDIF.
ADD_FIELD 'ZWERKS' 'ITAB_TOTAL' '工厂' SPACE SPACE . "
ADD_FIELD 'ZLGORT_S' 'ITAB_TOTAL' '源库存地' SPACE SPACE .
ADD_FIELD 'ZLGORT_D' 'ITAB_TOTAL' '目的库存地' SPACE SPACE .
ADD_FIELD 'ZTASK_TYPE' 'ITAB_TOTAL' '类型' SPACE SPACE .
ADD_FIELD 'ZJXDH' 'ITAB_TOTAL' '拣选单号' SPACE SPACE .
ADD_FIELD 'ZTAPOS' 'ITAB_TOTAL' '拣选行项目' SPACE SPACE .
ADD_FIELD 'ZMATNR' 'ITAB_TOTAL' '物料代码' SPACE SPACE .
ADD_FIELD 'ZMAKTX' 'ITAB_TOTAL' '物料描述' SPACE SPACE .
ADD_FIELD 'ZMENGE' 'ITAB_TOTAL' '数量' SPACE SPACE .
ADD_FIELD 'ZMEINS' 'ITAB_TOTAL' '单位' SPACE SPACE .
IF R_PRINT = 'X'.
ADD_FIELD 'ZDATE' 'ITAB_TOTAL' '下达日期' SPACE SPACE .
ADD_FIELD 'ZTIME' 'ITAB_TOTAL' '下达时间' SPACE SPACE .
ELSE.
ADD_FIELD 'ZDATE' 'ITAB_TOTAL' '创建日期' SPACE SPACE .
ADD_FIELD 'ZTIME' 'ITAB_TOTAL' '创建时间' SPACE SPACE .
ENDIF.
******build layout
CLEAR ITAB_LAYOUT.
WA_LAYOUT-ZEBRA = 'X'.
* LW_LAYOUT-INFO_FIELDNAME = 'COLOR'.
* WA_LAYOUT-BOX_FIELDNAME = 'SEL'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
MOVE-CORRESPONDING WA_LAYOUT TO ITAB_LAYOUT.
*****ALV DISPLY
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = ITAB_LAYOUT
IT_FIELDCAT = ITAB_FIELDCAT[]
* IT_EVENTS = GT_EVENTS[]
I_CALLBACK_PF_STATUS_SET = 'P_SET_STATUS'
* I_SAVE = 'A'
I_CALLBACK_USER_COMMAND = 'P_USER_COMMAND'
TABLES
T_OUTTAB = ITAB_TOTAL[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE '采用ALV显示报表出错' TYPE 'S'.
EXIT.
ENDIF.
ENDFORM.
FORM P_SET_STATUS USING extab TYPE slis_t_extab.
IF R_PRINT = 'X'. "如果勾选了打印,则没有下达按钮
SET PF-STATUS 'Z_ST05_2' .
ELSE.
SET PF-STATUS 'Z_ST05' .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_CREATE_TO_BY_RESB
*&---------------------------------------------------------------------*
* 转储 , 311 移库生成tr,然后生成to
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_CREATE_TO_BY_RESB .
DATA: GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
* GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
* headret TYPE bapi2017_gm_head_ret,
RETDOC TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
RETYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR,
RETURN TYPE BAPIRET2_T WITH HEADER LINE,
GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE WITH HEADER LINE.
CLEAR: WA_TOTAL,WA_FROM_RESB,ITAB_FROM_RESB.
LOOP AT ITAB_TOTAL INTO WA_TOTAL WHERE SEL = 'X'.
MOVE-CORRESPONDING WA_TOTAL TO WA_FROM_RESB.
APPEND WA_FROM_RESB TO ITAB_FROM_RESB.
ENDLOOP.
IF ITAB_FROM_RESB IS INITIAL.
MESSAGE '请勾选需要下达的项目' TYPE 'E'.
ENDIF.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = '正在生成TR...'
EXCEPTIONS
OTHERS = 1.
GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
GOODSMVT_HEADER-DOC_DATE = SY-DATUM.
GOODSMVT_HEADER-PR_UNAME = SY-UNAME.
SORT ITAB_FROM_RESB BY ZRSNUM ZRSPOS.
DATA ITAB_TEMP_RESB TYPE TABLE OF TY_RESB. "写回自建表准备
LOOP AT ITAB_FROM_RESB INTO WA_FROM_RESB.
CLEAR GOODSMVT_ITEM.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = WA_FROM_RESB-ZMATNR
IMPORTING
OUTPUT = GOODSMVT_ITEM-MATERIAL.
GOODSMVT_ITEM-PLANT = WA_FROM_RESB-ZWERKS."'2000'.
GOODSMVT_ITEM-STGE_LOC = WA_FROM_RESB-ZLGORT_S.
GOODSMVT_ITEM-MOVE_TYPE = '311'.
* GOODSMVT_ITEM-MOVE_STLOC = WA_FROM_RESB-ZLGORT_D. "接收库存地
GOODSMVT_ITEM-ENTRY_QNT = WA_FROM_RESB-ZMENGE. "数量
GOODSMVT_ITEM-ENTRY_UOM = WA_FROM_RESB-ZMEINS. "计量单位
GOODSMVT_ITEM-RESERV_NO = WA_FROM_RESB-ZRSNUM."预留号
GOODSMVT_ITEM-RES_ITEM = WA_FROM_RESB-ZRSPOS."预留行项
* GOODSMVT_ITEM-MVT_IND = 'B'. "移动标识 按采购订单的货物移动
GOODSMVT_ITEM-NO_MORE_GR = 1. "交货已完成标识
APPEND GOODSMVT_ITEM.
APPEND WA_FROM_RESB TO ITAB_TEMP_RESB.
AT END OF ZRSNUM.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER
GOODSMVT_CODE = '04'
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
* GOODSMVT_HEADRET = headret
MATERIALDOCUMENT = RETDOC
MATDOCUMENTYEAR = RETYEAR
TABLES
GOODSMVT_ITEM = GOODSMVT_ITEM[]
* GOODSMVT_SERIALNUMBER =
RETURN = RETURN[].
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
IF RETDOC IS NOT INITIAL.
COMMIT WORK AND WAIT.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = '已生成TR,正在生成TO'
EXCEPTIONS
OTHERS = 1.
DATA: T_LGNUM TYPE LGNUM, "仓库号
T_TBNUM TYPE TBNUM, "TR 号
T_TANUM TYPE TANUM." TO
PERFORM P_CREATE_TO_BY_TR USING RETDOC RETYEAR
CHANGING T_LGNUM T_TBNUM T_TANUM.
* 更新自建表
DATA: ITAB_WMJRW TYPE TABLE OF ZTA_WMJXRW,
WA_WMJXRW TYPE ZTA_WMJXRW.
* 为写入自建表内表赋值,同时需要跟新temp内表数据用于更新显示
LOOP AT ITAB_TEMP_RESB ASSIGNING FIELD-SYMBOL(<FS_TEMP2>).
WA_WMJXRW-ZTANUM = <FS_TEMP2>-ZTANUM = T_TANUM."转储单编号
WA_WMJXRW-ZTAPOS = <FS_TEMP2>-ZTAPOS = <FS_TEMP2>-ZRSPOS ."转储单项目--和预留一致 bg. flag
WA_WMJXRW-ZRSNUM = <FS_TEMP2>-ZRSNUM ."预留/相关需求的编号
WA_WMJXRW-ZRSPOS = <FS_TEMP2>-ZRSPOS ."预留 / 相关需求的项目编号
WA_WMJXRW-ZWERKS = <FS_TEMP2>-ZWERKS. "工厂
* WA_WMJXRW-ZVBELN = <FS_TEMP2>-ZVBELN ."交货
* WA_WMJXRW-ZPOSNR = <FS_TEMP2>-ZPOSNR ."交货项目
SHIFT T_TANUM LEFT DELETING LEADING '0'. "---------------存储去掉前导0
WA_WMJXRW-ZJXDH = <FS_TEMP2>-ZJXDH = T_LGNUM && '-' && T_TANUM."拣选单号(仓库号-TO号)
WA_WMJXRW-ZTBNUM = <FS_TEMP2>-ZTBNUM = T_TBNUM."TR号
WA_WMJXRW-ZTASK_TYPE = <FS_TEMP2>-ZTASK_TYPE."任务类型
WA_WMJXRW-ZPICK_LIGHT = <FS_TEMP2>-ZPICK_LIGHT = ICON_GREEN_LIGHT."拣选交通灯
WA_WMJXRW-ZDELIVERY_LIGHT = <FS_TEMP2>-ZDELIVERY_LIGHT = ICON_YELLOW_LIGHT."配送交通灯
WA_WMJXRW-ZLGORT_S = <FS_TEMP2>-ZLGORT_S."源仓库
WA_WMJXRW-ZLGORT_D = <FS_TEMP2>-ZLGORT_D."目的仓库
WA_WMJXRW-ZMATNR = <FS_TEMP2>-ZMATNR ."物料编号
WA_WMJXRW-ZMENGE = <FS_TEMP2>-ZMENGE ."数量
WA_WMJXRW-ZMEINS = <FS_TEMP2>-ZMEINS ."基本计量单位
* WA_WMJXRW-ZDATE = <FS_TEMP2>-ZDATE ."类型 DATS 的字段 ----
* WA_WMJXRW-ZTIME = <FS_TEMP2>-ZTIME."TIMS 类型的字段
WA_WMJXRW-ZDATE = <FS_TEMP2>-ZDATE = SY-DATUM ."类型 DATS 的字段 ---自建表存下达日期
WA_WMJXRW-ZTIME = <FS_TEMP2>-ZTIME = SY-UZEIT ."TIMS 类型的字段
APPEND WA_WMJXRW TO ITAB_WMJRW.
ENDLOOP.
INSERT ZTA_WMJXRW FROM TABLE ITAB_WMJRW[].
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* 刷新alv显示
LOOP AT ITAB_TEMP_RESB INTO <FS_TEMP2>.
* READ TABLE
CLEAR WA_TOTAL.
MOVE-CORRESPONDING <FS_TEMP2> TO WA_TOTAL.
MODIFY ITAB_TOTAL FROM WA_TOTAL
TRANSPORTING ZTANUM ZTAPOS ZJXDH ZTBNUM ZPICK_LIGHT ZDELIVERY_LIGHT
ZDATE ZTIME "ZLGORT_S ZLGORT_D
WHERE ZRSNUM = WA_TOTAL-ZRSNUM AND ZRSPOS = WA_TOTAL-ZRSPOS.
ENDLOOP.
REFRESH GOODSMVT_ITEM[].
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_CREATE_TO_BY_LIPS
*&---------------------------------------------------------------------*
* 调拨出库/销售出库时,根据交货单生成TO
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_CREATE_TO_BY_LIPS .
CLEAR: ITAB_FROM_LIPS,WA_FROM_LIPS.
DATA: ITAB_DELIT TYPE TABLE OF L03B_DELIT, "BAPI参数
WA_DELIT TYPE L03B_DELIT.
LOOP AT ITAB_TOTAL INTO WA_TOTAL WHERE SEL = 'X'.
MOVE-CORRESPONDING WA_TOTAL TO WA_FROM_LIPS.
APPEND WA_FROM_LIPS TO ITAB_FROM_LIPS.
ENDLOOP.
IF ITAB_FROM_LIPS IS INITIAL.
MESSAGE '请勾选需要下达的项目' TYPE 'E'.
ENDIF.
* 交货单生成TO,如果同时选择不同交货单行项,则分别生成to
SORT ITAB_FROM_LIPS BY ZVBELN ZPOSNR.
DATA: ITAB_TEMP_FOR_INSERT TYPE TABLE OF TY_LIPS .
LOOP AT ITAB_FROM_LIPS INTO WA_FROM_LIPS.
CLEAR WA_DELIT.
* bapi传参
WA_DELIT-POSNR = WA_FROM_LIPS-ZPOSNR."交货项目
WA_DELIT-ANFME = WA_FROM_LIPS-ZMENGE."以备选计量单位计的需求数量
WA_DELIT-ALTME = WA_FROM_LIPS-ZMEINS."帐面库存单位的可选计量单位
* WA_DELIT-LETYP = "仓储单位类型
SELECT SINGLE LETY1
FROM MLGN
INTO WA_DELIT-LETYP
WHERE MATNR = WA_FROM_LIPS-ZMATNR.
IF WA_DELIT-LETYP IS INITIAL.
MESSAGE WA_FROM_LIPS-ZMATNR && '找不到仓库单位类型' TYPE 'E'.
ENDIF.
APPEND WA_DELIT TO ITAB_DELIT.
APPEND WA_FROM_LIPS TO ITAB_TEMP_FOR_INSERT. "为写回自建表做准备
AT END OF ZVBELN.
DATA TANUM TYPE LTAK-TANUM. "生成的TO号
CALL FUNCTION 'L_TO_CREATE_DN'
EXPORTING
* I_LGNUM = WA_FROM_LIPS-ZLGNUM
* I_VBELN = WA_FROM_LIPS-ZVBELN
I_LGNUM = ITAB_TEMP_FOR_INSERT[ 1 ]-ZLGNUM
I_VBELN = ITAB_TEMP_FOR_INSERT[ 1 ]-ZVBELN
IT_DELIT = ITAB_DELIT[]
IMPORTING
E_TANUM = TANUM.
* E_TEILK =
IF SY-SUBRC <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
ENDIF.
* 写入自建表
DATA: ITAB_WMJRW TYPE TABLE OF ZTA_WMJXRW,
WA_WMJXRW TYPE ZTA_WMJXRW.
* 为写入自建表内表赋值,同时需要跟新temp内表数据用于更新显示
LOOP AT ITAB_TEMP_FOR_INSERT ASSIGNING FIELD-SYMBOL(<FS_TEMP>).
* MANDT MANDT CLNT 3 0 集团
WA_WMJXRW-ZTANUM = <FS_TEMP>-ZTANUM = TANUM."转储单编号
<FS_TEMP>-ZTAPOS = <FS_TEMP>-ZPOSNR ."
WA_WMJXRW-ZTAPOS = <FS_TEMP>-ZTAPOS / 10."转储单项目--和交货单一致 bg. flag to行项是1 2 3
* WA_WMJXRW-ZRSNUM = ."预留/相关需求的编号
* WA_WMJXRW-ZRSPOS = ."预留 / 相关需求的项目编号
WA_WMJXRW-ZWERKS = <FS_TEMP>-ZWERKS. "工厂
WA_WMJXRW-ZVBELN = <FS_TEMP>-ZVBELN ."交货
WA_WMJXRW-ZPOSNR = <FS_TEMP>-ZPOSNR ."交货项目
SHIFT TANUM LEFT DELETING LEADING '0'. "---------------存储去掉前导0
WA_WMJXRW-ZJXDH = <FS_TEMP>-ZJXDH = <FS_TEMP>-ZLGNUM && '-' && TANUM."拣选单号(仓库号-TO号)
* WA_WMJXRW-ZTBNUM = ."转移要求号
WA_WMJXRW-ZTASK_TYPE = <FS_TEMP>-ZTASK_TYPE."任务类型
WA_WMJXRW-ZPICK_LIGHT = <FS_TEMP>-ZPICK_LIGHT = ICON_GREEN_LIGHT."拣选交通灯
WA_WMJXRW-ZDELIVERY_LIGHT = <FS_TEMP>-ZDELIVERY_LIGHT = ICON_YELLOW_LIGHT."配送交通灯
WA_WMJXRW-ZLGORT_S = <FS_TEMP>-ZLGORT_S."源仓库
WA_WMJXRW-ZLGORT_D = <FS_TEMP>-ZLGORT_D."目的仓库
WA_WMJXRW-ZMATNR = <FS_TEMP>-ZMATNR ."物料编号
WA_WMJXRW-ZMENGE = <FS_TEMP>-ZMENGE ."数量
WA_WMJXRW-ZMEINS = <FS_TEMP>-ZMEINS ."基本计量单位
* WA_WMJXRW-ZDATE = <FS_TEMP>-ZDATE ."类型 DATS 的字段 ----
* WA_WMJXRW-ZTIME = <FS_TEMP>-ZTIME."TIMS 类型的字段
WA_WMJXRW-ZDATE = <FS_TEMP>-ZDATE = SY-DATUM ."类型 DATS 的字段
WA_WMJXRW-ZTIME = <FS_TEMP>-ZTIME = SY-UZEIT ."TIMS 类型的字段
APPEND WA_WMJXRW TO ITAB_WMJRW.
ENDLOOP.
INSERT ZTA_WMJXRW FROM TABLE ITAB_WMJRW[]..
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* 刷新alv显示
LOOP AT ITAB_TEMP_FOR_INSERT INTO <FS_TEMP>.
* READ TABLE
CLEAR WA_TOTAL.
MOVE-CORRESPONDING <FS_TEMP> TO WA_TOTAL.
MODIFY ITAB_TOTAL FROM WA_TOTAL
TRANSPORTING ZTANUM ZTAPOS ZJXDH ZPICK_LIGHT ZDELIVERY_LIGHT
ZLGORT_S ZLGORT_D ZDATE ZTIME
WHERE ZVBELN = WA_TOTAL-ZVBELN AND ZPOSNR = WA_TOTAL-ZPOSNR.
ENDLOOP.
REFRESH ITAB_TEMP_FOR_INSERT.
REFRESH ITAB_DELIT[].
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_CREATE_TO_BY_TR
*&---------------------------------------------------------------------*
* 通过物料凭证、凭证年度找到TR,然后生成 TO
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_CREATE_TO_BY_TR USING P_RETDOC TYPE MBLNR
P_RETYEAR TYPE MJAHR
CHANGING P_LGNUM TYPE LGNUM
P_TBNUM TYPE TBNUM
P_TANUM TYPE TANUM.
*根据前面生成的物料凭证找到TR
DATA:T_LGNUM TYPE LGNUM,
T_TBNUM TYPE TBNUM.
SELECT SINGLE
LGNUM
TBNUM
INTO (P_LGNUM,P_TBNUM)
FROM LTBK
WHERE MBLNR = P_RETDOC
AND MJAHR = P_RETYEAR.
IF P_TBNUM IS INITIAL.
MESSAGE '根据物料凭证找不到TR!' TYPE 'E'.
ENDIF.
*为L_TO_CREATE_TR函数填参
*该tr全部生成to
CALL FUNCTION 'L_TO_CREATE_TR'
EXPORTING
I_LGNUM = P_LGNUM "
I_TBNUM = P_TBNUM
I_SQUIT = 'X'
* IT_TRITE = ITAB_TRITE[]
IMPORTING
E_TANUM = P_TANUM
EXCEPTIONS
FOREIGN_LOCK = 1
QM_RELEVANT = 2
TR_COMPLETED = 3
XFELD_WRONG = 4
LDEST_WRONG = 5
DRUKZ_WRONG = 6
TR_WRONG = 7
SQUIT_FORBIDDEN = 8
NO_TO_CREATED = 9
UPDATE_WITHOUT_COMMIT = 10
NO_AUTHORITY = 11
PREALLOCATED_STOCK = 12
PARTIAL_TRANSFER_REQ_FORBIDDEN = 13
INPUT_ERROR = 14
OTHERS = 15.
IF SY-SUBRC <> 0.
SELECT SINGLE TEXT
FROM T100
INTO @DATA(MSG)
WHERE SPRSL = 1
AND ARBGB = @SY-MSGID
AND MSGNR = @SY-MSGNO.
MESSAGE '生成TO失败:' && MSG TYPE 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
EXIT.
ENDIF.
MESSAGE '生成TO成功:' && P_TANUM TYPE 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_PRINT
*&---------------------------------------------------------------------*
* 打印拣选单或发货单
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM P_PRINT .
DATA: FM_NAME TYPE FPNAME,
FM_NAME2 TYPE FPNAME.
CLEAR WA_TOTAL.
* ---------------------------------------------------待完成-根据分类调用不同类型表单
REFRESH ITAB_SF.
LOOP AT ITAB_TOTAL INTO WA_TOTAL WHERE SEL = 'X'.
IF WA_TOTAL-ZJXDH IS INITIAL. "该判断防止在下达界面,下达任务后,勾选其它未下达任务进行打印
MESSAGE '请勾选已经下达的的项目,不允许打印未下达任务' TYPE 'E'.
ENDIF.
APPEND WA_TOTAL TO ITAB_SF.
ENDLOOP.
IF ITAB_SF IS INITIAL.
MESSAGE '请勾选需要打印的项目' TYPE 'E'.
ENDIF.
IF R_RESB = 'X'.
FM_NAME2 = 'ZWMFM003'. "拣选单
ELSEIF R_LIPS = 'X'.
FM_NAME2 = 'ZWMFM004'. "发货单
* 取客户名
LOOP AT ITAB_SF INTO WA_SF.
DATA TEMP_SORT1 TYPE KUNNR.
SELECT SINGLE D~SORT1
INTO @TEMP_SORT1
FROM LIPS AS A INNER JOIN EKPO AS B ON A~VGBEL = B~EBELN
INNER JOIN TWLAD AS C ON B~LGORT = C~LGORT AND C~LFDNR = '000'
INNER JOIN ADRC AS D ON C~ADRNR = D~ADDRNUMBER
WHERE A~VBELN = @WA_SF-ZVBELN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "前缀补零
EXPORTING
INPUT = TEMP_SORT1
IMPORTING
OUTPUT = TEMP_SORT1.
SELECT SINGLE NAME1
INTO @WA_SF-NAME1
FROM KNA1
WHERE KUNNR = @TEMP_SORT1.
* 计算包装数量---
DATA TEMP_LHMG1 TYPE MLGN-LHMG1.
SELECT SINGLE LHMG1
INTO TEMP_LHMG1
FROM MLGN
WHERE MATNR = WA_SF-ZMATNR
AND LGNUM = WA_SF-ZLGNUM
.
IF TEMP_LHMG1 <> 0.
WA_SF-ZBZSL = WA_SF-ZMENGE / TEMP_LHMG1.
ENDIF.
MODIFY ITAB_SF FROM WA_SF.
ENDLOOP.
ENDIF.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = FM_NAME2 "拣选单
IMPORTING
FM_NAME = FM_NAME.
IF SY-SUBRC <> 0.
MESSAGE '无法找到function name' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
"call the function
CALL FUNCTION FM_NAME
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
ENDIF.
ENDFORM.
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)