• SD_BAPI


    创建销售订单BAPI及增强

    http://blog.sina.com.cn/s/blog_1647b3eff0102wi32.html

      DATA:lv_objtype TYPE nast-objtype.

    "SO BAPI参数
    DATA:ls_order_header_in       LIKE bapisdhd1.
    DATA:lt_order_header_in       LIKE TABLE OF  bapisdhd1.
    DATA:ls_order_header_inx      LIKE bapisdhd1x.
    DATA:lt_order_header_inx      LIKE TABLE OF bapisdhd1x.
    DATA:lt_order_items_in        TYPE TABLE OF bapisditm.
    DATA:lt_order_items_inx       LIKE TABLE OF bapisditmx.
    DATA:ls_order_items_in        LIKE bapisditm.
    DATA:ls_order_items_inx       LIKE bapisditmx.
    DATA:lt_order_partners        LIKE TABLE OF bapiparnr.
    DATA:ls_order_partners        LIKE LINE OF lt_order_partners.
    DATA:lt_schedules_in          LIKE TABLE OF bapischdl .
    DATA:lt_schedules_inx         LIKE TABLE OF  bapischdlx .
    DATA:ls_schedules_in          LIKE bapischdl .
    DATA:ls_schedules_inx         LIKE bapischdlx .
    DATA:lt_order_conditions_in   LIKE TABLE OF  bapicond .
    DATA:lt_order_conditions_inx  LIKE TABLE OF  bapicondx .
    DATA:ls_order_conditions_in   LIKE  bapicond .
    DATA:ls_order_conditions_inx  LIKE  bapicondx .
    
     LOOP AT p_gt_checkabox_so_header ASSIGNING FIELD-SYMBOL(<fs1>).
    *-------SO创建
        CLEAR:lv_ebeln.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
          EXPORTING
            input  = <fs1>-matnr
          IMPORTING
            output = <fs1>-matnr.
        ls_order_header_in = VALUE #( doc_type = 'ZRE3'  "订单类型
                                 sales_org = '5100'
                                 distr_chan = '10'
                                 division = '10'
                                 req_date_h = <fs1>-zthrq
                                 doc_date = sy-datum ).
    
        ls_order_header_inx = VALUE #( updateflag = 'I'
                                doc_type = 'X'
                                sales_org = 'X'
                                distr_chan = 'X'
                                division = 'X'
                                req_date_h = 'X'
                                doc_date = 'X' ).
    
        CLEAR :lt_order_items_in,lt_order_items_in[].
        CLEAR :lt_order_items_inx,lt_order_items_inx[].
        CLEAR :lt_order_partners,lt_order_partners[].
        CLEAR :lt_schedules_in,lt_schedules_in[].
        CLEAR :lt_schedules_inx,lt_schedules_inx[].
        CLEAR :lt_return,lt_return[].
    
        lt_order_partners = VALUE #( FOR ls_tpar IN lt_tpar_so
                      ( VALUE #( BASE CORRESPONDING #( ls_tpar ) partn_numb = <fs1>-kunnr ) ) ).
    
    
        LOOP AT p_gt_checkabox_so_items   WHERE  kunnr =  <fs1>-kunnr
                                              AND    zdbdh =  <fs1>-zthdh
                                              AND    s_werks =  <fs1>-s_werks.
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
            EXPORTING
              input  = p_gt_checkabox_so_items-matnr
            IMPORTING
              output = p_gt_checkabox_so_items-matnr.
          ls_order_items_in-itm_number = p_gt_checkabox_so_items-zposnr ."items 号
          ls_order_items_in-material = p_gt_checkabox_so_items-matnr.
          ls_order_items_in-plant = p_gt_checkabox_so_items-s_werks."
          ls_order_items_in-store_loc    = '1001'.
          ls_order_items_in-target_qty   = p_gt_checkabox_so_items-menge."
    *        ls_order_items_in-ship_point   = p_vstel."装运点
          ls_order_items_in-target_qu    =  p_gt_checkabox_so_items-meins."
    *        ls_order_items_in-target_val   = 888."BAPIs 的货币金额(带有 9 个小数位)
    *        ls_order_items_in-purch_no_c   =  '客户参考'  .
          ls_order_items_in-item_categ   =  'REN'  ."销售凭证项目类别
    *        ls_order_items_in-item_categ   =   COND #( WHEN ls_order_header_in-doc_type = 'ZOR2' THEN 'TAS' ELSE 'TAN' ).
          APPEND ls_order_items_in TO lt_order_items_in.
    
          ls_schedules_inx-updateflag      = 'X'.
          ls_schedules_inx-itm_number      = 'X'.
          ls_schedules_inx-req_qty         = 'X'.
          ls_order_items_inx-material =  'X'.
          ls_order_items_inx-target_qty =  'X'.
          ls_order_items_inx-sales_unit =  'X'.
          ls_order_items_inx-plant =  'X'.
          ls_order_items_inx-purch_no_c =  'X'.
          ls_order_items_inx-item_categ =  'X'."销售凭证项目类别
          ls_order_items_inx-updateflag =  'I'.
          ls_order_items_inx-target_val =  'X'.
          APPEND ls_schedules_inx TO lt_schedules_inx.
    
    *SCHED_TYPE
    
          ls_schedules_in-itm_number      =  p_gt_checkabox_so_items-zposnr."items 号"
          ls_schedules_in-req_qty         = p_gt_checkabox_so_items-menge .
          APPEND ls_schedules_in TO lt_schedules_in.
    
          ls_schedules_inx-updateflag      = 'X'.
          ls_schedules_inx-itm_number      = 'X'.
          ls_schedules_inx-req_qty         = 'X'.
          APPEND ls_schedules_inx TO lt_schedules_inx.
        ENDLOOP.
    *    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    *      EXPORTING
    *        order_header_in     = ls_order_header_in
    *        order_header_inx    = ls_order_header_inx
    *      IMPORTING
    *        salesdocument       = lv_ebeln
    *      TABLES
    *        return              = lt_return
    *        order_items_in      = lt_order_items_in
    *        order_items_inx     = lt_order_items_inx
    *        order_partners      = lt_order_partners
    *        order_schedules_in  = lt_schedules_in
    *        order_schedules_inx = lt_schedules_inx.
    *-----------------------------------------------------------------------------------------------------------
    
        CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
          EXPORTING
    *       SALESDOCUMENTIN      =
            return_header_in     = ls_order_header_in
            return_header_inx    = ls_order_header_inx
          IMPORTING
            salesdocument        = lv_ebeln
          TABLES
            return               = lt_return
            return_items_in      = lt_order_items_in
            return_items_inx     = lt_order_items_inx
            return_partners      = lt_order_partners
            return_schedules_in  = lt_schedules_in
            return_schedules_inx = lt_schedules_inx.
    *-----------------------------------------------------------------------------------------------------------
        LOOP AT lt_return WHERE type CA 'AE'.
        ENDLOOP.
        IF sy-subrc EQ 0.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          e_type = 'E'.
          e_msg =  |销售订单 { lv_ebeln } 创建失败:{ lt_return-message } |.
        ELSE.
          e_type = 'S'.
          e_msg =  |销售订单 { lv_ebeln } 创建成功 !|..
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
  • 相关阅读:
    Stack集合 Queue队列集合 Hashtable哈希表
    冒泡排序
    2017-3-1 数组
    2017-2-26 三大类知识
    2017-2-25 练习题总结
    2017-2-25 循环语句 跳转语句 迭代法 穷举法 异常语句
    2017-2-22 if语句 if语句的嵌套 以及课堂练习 经典猜拳游戏,闰年判断,输出当前时间的天数等
    2017-2-20 运算符
    2017-2-18 net 输入输出语句
    【Ebola】python day3
  • 原文地址:https://www.cnblogs.com/ckstock/p/11284182.html
Copyright © 2020-2023  润新知