码迷,mamicode.com
首页 > 其他好文 > 详细

经典EXCEL导入程序

时间:2018-12-05 12:22:31      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:ica   ===   跳过   import   The   structure   wait   key   订单   

*&*********************************************************************
*&程序名称  ZSDG088
*&程序说明  *&所属模块  SD
**********************************************************************
*&修改日志
*&序   修改时间      修改人      请求号        修改说明
*001   **********************************************************************
REPORT ZSDG088.

TYPE-POOLS: SLIS. "ALV
TABLES:SSCRFIELDS..

*---------------------------------------------------------------------*
*& Data Type Declear
*---------------------------------------------------------------------*
TYPES:
  BEGIN OF TY_UPLOAD_DATA,
    MATNR TYPE MATNR,      "物料号
    ID(16),                "序列号或装箱号
    LFIMG TYPE LFIMG,      "交货数量
    VBELN TYPE VBELN_VL,   "交货单
  END OF TY_UPLOAD_DATA,

  BEGIN OF TY_VBELN,
    VBELN TYPE VBELN_VL,
  END OF TY_VBELN,

  BEGIN OF TY_LIPS,
    VBELN TYPE VBELN_VL,
    POSNR TYPE POSNR_VL,
    MATNR TYPE MATNR,
    LFIMG TYPE LFIMG,
    LGORT TYPE LGORT_D,
    VGBEL TYPE VBELN_VA,
    VGPOS TYPE POSNR_VA,
  END OF TY_LIPS,

  BEGIN OF TY_LFIMG,
    VBELN TYPE VBELN_VL,
    MATNR TYPE MATNR,
    LFIMG TYPE LFIMG,
  END OF TY_LFIMG,

  BEGIN OF TY_OUT,
    STATUS_LED TYPE CHAR4,
    VBELN LIKE LIPS-VBELN, "交货单
    POSNR LIKE LIPS-POSNR, "交货单行项目
    MATNR LIKE LIPS-MATNR, "物料代码
    MAKTX LIKE MAKT-MAKTX, "物料描述
    ID(16),                "序列号或装箱号
    LFIMG LIKE LIPS-LFIMG, "交货数量
    MSG   TYPE BAPIBAPI_MSG,
  END OF TY_OUT.

*---------------------------------------------------------------------*
*&Global Data Declear
*---------------------------------------------------------------------*
DATA:GT_UPLOAD_DATA TYPE TABLE OF TY_UPLOAD_DATA,
     GS_UPLOAD_DATA TYPE TY_UPLOAD_DATA.
DATA:GT_VBELN TYPE TABLE OF TY_VBELN,
     GS_VBELN TYPE TY_VBELN.
DATA:GT_LIPS  TYPE TABLE OF TY_LIPS,
     GS_LIPS  TYPE TY_LIPS.
DATA:GT_OUT   TYPE TABLE OF TY_OUT,
     GS_OUT   TYPE TY_OUT.


*---------------------------------------------------------------------*
*& Selection Screen Declear
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_PATH TYPE RLGRAP-FILENAME.

SELECTION-SCREEN: FUNCTION KEY 1.
SELECTION-SCREEN END OF BLOCK BLK1.

*======================================================================*
*  Selection Screen Events
*======================================================================*
*** Maintain Selection Screen Output


AT SELECTION-SCREEN OUTPUT.




*** F4 Value Help

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PATH.
  PERFORM FRM_GET_FILE.

*** Check Input Data


AT SELECTION-SCREEN.
  CASE SY-UCOMM.
    WHEN FC01.
      PERFORM FRM_DOWNLOAD_TEMPLATE.
    WHEN OTHERS.
  ENDCASE.


*AT SELECTION-SCREEN ON <f>.
*AT SELECTION-SCREEN ON BLOCK <>.
****CHECK ON SELECT SCREEN INPUT


*======================================================================*
*  report events
*======================================================================*
*** initial data


INITIALIZATION.
  PERFORM FRM_INIT_FCODE.  "定义按钮文本


*** Prepare Report Data
START-OF-SELECTION.
  PERFORM FRM_UPLOAD_FILE.
  PERFORM FRM_CHECK_DATA.
  PERFORM FRM_POST_GOODS_ISSUE.
*** Output Report
END-OF-SELECTION.

  PERFORM FRM_ALV_DISPLAY.



*======================================================================*
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_FILE .
  CALL FUNCTION WS_FILENAME_GET
    EXPORTING
      MASK             = *.xls.
      TITLE            = 选择文件(100)
    IMPORTING
      FILENAME         = P_PATH
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
  IF SY-SUBRC <> 0 AND SY-SUBRC <> 3.
    MESSAGE TEXT-101 TYPE E.
  ENDIF.
ENDFORM.                    " FRM_GET_FILE
*&---------------------------------------------------------------------*
*&      Form  FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DOWNLOAD_TEMPLATE .
  DATA:LV_MESSAGE TYPE STRING,
       LV_DIR     TYPE STRING,
       LV_FILE    TYPE RLGRAP-FILENAME,
       LV_TRC     LIKE SY-SUBRC,
       LS_OBJDATA LIKE WWWDATATAB.
  CONSTANTS:LC_FILENAME TYPE STRING VALUE  SA Outbound Serial No. Template,
            LC_OBJID    TYPE WWWDATA-OBJID VALUE ZSDG088.

* 保存路径取得
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY
    CHANGING
      DESKTOP_DIRECTORY    = LV_DIR
    EXCEPTIONS
      CNTL_ERROR           = 1
      ERROR_NO_GUI         = 2
      NOT_SUPPORTED_BY_GUI = 3
      OTHERS               = 4.
  IF SY-SUBRC <> 0.
*   下载模板失败
    MESSAGE TEXT-102 TYPE E.
  ENDIF.
  CALL METHOD CL_GUI_CFW=>FLUSH
    EXCEPTIONS
      CNTL_SYSTEM_ERROR = 1
      CNTL_ERROR        = 2
      OTHERS            = 3.
  IF SY-SUBRC <> 0.
*   下载模板失败
    MESSAGE TEXT-102 TYPE E.
  ENDIF.

  CONCATENATE LV_DIR \‘ LC_FILENAME  .xls INTO LV_FILE.

* 模板信息取得
  SELECT SINGLE
         RELID
         OBJID
    FROM WWWDATA
    INTO CORRESPONDING FIELDS OF LS_OBJDATA
   WHERE SRTF2 EQ 0
     AND RELID EQ MI
     AND OBJID EQ LC_OBJID.
  IF SY-SUBRC <> 0 OR LS_OBJDATA-OBJID EQ SPACE.
*   下载模板失败
    MESSAGE TEXT-102 TYPE E.
  ENDIF.

*下载模板
  CALL FUNCTION DOWNLOAD_WEB_OBJECT
    EXPORTING
      KEY         = LS_OBJDATA
      DESTINATION = LV_FILE
    IMPORTING
      RC          = LV_TRC.
  IF LV_TRC <> 0.
*   下载模板失败
    MESSAGE TEXT-102 TYPE E.
  ELSE.
*   下载模板成功
    CONCATENATE TEXT-103 LV_FILE INTO LV_MESSAGE.
    MESSAGE LV_MESSAGE TYPE S.
  ENDIF.

ENDFORM.                    " FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*&      Form  FRM_INIT_FCODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_INIT_FCODE .

  DATA: LS_FUNCTXT TYPE SMP_DYNTXT.

  LS_FUNCTXT-ICON_ID    = ICON_EXPORT.
  LS_FUNCTXT-QUICKINFO  = ‘‘.
  LS_FUNCTXT-ICON_TEXT  = TEXT-001.
  SSCRFIELDS-FUNCTXT_01 = LS_FUNCTXT.

ENDFORM.                    " FRM_INIT_FCODE
*&---------------------------------------------------------------------*
*&      Form  FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_UPLOAD_FILE .

  DATA:LT_EXCEL LIKE TABLE OF ALSMEX_TABLINE,
       LS_EXCEL TYPE ALSMEX_TABLINE.
  DATA:LV_INDEX TYPE I VALUE 1,
       LV_LFIMG TYPE STRING,
       LV_CHECK TYPE STRING VALUE 1234567890..
  FIELD-SYMBOLS:<FS> TYPE ANY.

  REFRESH:LT_EXCEL,GT_UPLOAD_DATA.
  CLEAR:GS_UPLOAD_DATA,LS_EXCEL.

  IF  P_PATH IS NOT INITIAL.
    CALL FUNCTION ALSM_EXCEL_TO_INTERNAL_TABLE
      EXPORTING
        FILENAME                = P_PATH
        I_BEGIN_COL             = 1
        I_BEGIN_ROW             = 2
        I_END_COL               = 4
        I_END_ROW               = 10000
      TABLES
        INTERN                  = LT_EXCEL
      EXCEPTIONS
        INCONSISTENT_PARAMETERS = 1
        UPLOAD_OLE              = 2
        OTHERS                  = 3.

    IF SY-SUBRC = 0.
      LOOP AT LT_EXCEL INTO LS_EXCEL.
*        ASSIGN COMPONENT lv_index OF
*           STRUCTURE gs_upload_data TO <fs>.
*        CONDENSE ls_excel-value NO-GAPS.
*        SEARCH ls_excel-value FOR @.
*        IF sy-subrc EQ 0.
*          <fs> = ls_excel-value(10).
*        ELSE.
*          <fs> = ls_excel-value.
*        ENDIF.
*        lv_index = lv_index + 1.
        CASE LS_EXCEL-COL.
          WHEN 0001.
            GS_UPLOAD_DATA-MATNR = LS_EXCEL-VALUE.
          WHEN 0002.
            SEARCH LS_EXCEL-VALUE FOR @.
            IF SY-SUBRC EQ 0.
              GS_UPLOAD_DATA-ID = LS_EXCEL-VALUE(10).
            ELSE.
              GS_UPLOAD_DATA-ID = LS_EXCEL-VALUE.
            ENDIF.
          WHEN 0003.
            CLEAR:LV_LFIMG.
            LV_LFIMG             = LS_EXCEL-VALUE.
            IF LV_LFIMG CO LV_CHECK.
              GS_UPLOAD_DATA-LFIMG = LV_LFIMG.
            ENDIF.
          WHEN 0004.
            GS_UPLOAD_DATA-VBELN = LS_EXCEL-VALUE.
          WHEN OTHERS.
        ENDCASE.
        AT END OF ROW.
          APPEND GS_UPLOAD_DATA TO GT_UPLOAD_DATA.
          CLEAR GS_UPLOAD_DATA.
*          lv_index = 1.
        ENDAT.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.                    " FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_DATA .

  FIELD-SYMBOLS:<FS_UPLOAD> TYPE TY_UPLOAD_DATA,
                <FS_VBELN>  TYPE TY_VBELN,
                <FS_OUT>    TYPE TY_OUT,
                <FS_LFIMG>  TYPE TY_LFIMG.
  DATA:LV_CHECK TYPE STRING VALUE 1234567890@.
  DATA:LT_LFIMG TYPE TABLE OF TY_LFIMG,
       LS_LFIMG TYPE TY_LFIMG.

  CLEAR:GS_VBELN,GS_UPLOAD_DATA.
  REFRESH:GT_VBELN,GT_LIPS.

  LOOP AT GT_UPLOAD_DATA ASSIGNING <FS_UPLOAD>.
    CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT
      EXPORTING
        INPUT  = <FS_UPLOAD>-VBELN
      IMPORTING
        OUTPUT = <FS_UPLOAD>-VBELN.
    CALL FUNCTION CONVERSION_EXIT_MATN1_INPUT
      EXPORTING
        INPUT        = <FS_UPLOAD>-MATNR
      IMPORTING
        OUTPUT       = <FS_UPLOAD>-MATNR
      EXCEPTIONS
        LENGTH_ERROR = 1
        OTHERS       = 2.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.
    GS_VBELN-VBELN = <FS_UPLOAD>-VBELN.
    LS_LFIMG-VBELN = <FS_UPLOAD>-VBELN.
    LS_LFIMG-MATNR = <FS_UPLOAD>-MATNR.
    LS_LFIMG-LFIMG = <FS_UPLOAD>-LFIMG.
    COLLECT LS_LFIMG INTO LT_LFIMG.
    GS_OUT-VBELN = <FS_UPLOAD>-VBELN.
    GS_OUT-MATNR = <FS_UPLOAD>-MATNR.
    GS_OUT-LFIMG = <FS_UPLOAD>-LFIMG.
    GS_OUT-ID    = <FS_UPLOAD>-ID.
    IF GS_OUT-ID CO LV_CHECK.
      IF GS_OUT-LFIMG < 1.
        GS_OUT-STATUS_LED = @0A@.
        GS_OUT-MSG        = No valid quantity data !.
      ENDIF.
    ELSE.
*      gs_out-status_led = @09@.
    ENDIF.
    APPEND GS_OUT TO GT_OUT.
    COLLECT GS_VBELN INTO GT_VBELN.
  ENDLOOP.

  SORT LT_LFIMG BY VBELN MATNR.

  LOOP AT GT_OUT ASSIGNING <FS_OUT> WHERE STATUS_LED <> @09@.
*检查交货单是否存在
    SELECT VBELN
           POSNR
           MATNR
           LFIMG
           LGORT
           VGBEL
           VGPOS
      APPENDING TABLE GT_LIPS
      FROM LIPS
      WHERE VBELN EQ <FS_OUT>-VBELN.
    IF SY-SUBRC NE 0.
      <FS_OUT>-STATUS_LED =@0A@.
      <FS_OUT>-MSG   = Delivery don’t exist.
      CONTINUE.
    ENDIF.
* 检查交货单是否已经过账
    SELECT COUNT(*) FROM VBFA
      WHERE VBELV EQ <FS_OUT>-VBELN
        AND POSNV EQ 10
        AND VBTYP_N EQ R.
    IF SY-SUBRC EQ 0.
      <FS_OUT>-STATUS_LED =@0A@.
      <FS_OUT>-MSG   = This delivery has already posted.
      CONTINUE.
    ENDIF.
*检查交货单下物料数量是否一致

    SEARCH <FS_OUT>-ID FOR @.
    IF SY-SUBRC EQ 0.
      LOOP AT LT_LFIMG  ASSIGNING <FS_LFIMG> WHERE VBELN = <FS_OUT>-VBELN.
        LOOP AT GT_LIPS INTO GS_LIPS WHERE VBELN = <FS_LFIMG>-VBELN
                                       AND MATNR = <FS_LFIMG>-MATNR.
          <FS_LFIMG>-LFIMG = <FS_LFIMG>-LFIMG - GS_LIPS-LFIMG.
        ENDLOOP.
        IF <FS_LFIMG>-LFIMG <> 0.
          GS_OUT-STATUS_LED =@0A@.
          GS_OUT-MSG   = The quantity of this material is different with delivery and excel !.
        ENDIF.
      ENDLOOP.
    ELSE.
      SEARCH <FS_OUT>-ID FOR N.
      IF SY-SUBRC NE 0.
        IF <FS_OUT>-LFIMG > 1.
          <FS_OUT>-STATUS_LED =@0A@.
          CONCATENATE <FS_OUT>-MSG  The quantity greater than 1. INTO <FS_OUT>-MSG.
          CONTINUE.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_POST_GOODS_ISSUE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_POST_GOODS_ISSUE .
  DATA:LV_SQNO   TYPE INT4,
       LV_LINE   TYPE I,
       LV_TIMES  TYPE I,
       LV_MSG    TYPE STRING,
       LV_PKCDE  TYPE ZZBCS_PKCDE,
       LV_AUFNR     TYPE AUFNR,
       LV_PKCUT     TYPE ZBCSE_PKSNR.
  DATA:LS_RETURN TYPE BAPIRET2.
  DATA:LT_BARCD  TYPE TABLE OF ZSSD_BARCD_MATNR,
       LS_BARCD  TYPE ZSSD_BARCD_MATNR,
       LT_PKTSK  TYPE TABLE OF ZBCS_PKTSK,
       LS_PKTSK  TYPE ZBCS_PKTSK,
       LS_EXCEP  TYPE ZBCS_EXCEP.

  DATA:BEGIN OF LS_BARCDM,
         BARCD TYPE ZBCSE_BARCD,
         MATNR TYPE MATNR,
       END OF LS_BARCDM,
       LT_BARCDM LIKE TABLE OF LS_BARCDM.
  DATA:LR_AUFNR LIKE RANGE OF ZBCS_COD02-AUFNR,
       LS_AUFNR LIKE LINE OF LR_AUFNR.

  DATA:LV_VBELN    LIKE LIKP-VBELN,
       LS_VBKOK    LIKE VBKOK,
       LT_PROTT    LIKE TABLE OF PROTT,  "Return Message
       LS_PROTT    LIKE PROTT,
       LT_VBPOK    LIKE TABLE OF VBPOK,
       LS_VBPOK    LIKE VBPOK.           "Delivery items

  FIELD-SYMBOLS:<FS_OUT> TYPE TY_OUT.

**先绑定序列号
*排除黄灯的,No Serial 的不要绑定序列号
  LOOP AT GT_OUT ASSIGNING <FS_OUT> .
    CLEAR:LV_PKCDE,LS_AUFNR,LR_AUFNR[],LV_LINE,LV_TIMES,
          LS_BARCD,LT_BARCD[].
    CASE  <FS_OUT>-ID(1).
* No Serial的不需要绑定序列号 写入自检表后 直接跳过
      WHEN N.
        READ TABLE GT_LIPS INTO GS_LIPS WITH KEY VBELN = <FS_OUT>-VBELN MATNR = <FS_OUT>-MATNR.
        IF SY-SUBRC EQ 0.
          CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT
            EXPORTING
              INPUT  = GS_LIPS-VBELN
            IMPORTING
              OUTPUT = GS_LIPS-VBELN.
          CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT
            EXPORTING
              INPUT  = GS_LIPS-POSNR
            IMPORTING
              OUTPUT = GS_LIPS-POSNR.
          CONCATENATE XA02 GS_LIPS-VBELN GS_LIPS-POSNR INTO LS_EXCEP-EXCLD.
          LS_EXCEP-CRNAME = SY-UNAME.
          LS_EXCEP-CRDATE = SY-DATUM.
          LS_EXCEP-CRTIME = SY-UZEIT.
          MODIFY ZBCS_EXCEP FROM LS_EXCEP.
          <FS_OUT>-STATUS_LED =@08@.
        ENDIF.
        CONTINUE.
*装箱号的,通过装箱号获取序列号
      WHEN @.
        LV_PKCDE = <FS_OUT>-ID.
        SELECT AUFNR
               PKCUT
               PKCDE
               MATNR
          INTO CORRESPONDING FIELDS OF TABLE LT_PKTSK
          FROM ZBCS_PKTSK
          WHERE PKCDE EQ LV_PKCDE.
        SORT LT_PKTSK BY AUFNR.
        DELETE ADJACENT DUPLICATES FROM LT_PKTSK COMPARING ALL FIELDS.
        LOOP AT LT_PKTSK INTO LS_PKTSK.
          CLEAR:LV_AUFNR,LV_PKCUT,LS_AUFNR.
          CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT
            EXPORTING
              INPUT  = LS_PKTSK-AUFNR
            IMPORTING
              OUTPUT = LV_AUFNR.
          CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT
            EXPORTING
              INPUT  = LS_PKTSK-PKCUT
            IMPORTING
              OUTPUT = LV_PKCUT.
          MOVE IEQ TO LS_AUFNR.
          CONCATENATE LV_AUFNR LV_PKCUT INTO LS_AUFNR-LOW.
          APPEND LS_AUFNR TO LR_AUFNR.
        ENDLOOP.
        IF LR_AUFNR[] IS INITIAL.
          <FS_OUT>-STATUS_LED =@0A@.
          CONCATENATE Carton ID is not exist,  <FS_OUT>-ID INTO <FS_OUT>-MSG.
          CONTINUE.
        ELSE.
          SELECT BARCD
            INTO TABLE LT_BARCDM
            FROM ZBCS_COD02
            WHERE AUFNR IN LR_AUFNR.
*              AND cview EQ 992.
          LV_LINE  = LINES( LT_BARCDM ).
          LV_TIMES = <FS_OUT>-LFIMG.
          IF LV_TIMES <> LV_LINE.
            <FS_OUT>-STATUS_LED =@0A@.
            CONCATENATE Quantity error in carton id : <FS_OUT>-ID INTO <FS_OUT>-MSG.
            CONTINUE.
          ENDIF.
          LOOP AT LT_BARCDM INTO LS_BARCDM.
            LS_BARCD-MATNR      = <FS_OUT>-MATNR.
            LS_BARCD-SEQUENCENO = LV_SQNO.
            LS_BARCD-BARCD      = LS_BARCDM-BARCD.
            APPEND LS_BARCD TO LT_BARCD.
            LV_SQNO = LV_SQNO + 1.
          ENDLOOP.
        ENDIF.
*获取序列号
      WHEN OTHERS.
        LS_BARCD-MATNR      = <FS_OUT>-MATNR.
        LS_BARCD-SEQUENCENO = 1.
        LS_BARCD-BARCD      = <FS_OUT>-ID.
        APPEND LS_BARCD TO LT_BARCD.
    ENDCASE.
    IF LT_BARCD[] IS NOT INITIAL.
      CALL FUNCTION Z_L_SD_UPDATE_SERIALNO
        EXPORTING
          IV_VBELN       = <FS_OUT>-VBELN
        IMPORTING
          ES_RETURN      = LS_RETURN
        TABLES
          IT_BARCD_MATNR = LT_BARCD.
    ENDIF.
    IF LS_RETURN-TYPE = E.
      <FS_OUT>-STATUS_LED =@0A@.
      <FS_OUT>-MSG        = LS_RETURN-MESSAGE.
    ELSE.
      <FS_OUT>-STATUS_LED =@08@.
      <FS_OUT>-MSG        = LS_RETURN-MESSAGE.
    ENDIF.
  ENDLOOP.

  LOOP AT GT_VBELN INTO GS_VBELN.
    CLEAR:LS_BARCD,LT_BARCD[],LS_RETURN,LV_SQNO,GS_OUT.
*step2 PGI
    LOOP AT GT_LIPS INTO GS_LIPS WHERE VBELN = GS_VBELN-VBELN.
      LS_VBPOK-VBELN_VL = GS_LIPS-VBELN.
      LS_VBPOK-POSNR_VL = GS_LIPS-POSNR.
      LS_VBPOK-VBELN    = GS_LIPS-VGBEL.
      LS_VBPOK-POSNN    = GS_LIPS-VGPOS.
      LS_VBPOK-LGORT    = GS_LIPS-LGORT. "库存地点
      LS_VBPOK-KZLGO    = X.           "库存地点可修改
      LS_VBPOK-LGMNG    = GS_LIPS-LFIMG. "捡配数量
      LS_VBPOK-LFIMG    = GS_LIPS-LFIMG. "交货数量
      APPEND LS_VBPOK TO LT_VBPOK.
      CLEAR: LS_VBPOK,GS_LIPS.
    ENDLOOP.
**锁订单
    PERFORM FRM_LOCK_DELIVERY USING GS_VBELN-VBELN.

    LS_VBKOK-VBELN_VL   = GS_VBELN-VBELN. "<- Delivery number
    LS_VBKOK-WABUC      = X.            "<- Automatic PGI
    LS_VBKOK-WADAT_IST  = SY-DATUM.       "<- Automatic PGI Date
* Perform Pick and PGI
    CALL FUNCTION WS_DELIVERY_UPDATE
      EXPORTING
        VBKOK_WA                 = LS_VBKOK
        SYNCHRON                 =  
        UPDATE_PICKING           = X
        COMMIT                   =  
        DELIVERY                 = GS_VBELN-VBELN
        NICHT_SPERREN            =  
        IF_ERROR_MESSAGES_SEND_0 =  
      TABLES
        PROT                     = LT_PROTT
        VBPOK_TAB                = LT_VBPOK
      EXCEPTIONS
        ERROR_MESSAGE            = 1
        OTHERS                   = 2.
    IF SY-SUBRC <> 0.
      <FS_OUT>-STATUS_LED =@0A@.
      <FS_OUT>-MSG        = Post error.
      GS_OUT-VBELN = GS_VBELN-VBELN.
      APPEND GS_OUT TO GT_OUT.
      ROLLBACK WORK.
    ELSE.
      LOOP AT LT_PROTT INTO LS_PROTT WHERE MSGTY EQ E OR MSGTY EQ A OR MSGTY EQ X.
        EXIT.
      ENDLOOP.
      IF SY-SUBRC EQ 0.
        CLEAR:LV_MSG.
        GS_OUT-STATUS_LED = @0A@.
        CALL FUNCTION Z_L_SD_MESSAGE_TEXT_BUILD
          EXPORTING
            LANGU               = E
            MSGID               = LS_PROTT-MSGID
            MSGNR               = LS_PROTT-MSGNO
            MSGV1               = LS_PROTT-MSGV1
            MSGV2               = LS_PROTT-MSGV2
            MSGV3               = LS_PROTT-MSGV3
            MSGV4               = LS_PROTT-MSGV4
          IMPORTING
            MESSAGE_TEXT_OUTPUT = GS_OUT-MSG.
        GS_OUT-VBELN = GS_VBELN-VBELN.
        APPEND GS_OUT TO GT_OUT.
      ELSE.
        GS_OUT-STATUS_LED = @08@.
        GS_OUT-MSG        = PGI Successfully.
        GS_OUT-VBELN = GS_VBELN-VBELN.
        APPEND GS_OUT TO GT_OUT.
        CALL FUNCTION BAPI_TRANSACTION_COMMIT
          EXPORTING
            WAIT = X.
      ENDIF.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " FRM_POST_GOODS_ISSUE
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .
  DATA:LS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
       LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
       LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DEFINE SET_FIELDCAT.
    LS_FIELDCAT-FIELDNAME      = &1.
    LS_FIELDCAT-REPTEXT_DDIC   = &2.
    APPEND LS_FIELDCAT TO LT_FIELDCAT.
    CLEAR LS_FIELDCAT.
  END-OF-DEFINITION.

  SET_FIELDCAT STATUS_LED TEXT-004 .
  SET_FIELDCAT VBELN TEXT-002 .
  SET_FIELDCAT POSNR TEXT-003 .
  SET_FIELDCAT MATNR TEXT-009 .
  SET_FIELDCAT LFIMG TEXT-011 .
  SET_FIELDCAT ID    TEXT-012 .
  SET_FIELDCAT MSG   TEXT-015 .

  CALL FUNCTION REUSE_ALV_GRID_DISPLAY
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IS_LAYOUT          = LS_LAYOUT
      IT_FIELDCAT        = LT_FIELDCAT
    TABLES
      T_OUTTAB           = GT_OUT
    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.                    " FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  FRM_LOCK_DELIVERY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_VBELN  text
*----------------------------------------------------------------------*
FORM FRM_LOCK_DELIVERY  USING   P_DELIVERY.

  DATA: LV_TIME TYPE P DECIMALS 2 VALUE 0.50.

  CHECK P_DELIVERY IS NOT INITIAL.

  DO 10 TIMES.

    CALL FUNCTION ENQUEUE_EVVBLKE
      EXPORTING
        VBELN          = P_DELIVERY
      EXCEPTIONS
        FOREIGN_LOCK   = 1
        SYSTEM_FAILURE = 2
        OTHERS         = 3.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

    IF SY-SUBRC EQ 0.

      CALL FUNCTION DEQUEUE_EVVBLKE
        EXPORTING
          MODE_LIKP = E
          MANDT     = SY-MANDT
          VBELN     = P_DELIVERY
          X_VBELN   =  
          _SCOPE    = 3
          _SYNCHRON =  
          _COLLECT  =  .
      WAIT UP TO LV_TIME SECONDS.
      EXIT.
    ELSE.
      WAIT UP TO LV_TIME SECONDS.
    ENDIF.
  ENDDO.

ENDFORM.                    " FRM_LOCK_DELIVERY

 

经典EXCEL导入程序

标签:ica   ===   跳过   import   The   structure   wait   key   订单   

原文地址:https://www.cnblogs.com/ferzalez/p/10069234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!