ABAP VA31创建销售计划协议

Posted 想发财的小夏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP VA31创建销售计划协议相关的知识,希望对你有一定的参考价值。

发现VA31和VA01使用相同程序SAPMV45A,所以也是使用相同底层bapi:SD_SALESDOCUMENT_CREATE


  DATA:
    ls_header  TYPE bapisdhd1,  "表头
    ls_headerx TYPE bapisdhd1x, "表头标志
    ls_item    TYPE bapisditm,  "行项目
    ls_itemx   TYPE bapisditmx,
    ls_partner TYPE bapiparnr,
    lt_partner TYPE STANDARD TABLE OF bapiparnr,
    lt_item    TYPE STANDARD TABLE OF bapisditm,
    lt_itemx   TYPE STANDARD TABLE OF bapisditmx,
    lt_return  TYPE STANDARD TABLE OF bapiret2,
    ls_output  LIKE bapisdhd,
    lv_posnr   TYPE posnr_va,
    lv_msg     TYPE bapi_msg.

  " 按照客户合并创建
  LOOP AT gt_excel1 INTO DATA(ls_group) WHERE icon NE gc_green GROUP BY ( kunnr = ls_group-kunnr ).

* Header
    CLEAR:ls_header,ls_headerx.
    ls_header-doc_type   = ls_group-auart.
    ls_header-ct_valid_f = sy-datum.
    ls_header-sales_org  = p_vkorg.
    ls_header-distr_chan = '20'.  "分销渠道
    ls_header-division   = '10'.  "产品组
    ls_header-purch_no_c = ls_group-auart.

    ls_headerx-doc_type   = 'X'.
    ls_headerx-ct_valid_f = 'X'.
    ls_headerx-sales_org  = 'X'.
    ls_headerx-purch_no_c = 'X'.
    ls_headerx-distr_chan = 'X'.  "分销渠道
    ls_headerx-division   = 'X'.  "产品组
    ls_headerx-updateflag = 'I'.

    CLEAR:lv_posnr,lt_item,lt_itemx,lt_partner.
    LOOP AT GROUP ls_group ASSIGNING FIELD-SYMBOL(<fs_excel>).

      CLEAR ls_item.
      lv_posnr = lv_posnr + 10.
      <fs_excel>-posnr = lv_posnr.
      ls_item-itm_number = lv_posnr.
      ls_item-material   = <fs_excel>-matnr.   "物料
      ls_item-cust_mat35 = <fs_excel>-maktx.
      APPEND ls_item TO lt_item.

      ls_itemx-itm_number = lv_posnr.
      ls_itemx-material   = 'X'.
      ls_itemx-cust_mat35 = 'X'.
      ls_itemx-updateflag = 'I'.
      APPEND ls_itemx TO lt_itemx.
      CLEAR ls_itemx.

    ENDLOOP.

    "销售合作伙伴
    ls_partner-partn_role = 'AG'."售达方
    ls_partner-partn_numb = ls_group-kunnr."售达方编号
    APPEND ls_partner TO lt_partner.
    CLEAR ls_partner.

    ls_partner-partn_role = 'WE'."送达方
    ls_partner-partn_numb = ls_group-kunnr."送达方编号
    APPEND ls_partner TO lt_partner.
    CLEAR ls_partner.

    CLEAR:lt_return,ls_output.
    CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
      EXPORTING
*       SALESDOCUMENT    =
        sales_header_in  = ls_header
        sales_header_inx = ls_headerx
*       SENDER           =
*       BINARY_RELATIONSHIPTYPE       = ' '
*       INT_NUMBER_ASSIGNMENT         = ' '
*       BEHAVE_WHEN_ERROR   = ' '
*       LOGIC_SWITCH     = ' '
        business_object  = 'BUS2035'
*       TESTRUN          =
*       CONVERT_PARVW_AUART = ' '
*       STATUS_BUFFER_REFRESH         = 'X'
      IMPORTING
*       SALESDOCUMENT_EX =
        sales_header_out = ls_output
*       SALES_HEADER_STATUS =
      TABLES
        return           = lt_return
        sales_items_in   = lt_item
        sales_items_inx  = lt_itemx
        sales_partners   = lt_partner.

    CLEAR lv_msg.
    LOOP AT lt_return INTO DATA(ls_return) WHERE type CA 'AEX'.
      PERFORM frm_message_set USING ls_return-message
                      CHANGING lv_msg.
    ENDLOOP.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
      gs_excel1-vbeln = ls_output-doc_number.
      gs_excel1-icon = gc_green.
      gs_excel1-msg = '创建成功'.
      MODIFY gt_excel1 FROM gs_excel1 TRANSPORTING icon msg vbeln WHERE kunnr = ls_group-kunnr.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
      gs_excel1-icon = gc_red.
      gs_excel1-msg = lv_msg.
      MODIFY gt_excel1 FROM gs_excel1 TRANSPORTING icon msg WHERE kunnr = ls_group-kunnr.
    ENDIF.

  ENDLOOP.

以上是关于ABAP VA31创建销售计划协议的主要内容,如果未能解决你的问题,请参考以下文章

SAP SD顾问请进

ABAP获取销售合同执行数量

ABAP ALV输出前面空格

ABAP ALV输出前面空格

ABAP ALV输出前面空格

VA02 释放行项目计划行确认数量