ABAP sales order creation BAPI: BAPI_SALESORDER_CREATEFROMDAT2 summary

tags: ABAP SD development  abap  sap  java  sql

1. Problems and causes of the application process

1.1 Error: Please enter the buyer or ship-to party


the reason: In fact, there is no buyer on the header of the order, mainly because the field ITM_NUMBER in the sales order partner table ORDER_PARTNERS is assigned to the item number of the sales and distribution voucher. These data are the partners of the project data, so the partner information on the header is missing .
Solution: When assigning values ​​to the sales order partner table ORDER_PARTNERS, the field ITM_NUMBER does not need to be assigned.

1.2 Although the sales order is created successfully, the order quantity is missing



the reason: At first, I thought that BAPI: BAPI_SALESORDER_CREATEFROMDAT2 in the row item table ORDER_ITEMS_IN field TARGET_QTY target quantity can be assigned. If there is no assignment in the plan line, the above situation will occur.
Solution: Assign the order quantity to the field REQ_QTY in the schedule table ORDER_SCHEDULES_IN.

1.3 An error was reported when creating a return order: the combination of business object BUS2032 and sales document category H is not allowed


the reason: This is because BAPI: SD_SALESDOCUMENT_CREATE is called in BAPI_SALESORDER_CREATEFROMDAT2, and the business object business_object in SD_SALESDOCUMENT_CREATE is defined as BUS2032, and the business object BUS2032 cannot create a return order.

Solution: When creating a return order, do not use BAPI: BAPI_SALESORDER_CREATEFROMDAT2 to create, instead use BAPI: SD_SALESDOCUMENT_CREATE to enter

2. Use BAPI to create sales order source code

form frm_va01_bapi.
  data:l_order_header_in like bapisdhd1, "Sales order header
               l_order_header_inx like bapisdhd1x, "Update the sales order header
               gt_return like table of bapiret2 with header line, "Return parameters
               gt_order_items_in like table of bapisditm with header line, "Sales order items
               gt_order_items_inx like table of bapisditmx with header line, "Sales order item update
               gt_order_partners like table of bapiparnr with header line, "Sales order partners
               l_sender like bapi_sender, "Sender logic system
               l_salesdocumentin like bapivbeln-vbeln, "Sales order
               l_logic_switch like bapisdls, "Logic Switch SD checkbox
               l_order_conditions_in like table of bapicond with header line, "condition type
               l_order_conditions_inx like table of bapicondx with header line, "condition type update
               l_salesdocument like bapivbeln-vbeln, "BAPI sales order
               gt_order_schedules_in like table of bapischdl with header line, "plan line
               gt_order_schedules_inx like table of bapischdlx with header line, "Schedule line update.
               GT_ORDER_TEXT LIKE TABLE OF BAPISDTEXT WITH HEADER LINE." text
  data:cp_eind type string,
       l_w     type string,
       i_mes   type char200.


     "Record the sales order header for recycling
  data:begin of gt_head occurs 0,
                   index type string, "Sales order
                   auart type string, "Sales document type
                   vkorg type string, "Sales Organization
                   vtweg type string, "distribution channel
                   spart type string, "product group
                   vkbur type string, "Sales Office
                   bstnk type string, "Customer Reference
                   augru type string, "reason for order
                   kunnr type string, "Sold-to party
                   kunag type string, "Delivery Party
          Remarks TYPE STRING,
       end of gt_head.

     "Get the selected order
  loop at gt_out where box = 'X'.
    gt_head-index = gt_out-index.
    gt_head-auart = gt_out-auart.
    gt_head-vkorg = gt_out-vkorg.
    gt_head-vtweg = gt_out-vtweg.
    gt_head-spart = gt_out-spart.
    gt_head-vkbur = gt_out-vkbur.
    gt_head-bstnk = gt_out-bstnk.
    gt_head-augru = gt_out-augru.
    gt_head-kunnr = gt_out-kunnr .
    gt_head-kunag = gt_out-kunag.
    GT_HEAD-Remarks = GT_OUT-Remarks.
    append gt_head.
  endloop.
     "Delete duplicates
  delete adjacent duplicates from gt_head comparing all fields.
  sort gt_head.
*  break k99997.

     "For data processing
  loop at gt_head.
         "Sales order
    clear l_salesdocumentin.
*  L_SALESDOCUMENTIN = GT_HEAD-INDEX.
    l_logic_switch-pricing = 'G'.
         "Sales order header
    clear l_order_header_in.
         l_order_header_in-doc_type = gt_head-auart. "Sales order document type
         l_order_header_in-sales_org = gt_head-vkorg. "Sales Organization
         l_order_header_in-distr_chan = gt_head-vtweg. "distribution channel
         l_order_header_in-division = gt_head-spart. "Product Group
         l_order_header_in-sales_off = gt_head-vkbur. "Sales Office
         l_order_header_in-purch_no_c = gt_head-bstnk. "Customer Reference
         l_order_header_in-req_date_h = sy-datum. "Required delivery date
         l_order_header_in-doc_date = sy-datum. "Voucher date (received/sent)

    if gt_head-auart = 'ZRE' or gt_head-auart = 'ZFR'.
      l_order_header_in-ord_reason = gt_head-augru. "Order reason
    endif.

         "Head up update
    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-sales_off = 'X'.
    l_order_header_inx-purch_no_c = 'X'.
    l_order_header_inx-req_date_h = 'X'.
    l_order_header_inx-doc_date = 'X'.
    if gt_out-auart = 'ZRE'.
      l_order_header_inx-ord_reason = 'X'.
    endif.
         "Sales Partner

         gt_order_partners-partn_role ='AG'. "Sold-to party
         gt_order_partners-partn_numb = gt_head-kunnr. "Sold-to party number
 * GT_ORDER_PARTNERS-ITM_NUMBER = GT_OUT-POSNR. "Sales order item
    append gt_order_partners.
    clear gt_order_partners.

         gt_order_partners-partn_role ='WE'. "Delivery party
         gt_order_partners-partn_numb = gt_head-kunag. "Delivery party number
 * GT_ORDER_PARTNERS-ITM_NUMBER = GT_OUT-POSNR. "Sales order item
    append gt_order_partners.
    clear gt_order_partners.

         "Header Notes
         GT_ORDER_TEXT-TEXT_ID ='Z003'. "Text ID
         GT_ORDER_TEXT-LANGU = '1'. "Language
         GT_ORDER_TEXT-TEXT_LINE = gt_head-Remarks." text
    APPEND GT_ORDER_TEXT.
    CLEAR GT_ORDER_TEXT.



    loop at gt_out where box = 'X' and index = gt_head-index.
      call function 'CONVERSION_EXIT_CUNIT_INPUT'
        exporting
          input  = gt_out-kmein
        importing
          output = gt_out-kmein.



             "Sales Order Item
             gt_order_items_in-itm_number = gt_out-posnr. "Sales order item
             gt_order_items_in-material = gt_out-matnr. "Material code
             gt_order_items_in-plant = gt_out-werks. "Factory
             gt_order_items_in-store_loc = gt_out-lgort. "Inventory location
             gt_order_items_in-target_qty = gt_out-kwmeng. "Target quantity
             gt_order_items_in-price_date = gt_out-prsdt. "Line item pricing date
      append gt_order_items_in.
      clear gt_order_items_in.
             "Sales order item update

      gt_order_items_inx-itm_number = gt_out-posnr.
      gt_order_items_inx-material = 'X'.
      gt_order_items_inx-plant = 'X'.
      gt_order_items_inx-store_loc = 'X'.
      gt_order_items_inx-target_qty = 'X'.
      gt_order_items_inx-price_date = 'X'.
      append gt_order_items_inx.
      clear gt_order_items_inx.

             "Plan line
             gt_order_schedules_in-itm_number = gt_out-posnr. "Sales voucher item
             gt_order_schedules_in-req_qty = gt_out-kwmeng. "Order quantity of each sales unit
      append gt_order_schedules_in.
      clear gt_order_schedules_in.
             gt_order_schedules_inx-itm_number = gt_out-posnr. "Sales voucher item
             gt_order_schedules_inx-req_qty ='X'. "The number of orders per sales unit
      append gt_order_schedules_inx.
      clear gt_order_schedules_inx.

             "Condition Type
             l_order_conditions_in-itm_number = gt_out-posnr. "Sales order item
             l_order_conditions_in-cond_type = gt_out-kschl. "Condition type
             l_order_conditions_in-cond_value = gt_out-kbetr. "Condition amount
             l_order_conditions_in-currency = gt_out-konwa. "Condition currency
             l_order_conditions_in-cond_unit = gt_out-kmein. "Condition unit
             l_order_conditions_in-cond_p_unt = gt_out-kpein. "Condition pricing unit
             l_order_conditions_in-curr_iso = gt_out-konwa. "IOS code currency
      append l_order_conditions_in.
      clear l_order_conditions_in.
             "Condition Type Update
             l_order_conditions_inx-itm_number = gt_out-posnr. "Sales order item
             l_order_conditions_inx-cond_type = gt_out-kschl. "Condition type
             l_order_conditions_inx-cond_value ='X'. "Condition amount
             l_order_conditions_inx-currency ='X'. "Condition currency
             l_order_conditions_inx-cond_unit ='X'. "Condition unit
      l_order_conditions_inx-cond_p_unt ='X'. "Condition pricing unit
      append l_order_conditions_inx.
      clear l_order_conditions_inx.

                     "Project Notes
         GT_ORDER_TEXT-TEXT_ID ='Z005'. "Text ID
         GT_ORDER_TEXT-ITM_NUMBER = gt_out-posnr. "Sales order item
         GT_ORDER_TEXT-LANGU = '1'. "Language code
         GT_ORDER_TEXT-TEXT_LINE = gt_out-LIN. "Text line
    APPEND GT_ORDER_TEXT.
    CLEAR GT_ORDER_TEXT.


    endloop.

         "Call sales order to create BAPI
    if gt_head-auart = 'ZRE'.
             "Because BAPI:BAPI_SALESORDER_CREATEFROMDAT2 defines the business object dead, the return order is created with this BAPI
      call function 'SD_SALESDOCUMENT_CREATE'
        exporting
*         salesdocument        = salesdocumentin
          sales_header_in      = l_order_header_in
          sales_header_inx     = l_order_header_inx
*         sender               = sender
*         binary_relationshiptype = binary_relationshiptype
*         int_number_assignment   = int_number_assignment
*         behave_when_error    = behave_when_error
          logic_switch         = l_logic_switch
*         business_object      = 'BUS2032'
*         testrun              = testrun
*         convert_parvw_auart  = convert
        importing
          salesdocument_ex     = l_salesdocument
        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_order_schedules_in[]
          sales_schedules_inx  = gt_order_schedules_inx[]
          sales_conditions_in  = l_order_conditions_in[]
          sales_conditions_inx = l_order_conditions_inx[]
*         sales_cfgs_ref       = order_cfgs_ref
*         sales_cfgs_inst      = order_cfgs_inst
*         sales_cfgs_part_of   = order_cfgs_part_of
*         sales_cfgs_value     = order_cfgs_value
*         sales_cfgs_blob      = order_cfgs_blob
*         sales_cfgs_vk        = order_cfgs_vk
*         sales_cfgs_refinst   = order_cfgs_refinst
*         sales_ccard          = order_ccard
         sales_text           = GT_ORDER_TEXT[]
*         sales_keys           = order_keys
*         extensionin          = extensionin
*         partneraddresses     = partneraddresses
*         extensionex          = extensionex
        .
    else.
      clear l_salesdocument.
      call function 'BAPI_SALESORDER_CREATEFROMDAT2'
        exporting
*         SALESDOCUMENTIN      = L_SALESDOCUMENTIN
          order_header_in      = l_order_header_in
          order_header_inx     = l_order_header_inx
*         SENDER               = L_SENDER
*         BINARY_RELATIONSHIPTYPE       =
*         INT_NUMBER_ASSIGNMENT         =
*         BEHAVE_WHEN_ERROR    =
          logic_switch         = l_logic_switch
*         TESTRUN              =
*         CONVERT              = ' '
        importing
          salesdocument        = l_salesdocument
        tables
          return               = gt_return[]
          order_items_in       = gt_order_items_in[]
          order_items_inx      = gt_order_items_inx[]
          order_partners       = gt_order_partners[]
          order_schedules_in   = gt_order_schedules_in[]
          order_schedules_inx  = gt_order_schedules_inx[]
          order_conditions_in  = l_order_conditions_in[]
          order_conditions_inx = l_order_conditions_inx[]
*         ORDER_CFGS_REF       =
*         ORDER_CFGS_INST      =
*         ORDER_CFGS_PART_OF   =
*         ORDER_CFGS_VALUE     =
*         ORDER_CFGS_BLOB      =
*         ORDER_CFGS_VK        =
*         ORDER_CFGS_REFINST   =
*         ORDER_CCARD          =
         ORDER_TEXT           = GT_ORDER_TEXT[]
*         ORDER_KEYS           =
*         EXTENSIONIN          =
*         PARTNERADDRESSES     =
*         EXTENSIONEX          =
*         NFMETALLITMS         =
        .
    endif.


 * Handling error messages: Judge whether BAPI is successful by judging the type of message
    clear i_mes.
    loop at gt_return.
      i_mes = i_mes && '*' &&  gt_return-type && gt_return-number && gt_return-message.
      if gt_return-type eq 'E' or
          gt_return-type = 'A' or
          gt_return = 'X'.
                 cp_eind ='X'. "Failed
      endif.

      if gt_return-type eq 'W'.
        l_w = 'X'.
      endif.
    endloop.

    if cp_eind ne 'X'.
      if l_w <>  'X'.
                 "Warning message exists
        loop at gt_out where index = gt_head-index and box = 'X'.
          gt_out-tabix = i_mes.
          gt_out-text = icon_green_light .
          gt_out-index = l_salesdocument.
          modify gt_out.
        endloop.
      else.
                 "Order successfully generated
        loop at gt_out where index = gt_head-index and box = 'X'.
          gt_out-tabix = i_mes.
          gt_out-text = icon_yellow_light  .
          gt_out-index = l_salesdocument.
          modify gt_out.
        endloop.
      endif.

             "Commit transaction
      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait = 'X'.
      commit work and wait.
    else.
             "There was an error, the creation failed
      loop at gt_out where index = gt_head-index and box = 'X'.
        gt_out-tabix = i_mes.
        gt_out-text = icon_red_light .
        modify gt_out.
      endloop.
             "Rollback transaction
      call function 'BAPI_TRANSACTION_ROLLBACK' .
    endif.

    clear l_order_header_in.
    clear l_order_header_inx.
    clear l_logic_switch.
    clear l_salesdocument.
    clear gt_return[].
    clear gt_order_items_in[].
    clear gt_order_items_inx[].
    clear gt_order_partners[].
    clear l_order_conditions_in[].
    clear l_order_conditions_inx[].
    clear gt_order_schedules_in[].
    clear gt_order_schedules_inx[].
    clear cp_eind.
    clear l_w.
  endloop.

Intelligent Recommendation

[ABAP] Sales Order Billing Plan creation

Sales order creation issued an invoice plan Customers have such a demand feedback, through the sales order created by the interface, one of the types of orders requires simultaneous creation of the in...

[ABAP] BAPI Committee Order Introduction

The BAPI commission will add three fields, line_id, parent_id, line_depth. The upper layer of the commission will only need line_id, and the lower layer needs line_id, parent_id, line_depth. LINE_ID T...

SAP ABAP VA01 / VA02 / VA03 Sales Order Walk Project Enhancement and BAPI

The effect is as follows: VBAP adds a guest manufacturing field. Sub-screen 8459 adds an enhancement field. Pbo changes attributes. MODULE CHANGE_ATT OUTPUT. if T180-TRTYP eq ...

SAP ABAP BAPI Create the delivery bill with reference to the sales order, pick allocated, bapi_outb_delivery_create_sls)

Create the delivery order BAPI with reference to the sales order: BAPI_OUTB_DELIVERY_CREATE_SLS Picking: WS_DELIVERY_UPDATE Over the account: BAPI_OUTB_DELIVERY_CONFIRM_DEC Delivery form: vl01n, vl02n...

More Recommendation

BAPI: Create sales order (VA01)

Business: If the user fills in the sales price by himself, the sales order pricing conditions will be maintained according to the filled prices. If not, it will be automatically brought out according ...

BAPI: Sales Order Delete - BAPI_SALESORDER_CHANGE

DATA: ls_headinx LIKE bapisdh1x, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2. CLEAR: ls_headinx . ls_headinx-updateflag = ‘D’. CALL FUNCTION ‘BAPI_SALESORDER_CHANGE&rsq...

BAPI_SALESORDER_CREATEFROMDAT2 does not have a reference order to create a sales order

Project scene: Create sales orders without reference Example:...

How to assign value to enhanced field when creating sales order [BAPI_SALESORDER_CREATEFROMDAT2]

When creating sales orders using bapi_SALESORDER_CREATEFROMDAT2, you can assign values ​​to custom parameters through the extensionin parameter. The specific usage method can be viewed by clicking Fun...

How to modify the fields of Sales Order with BAPI SD_SALESDOCUMENT_CHANGE

Suppose I want to modify the Service Date field SERV_DATE of the Sales Order header in S/4HANA: First find the value before the SERV_DATE modification from the database table VBKD. January 1, 2020 Use...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top