ABAP EXCEL批导+后台作业(JOB)—创建工艺路线+物料分配详解编程语言

需求:用户操作界面下载excel模板,填写数据并上传。程序收到数据并检查,将检查不通过的数据通过ALV展示出来,检查通过的数据创建后台JOB并将执行结果写入日志表。

第一部分程序:

REPORT ZPPU0006. 
TYPE-POOLS:  OLE2 ,ICON ,SLIS. 
TABLES: SSCRFIELDS. 
INCLUDE ZPPU0006_TOP. 
INCLUDE ZPPU0006_SEL. 
INCLUDE ZPPU0006_F01. 
 
*&---------------------------------------------------------------------* 
*&      INITIALIZATION. 
*&---------------------------------------------------------------------* 
INITIALIZATION. 
  FUNCTXT-ICON_ID   = ICON_EXPORT. 
  FUNCTXT-QUICKINFO = 'Download the template'. 
  FUNCTXT-ICON_TEXT = 'Download the template'. 
  SSCRFIELDS-FUNCTXT_01 = FUNCTXT. 
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. 
  CALL FUNCTION 'F4_FILENAME' 
    IMPORTING 
      FILE_NAME = P_FILE. 
 
AT SELECTION-SCREEN. 
  CASE SSCRFIELDS-UCOMM. 
    WHEN 'FC01'. 
      PERFORM DOWNLOAD_EXCEL. 
    WHEN OTHERS. 
  ENDCASE. 
 
START-OF-SELECTION. 
 
  IF P_FILE IS INITIAL. 
    MESSAGE 'Please enter the file path!' TYPE 'S' DISPLAY LIKE 'E'. 
    LEAVE LIST-PROCESSING. 
  ENDIF. 
 
  IF SY-BATCH IS INITIAL. 
    PERFORM FORM_UPLOAD_DATA USING P_FILE. 
    PERFORM FORM_CHECK_DATA. 
    PERFORM FORM_SAVE_ZTABLE. 
    PERFORM FORM_CHECK_VAR. 
    PERFORM FORM_CREATE_JOB. 
  ELSE. 
    PERFORM FORM_GET_DATA. 
    IF D1 = 'X'. 
      PERFORM FORM_CREATE_ROS. 
    ELSEIF D2 = 'X'. 
      PERFORM FORM_ASSIGN_MATERIAL. 
    ENDIF. 
  ENDIF.

INCLUDE ZPPU0006_TOP

*&---------------------------------------------------------------------* 
*& Include          ZPPU0006_TOP 
*&---------------------------------------------------------------------* 
DATA:BEGIN OF T_FILE1 OCCURS 0, 
       TAKE_POZATION, 
       LOEKZ         TYPE LOEKZ, "删除标记 
       PLNTY         TYPE PLNTY, "task list type 
       MATNR(40), 
       WERKS(4), 
       PLNNR(8),"工艺路线组 
       PLNNR_ALT     TYPE PLKO-PLNNR_ALT, "old routing number 
       PLNAL(2), 
       KTEXT(40), 
       LOSVN(17),"从批量 
       LOSBS(17),"到批量 
       PLNME(3),"单位 
       VORNR(4), 
       KTSCH(7), 
       LTXA1(40), 
       ARBPL(8), 
       WERKS_D(4),"工厂(工序) 
       STEUS(4), 
       BMSCH(20), 
       MEINH(3),"单位 
       STD01(15), 
       STP01(6), 
       STD02(15), 
       STP02(6), 
       STD03(15), 
       STP03(6), 
       STD04(15), 
       STP04(6), 
       STD05(15), 
       STP05(6), 
       STD06(15), 
       STP06(6), 
       ZWNOR         TYPE PLPO-ZWNOR, 
       ZEIWN         TYPE PLPO-ZEIWN, 
       ICON          TYPE CHAR4, 
       ZMSG          TYPE STRING, 
     END OF T_FILE1, 
 
     BEGIN OF T_FILE2 OCCURS 0, 
       TAKE_POZATION, 
       MATNR(40), 
       PLNNR(8),"工艺路线组 
       PLNAL(2), 
       WERKS(4), 
       PLNTY         TYPE PLNTY, 
       LOEKZ         TYPE LOEKZ, 
       PLNNR_ALT     TYPE PLKO-PLNNR_ALT, 
       ICON          TYPE CHAR4, 
       ZMSG          TYPE STRING, 
     END OF T_FILE2, 
 
     BEGIN OF IT_MATNRCHECK OCCURS 0, 
       MATNR LIKE MAPL-MATNR, 
     END OF IT_MATNRCHECK, 
 
     BEGIN OF IT_ZAEHL OCCURS 0, 
       ZAEHL LIKE MAPL-ZAEHL, 
     END OF IT_ZAEHL, 
 
     BEGIN OF LS_JOB, 
       JOBCOUNT LIKE TBTCJOB-JOBCOUNT, 
       JOBNAME  LIKE TBTCJOB-JOBNAME, 
     END OF LS_JOB, 
 
     BEGIN OF LS_PROG , 
       REPORT  LIKE RSVAR-REPORT, 
       VARIANT LIKE RSVAR-VARIANT, 
     END OF LS_PROG. 
 
DATA:BEGIN OF LT_VARID OCCURS 0. 
    INCLUDE STRUCTURE VARID. 
DATA:END OF LT_VARID. 
 
DATA: BEGIN OF LT_RSPARAMS_TAB OCCURS 0. 
    INCLUDE STRUCTURE RSPARAMS. 
DATA: END OF LT_RSPARAMS_TAB. 
 
DATA: BEGIN OF LS_VARID_TAB. 
    INCLUDE STRUCTURE VARID. 
DATA: END OF LS_VARID_TAB. 
 
DATA: BEGIN OF LT_VARIT_TAB OCCURS 0. 
    INCLUDE STRUCTURE VARIT. 
DATA: END OF LT_VARIT_TAB. 
 
DATA: BEGIN OF BDCDATA OCCURS 0. 
    INCLUDE STRUCTURE BDCDATA. 
DATA: END OF BDCDATA. 
 
DATA:MESSTAB      TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE, 
     LT_XTBTCSTEP LIKE TBTCSTEP OCCURS 0 WITH HEADER LINE, 
     T_FILE1_CUR  LIKE T_FILE1 OCCURS 0 WITH HEADER LINE, 
     T_FILE1_OUT  LIKE T_FILE1 OCCURS 0 WITH HEADER LINE, 
     T_FILE2_CUR  LIKE T_FILE2 OCCURS 0 WITH HEADER LINE, 
     T_FILE2_OUT  LIKE T_FILE2 OCCURS 0 WITH HEADER LINE, 
     LT_TAB1      TYPE TABLE OF ZPPT0011 WITH HEADER LINE, 
     GS_MSG1      TYPE TABLE OF ZPPT0012 WITH HEADER LINE, 
     LT_TAB2      TYPE TABLE OF ZPPT0003 WITH HEADER LINE, 
     GS_MSG2      TYPE TABLE OF ZPPT0013 WITH HEADER LINE, 
     TAB          LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE, 
     LT_PARAMS    LIKE VANZ OCCURS 0 WITH HEADER LINE. 
 
DATA: BLDAT_S(10)     TYPE C, 
      G_LINES         TYPE I, 
      S0              TYPE CHAR20, 
      S1              TYPE I, 
      S2              TYPE CHAR20, 
      N               TYPE N, 
      X               TYPE N, 
      G_PERC          TYPE P, 
      G_SPERC         TYPE C, 
      G_TEXT          TYPE STRING, 
      GS_LAYOUT       TYPE LVC_S_LAYO, 
      GT_FIELDCAT     TYPE LVC_T_FCAT, 
      GS_FIELDCAT     TYPE LVC_S_FCAT, 
      FUNCTXT         TYPE SMP_DYNTXT, 
      G_KEY(30)       TYPE C, 
      S_MODE          TYPE C VALUE 'N', 
      C_UPDATE        TYPE C VALUE 'S', 
      GS_FUNCTXT      TYPE SMP_DYNTXT, 
      LV_MESSAGE      TYPE STRING, 
      WA              LIKE MESSTAB, 
      LS_XTBTCJOB     TYPE TBTCJOB, 
      LS_XTBTCSTRT    TYPE TBTCSTRT, 
      L_FULLPATH      TYPE STRING, 
      L_PATH          TYPE STRING, 
      L_NAME          TYPE STRING, 
      L_INIT_PATH     TYPE STRING, 
      L_INIT_FNAME    TYPE STRING, 
      L_FILENAME      TYPE STRING, 
      L_OBJDATA       LIKE WWWDATATAB, 
      L_MIME          LIKE W3MIME, 
      L_DESTINATION   LIKE RLGRAP-FILENAME, 
      L_OBJNAM        TYPE STRING, 
      L_RC            LIKE SY-SUBRC, 
      L_ERRTXT        TYPE STRING, 
      L_RESULT, 
      L_SUBRC         TYPE SY-SUBRC, 
      L_OBJID         TYPE WWWDATATAB-OBJID, 
      T_RAW_DATA      TYPE TRUXS_T_TEXT_DATA, 
      LT_RETURN       TYPE BAPIRET2_T, 
      LD_INDEX        TYPE I, 
      L_NO_JOBS       TYPE I, 
      L_FINISH_CANCEL TYPE I, 
      L_JOBNAME       TYPE TBTCO-JOBNAME, 
      L_COUNT         TYPE TBTCO-JOBCOUNT, 
      L_USED          TYPE I, 
      IT_STPOX        TYPE TABLE OF STPOX, 
      WA_STPOX        TYPE STPOX, 
      LV_MATNR        TYPE MARA-MATNR, 
      LV_NUM          TYPE I, 
      IT_MARC         TYPE TABLE OF MARC, 
      IT_MAPL         TYPE TABLE OF MAPL. 
 
FIELD-SYMBOLS: <FS1>. 
FIELD-SYMBOLS: <FS2>.

INCLUDE ZPPU0006_SEL

*&---------------------------------------------------------------------* 
*& Include          ZPPU0006_SEL 
*&---------------------------------------------------------------------* 
*----------------------------------------------------------------------* 
* Selection Screen 
*----------------------------------------------------------------------* 
SELECTION-SCREEN: FUNCTION KEY 1."在屏幕定义功能码 
SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001. 
PARAMETERS: 
  P_FILE  TYPE LOCALFILE MEMORY ID ME1. 
 
PARAMETERS: S_PRF LIKE TCA41-PROFIDNETZ OBLIGATORY. 
 
 
PARAMETERS: D1 RADIOBUTTON GROUP G1 DEFAULT 'X',  "Create ROS 
 
            D2 RADIOBUTTON GROUP G1.              "Assign material 
 
SELECTION-SCREEN END OF BLOCK BLK.

INCLUDE ZPPU0006_F01

*&---------------------------------------------------------------------* 
*& Include          ZPPU0006_F01 
*&---------------------------------------------------------------------* 
FORM DOWNLOAD_EXCEL. 
* 用户选择保存路径 
PERFORM FRM_GET_FULLPATH CHANGING L_FULLPATH L_PATH L_NAME. 
* 路径为空则退出 
IF L_FULLPATH IS INITIAL. 
MESSAGE 'User cancel operation' TYPE 'S'. 
RETURN. 
ENDIF. 
"下载模板 
PERFORM FRM_DOWNLOAD_EXCEL_FROM_SERVER USING L_FULLPATH. 
ENDFORM. 
FORM FRM_GET_FULLPATH CHANGING P_FULLPATH 
P_PATH 
P_NAME. 
* 初始名称(输出的文件名称) 
IF D2 = 'X'. 
L_INIT_FNAME = 'Z_ASSIGNMATERIALTOROS' && '.xls'. 
ELSE. 
L_INIT_FNAME = 'Z_ROUTINGUPLOAD' && '.xls'. 
ENDIF. 
* 获取桌面路径 
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY 
CHANGING 
DESKTOP_DIRECTORY    = L_INIT_PATH 
EXCEPTIONS 
CNTL_ERROR           = 1 
ERROR_NO_GUI         = 2 
NOT_SUPPORTED_BY_GUI = 3 
OTHERS               = 4. 
IF SY-SUBRC <> 0. 
EXIT. 
ENDIF. 
* 用户选择名称、路径 
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG 
EXPORTING 
DEFAULT_EXTENSION    = 'XLSX' 
DEFAULT_FILE_NAME    = L_INIT_FNAME 
FILE_FILTER          = CL_GUI_FRONTEND_SERVICES=>FILETYPE_ALL           "文件类型 all代表全部类型,但是下载输出时必须指明文件类型,不然是白的 
INITIAL_DIRECTORY    = L_INIT_PATH 
PROMPT_ON_OVERWRITE  = 'X' 
CHANGING 
FILENAME             = L_FILENAME 
PATH                 = L_PATH 
FULLPATH             = L_FULLPATH 
EXCEPTIONS 
CNTL_ERROR           = 1 
ERROR_NO_GUI         = 2 
NOT_SUPPORTED_BY_GUI = 3 
OTHERS               = 4. 
IF SY-SUBRC = 0. 
P_FULLPATH = L_FULLPATH. 
P_PATH     = L_PATH. 
ENDIF. 
ENDFORM. 
FORM FRM_DOWNLOAD_EXCEL_FROM_SERVER USING P_FILENAME. 
IF D1 = 'X'. 
L_OBJID = 'Z_ROUTINGUPLOAD'. 
ELSEIF D2 = 'X'. 
L_OBJID = 'Z_ASSIGNMATERIALTOROS'. 
ENDIF. 
"查找文件是否存在。 
SELECT SINGLE RELID OBJID 
FROM WWWDATA 
INTO CORRESPONDING FIELDS OF L_OBJDATA 
WHERE SRTF2    = 0 
AND   RELID    = 'MI' 
AND   OBJID    = L_OBJID. 
"判断模版不存在则报错 
IF SY-SUBRC NE 0 OR L_OBJDATA-OBJID EQ SPACE. 
CONCATENATE 'Template:' L_OBJID 'not exist' 
INTO L_ERRTXT. 
MESSAGE E000(SU) WITH L_ERRTXT. 
ENDIF. 
L_FILENAME = P_FILENAME. 
"判断本地地址是否已经存在此文件。 
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST 
EXPORTING 
FILE                 = L_FILENAME 
RECEIVING 
RESULT               = L_RESULT 
EXCEPTIONS 
CNTL_ERROR           = 1 
ERROR_NO_GUI         = 2 
WRONG_PARAMETER      = 3 
NOT_SUPPORTED_BY_GUI = 4 
OTHERS               = 5. 
IF L_RESULT EQ 'X'.  "如果存在则删除原始文件,重新覆盖 
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE 
EXPORTING 
FILENAME             = L_FILENAME 
CHANGING 
RC                   = L_SUBRC 
EXCEPTIONS 
FILE_DELETE_FAILED   = 1 
CNTL_ERROR           = 2 
ERROR_NO_GUI         = 3 
FILE_NOT_FOUND       = 4 
ACCESS_DENIED        = 5 
UNKNOWN_ERROR        = 6 
NOT_SUPPORTED_BY_GUI = 7 
WRONG_PARAMETER      = 8 
OTHERS               = 9. 
IF L_SUBRC <> 0. "如果删除失败,则报错。 
CONCATENATE 'The EXCEL file with the same name has been opened' 'please close the EXCEL and try again' 
INTO L_ERRTXT. 
MESSAGE E000(SU) WITH L_ERRTXT. 
ENDIF. 
ENDIF. 
L_DESTINATION   = P_FILENAME. 
"下载模版。 
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' 
EXPORTING 
KEY         = L_OBJDATA 
DESTINATION = L_DESTINATION 
IMPORTING 
RC          = L_RC. 
IF L_RC NE 0. 
CONCATENATE 'Template' 'download failed' INTO L_ERRTXT. 
MESSAGE E000(SU) WITH L_ERRTXT. 
ENDIF. 
ENDFORM. 
FORM FORM_UPLOAD_DATA USING P_FILE. 
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 
EXPORTING 
FILENAME                = P_FILE 
I_BEGIN_COL             = 1 
I_BEGIN_ROW             = 5 
I_END_COL               = 99 
I_END_ROW               = 50000 
TABLES 
INTERN                  = TAB 
EXCEPTIONS 
INCONSISTENT_PARAMETERS = 1 
UPLOAD_OLE              = 2 
OTHERS                  = 3. 
LOOP AT TAB. 
MOVE TAB-COL TO LD_INDEX. 
IF D1 = 'X'. 
ASSIGN COMPONENT LD_INDEX OF STRUCTURE T_FILE1 TO <FS1>. 
MOVE TAB-VALUE TO <FS1>. 
AT END OF ROW. 
T_FILE1-ICON = ICON_YELLOW_LIGHT. 
APPEND T_FILE1. 
CLEAR T_FILE1. 
ENDAT. 
ELSEIF D2 = 'X'. 
ASSIGN COMPONENT LD_INDEX OF STRUCTURE T_FILE2 TO <FS2>. 
MOVE TAB-VALUE TO <FS2>. 
AT END OF ROW. 
T_FILE2-ICON = ICON_YELLOW_LIGHT. 
APPEND T_FILE2. 
CLEAR  T_FILE2. 
ENDAT. 
ENDIF. 
ENDLOOP. 
IF T_FILE1[] IS INITIAL AND T_FILE2[] IS INITIAL. 
MESSAGE 'The uploaded file does not contain any valid data!' TYPE 'S' DISPLAY LIKE 'E'. 
LEAVE LIST-PROCESSING. 
ENDIF. 
ENDFORM. 
FORM FORM_CHECK_DATA. 
IF D1 = 'X'. 
SORT T_FILE1 BY PLNTY WERKS PLNAL. 
LOOP AT T_FILE1. 
N = LINES( T_FILE1 ). 
X = SY-TABIX. 
G_PERC = ( X / N ) * 100 . 
G_SPERC = G_PERC. 
G_TEXT = |{ 'Data checking'}{ G_PERC }{ '%' }|. 
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
EXPORTING 
PERCENTAGE = G_PERC 
TEXT       = G_TEXT. 
ENDLOOP. 
CLEAR: T_FILE1_OUT[],T_FILE1_CUR[]. 
T_FILE1_CUR[] = T_FILE1[]. 
DELETE T_FILE1_CUR WHERE ICON = ICON_RED_LIGHT. 
T_FILE1_OUT[] = T_FILE1[]. 
DELETE T_FILE1_OUT WHERE ICON NE ICON_RED_LIGHT. 
CLEAR T_FILE1[]. 
T_FILE1[] = T_FILE1_CUR[]. 
ELSEIF D2 = 'X'. 
SORT T_FILE2 BY PLNTY WERKS MATNR PLNAL. 
LOOP AT T_FILE2. 
N = LINES( T_FILE2 ). 
X = SY-TABIX. 
G_PERC = ( X / N ) * 100 . 
G_SPERC = G_PERC. 
G_TEXT = |{ 'Data checking'}{ G_PERC }{ '%' }|. 
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
EXPORTING 
PERCENTAGE = G_PERC 
TEXT       = G_TEXT. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT  = T_FILE2-PLNAL 
IMPORTING 
OUTPUT = T_FILE2-PLNAL. 
*      CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' 
*        EXPORTING 
*          input        = gs_tab-matnr 
*        IMPORTING 
*          output       = gs_tab-matnr 
*        EXCEPTIONS 
*          length_error = 1 
*          OTHERS       = 2. 
CLEAR IT_MATNRCHECK. 
SELECT SINGLE MATNR INTO IT_MATNRCHECK FROM MARC 
WHERE MATNR = T_FILE2-MATNR AND WERKS = T_FILE2-WERKS. 
IF IT_MATNRCHECK IS INITIAL. 
T_FILE2-ICON = ICON_RED_LIGHT. 
T_FILE2-ZMSG = 'Material is not exist in the plant'. 
MODIFY T_FILE2. 
CLEAR: T_FILE2,IT_MATNRCHECK. 
CONTINUE. 
ENDIF. 
CLEAR IT_MATNRCHECK. 
SELECT SINGLE MATNR INTO IT_MATNRCHECK FROM MAPL 
WHERE MATNR = T_FILE2-MATNR AND PLNAL = T_FILE2-PLNAL 
AND WERKS = T_FILE2-WERKS AND PLNTY = 'S' AND LOEKZ NE 'X'. 
IF IT_MATNRCHECK IS NOT INITIAL. 
T_FILE2-ICON = ICON_RED_LIGHT. 
T_FILE2-ZMSG = ' Assignment of material to reference operation set already exists '. 
MODIFY T_FILE2. 
CLEAR: T_FILE2,IT_MATNRCHECK. 
CONTINUE. 
ENDIF. 
ENDLOOP. 
CLEAR: T_FILE2_OUT[],T_FILE2_CUR[]. 
T_FILE2_CUR[] = T_FILE2[]. 
DELETE T_FILE2_CUR WHERE ICON = ICON_RED_LIGHT. 
T_FILE2_OUT[] = T_FILE2[]. 
DELETE T_FILE2_OUT WHERE ICON NE ICON_RED_LIGHT. 
CLEAR T_FILE2[]. 
T_FILE2[] = T_FILE2_CUR[]. 
ENDIF. 
ENDFORM. 
FORM FORM_ALV. 
PERFORM FORM_SET_LAYOUT. 
PERFORM FORM_SET_FCAT. 
PERFORM FORM_OUTPUT. 
ENDFORM. 
FORM FORM_SET_LAYOUT. 
CLEAR GS_LAYOUT. 
GS_LAYOUT-ZEBRA = 'X'. 
GS_LAYOUT-CWIDTH_OPT = 'X'. 
GS_LAYOUT-SEL_MODE = 'D'. 
ENDFORM. 
FORM FORM_SET_FCAT. 
DEFINE ADD_FIELD. 
CLEAR gs_fieldcat. 
gs_fieldcat-fieldname = &1. 
gs_fieldcat-scrtext_l = &2. 
gs_fieldcat-scrtext_m = &2. 
gs_fieldcat-scrtext_s = &2. 
APPEND gs_fieldcat TO gt_fieldcat. 
END-OF-DEFINITION. 
CLEAR GT_FIELDCAT[]. 
IF D1 = 'X'. 
ADD_FIELD 'ICON' 'LED'. 
ADD_FIELD 'PLNNR_ALT' 'Old routing number'. 
ADD_FIELD 'ZMSG' 'Message'. 
ELSEIF D2 = 'X'. 
ADD_FIELD 'ICON' 'LED'. 
ADD_FIELD 'MATNR' 'Material'. 
ADD_FIELD 'PLNNR' 'Routing number'. 
ADD_FIELD 'ZMSG' 'Message'. 
ENDIF. 
ENDFORM. 
FORM FORM_OUTPUT. 
IF D1 = 'X'. 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' 
EXPORTING 
IS_LAYOUT_LVC   = GS_LAYOUT 
IT_FIELDCAT_LVC = GT_FIELDCAT 
TABLES 
T_OUTTAB        = T_FILE1_OUT. 
ELSEIF D2 = 'X'. 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' 
EXPORTING 
IS_LAYOUT_LVC   = GS_LAYOUT 
IT_FIELDCAT_LVC = GT_FIELDCAT 
TABLES 
T_OUTTAB        = T_FILE2_OUT. 
ENDIF. 
ENDFORM. 
FORM FORM_SAVE_ZTABLE . 
IF D2 = 'X'. 
G_KEY = |{ 'AM' }{ SY-DATUM+2(6) }{ SY-UZEIT }|. 
LOOP AT T_FILE2. 
LT_TAB2-ZKEY = G_KEY. 
LT_TAB2-MATNR = T_FILE2-MATNR. 
LT_TAB2-PLNNR = T_FILE2-PLNNR. 
LT_TAB2-PLNAL = T_FILE2-PLNAL. 
LT_TAB2-WERKS = T_FILE2-WERKS. 
LT_TAB2-PLNTY = T_FILE2-PLNTY. 
LT_TAB2-LOEKZ = T_FILE2-LOEKZ. 
LT_TAB2-PLNNR_ALT = T_FILE2-PLNNR_ALT. 
APPEND LT_TAB2. 
CLEAR:LT_TAB2,T_FILE2. 
ENDLOOP. 
INSERT ZPPT0003 FROM TABLE LT_TAB2. 
ELSEIF D1 = 'X'. 
G_KEY = |{ 'CR' }{ SY-DATUM+2(6) }{ SY-UZEIT }|. 
LOOP AT T_FILE1. 
LT_TAB1-ZKEY = G_KEY. 
LT_TAB1-PLNTY = T_FILE1-PLNTY. 
LT_TAB1-MATNR = T_FILE1-MATNR. 
LT_TAB1-WERKS = T_FILE1-WERKS. 
LT_TAB1-PLNNR = T_FILE1-PLNNR. 
LT_TAB1-PLNNR_ALT = T_FILE1-PLNNR_ALT. 
LT_TAB1-PLNAL = T_FILE1-PLNAL. 
LT_TAB1-LOEKZ = T_FILE1-LOEKZ. 
LT_TAB1-KTEXT = T_FILE1-KTEXT. 
LT_TAB1-LOSVN = T_FILE1-LOSVN. 
LT_TAB1-LOSBS = T_FILE1-LOSBS. 
LT_TAB1-PLNME = T_FILE1-PLNME. 
LT_TAB1-VORNR = T_FILE1-VORNR. 
LT_TAB1-KTSCH = T_FILE1-KTSCH. 
LT_TAB1-LTXA1 = T_FILE1-LTXA1. 
LT_TAB1-ARBPL = T_FILE1-ARBPL. 
LT_TAB1-WERKS_D = T_FILE1-WERKS_D. 
LT_TAB1-STEUS = T_FILE1-STEUS. 
LT_TAB1-BMSCH = T_FILE1-BMSCH. 
LT_TAB1-MEINH = T_FILE1-MEINH. 
LT_TAB1-VGW01 = T_FILE1-STD01. 
LT_TAB1-VGE01 = T_FILE1-STP01. 
LT_TAB1-VGW02 = T_FILE1-STD02. 
LT_TAB1-VGE02 = T_FILE1-STP02. 
LT_TAB1-VGW03 = T_FILE1-STD03. 
LT_TAB1-VGE03 = T_FILE1-STP03. 
LT_TAB1-VGW04 = T_FILE1-STD04. 
LT_TAB1-VGE04 = T_FILE1-STP04. 
LT_TAB1-VGW05 = T_FILE1-STD05. 
LT_TAB1-VGE05 = T_FILE1-STP05. 
LT_TAB1-VGW06 = T_FILE1-STD06. 
LT_TAB1-VGE06 = T_FILE1-STP06. 
LT_TAB1-ZWNOR = T_FILE1-ZWNOR. 
LT_TAB1-ZEIWN = T_FILE1-ZEIWN. 
APPEND LT_TAB1. 
CLEAR:LT_TAB1,T_FILE1. 
ENDLOOP. 
INSERT ZPPT0011 FROM TABLE LT_TAB1. 
ENDIF. 
COMMIT WORK AND WAIT. 
ENDFORM. 
FORM FORM_CHECK_VAR . 
IF D1 = 'X'. 
SELECT * 
FROM VARID CLIENT SPECIFIED 
INTO CORRESPONDING FIELDS OF TABLE LT_VARID 
WHERE MANDT = SY-MANDT 
AND   REPORT   = 'ZPPU0006' 
AND   VARIANT  LIKE 'CR%' 
AND   FLAG1    = SPACE 
AND   FLAG2    = SPACE. 
ELSEIF D2 = 'X'. 
SELECT * 
FROM VARID CLIENT SPECIFIED 
INTO CORRESPONDING FIELDS OF TABLE LT_VARID 
WHERE MANDT = SY-MANDT 
AND   REPORT   = 'ZPPU0006' 
AND   VARIANT  LIKE 'AM%' 
AND   FLAG1    = SPACE 
AND   FLAG2    = SPACE. 
ENDIF. 
IF SY-SUBRC = 0. 
LOOP AT LT_VARID. 
CLEAR:L_NO_JOBS      , 
L_FINISH_CANCEL, 
L_JOBNAME      , 
L_COUNT        , 
L_USED         . 
CALL FUNCTION 'BP_VARIANT_USED_IN_JOB' 
EXPORTING 
REPNAME                        = 'ZPPU0006' 
VARNAME                        = LT_VARID-VARIANT 
CLIENT                         = SY-MANDT 
IMPORTING 
NO_JOBS_STILL_USING            = L_NO_JOBS 
NO_JOBS_FINISHED_CANCELD_USING = L_FINISH_CANCEL 
JOBNAME                        = L_JOBNAME 
JOBCOUNT                       = L_COUNT 
EXCEPTIONS 
REPNAME_MISSING                = 1 
VARNAME_MISSING                = 2 
OTHERS                         = 3. 
IF SY-SUBRC <> 0. 
CLEAR LT_VARID. 
CONTINUE. 
ENDIF. 
L_USED = L_NO_JOBS - L_FINISH_CANCEL. 
IF L_USED NE 0. 
CLEAR LT_VARID. 
CONTINUE. 
ENDIF. 
CALL FUNCTION 'RS_VARIANT_DELETE' 
EXPORTING 
REPORT               = 'ZPPU0006' 
VARIANT              = LT_VARID-VARIANT 
FLAG_CONFIRMSCREEN   = 'X' 
FLAG_DELALLCLIENT    = 'X' 
EXCEPTIONS 
NOT_AUTHORIZED       = 1 
NOT_EXECUTED         = 2 
NO_REPORT            = 3 
REPORT_NOT_EXISTENT  = 4 
REPORT_NOT_SUPPLIED  = 5 
VARIANT_LOCKED       = 6 
VARIANT_NOT_EXISTENT = 7 
NO_CORR_INSERT       = 8 
VARIANT_PROTECTED    = 9 
OTHERS               = 10. 
ENDLOOP. 
ENDIF. 
PERFORM FORM_CREATE_VAR. 
ENDFORM. 
FORM FORM_CREATE_VAR . 
LS_PROG-REPORT  = 'ZPPU0006'. 
LS_PROG-VARIANT = G_KEY. 
CLEAR LS_VARID_TAB. 
CONCATENATE SY-UZEIT SY-UNAME INTO LS_VARID_TAB-VARIANT. 
LS_VARID_TAB-MANDT        = SY-MANDT. 
LS_VARID_TAB-REPORT       = LS_PROG-REPORT. 
LS_VARID_TAB-VARIANT      = LS_PROG-VARIANT. 
LS_VARID_TAB-FLAG1        = SPACE. 
LS_VARID_TAB-FLAG2        = SPACE. 
LS_VARID_TAB-TRANSPORT    = SPACE. 
LS_VARID_TAB-ENVIRONMNT   = 'A'.        "Variant for batch and online 
LS_VARID_TAB-PROTECTED    = SPACE. 
LS_VARID_TAB-SECU         = SPACE. 
LS_VARID_TAB-VERSION      = '1'. 
LS_VARID_TAB-ENAME        = SY-UNAME. 
LS_VARID_TAB-EDAT         = SY-DATUM. 
LS_VARID_TAB-ETIME        = SY-UZEIT. 
LS_VARID_TAB-AENAME       = SPACE. 
LS_VARID_TAB-AEDAT        = SPACE. 
LS_VARID_TAB-AETIME       = SPACE. 
LS_VARID_TAB-MLANGU       = SY-LANGU. 
CLEAR LT_VARIT_TAB. 
REFRESH LT_VARIT_TAB. 
LT_VARIT_TAB-MANDT      = SY-MANDT. 
LT_VARIT_TAB-LANGU      = SY-LANGU. 
LT_VARIT_TAB-REPORT     = LS_PROG-REPORT. 
LT_VARIT_TAB-VARIANT    = LS_PROG-VARIANT. 
LT_VARIT_TAB-VTEXT      = LS_PROG-REPORT. 
LT_VARIT_TAB-VTEXT+9    = LS_PROG-VARIANT. 
APPEND LT_VARIT_TAB. 
REFRESH LT_RSPARAMS_TAB. 
PERFORM FILL_RSPARAMS_TAB TABLES LT_RSPARAMS_TAB[] 
USING 'S_PRF' 'P' '' '' S_PRF ''. 
PERFORM FILL_RSPARAMS_TAB TABLES LT_RSPARAMS_TAB[] 
USING 'P_FILE' 'P' '' '' P_FILE ''. 
CALL FUNCTION 'RS_CREATE_VARIANT' 
EXPORTING 
CURR_REPORT               = LS_VARID_TAB-REPORT 
CURR_VARIANT              = LS_VARID_TAB-VARIANT 
VARI_DESC                 = LS_VARID_TAB 
TABLES 
VARI_CONTENTS             = LT_RSPARAMS_TAB 
VARI_TEXT                 = LT_VARIT_TAB 
EXCEPTIONS 
ILLEGAL_REPORT_OR_VARIANT = 1 
ILLEGAL_VARIANTNAME       = 2 
NOT_AUTHORIZED            = 3 
NOT_EXECUTED              = 4 
REPORT_NOT_EXISTENT       = 5 
REPORT_NOT_SUPPLIED       = 6 
VARIANT_EXISTS            = 7 
VARIANT_LOCKED            = 8 
OTHERS                    = 9. 
WAIT UP TO 1 SECONDS. 
ENDFORM. 
FORM FILL_RSPARAMS_TAB  TABLES P_LT_RSPARAMS_TAB STRUCTURE RSPARAMS 
USING SELNAME KIND SIGN OPTION LOW HIGH. 
DATA:LS_RSPARAMS_TAB LIKE LINE OF P_LT_RSPARAMS_TAB. 
LS_RSPARAMS_TAB-SELNAME = SELNAME. 
LS_RSPARAMS_TAB-KIND    = KIND. 
LS_RSPARAMS_TAB-SIGN    = SIGN. 
LS_RSPARAMS_TAB-OPTION  = OPTION. 
LS_RSPARAMS_TAB-LOW     = LOW. 
LS_RSPARAMS_TAB-HIGH    = HIGH. 
APPEND LS_RSPARAMS_TAB TO P_LT_RSPARAMS_TAB . 
ENDFORM. 
FORM FORM_CREATE_JOB . 
CONCATENATE SY-UNAME SY-DATUM SY-UZEIT 'ZPPU0006' INTO LS_JOB-JOBNAME. 
WRITE SY-UZEIT TO LS_JOB-JOBCOUNT. 
LS_XTBTCJOB-JOBNAME   = LS_JOB-JOBNAME. 
LS_XTBTCJOB-JOBCOUNT  = LS_JOB-JOBCOUNT. 
LS_XTBTCJOB-INTREPORT = 'ZPPU0006'. 
LS_XTBTCJOB-SDLSTRTDT = SY-DATUM. 
LS_XTBTCJOB-SDLSTRTTM = SY-UZEIT + 2. 
LS_XTBTCJOB-PRIORITY  = '1'. 
LS_XTBTCJOB-JOBCLASS  = 'A'. 
LS_XTBTCJOB-NEWFLAG = 'O'. 
LS_XTBTCJOB-SDLUNAME = SY-UNAME. 
LS_XTBTCSTRT-SDLSTRTDT = SY-DATUM. 
LS_XTBTCSTRT-SDLSTRTTM = SY-UZEIT + 2. 
CLEAR LT_XTBTCSTEP. 
LT_XTBTCSTEP-PROGRAM     =  'ZPPU0006'. 
LT_XTBTCSTEP-PARAMETER   =  G_KEY. 
LT_XTBTCSTEP-AUTHCKNAM   =  SY-UNAME. 
LT_XTBTCSTEP-TYP         =  'A'. 
LT_XTBTCSTEP-LANGUAGE    =  SY-LANGU. 
LT_XTBTCSTEP-STATUS = 'P'. 
APPEND LT_XTBTCSTEP. 
CALL FUNCTION 'BP_JOB_CREATE' 
EXPORTING 
JOB_CR_DIALOG       = 'N' 
JOB_CR_HEAD_INP     = LS_XTBTCJOB 
IMPORTING 
JOB_CR_HEAD_OUT     = LS_XTBTCJOB 
JOB_CR_STDT_OUT     = LS_XTBTCSTRT 
TABLES 
JOB_CR_STEPLIST     = LT_XTBTCSTEP 
EXCEPTIONS 
CANT_CREATE_JOB     = 1 
INVALID_DIALOG_TYPE = 2 
INVALID_JOB_DATA    = 3 
JOB_CREATE_CANCELED = 4 
OTHERS              = 5. 
IF SY-SUBRC <> 0. 
PERFORM FORM_DEL_ZTABLE. 
MESSAGE 'Create Background Job Failed.' TYPE 'E'. 
ELSE. 
MESSAGE 'Create Background Job Successfully.' TYPE 'S'. 
PERFORM FORM_ALV. 
"LEAVE TO SCREEN 0. 
ENDIF. 
ENDFORM. 
FORM FORM_DEL_ZTABLE. 
IF D1 = 'X'. 
DELETE FROM ZPPT0011 WHERE ZKEY = G_KEY. 
ELSEIF D2 = 'X'. 
DELETE FROM ZPPT0003 WHERE ZKEY = G_KEY. 
ENDIF. 
ENDFORM. 
FORM BDC_DYNPRO USING PROGRAM DYNPRO. 
CLEAR BDCDATA. 
BDCDATA-PROGRAM  = PROGRAM. 
BDCDATA-DYNPRO   = DYNPRO. 
BDCDATA-DYNBEGIN = 'X'. 
APPEND BDCDATA. 
ENDFORM. 
FORM BDC_FIELD USING FNAM FVAL. 
CLEAR BDCDATA. 
BDCDATA-FNAM = FNAM. 
BDCDATA-FVAL = FVAL. 
APPEND BDCDATA. 
ENDFORM. 
FORM FORM_GET_DATA . 
REFRESH:LT_TAB1,LT_TAB2. 
CLEAR:LT_TAB1,LT_TAB2. 
IF D1 = 'X'. 
SELECT * 
FROM ZPPT0011 
INTO CORRESPONDING FIELDS OF TABLE LT_TAB1 
WHERE ZKEY = SY-SLSET. 
ELSEIF D2 = 'X'. 
SELECT * 
FROM ZPPT0003 
INTO CORRESPONDING FIELDS OF TABLE LT_TAB2 
WHERE ZKEY = SY-SLSET. 
ENDIF. 
ENDFORM. 
FORM FORM_ASSIGN_MATERIAL. 
LOOP AT LT_TAB2. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT  = LT_TAB2-PLNNR 
IMPORTING 
OUTPUT = LT_TAB2-PLNNR. 
CLEAR IT_ZAEHL. 
SELECT ZAEHL INTO IT_ZAEHL FROM MAPL 
WHERE PLNNR = LT_TAB2-PLNNR. 
ENDSELECT. 
APPEND IT_ZAEHL. 
G_LINES = IT_ZAEHL. 
S1 = 02."g_lines + 1. 
PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '1001'. 
PERFORM BDC_FIELD       USING 'BDC_CURSOR' 
'RC271-PLNNR'. 
PERFORM BDC_FIELD       USING 'BDC_OKCODE' 
'=ALUE'. 
PERFORM BDC_FIELD       USING 'RC271-PLNNR' 
LT_TAB2-PLNNR. 
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' 
EXPORTING 
DATE_INTERNAL = SY-DATUM "'20010101' 
IMPORTING 
DATE_EXTERNAL = BLDAT_S. 
PERFORM BDC_FIELD       USING 'RC271-STTAG' 
BLDAT_S. 
PERFORM BDC_FIELD       USING 'RC271-WERKS' 
LT_TAB2-WERKS. 
PERFORM BDC_FIELD       USING 'RC271-PLNAL' 
LT_TAB2-PLNAL. 
PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '1200'. 
PERFORM BDC_FIELD       USING 'BDC_CURSOR' 
'RC27X-ENTRY_ACT'. 
PERFORM BDC_FIELD       USING 'BDC_OKCODE' 
'=MTUE'. 
PERFORM BDC_FIELD       USING 'RC27X-ENTRY_ACT' 
'1'. 
PERFORM BDC_DYNPRO      USING 'SAPLCZDI' '1010'. 
PERFORM BDC_FIELD       USING 'BDC_CURSOR' 
'RC27X-ENTRY_ACT'. 
PERFORM BDC_FIELD       USING 'BDC_OKCODE' 
'=ENT1'. 
S0 = '' && G_LINES && ''. 
PERFORM BDC_FIELD       USING 'RC27X-ENTRY_ACT' 
S0. 
PERFORM BDC_DYNPRO      USING 'SAPLCZDI' '1010'. 
PERFORM BDC_FIELD       USING 'BDC_CURSOR' 
'MAPL-WERKS(01)'. 
PERFORM BDC_FIELD       USING 'BDC_OKCODE' 
'=BACK'. 
S2 = 'MAPL-PLNAL(' && S1 && ')'. 
PERFORM BDC_FIELD       USING S2 
LT_TAB2-PLNAL. 
CLEAR S2. 
S2 = 'MAPL-MATNR(' && S1 && ')'. 
PERFORM BDC_FIELD       USING S2 
LT_TAB2-MATNR. 
CLEAR S2. 
S2 = 'MAPL-WERKS(' && S1 && ')'. 
PERFORM BDC_FIELD       USING S2 
LT_TAB2-WERKS. 
CLEAR S2. 
PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '1200'. 
PERFORM BDC_FIELD       USING 'BDC_CURSOR' 
'RC27X-ENTRY_ACT'. 
PERFORM BDC_FIELD       USING 'BDC_OKCODE' 
'=BU'. 
PERFORM BDC_FIELD       USING 'RC27X-ENTRY_ACT' 
'1'. 
CALL TRANSACTION 'CA12' USING   BDCDATA  MODE S_MODE UPDATE  C_UPDATE 
MESSAGES INTO MESSTAB. 
CLEAR: BDCDATA[],GS_MSG2,WA. 
READ TABLE MESSTAB INTO WA WITH KEY MSGTYP = 'S'. 
IF SY-SUBRC = 0 AND ( WA-MSGID NE '00' AND WA-MSGNR NE '344' ). 
GS_MSG2-ICON = ICON_GREEN_LIGHT. 
GS_MSG2-ZMSG = 'Success!'. 
ELSE. 
CLEAR:LV_MESSAGE. 
CONCATENATE WA-MSGV1 WA-MSGV2 WA-MSGV3 WA-MSGV4 
INTO  LV_MESSAGE. 
GS_MSG2-ICON = ICON_RED_LIGHT. 
GS_MSG2-ZMSG = 'Upload failed!' && LV_MESSAGE. 
ENDIF. 
GS_MSG2-MATNR = LT_TAB2-MATNR. 
GS_MSG2-PLNNR = LT_TAB2-PLNNR. 
GS_MSG2-ZUSER = SY-UNAME. 
GS_MSG2-ZDATE = |{ SY-DATUM }{ '-' }{ SY-UZEIT }|. 
INSERT ZPPT0013 FROM GS_MSG2. 
CLEAR:MESSTAB,MESSTAB[],GS_MSG2. 
ENDLOOP. 
ENDFORM. 
FORM FORM_CREATE_ROS. 
DATA:BEGIN OF IT_OLDNUM OCCURS 0, 
OLDNUM LIKE PLKO-PLNNR_ALT, 
END OF IT_OLDNUM. 
DATA: LV_PLNNR                  TYPE MAPL-PLNNR, 
IT_TASK                   TYPE TABLE OF BAPI1190_TSK_C, "任务清单头数据 
WA_TASK                   TYPE BAPI1190_TSK_C, 
IT_MATERIALTASKALLOCATION TYPE TABLE OF BAPI1190_MTK_C, "物料任务清单分配 
WA_MATERIALTASKALLOCATION TYPE BAPI1190_MTK_C, 
IT_OPERATION              TYPE TABLE OF BAPI1190_OPR_C, "工序 
WA_OPERATION              TYPE BAPI1190_OPR_C, 
IT_COMPONENTALLOCATION    TYPE TABLE OF BAPI1190_COM_C, "组件 
WA_COMPONENTALLOCATION    TYPE BAPI1190_COM_C, 
IT_RETURN                 TYPE TABLE OF BAPIRET2,     "返回消息 
WA_RETURN                 TYPE BAPIRET2, 
WA_GROUP                  TYPE BAPI1190_TSK_C-TASK_LIST_GROUP,  "任务清单 
WA_GROUPCOUNTER           TYPE BAPI1190_TSK_C-GROUP_COUNTER.  "组计数器 
LOOP AT LT_TAB1. 
IT_OLDNUM-OLDNUM = LT_TAB1-PLNNR_ALT. 
APPEND IT_OLDNUM. 
CLEAR: LT_TAB1,IT_OLDNUM. 
ENDLOOP. 
SORT IT_OLDNUM BY OLDNUM. 
DELETE ADJACENT DUPLICATES FROM IT_OLDNUM COMPARING ALL FIELDS. 
LOOP AT IT_OLDNUM. 
"头数据 
LOOP AT LT_TAB1 WHERE PLNNR_ALT = IT_OLDNUM-OLDNUM. 
WA_TASK-TASK_LIST_GROUP  = LT_TAB1-PLNNR. 
WA_TASK-GROUP_COUNTER    = LT_TAB1-PLNAL.  "组计数器 
WA_TASK-VALID_FROM       = '20010101'. "有效起始日期 
WA_TASK-VALID_TO_DATE    = '99991231'.    "有效截止日期 
IF LT_TAB1-LOSVN IS NOT INITIAL. 
WA_TASK-LOT_SIZE_FROM  = LT_TAB1-LOSVN. 
ELSE. 
WA_TASK-LOT_SIZE_FROM  = ''.            "从批量 
ENDIF. 
IF LT_TAB1-LOSBS IS NOT INITIAL. 
WA_TASK-LOT_SIZE_TO    = LT_TAB1-LOSBS. 
ELSE. 
WA_TASK-LOT_SIZE_TO    = '99999999'.    "到批量 
ENDIF. 
WA_TASK-DESCRIPTION      = LT_TAB1-KTEXT.  "任务清单描述 
WA_TASK-DEL_IND          = LT_TAB1-LOEKZ. "删除标记 
WA_TASK-OLD_NUMBER_OF_TASK_LIST = LT_TAB1-PLNNR_ALT.  "old number 
APPEND WA_TASK TO IT_TASK. 
CLEAR:WA_TASK,LT_TAB1. 
ENDLOOP. 
SORT IT_TASK BY OLD_NUMBER_OF_TASK_LIST. 
DELETE ADJACENT DUPLICATES FROM IT_TASK COMPARING ALL FIELDS. 
"工序 
LOOP AT LT_TAB1 WHERE PLNNR_ALT = IT_OLDNUM-OLDNUM. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT  = LT_TAB1-PLNAL 
IMPORTING 
OUTPUT = LT_TAB1-PLNAL. 
WA_OPERATION-OPERATION_MEASURE_UNIT = LT_TAB1-MEINH."作业的计量单位 
WA_OPERATION-TASK_LIST_GROUP     = LT_TAB1-PLNNR. 
WA_OPERATION-GROUP_COUNTER       = LT_TAB1-PLNAL. "组计数器 
WA_OPERATION-VALID_FROM          = '20010101'.     "有效起始日期 
WA_OPERATION-VALID_TO_DATE       = '99991231'.   "有效截止日期 
WA_OPERATION-ACTIVITY            = LT_TAB1-VORNR. "工序 
WA_OPERATION-CONTROL_KEY         = LT_TAB1-STEUS. "控制码 
WA_OPERATION-WORK_CNTR           = LT_TAB1-ARBPL. "工作中心 
IF LT_TAB1-BMSCH IS NOT INITIAL. 
WA_OPERATION-BASE_QUANTITY       = LT_TAB1-BMSCH. "基本数量 
ELSE . 
WA_OPERATION-BASE_QUANTITY       = '1'. 
LT_TAB1-BMSCH = '1'. 
ENDIF. 
WA_OPERATION-DENOMINATOR         = '1'.          "用于转换工艺路线和工序单位的分母 
WA_OPERATION-NOMINATOR           = '1'.          "用于转换任务清单和工序计量单位的计数器 
WA_OPERATION-COST_RELEVANT       = 'X'. 
WA_OPERATION-DESCRIPTION         = LT_TAB1-LTXA1. "工序描述 
WA_OPERATION-ACTTYPE_01          = 'A001'. 
WA_OPERATION-STD_VALUE_01        = LT_TAB1-VGW01. "机器 
WA_OPERATION-STD_UNIT_01        = LT_TAB1-VGE01. "单位 
WA_OPERATION-ACTTYPE_02          = 'A002'. 
WA_OPERATION-STD_VALUE_02        = LT_TAB1-VGW02. "计件人工 
WA_OPERATION-STD_UNIT_02        = LT_TAB1-VGE02. "单位 
WA_OPERATION-ACTTYPE_03          = 'A003'. 
WA_OPERATION-STD_VALUE_03        = LT_TAB1-VGW03. "间接人工 
WA_OPERATION-STD_UNIT_03        = LT_TAB1-VGE03. "单位 
WA_OPERATION-ACTTYPE_04          = 'A004'. 
WA_OPERATION-STD_VALUE_04        = LT_TAB1-VGW04. "低耗品 
WA_OPERATION-STD_UNIT_04       = LT_TAB1-VGE04. "单位 
WA_OPERATION-ACTTYPE_05          = 'A005'. 
WA_OPERATION-STD_VALUE_05        = LT_TAB1-VGW05. "其他制造费用 
WA_OPERATION-STD_UNIT_05        = LT_TAB1-VGE05. "单位 
WA_OPERATION-ACTTYPE_06          = 'A006'. 
WA_OPERATION-STD_VALUE_06        = LT_TAB1-VGW06. "自制动力 
WA_OPERATION-STD_UNIT_06        = LT_TAB1-VGE06. "单位 
WA_OPERATION-STANDARD_TEXT_KEY = LT_TAB1-KTSCH. "标准文本码 
WA_OPERATION-PLANT = LT_TAB1-WERKS_D."工厂 工序 
WA_OPERATION-DEL_IND = LT_TAB1-LOEKZ. "删除标记 
WA_OPERATION-STANDARD_QUEUE_TIME = LT_TAB1-ZWNOR. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT          = LT_TAB1-ZEIWN 
IMPORTING 
OUTPUT         = LT_TAB1-ZEIWN 
EXCEPTIONS 
UNIT_NOT_FOUND = 1 
OTHERS         = 2. 
WA_OPERATION-STANDARD_QUEUE_TIME_UNIT = LT_TAB1-ZEIWN. 
APPEND WA_OPERATION TO IT_OPERATION. 
CLEAR:WA_OPERATION,LT_TAB1. 
ENDLOOP. 
CALL FUNCTION 'BAPI_REFSETOFOPERATIONS_CREATE' 
EXPORTING 
PROFILE             = S_PRF 
IMPORTING 
GROUP               = WA_GROUP 
GROUPCOUNTER        = WA_GROUPCOUNTER 
TABLES 
TASK                = IT_TASK 
OPERATION           = IT_OPERATION 
COMPONENTALLOCATION = IT_COMPONENTALLOCATION 
RETURN              = IT_RETURN. 
CLEAR : WA_RETURN,GS_MSG1. 
READ TABLE  IT_RETURN INTO WA_RETURN WITH KEY ID = 'BAPI'  NUMBER = '000'. 
IF SY-SUBRC EQ  0 . 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. 
GS_MSG1-ICON = ICON_GREEN_LIGHT. 
GS_MSG1-PLNNR_ALT = IT_OLDNUM-OLDNUM. 
GS_MSG1-ZMSG = WA_GROUP. 
GS_MSG1-ZUSER = SY-UNAME. 
GS_MSG1-ZDATE = |{ SY-DATUM }{ '-' }{ SY-UZEIT }|. 
ELSE. 
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. 
GS_MSG1-ICON = ICON_RED_LIGHT. 
GS_MSG1-PLNNR_ALT = IT_OLDNUM-OLDNUM. 
GS_MSG1-ZMSG = WA_RETURN-MESSAGE. 
GS_MSG1-ZUSER = SY-UNAME. 
GS_MSG1-ZDATE = |{ SY-DATUM }{ '-' }{ SY-UZEIT }|. 
ENDIF. 
INSERT ZPPT0012 FROM GS_MSG1. 
CLEAR:IT_TASK[],WA_GROUP,WA_GROUPCOUNTER,IT_OPERATION[], 
IT_COMPONENTALLOCATION[],IT_RETURN[],GS_MSG1,GS_MSG1[]. 
ENDLOOP. 
ENDFORM.

文本元素

ABAP EXCEL批导+后台作业(JOB)---创建工艺路线+物料分配详解编程语言

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19565.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论