• 周日. 5月 26th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

SAP创建销售订单以FTP方式进行数据交互

admin

11月 28, 2021

*&———————————————————————*
*& Report  ZMM_IF_CREATE_SALES
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZMM_IF_CREATE_SALES.
TYPES:BEGIN OF TY_CREATE_SALES_DATA_HEADER,
      VSNMR_V TYPE STRING, “DOP order numbe
      AUART   TYPE STRING, “Doc Type
      VKORG   TYPE STRING, “Sales Org
      VTWEG   TYPE STRING, “Distr. Ch
      SPART   TYPE STRING, “Division
      KUNNR   TYPE STRING, “Sold-to Party
      KUNNR1  TYPE STRING, “Ship-to Party
      BSTNK   TYPE STRING, “PO Number
      IHREZ   TYPE STRING, “DOP order type
      VDATU   TYPE STRING, “Req.Deliv.Date
      END OF TY_CREATE_SALES_DATA_HEADER.
TYPES:BEGIN OF TY_CREATE_SALES_DATA_ITEM,
      POSNR TYPE STRING, “Item Num
      MATNR TYPE STRING, “Material Code
      KWMENG TYPE STRING, ” order quantity
      WERKS TYPE STRING, “PLANT
      KZWI4 TYPE STRING,”Item Price
      AESKD TYPE STRING,”Shipping Type
      BSTKD_E TYPE STRING,”PO Number In The Item
      END OF TY_CREATE_SALES_DATA_ITEM.
TYPES: BEGIN OF TY_PUSH_DATA,
         LDATA TYPE STRING,
       END OF TY_PUSH_DATA.
TYPES:BEGIN OF TY_BACK_ORDER_DATA,
      VSNMR_V TYPE STRING, “DOP order numbe
      VBELN TYPE STRING, “SALES ORDER NUMBER
      ERDAT TYPE STRING, “Sales Order Creation Date
      STATUS TYPE STRING,
      MESSAGE TYPE STRING,”ERROR MESSAGE
      END OF TY_BACK_ORDER_DATA.
*DATA:P_FILE TYPE CHAR100 VALUE ‘/gestopeDRC/DIR_DOP/in/Jave2Sap/CreateOrder/’.
DATA: GC_TAB TYPE CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
      GC_MSG   TYPE BAPI_MSG.
DATA: GT_HEADER TYPE STANDARD TABLE OF TY_CREATE_SALES_DATA_HEADER,
       GS_HEADER TYPE TY_CREATE_SALES_DATA_HEADER,
       GT_ITEM TYPE STANDARD TABLE OF TY_CREATE_SALES_DATA_ITEM,
       GS_ITEM TYPE TY_CREATE_SALES_DATA_ITEM.
DATA : DIR_NAME TYPE EPSF-EPSDIRNAM,       “directory
       LT_DIR_LIST TYPE TABLE OF EPSFILI,  “In Process Directory List
       LS_DIR_LIST TYPE EPSFILI.
DATA:LT_SAVE_HEAD TYPE TABLE OF ZFPT_SD_002,
     LS_SAVE_HEAD TYPE ZFPT_SD_002,
     LT_SAVE_ITEM TYPE TABLE OF ZFPT_SD_003,
     LS_SAVE_ITEM TYPE ZFPT_SD_003,
     LV_VBELN LIKE BAPIVBELN-VBELN, ” FOR SAVE Sales Order Number TO USE
     LV_VERSION LIKE BAPISDHD1-VERSION, ” FOR SAVE DOP ORDER NUMBER TO USE
     LV_MESSAGE TYPE string. ” FOR SAVE BAPI ERROR LOG TO USE
DATA:LV_SYSTEM TYPE C LENGTH 3,
     P_FILE TYPE CHAR100,
     T_FILE TYPE CHAR100,
     P_FILE1 TYPE CHAR100,
     LH_OFILE TYPE CHAR100.
DATA: LT_HISTORY_FILE TYPE STANDARD TABLE OF TY_PUSH_DATA.
DATA: LS_HISTORY_FILE TYPE TY_PUSH_DATA.
*SELECTION-SCREEN BEGIN OF BLOCK B01  WITH FRAME TITLE TEXT-B01.
*
*SELECTION-SCREEN BEGIN OF LINE.
**PARAMETERS: R_NORMAL TYPE CHAR1 RADIOBUTTON GROUP RB1 USER-COMMAND R1 DEFAULT ‘X’.
**SELECTION-SCREEN COMMENT (10) TEXT-R01 FOR FIELD R_NORMAL.
**
**SELECTION-SCREEN  POSITION 20.
**
**PARAMETERS: R_RESET  TYPE CHAR1 RADIOBUTTON GROUP RB1.
**SELECTION-SCREEN COMMENT (10) TEXT-R02 FOR FIELD R_RESET.
**SELECTION-SCREEN END OF LINE.
**
**SELECTION-SCREEN SKIP 1.
*
** normal
*PARAMETERS: P_FILE TYPE CHAR100 DEFAULT ” LOWER CASE MODIF ID M1.
*PARAMETERS: P_INIT  TYPE CHAR1 AS CHECKBOX DEFAULT ‘ ‘ MODIF ID M1.
*
**reset
*PARAMETERS: P_DATUM TYPE SY-DATUM DEFAULT SY-DATUM MODIF ID M2.
*PARAMETERS: P_UZEIT TYPE SY-UZEIT MODIF ID M2.
*
*SELECTION-SCREEN END OF BLOCK B01.

INITIALIZATION.
LV_SYSTEM = SY-SYSID.
IF LV_SYSTEM = ‘DRC’.
  P_FILE = ‘/gestopeDRC/DIR_DOP/in/Jave2Sap/CreateOrder/’.
  P_FILE1 = ‘/gestopeDRC/DIR_DOP/out/Sap2Java/SalesOrder/’.
  LH_OFILE = ‘/gestopeDRC/DIR_DOP/in/Jave2Sap/CreateOrderHistory/’.
  ELSEIF LV_SYSTEM = ‘QRC’.
    P_FILE = ‘/gestopeQRC/DIR_DOP/in/Jave2Sap/CreateOrder/’.
    P_FILE1 = ‘/gestopeQRC/DIR_DOP/out/Sap2Java/SalesOrder/’.
    LH_OFILE = ‘/gestopeQRC/DIR_DOP/in/Jave2Sap/CreateOrderHistory/’.
ENDIF.
T_FILE = P_FILE.
START-OF-SELECTION.
  PERFORM FRM_GET_PATH_FILE. “GET ALL FILES IN THE PATH

  IF LT_DIR_LIST[] IS NOT INITIAL.
    PERFORM FRM_GET_DATA. “GET SERVICE FILE  TEANSFORM
    ELSE.
*   Message output
    CLEAR:GC_MSG.
    MESSAGE E001(ZFPT) INTO GC_MSG.
*   Save Data Log
    PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.
*   No push data
    MESSAGE E001(ZFPT).
  ENDIF.

*&———————————————————————*
*&      Form  FRM_GET_PATH_FILE
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM FRM_GET_PATH_FILE .
  DATA : DIR_NAME TYPE EPSF-EPSDIRNAM.
  CLEAR DIR_NAME.
  DIR_NAME = P_FILE.
  IF P_FILE IS NOT INITIAL.
    CLEAR:LT_DIR_LIST,LS_DIR_LIST.
    CALL FUNCTION ‘EPS_GET_DIRECTORY_LISTING’
             EXPORTING
               DIR_NAME                     = DIR_NAME
*            FILE_MASK                    = ‘ ‘
*          IMPORTING
*            DIR_NAME                     =
*            FILE_COUNTER                 =
*            ERROR_COUNTER                =
             TABLES
               DIR_LIST                     = LT_DIR_LIST
*          EXCEPTIONS
*            INVALID_EPS_SUBDIR           = 1
*            SAPGPARAM_FAILED             = 2
*            BUILD_DIRECTORY_FAILED       = 3
*            NO_AUTHORIZATION             = 4
*            READ_DIRECTORY_FAILED        = 5
*            TOO_MANY_READ_ERRORS         = 6
*            EMPTY_DIRECTORY_LIST         = 7
*            OTHERS                       = 8
                     .
    IF SY-SUBRC <> 0.
      MESSAGE E003(ZFPT).
      EXIT.
    ENDIF.
  ENDIF.
ENDFORM.                    ” FRM_GET_PATH_FILE
*&———————————————————————*
*&      Form  FRM_GET_DATA
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM FRM_GET_DATA .
  DATA:W_INFILE TYPE STRING.
  DATA:L_NUM TYPE I.
  DATA: LC_OFILE TYPE STRING,
        L_LEN TYPE I,
        L_NAME TYPE CHAR3.
  DATA:BEGIN OF LS_FILE,
       FILENAME TYPE ZFPT_SD_004-FILENAME,
       VBELN TYPE ZFPT_SD_004-VBELN,
       END OF LS_FILE,
       LT_FILE LIKE STANDARD TABLE OF LS_FILE.
  CLEAR:W_INFILE,L_NUM,GT_HEADER,GS_HEADER,GT_ITEM,GS_ITEM,
        LC_OFILE,LT_FILE,LS_FILE,LT_HISTORY_FILE,LS_HISTORY_FILE.
  “Get Has Created Sales Order Sucessed File Name Only Today
  SELECT FILENAME VBELN
    INTO TABLE LT_FILE
    FROM ZFPT_SD_004
    WHERE DATUM = SY-DATUM.
  LOOP AT LT_DIR_LIST INTO LS_DIR_LIST.
    CLEAR:L_LEN,L_NAME,P_FILE.
    P_FILE = T_FILE.
    L_LEN = STRLEN( LS_DIR_LIST-NAME ).
    L_LEN = L_LEN – 3.
    L_NAME = LS_DIR_LIST-NAME+L_LEN(3).
    IF L_NAME = ‘TXT’ OR L_NAME = ‘txt’ OR L_NAME = ‘Txt’. “Only Process ‘TXT’ File Type
      READ TABLE LT_FILE INTO LS_FILE WITH KEY FILENAME = LS_DIR_LIST-NAME. “Has Created Sales Order File Won’t Implement Again
      IF SY-SUBRC = 0.
        CONTINUE.
      ENDIF.
      CONCATENATE P_FILE LS_DIR_LIST-NAME INTO P_FILE.
      OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING UTF-8.
      IF SY-SUBRC <> 0.
        CLEAR: GC_MSG.
        MESSAGE S003(ZFPT) WITH LS_DIR_LIST-NAME INTO GC_MSG.
        “COMMON LOG TO SAVE
        PERFORM FRM_SAVE_LOG USING ‘S’ GC_MSG.
        CONTINUE.
      ELSE.
        DO.
          READ DATASET P_FILE INTO W_INFILE.
            IF SY-SUBRC <> 0.
              EXIT.
            ENDIF.
          “Save File To History –Begin
          IF W_INFILE IS NOT INITIAL.
            LS_HISTORY_FILE-LDATA = W_INFILE.
            APPEND LS_HISTORY_FILE TO LT_HISTORY_FILE.
          ENDIF.
          “– End —
          L_NUM = L_NUM + 1.
          IF L_NUM EQ 2.”HEADER DATA
              IF W_INFILE IS NOT INITIAL.
                SPLIT W_INFILE AT GC_TAB INTO
                               GS_HEADER-VSNMR_V
                               GS_HEADER-AUART
                               GS_HEADER-VKORG
                               GS_HEADER-VTWEG
                               GS_HEADER-SPART
                               GS_HEADER-KUNNR
                               GS_HEADER-KUNNR1
                               GS_HEADER-BSTNK
                               GS_HEADER-IHREZ
                               GS_HEADER-VDATU.
                APPEND GS_HEADER TO GT_HEADER.
              ENDIF.

          ENDIF.
          IF L_NUM >= 4. ” ITEM DATA
              IF W_INFILE IS NOT INITIAL.
                SPLIT W_INFILE AT GC_TAB INTO
                               GS_ITEM-POSNR
                               GS_ITEM-MATNR
                               GS_ITEM-KWMENG
                               GS_ITEM-WERKS
                               GS_ITEM-KZWI4
                               GS_ITEM-AESKD
                               GS_ITEM-BSTKD_E.
                APPEND GS_ITEM TO GT_ITEM.
              ENDIF.
          ENDIF.
        ENDDO.
        IF GT_HEADER IS INITIAL OR GT_ITEM IS INITIAL.
         MESSAGE E006(ZFPT) INTO GC_MSG.
*   Save Data Log
        PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.
        MESSAGE E006(ZFPT).
        ELSE.
        “CREATE SALES ORDER
        PERFORM CREATE_ORDER.
        “When Create Sales Order is sucess then push the data to Dop system
        PERFORM PUSH_DATA_TO_DOP.
        CLEAR: GC_MSG.
        MESSAGE S005(ZFPT) INTO GC_MSG.
*   Save Data Log
        PERFORM FRM_SAVE_LOG USING ‘S’ GC_MSG.
*   Data push successful
        MESSAGE S005(ZFPT).
        ENDIF.
      ENDIF.
      CLOSE DATASET P_FILE.
    ENDIF.
  ENDLOOP.
ENDFORM.                    ” FRM_GET_DATA
*&———————————————————————*
*&      Form  CREATE_ORDER
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM CREATE_ORDER .
  DATA:L_ORDER_HEADER_IN      LIKE BAPISDHD1,
       L_ORDER_HEADER_INX     LIKE BAPISDHD1X,
       GT_RETURN              LIKE TABLE OF BAPIRET2 WITH HEADER LINE,
       GT_ORDER_ITEMS_IN      LIKE TABLE OF BAPISDITM WITH HEADER LINE,
       GT_ORDER_ITEMS_INX     LIKE TABLE OF BAPISDITMX WITH HEADER LINE,
       GT_ORDER_PARTNERS      LIKE TABLE OF BAPIPARNR WITH HEADER LINE,
       GT_BAPICOND LIKE TABLE OF BAPICOND WITH HEADER LINE,
       GT_BAPICONDX LIKE TABLE OF BAPICONDX WITH HEADER LINE,
       GT_SCHEDULES_IN LIKE TABLE OF BAPISCHDL  WITH HEADER LINE,
       GT_SCHEDULES_INX LIKE TABLE OF BAPISCHDLX  WITH HEADER LINE,
       LV_MATNR TYPE VBAP-MATNR,
       LV_KUNNR TYPE VBAK-KUNNR.
  IF GT_HEADER IS NOT INITIAL AND GT_ITEM IS NOT INITIAL.
    CLEAR:L_ORDER_HEADER_IN,L_ORDER_HEADER_INX,GT_RETURN,GT_ORDER_ITEMS_IN,
          GT_ORDER_ITEMS_INX,GT_ORDER_PARTNERS,GT_BAPICOND,GT_BAPICONDX,
          LT_SAVE_HEAD,LS_SAVE_HEAD,LT_SAVE_ITEM,LS_SAVE_ITEM.
    LOOP AT GT_HEADER INTO GS_HEADER.
      CLEAR L_ORDER_HEADER_IN.
      L_ORDER_HEADER_IN-DOC_TYPE = GS_HEADER-AUART.
      L_ORDER_HEADER_IN-SALES_ORG = GS_HEADER-VKORG.
      L_ORDER_HEADER_IN-DISTR_CHAN = GS_HEADER-VTWEG.
      L_ORDER_HEADER_IN-DIVISION = GS_HEADER-SPART.
      L_ORDER_HEADER_IN-PURCH_NO_C = GS_HEADER-BSTNK. ” PO NUM
      L_ORDER_HEADER_IN-REF_1 = GS_HEADER-IHREZ. ” DOP order type
      L_ORDER_HEADER_IN-DOC_DATE = SY-DATUM.”date
      L_ORDER_HEADER_IN-VERSION = GS_HEADER-VSNMR_V.”DOP order Number
      L_ORDER_HEADER_IN-REQ_DATE_H = GS_HEADER-VDATU.”Req.Deliv.Date
      “FOR SAVE ITEM LOG TO USE  Please Don Not Clear When End The Loop  –LV_VERSION
      CLEAR LV_VERSION.
      LV_VERSION = GS_HEADER-VSNMR_V.

      CLEAR L_ORDER_HEADER_INX.
      L_ORDER_HEADER_INX-DOC_TYPE = ‘X’.
      L_ORDER_HEADER_INX-SALES_ORG = ‘X’.
      L_ORDER_HEADER_INX-DISTR_CHAN = ‘X’.
      L_ORDER_HEADER_INX-DIVISION = ‘X’.
      L_ORDER_HEADER_INX-PURCH_NO_C = ‘X’.
      L_ORDER_HEADER_INX-REF_1 = ‘X’.
      L_ORDER_HEADER_INX-DOC_DATE = ‘X’.
      L_ORDER_HEADER_INX-VERSION = ‘X’.
      L_ORDER_HEADER_INX-REQ_DATE_H = ‘X’.

      CLEAR:GT_ORDER_PARTNERS,LV_KUNNR.
      GT_ORDER_PARTNERS-PARTN_ROLE = ‘AG’.
      LV_KUNNR = GS_HEADER-KUNNR.
      CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
        EXPORTING
          INPUT         = LV_KUNNR
        IMPORTING
          OUTPUT        = GT_ORDER_PARTNERS-PARTN_NUMB .”Sold-to Party NUMBER
      APPEND GT_ORDER_PARTNERS.
      CLEAR:GT_ORDER_PARTNERS,LV_KUNNR.
      GT_ORDER_PARTNERS-PARTN_ROLE = ‘WE’.
      LV_KUNNR = GS_HEADER-KUNNR1.
      CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
        EXPORTING
          INPUT         = LV_KUNNR
        IMPORTING
          OUTPUT        = GT_ORDER_PARTNERS-PARTN_NUMB.”Ship-to Party NUMBER
      APPEND GT_ORDER_PARTNERS.
      CLEAR GT_ORDER_PARTNERS.

      “SAVE HEAD DATA LOG FORM DOP
      LS_SAVE_HEAD-DATUM = SY-DATUM.
      LS_SAVE_HEAD-UZEIT = SY-UZEIT.
      LS_SAVE_HEAD-VSNMR_V = GS_HEADER-VSNMR_V.
      LS_SAVE_HEAD-AUART = GS_HEADER-AUART.
      LS_SAVE_HEAD-VKORG = GS_HEADER-VKORG.
      LS_SAVE_HEAD-VTWEG = GS_HEADER-VTWEG.
      LS_SAVE_HEAD-SPART = GS_HEADER-SPART.
      LS_SAVE_HEAD-KUNNR = GS_HEADER-KUNNR.
      LS_SAVE_HEAD-KUNNR1 = GS_HEADER-KUNNR1.
      LS_SAVE_HEAD-BSTNK = GS_HEADER-BSTNK.
      LS_SAVE_HEAD-IHREZ = GS_HEADER-IHREZ.
      LS_SAVE_HEAD-VDATU = GS_HEADER-VDATU.
      APPEND LS_SAVE_HEAD TO LT_SAVE_HEAD.
    ENDLOOP.

    LOOP AT GT_ITEM INTO GS_ITEM.
      GT_ORDER_ITEMS_IN-ITM_NUMBER = GS_ITEM-POSNR.”Item Num
      CLEAR LV_MATNR.
      LV_MATNR = GS_ITEM-MATNR.
      CALL FUNCTION ‘CONVERSION_EXIT_MATN1_INPUT’
        EXPORTING
          INPUT              = LV_MATNR
        IMPORTING
          OUTPUT             = LV_MATNR
*       EXCEPTIONS
*         LENGTH_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.
      GT_ORDER_ITEMS_IN-ITM_NUMBER = GS_ITEM-POSNR.
      GT_ORDER_ITEMS_IN-MATERIAL = LV_MATNR.”Material Code
      GT_ORDER_ITEMS_IN-PLANT = GS_ITEM-WERKS.”Plant
      REPLACE ‘#’ WITH ” INTO GS_ITEM-BSTKD_E.
      GT_ORDER_ITEMS_IN-PURCH_NO_S = GS_ITEM-BSTKD_E.”Ship to party’s PO num
      GT_ORDER_ITEMS_IN-REF_1_S = GS_ITEM-AESKD.
      APPEND GT_ORDER_ITEMS_IN.
      CLEAR GT_ORDER_ITEMS_IN.

      GT_ORDER_ITEMS_INX-ITM_NUMBER = GS_ITEM-POSNR.
      GT_ORDER_ITEMS_INX-MATERIAL = ‘X’.
      GT_ORDER_ITEMS_INX-PLANT = ‘X’.
      GT_ORDER_ITEMS_INX-TARGET_QTY = ‘X’.
      GT_ORDER_ITEMS_INX-EAN_UPC = ‘X’.
      GT_ORDER_ITEMS_INX-PURCH_NO_S = ‘X’.
      GT_ORDER_ITEMS_INX-REF_1_S = ‘X’.
      APPEND GT_ORDER_ITEMS_INX.
      CLEAR GT_ORDER_ITEMS_INX.

      GT_BAPICOND-ITM_NUMBER = GS_ITEM-POSNR.
      GT_BAPICOND-CURRENCY = ‘CNY’.
      GT_BAPICOND-COND_TYPE = ‘ZE01’.
      GT_BAPICOND-COND_VALUE = GS_ITEM-KZWI4.
      APPEND GT_BAPICOND.
      CLEAR GT_BAPICOND.

      GT_BAPICONDX-ITM_NUMBER = GS_ITEM-POSNR.
      GT_BAPICONDX-COND_VALUE = ‘X’.
      GT_BAPICONDX-CURRENCY = ‘X’.
      GT_BAPICONDX-COND_TYPE = ‘X’.
      APPEND GT_BAPICONDX.
      CLEAR GT_BAPICONDX.

      GT_SCHEDULES_IN-ITM_NUMBER = GS_ITEM-POSNR.
      GT_SCHEDULES_IN-REQ_QTY = GS_ITEM-KWMENG.
      APPEND GT_SCHEDULES_IN.
      CLEAR GT_SCHEDULES_IN.

      GT_SCHEDULES_INX-ITM_NUMBER = ‘X’.
      GT_SCHEDULES_INX-REQ_QTY = ‘X’.
      APPEND GT_SCHEDULES_INX.
      CLEAR  GT_SCHEDULES_INX.
      “SAVE ITEM DATA LOG FORM DOP
      LS_SAVE_ITEM-DATUM = SY-DATUM.
      LS_SAVE_ITEM-UZEIT = SY-UZEIT.
      LS_SAVE_ITEM-VSNMR_V = LV_VERSION.
      LS_SAVE_ITEM-POSNR = GS_ITEM-POSNR.
      LS_SAVE_ITEM-MATNR = LV_MATNR.
      LS_SAVE_ITEM-KWMENG = GS_ITEM-KWMENG.
      LS_SAVE_ITEM-WERKS = GS_ITEM-WERKS.
      LS_SAVE_ITEM-KZWI4 = GS_ITEM-KZWI4.
      LS_SAVE_ITEM-REF_1_S = GS_ITEM-AESKD.
      LS_SAVE_ITEM-PURCH_NO_S = GS_ITEM-BSTKD_E.
      APPEND LS_SAVE_ITEM TO LT_SAVE_ITEM.
    ENDLOOP.
    IF LT_SAVE_HEAD[] IS NOT INITIAL.
      MODIFY ZFPT_SD_002 FROM TABLE LT_SAVE_HEAD.
      IF SY-SUBRC = 0.
        COMMIT WORK AND WAIT.
        ELSE.
          ROLLBACK WORK.
          CLEAR: GC_MSG.
          MESSAGE S002(ZFPT) WITH ‘ZFPT_SD_002 HEAD’ INTO GC_MSG.
          “COMMON LOG TO SAVE
        PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.
      ENDIF.
    ENDIF.
    IF LT_SAVE_ITEM[] IS NOT INITIAL.
      MODIFY ZFPT_SD_003 FROM TABLE LT_SAVE_ITEM.
      IF SY-SUBRC = 0.
        COMMIT WORK AND WAIT.
        ELSE.
          ROLLBACK WORK.
          CLEAR: GC_MSG.
          MESSAGE S002(ZFPT) WITH ‘ZFPT_SD_003 ITEM’ INTO GC_MSG.
          “COMMON LOG TO SAVE
      PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.
      ENDIF.
    ENDIF.
    CLEAR LV_VBELN.
    CALL FUNCTION ‘SD_SALESDOCUMENT_CREATE’
      EXPORTING
*   SALESDOCUMENT                 =
        SALES_HEADER_IN               = L_ORDER_HEADER_IN
        SALES_HEADER_INX              = L_ORDER_HEADER_INX
     IMPORTING
       SALESDOCUMENT_EX              = LV_VBELN
*   SALES_HEADER_OUT              =
*   SALES_HEADER_STATUS           =
     TABLES
       RETURN                        = GT_RETURN
       SALES_ITEMS_IN                = GT_ORDER_ITEMS_IN
       SALES_ITEMS_INX               = GT_ORDER_ITEMS_INX
       SALES_PARTNERS                = GT_ORDER_PARTNERS
       SALES_SCHEDULES_IN            = GT_SCHEDULES_IN
       SALES_SCHEDULES_INX           = GT_SCHEDULES_INX
       SALES_CONDITIONS_IN           = GT_BAPICOND
       SALES_CONDITIONS_INX          = GT_BAPICONDX .

    IF SY-SUBRC EQ 0 AND LV_VBELN IS NOT INITIAL.
      CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
        EXPORTING
          WAIT = ‘X’.
*       IMPORTING
*         RETURN        =
        CLEAR: GC_MSG.
        MESSAGE S000(ZFPT) WITH ‘Sales Order Create Success:’ INTO GC_MSG.
        “COMMON LOG TO SAVE
       CONCATENATE GC_MSG ‘:’ LV_VBELN INTO GC_MSG.
       PERFORM FRM_SAVE_LOG USING ‘S’ GC_MSG.
    ELSE.
      CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
      CLEAR LV_MESSAGE.
      LOOP AT GT_RETURN WHERE TYPE = ‘E’.
        CONCATENATE GT_RETURN-MESSAGE LV_MESSAGE INTO LV_MESSAGE.
      ENDLOOP.
      CLEAR: GC_MSG.
      MESSAGE S000(ZFPT) WITH LV_MESSAGE INTO GC_MSG.
      “COMMON LOG TO SAVE
     PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.

    ENDIF.
  ENDIF.
ENDFORM.                    ” CREATE_ORDER
*&———————————————————————*
*&      Form  PUSH_DATA_TO_DOP
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM PUSH_DATA_TO_DOP .
  DATA: LT_PUSH_DATA TYPE STANDARD TABLE OF TY_PUSH_DATA.
  DATA: LS_PUSH_DATA LIKE LINE OF LT_PUSH_DATA.
  DATA:LS_ORDER_DATA_STRING TYPE TY_BACK_ORDER_DATA.
  DATA: LC_OFILE TYPE STRING.

  CLEAR: LT_PUSH_DATA.
  CLEAR: LS_PUSH_DATA.
  CONCATENATE TEXT-H01
              TEXT-H02
              TEXT-H03
              TEXT-H04
              TEXT-H05
          INTO LS_PUSH_DATA-LDATA SEPARATED BY GC_TAB.
  IF LS_PUSH_DATA IS NOT INITIAL.
    APPEND LS_PUSH_DATA TO LT_PUSH_DATA.
  ENDIF.
    CLEAR LS_PUSH_DATA.
    CLEAR LS_ORDER_DATA_STRING.
    LS_ORDER_DATA_STRING-VSNMR_V = LV_VERSION. “DOP order numbe
    CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’
      EXPORTING
        INPUT         = LV_VBELN
      IMPORTING
        OUTPUT        = LV_VBELN     .

    LS_ORDER_DATA_STRING-VBELN = LV_VBELN. “Sales Order number
    LS_ORDER_DATA_STRING-ERDAT = SY-DATUM. “Sales Order Create Date
    IF LV_VBELN IS NOT INITIAL AND LV_MESSAGE IS INITIAL. “Create Sales Order Sucess
      LS_ORDER_DATA_STRING-STATUS = ‘S’.
      LS_ORDER_DATA_STRING-MESSAGE = ‘ ’.
      ELSEIF LV_VBELN IS INITIAL AND LV_MESSAGE IS NOT INITIAL. “Create Sales Order fail
        LS_ORDER_DATA_STRING-STATUS = ‘E’.
        LS_ORDER_DATA_STRING-MESSAGE = LV_MESSAGE.
    ENDIF.
    CONCATENATE LS_ORDER_DATA_STRING-VSNMR_V
                LS_ORDER_DATA_STRING-VBELN
                LS_ORDER_DATA_STRING-ERDAT
                LS_ORDER_DATA_STRING-STATUS
                LS_ORDER_DATA_STRING-MESSAGE
             INTO LS_PUSH_DATA-LDATA SEPARATED BY GC_TAB.
     APPEND LS_PUSH_DATA TO LT_PUSH_DATA.

   CLEAR: LC_OFILE.
   CONCATENATE P_FILE1 TEXT-F01 SY-DATUM SY-UZEIT TEXT-E01
         INTO LC_OFILE.

     OPEN DATASET LC_OFILE FOR OUTPUT IN TEXT MODE ENCODING UTF-8.

  IF SY-SUBRC = 0.
    LOOP AT LT_PUSH_DATA INTO LS_PUSH_DATA.
      TRANSFER LS_PUSH_DATA-LDATA TO LC_OFILE.
    ENDLOOP.
    IF LV_VBELN IS NOT INITIAL.
     PERFORM SAVE_FILE_NAME. “SAVE CREATE SALES ORDER’s FILE NAME When Successed
     PERFORM MOVE_FILE_TO_HISTORY.”Put The Dop’s File To History Path When Create Slaes Order Successed
     ELSE.
       PERFORM MOVE_FILE_TO_HISTORY.”Put The Dop’s File To History Path When Create Slaes Order Successed
    ENDIF.
  ELSE.
    CLEAR: GC_MSG.
    MESSAGE E003(ZFPT) WITH LV_VBELN INTO GC_MSG.

    PERFORM FRM_SAVE_LOG USING ‘E’ GC_MSG.

*   File open failed
    MESSAGE E003(ZFPT).
  ENDIF.
  CLOSE DATASET LC_OFILE.

ENDFORM.                    ” PUSH_DATA_TO_DOP
*&———————————————————————*
*&      Form  FRM_SAVE_LOG
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_0257   text
*      –>P_GC_MSG  text
*———————————————————————-*
FORM FRM_SAVE_LOG USING U_STATE TYPE CHAR1
                        U_MSG   TYPE BAPI_MSG.

  DATA: LS_ZFPT_COMM_001 TYPE ZFPT_COMM_001.

  LS_ZFPT_COMM_001-DATUM   = SY-DATUM.
  LS_ZFPT_COMM_001-UZEIT   = SY-UZEIT.
  LS_ZFPT_COMM_001-CPROG   = SY-CPROG.
  LS_ZFPT_COMM_001-OPERA   = ‘P’.
  LS_ZFPT_COMM_001-UNAME   = SY-UNAME.
  LS_ZFPT_COMM_001-DCOUNT  = LINES( LT_SAVE_HEAD ).
  LS_ZFPT_COMM_001-STATE   = U_STATE.
  LS_ZFPT_COMM_001-MESSAGE = U_MSG.

  IF SY-BATCH IS NOT INITIAL.
    CALL FUNCTION ‘GET_JOB_RUNTIME_INFO’
      IMPORTING
*       EVENTID                       =
*       EVENTPARM                     =
*       EXTERNAL_PROGRAM_ACTIVE       =
*       JOBCOUNT                      =
        JOBNAME                       = LS_ZFPT_COMM_001-JOBNAME
*       STEPCOUNT                     =
     EXCEPTIONS
       NO_RUNTIME_INFO                = 1
       OTHERS                         = 2
              .
    IF SY-SUBRC <> 0.
      CLEAR: LS_ZFPT_COMM_001-JOBNAME.
    ENDIF.

  ELSE.
    LS_ZFPT_COMM_001-JOBNAME = ‘MANUAL’.
  ENDIF.

  MODIFY ZFPT_COMM_001 FROM LS_ZFPT_COMM_001.

  IF SY-SUBRC = 0.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
    MESSAGE S002(ZFPT) WITH ‘ZFPT_COMM_001’.
  ENDIF.

ENDFORM.                    ” FRM_SAVE_LOG
*&———————————————————————*
*&      Form  SAVE_FILE_NAME
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM SAVE_FILE_NAME .
DATA:LS_SAVE_FILE TYPE ZFPT_SD_004.
LS_SAVE_FILE-FILENAME = LS_DIR_LIST-NAME. “THE FILE NAME FROM DOP SYSTEM
LS_SAVE_FILE-VBELN = LV_VBELN. “Sales Order umber
LS_SAVE_FILE-DATUM = SY-DATUM.
LS_SAVE_FILE-UZEIT = SY-UZEIT.

 MODIFY ZFPT_SD_004 FROM LS_SAVE_FILE.

  IF SY-SUBRC = 0.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
    MESSAGE S002(ZFPT) WITH ‘ZFPT_SD_004’.
  ENDIF.
ENDFORM.                    ” SAVE_FILE_NAME
*&———————————————————————*
*&      Form  MOVE_FILE_TO_HISTORY
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM MOVE_FILE_TO_HISTORY .
CONCATENATE LH_OFILE LS_DIR_LIST-NAME INTO LH_OFILE.
IF LT_HISTORY_FILE IS NOT INITIAL.
OPEN DATASET LH_OFILE FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
  IF SY-SUBRC = 0.
    LOOP AT LT_HISTORY_FILE INTO LS_HISTORY_FILE.
      TRANSFER LS_HISTORY_FILE-LDATA TO LH_OFILE.
    ENDLOOP.
    “Delete Dop File When Has Creeated Sales Order Successed.
    DELETE DATASET P_FILE.
  ENDIF.
 CLOSE DATASET LH_OFILE.
ENDIF.
ENDFORM.                    ” MOVE_FILE_TO_HISTORY

社会很单纯,复杂的是人

《SAP创建销售订单以FTP方式进行数据交互》有一个想法
  1. Wow, awesome weblog format! How long have you been blogging for?
    you make running a blog glance easy. The whole look of your site
    is magnificent, as smartly as the content material! You can see similar here sklep internetowy

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注