批导-bdc

*************************主程序**************************
REPORT  YTEST_IMPORTS.

INCLUDE YTEST_IMPORTS_TOP                       .    " global Data
INCLUDE YTEST_IMPORTS_F01                       .  " FORM-Routines

AT SELECTION-SCREEN OUTPUT.        "PBO
  BUT = '下载模板'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.   "字段级的PAI
  PERFORM F4_BUILD USING P_FILE.

AT SELECTION-SCREEN.   "屏幕级的PAI
  IF SSCRFIELDS-UCOMM = 'DOWNLOAD'.
    PERFORM SUB_TEMPLETE_DOWNLOAD.
  ENDIF.

START-OF-SELECTION.
  PERFORM GET_DATA USING P_FILE.


END-OF-SELECTION.
  PERFORM BUILD_ALV.
********************************************************

***********************头文件***************************
TYPE-POOLS: SLIS,ICON.

TABLES SSCRFIELDS.

*   EXCEL 转换成内表所需的数据声明
DATA: GIT_EXCEL TYPE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

*   ALV 数据声明
DATA: GIT_FIELD TYPE SLIS_T_FIELDCAT_ALV,
      GWA_FIELD TYPE SLIS_FIELDCAT_ALV,
      GWA_LAYOUT TYPE SLIS_LAYOUT_ALV.

DEFINE ADD_FIELD.
  CLEAR GWA_FIELD.
  GWA_FIELD-COL_POS = &1.
  GWA_FIELD-FIELDNAME = &2.
  GWA_FIELD-SELTEXT_M = &3.
  GWA_FIELD-EDIT = &4.
  GWA_FIELD-NO_ZERO = 'X'.
  APPEND GWA_FIELD TO GIT_FIELD.
  CLEAR GWA_FIELD.
END-OF-DEFINITION.

TYPES: BEGIN OF TYP_OUTPUT,
  VBELN_CK TYPE LV45C-VBELN,      "参考合同编号
  AUART TYPE VBAK-AUART,          "订单类型
  VKORG TYPE VBAK-VKORG,          "销售组织
  VTWEG TYPE VBAK-VTWEG,          "分销渠道
  SPART TYPE VBAK-SPART,          "产品组
  VKBUR TYPE VBAK-VKBUR,          "销售部门
  VKGRP TYPE VBAK-VKGRP,          "销售组
  VBELN TYPE LV45C-VBELN,         "合同编号
  KUANR TYPE KUAGV-KUNNR,         "售达方
  KUNNR TYPE KUWEV-KUNNR,         "送达方
  PRSDT TYPE VBKD-PRSDT,          "定价日期
  MATNR TYPE MSEG-MATNR,          "物料
  ZMENG TYPE VBAP-ZMENG,          "数量
  WERKS TYPE VBAP-WERKS,          "工厂
  VSART TYPE VBKD-VSART,          "装运类型
  SEL   TYPE C,
  LIGHT(4) TYPE C,                "状态灯
  LOG   TYPE STRING,              "日志
END OF TYP_OUTPUT.

DATA: GIT_OUTPUT TYPE TABLE OF TYP_OUTPUT,
      GWA_OUTPUT TYPE TYP_OUTPUT.

DATA: OK_CODE TYPE SY-UCOMM,
      SAVE_OK TYPE SY-UCOMM.

DATA: G_LOG TYPE STRING,
      G_VBELN TYPE VBAK-VBELN.

*----------BDC 定义
DATA: BDCDATA LIKE BDCDATA   OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.
  PARAMETERS: P_FILE TYPE RLGRAP-FILENAME.
  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN PUSHBUTTON /1(10) BUT USER-COMMAND DOWNLOAD VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK BK1.
********************************************************

************************函数文件************************
*&---------------------------------------------------------------------*
*&      Form  F4_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*----------------------------------------------------------------------*
FORM F4_BUILD  USING    P_P_FILE.
  CALL FUNCTION 'WS_FILENAME_GET'
*   EXPORTING
*     DEF_FILENAME           = ' '
*     DEF_PATH               = ' '
*     MASK                   = ' '
*     MODE                   = ' '
*     TITLE                  = ' '
   IMPORTING
     FILENAME               = P_P_FILE
*     RC                     =
   EXCEPTIONS
     INV_WINSYS             = 1
     NO_BATCH               = 2
     SELECTION_CANCEL       = 3
     SELECTION_ERROR        = 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.                    " F4_BUILD
*&---------------------------------------------------------------------*
*&      Form  SUB_TEMPLETE_DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_TEMPLETE_DOWNLOAD .
  DATA: OBJDATA LIKE WWWDATATAB.
  OBJDATA-RELID = 'MI'.             "DOWNLOAD_WEB_OBJECT需要声明这个字段
  OBJDATA-OBJID = 'YTEST_IMPORTS'.  "smw0创建excel模板

  DATA: L_TEMPFILE LIKE RLGRAP-FILENAME,
        L_TEMP_FILE(65),
        L_MSG(255) TYPE C,
        P_PATH LIKE RLGRAP-FILENAME.

  P_PATH = 'C:\'.

  CALL FUNCTION 'WS_FILENAME_GET'
   EXPORTING
     DEF_FILENAME           = '化工销售日计划批导入模板.xls'
     DEF_PATH               = P_PATH
     MASK                   = ',*.xls,*.xls,*.doc,*.doc.'
     MODE                   = 'S'
   IMPORTING
     FILENAME               = L_TEMPFILE   "默认下载路径为以上路径
   EXCEPTIONS
     INV_WINSYS             = 1
     NO_BATCH               = 2
     SELECTION_CANCEL       = 3
     SELECTION_ERROR        = 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.

  IF L_TEMPFILE IS NOT INITIAL.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
*       PERCENTAGE       = 0
       TEXT             = 'Downloading to Excel,Please waiting!'
              .

    CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
      EXPORTING
        KEY               = OBJDATA
        DESTINATION       = L_TEMPFILE
      CHANGING
        TEMP              = L_TEMP_FILE
              .

    IF SY-SUBRC EQ 0.
      CONCATENATE '导入模板:' L_TEMP_FILE '已下载!' INTO L_MSG.
      MESSAGE L_MSG TYPE 'S'.
    ENDIF.

  ENDIF.

ENDFORM.                    " SUB_TEMPLETE_DOWNLOAD
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*----------------------------------------------------------------------*
FORM GET_DATA  USING    P_P_FILE.
*这个函数模块可以把用户本地 EXCEL 文件中的一个矩形块中的内容上传到一个内表中
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME                      = P_P_FILE      "最长 128 个字符的路径名称
      I_BEGIN_COL                   = 1             "导入单元格的开始列
      I_BEGIN_ROW                   = 1             "导入单元格的开始行
      I_END_COL                     = 100           "导入单元格的结束列
      I_END_ROW                     = 1000          "导入单元格的结束行
    TABLES
      INTERN                        = GIT_EXCEL     "INTERN:内表,存储单元格的内容。结构如下:
*-ROW:数据所在行 -COL:数据所在列 -VALUE:数据,最长 50 个字符,如果超过,则相同 ROW COL 的记录出现多行
   EXCEPTIONS
     INCONSISTENT_PARAMETERS       = 1
     UPLOAD_OLE                    = 2
     OTHERS                        = 3
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT GIT_EXCEL WHERE ROW > 1.
    AT NEW ROW.
      CLEAR GWA_OUTPUT.
    ENDAT.

    CASE GIT_EXCEL-COL.
      WHEN 1.
        GWA_OUTPUT-VBELN_CK = GIT_EXCEL-VALUE.
      WHEN 2.
        GWA_OUTPUT-AUART = GIT_EXCEL-VALUE.
      WHEN 4.
        GWA_OUTPUT-VKORG = GIT_EXCEL-VALUE.
      WHEN 6.
        GWA_OUTPUT-VTWEG = GIT_EXCEL-VALUE.
      WHEN 8.
        GWA_OUTPUT-SPART = GIT_EXCEL-VALUE.
      WHEN 10.
        GWA_OUTPUT-VKBUR = GIT_EXCEL-VALUE.
      WHEN 12.
        GWA_OUTPUT-VKGRP = GIT_EXCEL-VALUE.
      WHEN 14.
        GWA_OUTPUT-KUANR = GIT_EXCEL-VALUE.
      WHEN 16.
        GWA_OUTPUT-KUNNR = GIT_EXCEL-VALUE.
      WHEN 18.
        GWA_OUTPUT-MATNR = GIT_EXCEL-VALUE.
      WHEN 20.
        GWA_OUTPUT-ZMENG = GIT_EXCEL-VALUE.
      WHEN 22.
        GWA_OUTPUT-VSART = GIT_EXCEL-VALUE.
    ENDCASE.

    AT END OF ROW.
      APPEND GWA_OUTPUT TO GIT_OUTPUT.
    ENDAT.
  ENDLOOP.
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  BUILD_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_ALV .
  GWA_LAYOUT-ZEBRA = 'A'.
  GWA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  GWA_LAYOUT-BOX_FIELDNAME = 'SEL'.

  ADD_FIELD '1'  'LIGHT' '状态灯' ''.
  ADD_FIELD '2'  'VBELN_CK' '参照创建合同编号' ''.
  ADD_FIELD '3'  'AUART' '订单类型' ''.
  ADD_FIELD '4'  'VKORG' '销售组织' ''.
  ADD_FIELD '5'  'VTWEG' '分销渠道' ''.
  ADD_FIELD '6'  'SPART' '产品组' ''.
  ADD_FIELD '7'  'VKBUR' '销售部门' ''.
  ADD_FIELD '8'  'VKGRP' '销售组' ''.
  ADD_FIELD '9'  'KUANR' '售达方' ''.
  ADD_FIELD '10' 'KUNNR' '送达方' ''.
  ADD_FIELD '11' 'PRSDT' '定价日期' ''.
  ADD_FIELD '12' 'MATNR' '物料' ''.
*  ADD_FIELD '13' 'ZMENG' '数量' 'X'.
   CLEAR GWA_FIELD.
  GWA_FIELD-COL_POS = '13'.
  GWA_FIELD-FIELDNAME = 'ZMENG'.
  GWA_FIELD-SELTEXT_M = '数量'.
  GWA_FIELD-EDIT = 'X'.
  GWA_FIELD-DATATYPE = 'MENG13'.           "以防alv界面修改数据后,更新到内表发生变化
  APPEND GWA_FIELD TO GIT_FIELD.
  CLEAR GWA_FIELD.

  ADD_FIELD '14' 'WERKS' '工厂' ''.
  ADD_FIELD '15' 'VSART' '装运类型' ''.
  ADD_FIELD '16' 'LOG'   '日志' ''.

  LOOP AT GIT_OUTPUT INTO GWA_OUTPUT.
    GWA_OUTPUT-LIGHT = '@08@'.
    IF GWA_OUTPUT-AUART IS INITIAL OR GWA_OUTPUT-VKORG IS INITIAL OR GWA_OUTPUT-VTWEG IS INITIAL OR
       GWA_OUTPUT-SPART IS INITIAL OR GWA_OUTPUT-VKBUR IS INITIAL OR GWA_OUTPUT-VKGRP IS INITIAL OR
       GWA_OUTPUT-KUANR IS INITIAL OR GWA_OUTPUT-MATNR IS INITIAL OR GWA_OUTPUT-ZMENG IS INITIAL OR
       GWA_OUTPUT-VSART IS INITIAL.
      GWA_OUTPUT-LIGHT = '@0A@'.
      CONCATENATE '请输入必输字段!' GWA_OUTPUT-LOG INTO GWA_OUTPUT-LOG SEPARATED BY SPACE.
    ENDIF.

    MODIFY GIT_OUTPUT FROM GWA_OUTPUT.
  ENDLOOP.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     I_INTERFACE_CHECK                 = SY-REPID
     I_CALLBACK_PROGRAM                = SY-REPID
     I_CALLBACK_PF_STATUS_SET          = 'SET_STATUS'
     I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
     IS_LAYOUT                         = GWA_LAYOUT
     IT_FIELDCAT                       = GIT_FIELD
     I_SAVE                            = 'A'
    TABLES
      T_OUTTAB                          = GIT_OUTPUT
   EXCEPTIONS
     PROGRAM_ERROR                     = 1
     OTHERS                            = 2
            .
  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.                    " BUILD_ALV

*&---------------------------------------------------------------------*
*&      Form  SET_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->EX_TAB     text
*----------------------------------------------------------------------*
FORM SET_STATUS USING EX_TAB TYPE  SLIS_T_EXTAB.
  SET PF-STATUS 'ALV_STATUS' EXCLUDING EX_TAB.
  SET TITLEBAR 'ALV_TITLE'.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->OK_CODE    text
*      -->SEL_FIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING OK_CODE TYPE SY-UCOMM
                        SEL_FIELD TYPE SLIS_SELFIELD.
  DATA L_ANSWER TYPE C.
  SEL_FIELD-REFRESH = 'X'.              "内表修改更新到alv
  OK_CODE = SY-UCOMM.

  DATA: ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = ALV_GRID.
  CALL METHOD ALV_GRID->CHECK_CHANGED_DATA.            "alv修改更新到内表

  CASE OK_CODE.
    WHEN 'CREAT'.
*      READ TABLE GIT_OUTPUT INTO GWA_OUTPUT WITH KEY SEL = 'X'.
*      IF SY-SUBRC EQ 0.
*        GWA_OUTPUT-ZMENG = 100.
*        MODIFY TABLE GIT_OUTPUT FROM GWA_OUTPUT.
*      ENDIF.
      READ TABLE GIT_OUTPUT INTO GWA_OUTPUT WITH KEY SEL = 'X'.
      IF SY-SUBRC NE 0.
        MESSAGE '请至少选择一行!' TYPE 'E'.
      ENDIF.
      LOOP AT GIT_OUTPUT INTO GWA_OUTPUT WHERE SEL = 'X'.
        IF GWA_OUTPUT-LIGHT EQ '@0A@'.
          MESSAGE '请选择状态灯是绿色的数据!' TYPE 'E'.
        ENDIF.
      ENDLOOP.

      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
*         TITLEBAR                    = ' '
*         DIAGNOSE_OBJECT             = ' '
          TEXT_QUESTION               = TEXT-002
          TEXT_BUTTON_1               = '是'
          TEXT_BUTTON_2               = '否'
        IMPORTING
          ANSWER                      = L_ANSWER.
*       TABLES
*         PARAMETER                   =
*       EXCEPTIONS
*         TEXT_NOT_FOUND              = 1
*         OTHERS                      = 2
                .

      IF L_ANSWER EQ '1'.
        PERFORM SUB_BDC_CREATE.
      ELSE.
        EXIT.
      ENDIF.
  ENDCASE.
ENDFORM.                    "USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  SUB_BDC_CREATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUB_BDC_CREATE .
  REFRESH: BDCDATA, MESSTAB.
  DATA: L_OPTION TYPE CTU_PARAMS.
  DATA: SW_MESSTAB LIKE LINE OF MESSTAB,
        LIT_RETURN TYPE TABLE OF BAPIRET2,
        LWA_RETURN LIKE LINE OF LIT_RETURN.

  DATA: L_ZMENG TYPE C LENGTH 17.

  L_OPTION-RACOMMIT = 'X'.
  L_OPTION-UPDMODE  = 'N'.
  L_OPTION-DEFSIZE  = 'X'.
  L_OPTION-NOBINPT  = 'X'.
  L_OPTION-DISMODE  = 'N'.
  LOOP AT GIT_OUTPUT INTO GWA_OUTPUT WHERE SEL = 'X'.
    REFRESH: BDCDATA, MESSTAB.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        INPUT  = GWA_OUTPUT-KUANR
      IMPORTING
        OUTPUT = GWA_OUTPUT-KUANR.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        INPUT  = GWA_OUTPUT-KUNNR
      IMPORTING
        OUTPUT = GWA_OUTPUT-KUNNR.

    WRITE GWA_OUTPUT-ZMENG TO L_ZMENG.
    CONDENSE L_ZMENG NO-GAPS.

    IF GWA_OUTPUT-VBELN_CK EQ SPACE.
      PERFORM BDC_DYNPRO      USING 'SAPMV45A' '0101'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR' 'VBAK-AUART'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE' '/00'.
      PERFORM BDC_FIELD       USING 'VBAK-AUART' GWA_OUTPUT-AUART.
      PERFORM BDC_FIELD       USING 'VBAK-VKORG' GWA_OUTPUT-VKORG.
      PERFORM BDC_FIELD       USING 'VBAK-VTWEG' GWA_OUTPUT-VTWEG.
      PERFORM BDC_FIELD       USING 'VBAK-SPART' GWA_OUTPUT-SPART.
      PERFORM BDC_FIELD       USING 'VBAK-VKBUR' GWA_OUTPUT-VKBUR.
      PERFORM BDC_FIELD       USING 'VBAK-VKGRP' GWA_OUTPUT-VKGRP.

      PERFORM BDC_DYNPRO      USING 'SAPMV45A' '4001'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE' 'SICH'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4021SUBSCREEN_HEADER'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4701PART-SUB'.
      PERFORM BDC_FIELD       USING 'KUAGV-KUNNR' GWA_OUTPUT-KUANR.
      PERFORM BDC_FIELD       USING 'KUWEV-KUNNR' GWA_OUTPUT-KUNNR.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4406SUBSCREEN_BODY'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4440HEADER_FRAME'.
      PERFORM BDC_FIELD       USING 'VBAK-GUEBG' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBAK-GUEEN' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBKD-PRSDT' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBKD-OIC_TIME' SY-UZEIT.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                8310HEAD_USER'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPLV45W                                0400SUBSCREEN_VERTRAG'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4906SUBSCREEN_TC'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR' 'VBAP-ZMENG(01)'.
      PERFORM BDC_FIELD       USING 'RV45A-MABNR(01)' GWA_OUTPUT-MATNR.
      PERFORM BDC_FIELD       USING 'VBAP-ZMENG(01)' L_ZMENG.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4052SUBSCREEN_BUTTONS'.
      PERFORM BDC_FIELD       USING 'VBAP-WERKS(01)' 'C0B4'.

      PERFORM BDC_DYNPRO      USING 'SAPMSSY0' '0120'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR' '07/23'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE' '=FEBE'.

      PERFORM BDC_DYNPRO      USING 'SAPMV45A' '4003'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE' '=FEBA'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4013SUBSCREEN_HEADER'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4452SUBSCREEN_BODY'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR' 'VBKD-VSART'.
      PERFORM BDC_FIELD       USING 'VBAP-WERKS' 'C0B4'.
      PERFORM BDC_FIELD       USING 'VBAP-ANTLF' '9'.
      PERFORM BDC_FIELD       USING 'VBKD-KZAZU' 'X'.
      PERFORM BDC_FIELD       USING 'VBKD-VSART' GWA_OUTPUT-VSART.
      PERFORM BDC_FIELD       USING 'VBKD-PODKZ' 'X'.
      PERFORM BDC_FIELD       USING 'VBAP-GEWEI' 'kg'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPLOIIO                                0100OIISOC'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPLOIKS                                0200OIKSTATI'.

      PERFORM BDC_DYNPRO      USING 'SAPMV45A' '4001'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE' '=SICH'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4021SUBSCREEN_HEADER'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4701PART-SUB'.
      PERFORM BDC_FIELD       USING 'KUAGV-KUNNR' GWA_OUTPUT-KUANR.
      PERFORM BDC_FIELD       USING 'KUWEV-KUNNR' GWA_OUTPUT-KUNNR.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4406SUBSCREEN_BODY'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4440HEADER_FRAME'.
      PERFORM BDC_FIELD       USING 'VBAK-GUEBG' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBAK-GUEEN' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBKD-PRSDT' SY-DATUM.
      PERFORM BDC_FIELD       USING 'VBKD-OIC_TIME' SY-UZEIT.
      PERFORM BDC_FIELD       USING 'VBAK-VSBED' '01'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                8310HEAD_USER'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPLV45W                                0400SUBSCREEN_VERTRAG'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4906SUBSCREEN_TC'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR' 'RV45A-MABNR(02)'.
      PERFORM BDC_FIELD       USING 'BDC_SUBSCR' 'SAPMV45A                                4052SUBSCREEN_BUTTONS'.
    ENDIF.

    CALL TRANSACTION 'VA41' USING BDCDATA
                            OPTIONS FROM L_OPTION
                            MESSAGES INTO MESSTAB.

    PERFORM SUB_MESS_INFORMATION.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT         = GWA_OUTPUT-KUANR
      IMPORTING
        OUTPUT        = GWA_OUTPUT-KUANR.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT         = GWA_OUTPUT-KUNNR
      IMPORTING
        OUTPUT        = GWA_OUTPUT-KUNNR.

    GWA_OUTPUT-LOG = G_LOG.
    GWA_OUTPUT-VBELN = G_VBELN.

    MODIFY GIT_OUTPUT FROM GWA_OUTPUT.
  ENDLOOP.
ENDFORM.                    " SUB_BDC_CREATE
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PROGRAM   text
*      -->DYNPRO   text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO  USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.
ENDFORM.                    " BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FNAM   text
*      -->FVAL   text
*----------------------------------------------------------------------*
FORM BDC_FIELD  USING FNAM FVAL.
  CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.
ENDFORM.                    " BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  SUB_MESS_INFORMATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM  SUB_MESS_INFORMATION .
DATA: X_MSGIN LIKE MSG_LOG,
       X_MSGOUT LIKE MSG_TEXT.

DATA: BEGIN OF LT_LOGINFO OCCURS 0,
        LOGTX(72) TYPE C,
       END OF LT_LOGINFO.
CLEAR G_LOG.
CLEAR G_VBELN.

LOOP AT MESSTAB WHERE MSGTYP EQ 'A' OR MSGTYP EQ 'E'.
   CLEAR: X_MSGIN, X_MSGOUT.
   X_MSGIN-MSGID = MESSTAB-MSGID.
   X_MSGIN-MSGNO = MESSTAB-MSGNR.
   X_MSGIN-MSGTY = MESSTAB-MSGTYP.
   X_MSGIN-MSGV1 = MESSTAB-MSGV1.
   X_MSGIN-MSGV2 = MESSTAB-MSGV2.
   X_MSGIN-MSGV3 = MESSTAB-MSGV3.
   X_MSGIN-MSGV4 = MESSTAB-MSGV4.

   CALL FUNCTION 'MESSAGE_TEXTS_READ'
    EXPORTING
      MSG_LOG_IMP    = X_MSGIN
    IMPORTING
      MSG_TEXT_EXP   = X_MSGOUT.

   LT_LOGINFO-LOGTX = X_MSGOUT-MSGTX.
   APPEND LT_LOGINFO.
   CLEAR LT_LOGINFO-LOGTX.
ENDLOOP.

IF SY-SUBRC = 0.
   LOOP AT LT_LOGINFO.
     CONCATENATE G_LOG LT_LOGINFO-LOGTX INTO G_LOG SEPARATED BY ';'.
   ENDLOOP.

   GWA_OUTPUT-LIGHT = '@0A@'.
ELSE.
   LOOP AT MESSTAB WHERE MSGTYP = 'S' AND MSGID = 'V1' AND MSGNR = '311'.
     G_VBELN = MESSTAB-MSGV2.
   ENDLOOP.
   G_LOG = '化工销售日计划已创建成功'.
   REFRESH LT_LOGINFO.
ENDIF.
ENDFORM.                    " SUB_MESS_INFORMATION
**********************************************************


注释:录屏shdb,创建记录,填写要录屏的事物码。

你可能感兴趣的:(c)