'BAPI_SALESORDER_CREATEFROMDAT2' Comp_quant.

Hello, there.
I'm trying to create order, with some positions. I've populated field comp_quant as follows, but after sucessfull returning, Quantity field stays null. Please give me some direction to solve this problem.
  LOOP AT it_bapi.
    CLEAR gt_order_items_inx.
    CLEAR gt_order_items_in.
    gt_order_items_inx-updateflag = 'I'.
*Matnr
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input  = it_bapi-mabnr
      IMPORTING
        output = gt_order_items_in-material.
    gt_order_items_inx-material = 'X'.
*Item Position
    gt_order_items_in-itm_number  = sy-tabix * 10.
    gt_order_schedules_in-itm_number = gt_order_items_in-itm_number.
    gt_order_items_inx-itm_number = 'X'.
    gt_order_schedules_inx-itm_number = 'X'.
*Quantity
    gt_order_items_in-comp_quant = it_bapi-kwmeng.
    gt_order_items_inx-comp_quant = 'X'.
    gt_order_items_inx-target_qty = 'X'.
    APPEND gt_order_items_in.
    APPEND gt_order_items_inx.
  ENDLOOP.
*Description
  gt_order_text-itm_number = ''.
  gt_order_text-text_id    = '0002'.
  gt_order_text-langu      = sy-langu.
  gt_order_text-format_col = '*'.
  gt_order_text-text_line  = ctext.
  APPEND gt_order_text.
  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
      order_header_in     = gs_order_header_in
      testrun             = testrun
    IMPORTING
      salesdocument       = gv_salesdocument
    TABLES
      return              = messtab[]
      order_items_in      = gt_order_items_in[]
      order_items_inx     = gt_order_items_inx[]
      order_partners      = gt_order_partners[]
      order_text          = gt_order_text[].

Do mean smth like this? It take no effect actualy.
  loop at it_bapi.
    clear gt_order_items_inx.
    clear gt_order_items_in.
    gt_order_items_inx-updateflag = 'I'.
    gt_order_schedules_inx-updateflag = 'I'.
*Matnr
    call function 'CONVERSION_EXIT_MATN1_INPUT'
      exporting
        input  = it_bapi-mabnr
      importing
        output = gt_order_items_in-material.
    gt_order_items_inx-material = 'X'.
*Item_pos
    gt_order_items_in-itm_number  = sy-tabix * 10.
    gt_order_schedules_in-itm_number = gt_order_items_in-itm_number.
    gt_order_items_inx-itm_number = gt_order_items_in-itm_number.
    gt_order_schedules_inx-itm_number = gt_order_items_in-itm_number.
*Quantity
    gt_order_items_in-target_qty = it_bapi-kwmeng.
    gt_order_schedules_in-req_qty = it_bapi-kwmeng.
    gt_order_schedules_inx-req_qty = 'X'.
    gt_order_items_inx-target_qty = 'X'.
    append gt_order_schedules_in.
    append gt_order_schedules_inx.
    append gt_order_items_in.
    append gt_order_items_inx.
  endloop.
  call function 'BAPI_SALESORDER_CREATEFROMDAT2'
    exporting
      order_header_in     = gs_order_header_in
      testrun             = testrun
    importing
      salesdocument       = gv_salesdocument
    tables
      return              = messtab[]
      order_items_in      = gt_order_items_in[]
      order_items_inx     = gt_order_items_inx[]
      order_schedules_in  = gt_order_schedules_in[]
      order_schedules_inx = gt_order_schedules_inx[]
      order_partners      = gt_order_partners[]
      order_text          = gt_order_text[].
Message was edited by:
        Long Nguyen
Message was edited by:
        Long Nguyen

Similar Messages

  • Not able to create sales order  using BAPI - BAPI_SALESORDER_CREATEFROMDAT2

    Hi Experts,
    I am not able to create sales order . I am using BAPI - BAPI_SALESORDER_CREATEFROMDAT2
    to create sales order .I am passing external sales order number to the parameter
    SALESDOCUMENTIN.
    I am getting following error.
    "524   |Only quantity 1 EA is allowed (Item 00001"
    Here EA is UOM(Unit of measurement).
    Below is the sample program through which i am trying to create the sales order.
    *& Report  ZSDC_SALES_TEST
    report  zsdc_sales_test.
    *DATA: wa_bapi_header    TYPE bapisdhd1.
    Include Name    - ZSDC_SALES_ORD_UPLOAD_TOP
    Program Name    - ZSDC_SALES_ORD_UPLOAD_1393
    Program Title   - Include for Data Declaration  and selection screen
    Created by      - Lalitha W
    Created on      - 18-Nov-2008
    Object ID       - SD_C_1393_SALES_ORDER_UPLOAD
    Request Id      - SD3K905579
    Description - This is a common INCLUDE for data declarations and
    *selection screen details.
                            HISTORY
    Date    |Developer |Req by    | Description              |Reference ID
            |          |          |                          |
            |          |          |                          |
                               TYPE-POOLS
    *TYPE-POOLS: truxs, abap, slis.
                              TABLES
    *TABLES: t100.
                               TYPES
    types:begin of   ty_header,
            auart(4)    type c,    " Sales Order Type
            vkorg(4)    type c,    " Sales Organization
            vtweg(2)    type c,    " Distrubution Channel
            spart(2)    type c,    " Division
            kunnr_1(10) type c,    " Sold to Party
            kunnr_2(10) type c,    " Ship to Party
            augru(3)    type c,    " Order Reason
            bstkd(35)   type c,    " PO Number
            bstdk(10)   type c,    " PO Date
            ketdat(10)  type c,    " Required Delivery Date
            zterm(4)    type c,    " Payment Terms
            inco1(3)    type c,    " Inco Terms -1
            inco2(28)   type c,    " Inco Terms -2
            prsdt(10)   type c,    " pricing date
            waerk(5)    type c,    " Document Currency
            vkbur(4)    type c,    " Sales Office
            vkgrp(3)    type c,    " Sales group
            pltyp(2)    type c,    " Price List type
            kdgrp(2)    type c,    " Customer Group
            bstkd_e(35) type c,    " Ship-to-party PO number
            submi(10)   type c,    " Collective Number
            bname(35)   type c,    " Name
            ihrez(12)   type c,    " Your Reference
            kschl_1(4)   type c,    " Condition Type
            kbetr_1(11)  type c,    " Amount
            kschl_2(4)   type c,    " Condition Type
            kbetr_2(11)  type c,    " Amount
            kschl_3(4)   type c,    " Condition Type
            kbetr_3(11)  type c,    " Amount
           partner_1(25) TYPE c,    "  Partner(Bill To Party Number)
           partner_2(25) TYPE c,    "  Partner(Payer Number)
           partner_3(25) TYPE c,    "  Partner(Sales Responsible Number)
           partner_4(25) TYPE c,    "  Partner(Order admin)
           partner_5(25) TYPE c,    "  Partner(Contact person)
            partner_1(10) type c,    "  Partner(Bill To Party Number)
            partner_2(10) type c,    "  Partner(Payer Number)
            partner_3(10) type c,    "  Partner(Sales Responsible Number)
            partner_4(10) type c,    "  Partner(Order admin)
            partner_5(10) type c,    "  Partner(Contact person)
            tdspras_1(2)  type c,
            text_1(500)   type c,    " Text Before Items Z012
            tdspras_2(2)  type c,
            text_2(500)   type c,    " Invocie Up Z034
            tdspras_3(2)  type c,
            text_3(500)   type c,    " Invocie Down Z035
            tdspras_4(2)  type c,
            text_4(500)   type c,    " Customer Reference Continue Z018
            tdspras_5(2)  type c,
            text_5(500)   type c,    " Dispatch Marks/ Order Z019
            tdspras_6(2)  type c,
            text_6(500)   type c,    " Ordered By  Z003
            tdspras_7(2)  type c,
            text_7(500)   type c,    " Sales Parameters Z002
            kvgr1(3)      type c,    " Industry
            kvgr2(3)      type c,    " customer BU
    end of ty_header.
    types: begin of ty_item,
              bstkd(35)     type c,    " PO Number
              bstdk(10)     type c,    " PO Date
              bstkd_e(35)   type c,    " Ship-to-party PO number
              posnr(6)      type c,    " POSTION NUMBER
              matnr(18)     type c,    " Material Number
              kwmeng(18)    type c,    " Order Quantity
              pstyv(4)      type c,    " Sales doc. item categ
              kursk(18)     type c,    " EXCHANGE RATE****
              ffprf(8)      type c,    " DIP PROFILE
              werks(4)      type c,    " Delivering Plant
              vstel(4)      type c,    " SHIPPING POINT
              lgort(4)      type c,    " STORAGE LOCATION
              route(6)      type c,    " Route
              kurrf(18)     type c,    " EXCHANGE RATE-FI
              ntgew(18)     type c,    " Net Weight
              brgew(18)     type c,    " Gross Weight
              gewei(3)      type c,    " Weight Unit
              prctr(10)     type c,    " profit center
              abgrs(6)      type c,    " RESULT ANALYSIS KEY
              kalsm_k(4)    type c,    " COSTING SHEET
              kschl_1(4)    type c,    " Condition Type
              kbetr_1(11)   type c,    " Amount
              kschl_2(4)    type c,    " Condition Type
              kbetr_2(11)   type c,    " Amount
              kschl_3(4)    type c,    " Condition Type
              kbetr_3(11)   type c,    " Amount
              text_1(500)    type c,    " material Text 0001
              tdspras_1(1)   type c,
              text_2(500)    type c,    " Pr Text 9001
              tdspras_2(1)   type c,
           end of ty_item.
    types:  begin of ty_schedule_line,
             bstkd(35)       type c, "PO number
             bstdk(10)       type c, "PO date
             bstkd_e(35)     type c, "Ship-to-party PO number
             posnr(6)        type c, "sales doc.Item
             etdat(10)       type c, "Schedule line date
             wmeng(2)        type c, "Order Quantity
            end of ty_schedule_line.
    types: begin of ty_err  ,
            auart(4)    type c,    " Sales Order Type
            vkorg(4)    type c,    " Sales Organization
            vtweg(2)    type c,    " Distrubution Channel
            spart(2)    type c,    " Division
            kunnr_1(10) type c,    " Sold to Party
            kunnr_2(10) type c,    " Ship to Party
            augru(3)    type c,    " Order Reason
            bstkd(35)   type c,    " PO Number
            bstdk(10)   type c,    " PO Date
            ketdat(10)  type c,    " Required Delivery Date
            zterm(4)    type c,    " Payment Terms
            inco1(3)    type c,    " Inco Terms -1
            inco2(28)   type c,    " Inco Terms -2
            prsdt(10)   type c,    " pricing date
            waerk(5)    type c,    " Document Currency
            vkbur(2)    type c,    " Sales Office
            vkgrp(3)    type c,    " Sales group
            pltyp(2)    type c,    " Price List type
            kdgrp(2)    type c,    " Customer Group
            bstkd_e(35) type c,    " Ship-to-party PO number
            submi(10)   type c,    " Collective Number
            bname(35)   type c,    " Name
            ihrez(12)   type c,    " Your Reference
            kschl_1(4)   type c,    " Condition Type
            kbetr_1(11)  type c,    " Amount
            kschl_2(4)   type c,    " Condition Type
            kbetr_2(11)  type c,    " Amount
            kschl_3(4)   type c,    " Condition Type
            kbetr_3(11)  type c,    " Amount
            partner_1(25) type c,    "  Partner(Bill To Party Number)
            partner_2(25) type c,    "  Partner(Payer Number)
            partner_3(25) type c,    "  Partner(Sales Responsible Number)
            partner_4(25) type c,    "  Partner(Order admin)
            partner_5(25) type c,    "  Partner(Contact person)
            tdspras_1(2)  type c,
            text_1(500)   type c,    " Text Before Items Z012
            tdspras_2(2)  type c,
            text_2(500)   type c,    " Invocie Up Z034
            tdspras_3(2)  type c,
            text_3(500)   type c,    " Invocie Down Z035
            tdspras_4(2)  type c,
            text_4(500)   type c,    " Customer Reference Continue Z018
            tdspras_5(2)  type c,
            text_5(500)   type c,    " Dispatch Marks/ Order Z019
            tdspras_6(2)  type c,
            text_6(500)   type c,    " Ordered By  Z003
            tdspras_7(2)  type c,
            text_7(500)   type c,    " Sales Parameters Z002
            kvgr1(3)      type c,    " Industry
            kvgr2(3)      type c,    " customer BU
            message(600) type c,
      end of ty_err.
    types: begin of ty_t685a,
            kschl type kschl,
            krech type krech,
          end of ty_t685a.
                       INTERNAL TABLES
    ***header
    data:  g_krech_1(4)    type c,    " Calculation type for condition
           g_krech_2(4)    type c,    " Calculation type for condition
           g_krech_3(4)    type c.    " Calculation type for condition
          g_krech_4(4)    TYPE c,    " Calculation type for condition
          g_krech_5(4)    TYPE c,    " Calculation type for condition
          g_krech_6(4)    TYPE c,    " Calculation type for condition
          g_krech_7(4)    TYPE c,    " Calculation type for condition
          g_krech_8(4)    TYPE c,    " Calculation type for condition
          g_krech_9(4)    TYPE c,    " Calculation type for condition
          g_krech_10(4)   TYPE c,    " Calculation type for condition
          g_krech_11(4)   TYPE c,    " Calculation type for condition
          g_krech_12(4)   TYPE c,    " Calculation type for condition
          g_krech_13(4)   TYPE c,    " Calculation type for condition
          g_krech_14(4)   TYPE c,    " Calculation type for condition
          g_krech_15(4)   TYPE c,    " Calculation type for condition
          g_krech_16(4)   TYPE c,    " Calculation type for condition
          g_krech_17(4)   TYPE c,    " Calculation type for condition
          g_krech_18(4)   TYPE c,    " Calculation type for condition
          g_krech_19(4)   TYPE c,    " Calculation type for condition
          g_krech_20(4)   TYPE c.    " Calculation type for condition
    Items
    data:   g_krech_item_1(4)   type c,    " Calculation type for condition
            g_krech_item_2(4)   type c,    " Calculation type for condition
            g_krech_item_3(4)   type c.    " Calculation type for condition
           g_krech_item_4(4)   TYPE c,    " Calculation type for condition
           g_krech_item_5(4)   TYPE c,    " Calculation type for condition
           g_krech_item_6(4)   TYPE c,    " Calculation type for condition
           g_krech_item_7(4)   TYPE c,    " Calculation type for condition
           g_krech_item_8(4)   TYPE c,    " Calculation type for condition
           g_krech_item_9(4)   TYPE c,    " Calculation type for condition
           g_krech_item_10(4)  TYPE c,    " Calculation type for condition
           g_krech_item_11(4)  TYPE c,    " Calculation type for condition
           g_krech_item_12(4)  TYPE c,    " Calculation type for condition
           g_krech_item_13(4)  TYPE c,    " Calculation type for condition
           g_krech_item_14(4)  TYPE c,    " Calculation type for condition
           g_krech_item_15(4)  TYPE c,    " Calculation type for condition
           g_krech_item_16(4)  TYPE c.    " Calculation type for condition
    data: it_t685a  type standard table of ty_t685a.
    data: wa_bapi_header    type bapisdhd1,
         wa_bapi_headerx   TYPE bapisdhd1x,
          it_bapi_item      type table of bapisditm,
         it_bapi_itemx     TYPE TABLE OF bapisditmx,
          it_bapi_cond      type table of bapicond,
         it_bapi_condx     TYPE TABLE OF bapicondx,
          it_bapi_partner   type table of bapiparnr,
          it_bapi_shdl      type table of bapischdl,
         it_bapi_shdlx     TYPE TABLE OF bapischdlx,
         it_bapi_order_text type TABLE OF BAPISDTEXT,
          it_bapireturn     type table of bapiret2.
    data:  wa_bapi_item       like line of it_bapi_item,
          wa_bapi_itemx      LIKE LINE OF it_bapi_itemx,
           wa_bapi_cond       like line of it_bapi_cond,
          wa_bapi_condx      LIKE LINE OF it_bapi_condx,
           wa_bapi_partner    like line of it_bapi_partner,
           wa_bapi_shdl       like line of it_bapi_shdl,
          wa_bapi_shdlx      LIKE LINE OF it_bapi_shdlx,
          wa_bapi_order_text like LINE OF it_bapi_order_text,
           wa_bapireturn      like line of it_bapireturn.
    *DATA: zmode(1) VALUE 'N'.
    data: it_header      type standard table of ty_header.
    *DATA: it_temp_header TYPE STANDARD TABLE OF ty_header.
    data: it_item        type standard table of ty_item.
    *DATA: it_temp_item   TYPE STANDARD TABLE OF ty_item.
    data: it_err         type standard table of ty_err.
    data: it_fline1 type standard table of tline,
          wa_fline1 type tline.
    data: it_thead1 type thead.
    data: it_fline2 type standard table of tline,
          wa_fline2 type tline.
    data: it_thead2 type thead.
    data: it_fline3 type standard table of tline,
          wa_fline3 type tline.
    data: it_thead3 type thead.
    data: it_fline4 type standard table of tline,
          wa_fline4 type tline.
    data: it_thead4 type thead.
    data: it_fline5 type standard table of tline,
          wa_fline5 type tline.
    data: it_thead5 type thead.
    data: wa_header         like line of it_header,
          wa_item           like line of it_item,
          wa_err            type ty_err,
         wa_bill           LIKE LINE OF it_bill,
         wa_bill1          LIKE LINE OF it_bill,
          wa_iterr          like line of it_err,
          wa_t685a          like line of it_t685a.
         wa_bill_item TYPE ty_bill_item.
    data: it_schedule_line  type standard table of ty_schedule_line,
          wa_schedule_line type ty_schedule_line.
    data: sales_order_no     type bapivbeln-vbeln.
    data: ext_sales_order_no type bapivbeln-vbeln.
    Variable to be used to separate the fields which are concatenated by a
    runtime character
    *DATA: g_tabchar(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
    *DATA: wa_truxs_t_text_data TYPE truxs_t_text_data.
    *DATA: g_filename      TYPE string,
         g_path          TYPE string,
         g_fullpath      TYPE string,
         g_user_action   TYPE i,
         g_file_encoding TYPE abap_encoding.
    *DATA : g_text(8192),
    data : g_mstring1(100) type c,
          g_mstring2(100) type c,
          g_mstring3(100) type c,
          g_mstring4(100) type c,
          g_mstring5(100) type c.
    data: g_count1 type ebelp,
          g_str_count1(6) type c.
    data: g_count type ebelp,
          g_str_count(6) type c.
    *DATA: f_subrc      LIKE sy-subrc,
         f_subrc1     LIKE sy-subrc,
         f_error(500) TYPE c,
         item1(27)    TYPE c,
         item2(27)    TYPE c,
         item3(27)    TYPE c,
         item4(27)    TYPE c,
         i            TYPE ekpo-ebelp.
    *DATA: g_billplan_header TYPE c,
         g_billplan_item TYPE c.
    data : g_external_so type vbak-vbeln. "SO
                          SELECTION-SCREEN
    selection-screen begin of block frame1 with frame title text-001 .
    parameters:p_file1 type rlgrap-filename, "OBLIGATORY, "Header data.
               p_file2 type rlgrap-filename, "OBLIGATORY, "Item Data.
               p_file3 type rlgrap-filename,            "Schedule line.
               p_file4 type rlgrap-filename ."OBLIGATORY. "Error file.
    selection-screen end of block frame1.
    start-of-selection.
      wa_bapi_header-doc_type     =  'Z0MX'. "order type
      wa_bapi_header-sales_org    =  '0130'."sales org
      wa_bapi_header-distr_chan   =  '13'.  "distr channel
      wa_bapi_header-division     =  '13'.  "division
    Old code from copied program
    wa_bapi_header-purch_no_s   =  wa_header-kunnr_2.  " Ship to party
    New code as required in Finland project
    We are using to Header ->Order Tab -> Ship to Party -> Purchase order no (BSTKD_E) to store Old legacy SO number
      wa_bapi_header-purch_no_s   =  'MX100443'.  "External SO i.e Old legacey SO number
      wa_bapi_header-ref_1_s      = '0000666666'. "Sold to party
    wa_bapi_header-ord_reason   =  wa_header-augru.
      wa_bapi_header-purch_no_c   =  'ddr1234'.    " PO number
      wa_bapi_header-purch_date   =  sy-datum.    " PO date
      wa_bapi_header-req_date_h   =  sy-datum.   " Required Delivery Date
      wa_bapi_header-pmnttrms     =  '01'.    " Payment Terms
    wa_bapi_header-incoterms1   =  wa_header-inco1.
    wa_bapi_header-incoterms2   =  wa_header-inco2.
    wa_bapi_header-price_date   =  wa_header-prsdt.    " Pricing date
    wa_bapi_header-currency     =  wa_header-waerk.    " Document Currency
    wa_bapi_header-sales_grp  =  wa_header-vkgrp. " Sales group
    wa_bapi_header-price_list   =  wa_header-pltyp. " Price list type
    wa_bapi_header-cust_group   =  wa_header-kdgrp.   " Cust Group
    wa_bapi_header-ship_type    =  wa_header-vsart.   " Shipping Type
    wa_bapi_header-purch_no_s   =  wa_header-bstkd_e. " Ship-to-party po number
    wa_bapi_header-collect_no   =  wa_header-submi.   " Collective No.
    wa_bapi_header-name         =  wa_header-bname.   " Name
    wa_bapi_header-ref_1        =  wa_header-ihrez.   " Your Reference
    wa_bapi_header-cust_grp1    =  wa_header-kvgr1.   " Industry
    wa_bapi_header-cust_grp2    =  wa_header-kvgr2.   " Customer BU
    *ENDFORM.                    " f_header
    IF wa_header-partner_1 IS NOT INITIAL.
        wa_bapi_partner-partn_role = 'AG'.
        wa_bapi_partner-partn_numb = '0000666666'.
        wa_bapi_partner-itm_number = '000000'.
        append wa_bapi_partner to it_bapi_partner.
        clear wa_bapi_partner.
    ENDIF.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = wa_header-partner_2
        importing
          output = wa_header-partner_2.
    IF wa_header-partner_2 IS NOT INITIAL.
        wa_bapi_partner-partn_role = 'WE'.
        wa_bapi_partner-partn_numb = '0000666666'.
        wa_bapi_partner-itm_number = '000000'.
        append wa_bapi_partner to it_bapi_partner.
        clear wa_bapi_partner.
    ENDIF.
      perform f_item.
    data : order_items_inx type table of bapisditmx with header line.
      order_items_inx-material          = 'X'.  "
      order_items_inx-target_qty        = 'X'.  "
      order_items_inx-comp_quant        = 'X'.  "
      order_items_inx-trgqty_den        = 'X'.
      order_items_inx-rnddlv_qty        = 'X'.
    order_items_inx-updateflag = 'I'.
    order_items_inx-target_qu = 'X'.
      order_items_inx-plant             = 'X'.  "
      append order_items_inx.
      call function 'BAPI_SALESORDER_CREATEFROMDAT2'
        exporting
          salesdocumentin = 'MX11111152'
      order_header_in      = wa_bapi_header
             order_header_inx     = wa_bapi_headerx
      importing
      salesdocument        = sales_order_no
      tables
      return               = it_bapireturn
      order_items_in       = it_bapi_item
      order_items_inx      =  order_items_inx
      order_partners       = it_bapi_partner
       order_conditions_in  = it_bapi_cond.
      if sy-subrc is initial.
      commit work.
      endif.
    *&      Form  f_item
          text
    form f_item .
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = wa_item-posnr
        importing
          output = wa_item-posnr.
      wa_item-posnr = '000010'.
    IF sy-subrc EQ 0. "IS INITIAL.
      move wa_item-posnr to g_str_count."commented out by shakti
    ENDIF.
      wa_bapi_item-itm_number        =  wa_item-posnr.  " Line item
    WA_BAPI_ITEM-PO_ITM_NO         =  WA_ITEM-EBELP.
    wa_bapi_item-division          = wa_item-spart.
      wa_bapi_item-purch_no_c        = 'ddr1234'.   " po number
      wa_bapi_item-purch_date        = sy-datum.   " po date
      wa_bapi_item-purch_no_s        = 'MX11111112'. " Ship-to-party po number
      wa_item-matnr = 'MAXIMO_SERVICE'.
      call function 'CONVERSION_EXIT_MATN1_INPUT'
        exporting
          input        = wa_item-matnr
        importing
          output       = wa_item-matnr
        exceptions
          length_error = 1
          others       = 2.
      if sy-subrc is initial.
        wa_bapi_item-material        = wa_item-matnr.  "material
      endif.
      wa_bapi_item-target_qty        = '1'. " Order qty
      wa_bapi_item-comp_quant = '1'.
      wa_bapi_item-target_qu = 'EA'.
        wa_bapi_item-fixed_quan = '1'.
    wa_bapi_item-comp_quant        = wa_item-kwmeng.
    wa_bapi_item-trgqty_den        = '1'.
    wa_bapi_item-rnddlv_qty        = wa_item-kwmeng.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
         input  = wa_item-ps_psp_pnr
       IMPORTING
         output = wa_item-ps_psp_pnr.
    IF sy-subrc = 0.
       wa_bapi_item-wbs_elem          = wa_item-ps_psp_pnr.
    ENDIF.
      wa_bapi_item-item_categ        = 'ZMAX'.
    wa_bapi_item-ex_rate_fi        = wa_item-kurrf.
    wa_bapi_item-dli_profil        = wa_item-ffprf.   " Dynamic item processor profile
    wa_bapi_item-route             = wa_item-route.   " route
    wa_bapi_item-exchg_rate        = wa_item-kursk.
      wa_bapi_item-plant             = '2090'.   " Plant
      wa_bapi_item-ship_point        = 'FN11'.   " Shipping point
    wa_bapi_item-store_loc         = wa_item-lgort.   " stg loc
    REPLACE ALL OCCURRENCES OF  ',' IN wa_item-ntgew WITH '.'.
    REPLACE ALL OCCURRENCES OF  ',' IN wa_item-brgew WITH '.'.
    wa_bapi_item-net_weight        = wa_item-ntgew.  "
    wa_bapi_item-gross_wght        = wa_item-brgew.  "
      call function 'CONVERSION_EXIT_CUNIT_INPUT'
        exporting
          input    = wa_item-gewei
          language = sy-langu
        importing
          output   = wa_item-gewei.
       EXCEPTIONS
         unit_not_found = 1
         OTHERS         = 2.
    IF sy-subrc <> 0.
    ENDIF.
      wa_bapi_item-untof_wght        =  'KG'.  " weight unit
      replace all occurrences of  ',' in wa_item-kursk with '.'.
      replace all occurrences of  ',' in wa_item-kurrf with '.'.
    wa_bapi_item-profit_ctr        = wa_item-prctr.   " Profit center
    wa_bapi_item-resanalkey        = wa_item-abgrs.   " RESULT ANALYSIS KEY
    wa_bapi_item-cstg_sheet        = wa_item-kalsm_k. " COSTING SHEET
      append wa_bapi_item to it_bapi_item.
    endform.                    " f_item
    Thanks & regards,
    Chetan

    see the following to create sales order:-
    *& Report  ZSALESORDER
    *&DEVELOPED BY JANI KRUPA 4.10.2008
    REPORT  ZSALESORDER.
    Parameters
    Sales document type
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
    PARAMETERS: p_auart TYPE auart OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Sales organization
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
    PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Distribution channel
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
    PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Division.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
    PARAMETERS: p_spart TYPE spart OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SKIP 1.
    Sold-to
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
    PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Ship-to
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
    PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SKIP 1.
    Material
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
    PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Quantity.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
    PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    Plant
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
    PARAMETERS: p_plant TYPE werks_d .
    SELECTION-SCREEN END OF LINE.
    Complete Deliver
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(20) v_text10 FOR FIELD p_autlf.
    PARAMETERS: p_autlf TYPE autlf DEFAULT 'X'.
    SELECTION-SCREEN END OF LINE.
    Data declarations.
    DATA: v_vbeln            LIKE vbak-vbeln.
    DATA: header             LIKE bapisdhead1.
    DATA: headerx            LIKE bapisdhead1x.
    DATA: item               LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
    DATA: itemx              LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
    DATA: partner            LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
    DATA: return             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
    DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                             WITH HEADER LINE.
    DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                             WITH HEADER LINE.
    DATA: lt_schedules_ink    TYPE STANDARD TABLE OF bapisdhead1
                             WITH HEADER LINE.
    Initialization.
    INITIALIZATION.
    v_text   = 'Order type'.
    v_text1  = 'Sales Org'.
    v_text2  = 'Distribution channel'.
    v_text3  = 'Division'.
    v_text4  = 'Sold-to'.
    v_text5  = 'Ship-to'.
    v_text6  = 'Material'.
    v_text7  = 'Quantity'.
    v_text9  = 'Plant'.
    v_text10 = 'Complete delivery'.
    Start-of-selection.
    START-OF-SELECTION.
    Header data
    Sales document type
      header-doc_type = p_auart.
      headerx-doc_type = 'X'.
    Sales organization
      header-sales_org = p_vkorg.
      headerx-sales_org = 'X'.
    Distribution channel
      header-distr_chan  = p_vtweg.
      headerx-distr_chan = 'X'.
    Division
      header-division = p_spart.
      headerx-division = 'X'.
      headerx-updateflag = 'I'.
    *Complete delivery
        header-COMPL_DLV = p_autlf.
        header-COMPL_DLV = 'X'.
    Partner data
    Sold to
      partner-partn_role = 'AG'.
      partner-partn_numb = p_sold.
      APPEND partner.
    Ship to
      partner-partn_role = 'WE'.
      partner-partn_numb = p_ship.
      APPEND partner.
    ITEM DATA
      itemx-updateflag = 'I'.
    Line item number.
      item-itm_number = '000010'.
      itemx-itm_number = 'X'.
    Material
      item-material = p_matnr.
      itemx-material = 'X'.
    Plant
      item-plant    = p_plant.
      itemx-plant   = 'X'.
    Quantity
      item-target_qty = p_menge.
      itemx-target_qty = 'X'.
    item category
      itemx-ITEM_CATEG = 'X'.
      APPEND item.
      APPEND itemx.
      ITEM DATA
      itemx-updateflag = 'I'.
    Line item number.
      item-itm_number = '000020'.
      itemx-itm_number = 'X'.
    Material
      item-material = p_matnr.
      itemx-material = 'X'.
    Plant
      item-plant    = p_plant.
      itemx-plant   = 'X'.
    Quantity
      item-target_qty = p_menge.
      itemx-target_qty = 'X'.
      APPEND item.
      APPEND itemx.
      Fill schedule lines
      lt_schedules_in-itm_number = '000010'.
      lt_schedules_in-sched_line = '0001'.
      lt_schedules_in-req_qty    = p_menge.
      APPEND lt_schedules_in.
      Fill schedule line flags
      lt_schedules_inx-itm_number  = '000010'.
      lt_schedules_inx-sched_line  = '0001'.
      lt_schedules_inx-updateflag  = 'X'.
      lt_schedules_inx-req_qty     = 'X'.
      APPEND lt_schedules_inx.
      Fill schedule lines
      lt_schedules_in-itm_number = '000020'.
      lt_schedules_in-sched_line = '0001'.
      lt_schedules_in-req_qty    = p_menge.
      APPEND lt_schedules_in.
      Fill schedule line flags
      lt_schedules_inx-itm_number  = '000020'.
      lt_schedules_inx-sched_line  = '0001'.
      lt_schedules_inx-updateflag  = 'X'.
      lt_schedules_inx-req_qty     = 'X'.
      APPEND lt_schedules_inx.
    Call the BAPI to create the sales order.
      CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
           EXPORTING
                sales_header_in     = header
                sales_header_inx    = headerx
           IMPORTING
                salesdocument_ex    = v_vbeln
           TABLES
                return              = return
                sales_items_in      = item
                sales_items_inx     = itemx
                sales_schedules_in  = lt_schedules_in
                sales_schedules_inx = lt_schedules_inx
                sales_partners      = partner.
    Check the return table.
      LOOP AT return WHERE type = 'E' OR type = 'A'.
        EXIT.
      ENDLOOP.
      IF sy-subrc = 0.
        WRITE: / 'Error in creating document'.
      ELSE.
    Commit the work.
        COMMIT WORK AND WAIT.
        WRITE: / 'Document ', v_vbeln, ' created'.
      ENDIF.

  • BAPI_SALESORDER_CREATEFROMDAT2 is not updating the ITEM Qty after Free ITEM

    Hi,
    I am using BAPI_SALESORDER_CREATEFROMDAT2 to create a order.We have customization for populating a FREE ITEM for a Order ITEM.
    Now the Problem is that .....if I am passing more then one Material as ITEM it is not updating the next ITEM Qty and also not populating FREE ITEM afterwords first one.
    Please help me.
    Regards
    Ricky

    Hi,
    Find below the code :
      read table i_table_t into lwa_table_s index 1.
      if sy-subrc eq 0.
    *Order Header
        lwa_ord_head_in-doc_type          = 'ZSO'.
        lwa_ord_head_in-sales_org         = '1000'.
        lwa_ord_head_in-distr_chan        = '10'.
        lwa_ord_head_in-division          = '10'.
        lwa_ord_head_in-req_date_h        = lwa_table_s-delivery.
    *Order Header Update
        lwa_ord_head_inx-doc_type         = 'X'.
        lwa_ord_head_inx-sales_org        = 'X'.
        lwa_ord_head_inx-distr_chan       = 'X'.
        lwa_ord_head_inx-division         = 'X'.
        lwa_ord_head_inx-req_date_h       = 'X'.
        lwa_ord_partners-partn_role       =  'AG'.
        lwa_ord_partners-partn_numb       =  lwa_table_s-sold_to.
        append lwa_ord_partners to lt_ord_partners.
        if lwa_table_s-ship_to is initial.
          lwa_ord_partners-partn_role     =  'WE'.
          lwa_ord_partners-partn_numb     =  lwa_table_s-sold_to.
          append lwa_ord_partners to lt_ord_partners.
        else.
          lwa_ord_partners-partn_role     =  'WE'.
          lwa_ord_partners-partn_numb     =  lwa_table_s-ship_to.
          append lwa_ord_partners to lt_ord_partners.
        endif.
        lt_table_it_t = lwa_table_s-zsd_table_it_t.
        loop at   lt_table_it_t into lwa_table_it_s.
          lwa_ord_items_in-material      = lwa_table_it_s-matnr.
          lwa_ord_items_in-plant         = wa_table_s-plant.
          lwa_ord_items_in-target_qty    = lwa_table_it_s-qty.
          lwa_ord_items_in-comp_quant    = lwa_table_it_s-qty.
          append lwa_ord_items_in to lt_ord_items_in.
          lwa_ord_items_inx-material     = 'X'.
          lwa_ord_items_inx-plant        = 'X'.
          lwa_ord_items_inx-target_qty   = 'X'.
          lwa_ord_items_inx-comp_quant   = 'X'.
          lwa_ord_items_inx-updateflag   = 'I'.
          append lwa_ord_items_inx to lt_ord_items_inx.
    Schedule Line Information
          lwa_schedule_lines-sched_line  = 'X'.
          lwa_schedule_lines-req_date    = lwa_table_s-date_del.
          lwa_schedule_lines-date_type   = '1'.
          lwa_schedule_lines-req_qty     = lwa_table_it_s-qty.
          append lwa_schedule_lines to lt_schedule_lines.
          lwa_schedule_lines_x-updateflag = 'I'.
          lwa_schedule_lines_x-sched_line = 'X'.
          lwa_schedule_lines_x-req_date   = 'X'.
          lwa_schedule_lines_x-date_type  = 'X'.
          lwa_schedule_lines_x-req_qty    = 'X'.
          append lwa_schedule_lines_x to lt_schedule_lines_x.
        endloop.
    Here I am getting First Item and it's free configured Item perfectly for the Qty 1.
    But when I pass more then 1 Qty or Multiple ITEMS it is not populating other respective free configured ITEMS with them.Also IT is not updating the other ITEM Qty other the first one.
    For Example:
    Item  No      ITEM            Qty           .......
    10             ITEM1           1 EA        ..........
    20             FREE1          1 DAY     ..........
    30             ITEM2            0             ..........
    40             ITEM3            0             .........
    In above example After 30 and 40 two Free ITEM should be generated with 1 Day and for Qty 1 EA
    Regards
    Ricky

  • Error BAPI_SALESORDER_CREATEFROMDAT2

    hi..........
    error in uploading item details.
    can you guide me how to upload item details using BAPI_SALESORDER_CREATEFROMDAT2 method........
    thanks & regards
    prabhakar
    Edited by: Prabhakar on Mar 25, 2010 5:33 PM

    Try this:
    REPORT z_bapi_create_sales_order_test .
    Order header:
    - Order type: OR Important you must use the german code TA
    - Sales org: 1000
    - Distrb. chan.: 10
    - Division: 00
    - Sold to party: 1032
    - Ship to party: 1032
    - Purch order: DG-19970626-3
    Order item:
    - Material: P-100
    - Qty: 1
    DATA:
    Order partners
    li_order_partners TYPE STANDARD TABLE OF bapiparnr,
    l_order_partners LIKE bapiparnr,
    Structures for order header
    l_order_header_in LIKE bapisdhd1,
    l_order_header_inx LIKE bapisdhd1x,
    Tables for order items
    li_order_items_in TYPE STANDARD TABLE OF bapisditm,
    l_order_items_in LIKE bapisditm,
    li_order_items_inx TYPE STANDARD TABLE OF bapisditmx,
    l_order_items_inx LIKE bapisditmx,
    Return table from bapi call
    li_return TYPE STANDARD TABLE OF bapiret2,
    l_return TYPE bapiret2,
    Sales document number
    l_vbeln LIKE bapivbeln-vbeln,
    Error flag
    l_errflag(1) TYPE c.
    START-OF-SELECTION.
    Build partner information
    CLEAR l_order_partners.
    l_order_partners-partn_role = 'AG'. "Remember German codes !
    l_order_partners-partn_numb = '0000001032'.
    APPEND l_order_partners TO li_order_partners.
    Build order header
    Update flag
    l_order_header_inx-updateflag = 'I'.
    Sales document type
    l_order_header_in-doc_type = 'TA'. "Remember German codes !
    l_order_header_inx-doc_type = 'X'.
    Sales organization
    l_order_header_in-sales_org = '1000'.
    l_order_header_inx-sales_org = 'X'.
    Distribution channel
    l_order_header_in-distr_chan = '10'.
    l_order_header_inx-distr_chan = 'X'.
    Division
    l_order_header_in-division = '00'.
    l_order_header_inx-division = 'X'.
    Purchase order
    l_order_header_in-purch_no_c = 'DG-19970626-300'.
    l_order_header_inx-purch_no_c = 'X'.
    Build order item(s) - Only 1 is used in this example
    l_order_items_in-itm_number = '10'.
    l_order_items_inx-itm_number = '10'.
    l_order_items_in-material = 'P-100'.
    l_order_items_inx-material = 'X'.
    l_order_items_in-comp_quant = '1.000'.
    l_order_items_inx-comp_quant = 'X'.
    APPEND l_order_items_in TO li_order_items_in.
    l_order_items_inx-updateflag = 'I'.
    APPEND l_order_items_inx TO li_order_items_inx.
    CALL Bapi
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
    order_header_in = l_order_header_in
    order_header_inx = l_order_header_inx
    testrun = 'X'
    IMPORTING
    salesdocument = l_vbeln
    TABLES
    return = li_return
    order_items_in = li_order_items_in
    order_items_inx = li_order_items_inx
    order_partners = li_order_partners.
    END-OF-SELECTION.
    Check and write Return table
    CLEAR l_errflag.
    WRITE: / 'Sales dcoument: ', l_vbeln.
    LOOP AT li_return INTO l_return.
    WRITE: / l_return-type, l_return-message(50).
    IF l_return-type = 'E'.
    l_errflag = 'X'.
    ENDIF.
    ENDLOOP.
    No errors - Commit
    IF l_errflag IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.

  • Regarding sales order creation with "BAPI_SALESORDER_CREATEFROMDAT2"

    Hi Experts,
    I am facing an issue when creating a sales order with FM "BAPI_SALESORDER_CREATEFROMDAT2" it is showing the error
    V1 -761 as " unpermitted combination of BUS 2032 with Sales document category L" .
    In VA01 ,if i provide the fallowing details
    Sales org 1000
    dist        10
    div         10
    item no 10 material-52 plant 1000 shipping point -0001 target qty-1,uOM-EA,weight unit-KG
    billing date 11022011
    pricing date-11022011
    currency - GBP
    shipping party -1
    sold to party -1
    buyer - 1
    bill-to-party -1
    it is creating the sales order.
    what could be the problem with this BAPI..
    Please help.
    Regards
    Vishnu

    Hi Vishnu,
    First try with minimum data for header and item .Check the documentation of that bapi.
    DATA:
    Order partners
    li_order_partners TYPE STANDARD TABLE OF bapiparnr,l_order_partners LIKE bapiparnr,l_order_header_in LIKE bapisdhd1,
    li_order_items_in TYPE STANDARD TABLE OF bapisditm,l_order_items_in LIKE bapisditm,li_order_items_inx TYPE STANDARD TABLE OF bapisditmx,l_order_items_inx LIKE bapisditmx,return TYPE STANDARD TABLE OF bapiret2,l_return TYPE bapiret2,
    l_vbeln LIKE bapivbeln-vbeln,
    CLEAR l_order_partners.
    l_order_partners-partn_role = 'AG'. "Remember German codes !
    l_order_partners-partn_numb = '0000001032'.
    APPEND l_order_partners TO li_order_partners.
    Sales document type
    l_order_header_in-doc_type = 'TA'. "Remember German codes !
    l_order_header_inx-doc_type = 'X'.
    Sales organization
    l_order_header_in-sales_org = '1000'.
    l_order_header_in-distr_chan = '10'.
    l_order_header_in-division = '00'.
    l_order_items_in-itm_number = '10'.
    l_order_items_in-material = 'abcmaterial'.
    l_order_items_in-comp_quant = '1'.
    APPEND l_order_items_in TO li_order_items_in.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
    order_header_in = l_order_header_in
    IMPORTING
    salesdocument = l_vbeln
    TABLES
    return = li_return
    order_items_in = li_order_items_in
    order_partners = li_order_part
    WRITE: /  l_vbeln.
    IF l_errflag IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.
    For the above document type , sales organisation,distribution channel,division,customer,material check with you functional consultants and take the exact  combination of data. That combination is very important.Please ask t if you need more help in this.
    Regards,
    Madhu.
    Edited by: madhurao123 on Mar 3, 2011 5:11 AM

  • BAPI_SalesOrder_CreateFromDat2 fails for items with free goods

    Hi all, I have a very weird problem when I am trying to create a sales order using SAP .net connector with the BAPI function BAPI_SalesOrder_CreateFromDat2().  The problem happens through the following scenario:
    1 - Item X has a free good rule on it that states "If user buys 5 Cartoons of Item X he will take 1 pack of Item Y free of charge" while Item Z has no rules like this
    2 - using BAPI and .net connector, an order is needed to be created with following details:
            a - Item X with quantity 6 Cartoons.
            b- Item Z with quantity 3 Cartoons
    3 - If BAPI_SalesOrder_CreateFromDat2() assigns these details to Order_Items_In with the same order (a then b),  SAP will return an error for Item z that states "No item category available (Table T184 ZKE NORM  KEN)."; while if the function tries to create the order with details in reverse order (b then a ), the order will be created successfully.
    I have done the following steps:
    1 - Tried the same order in SAP GUI but it succeeded. (So no problem in Item Category Determination)
    2 - Tries the same order with the suspicious order in the BAPI function Test inside SAP GUI (using tcode BAPI or SE37) but the function had not return any errors also.
    3 - Tried to send Item Category in code when calling the bapi function (Forced the code to KEN), but the same message appeared as SAP insist on redetermining the Item Category and return this meaningless message.
    thanks

    Hi Mohamed Abd Elbaset,
    I am facing the same issue while creating the Sales order through "BAPI_SALESORDER_CREATEFROMDAT2" All is going well in normal cases but when I process the contract with FREE GOODS line items for which free goods condition record is maintained it fails
    to create the Sales order. Is there any special treatment for this Free goods case..
    Regards,

  • Problem with STORE_LOC in BAPI_SALESORDER_CREATEFROMDAT2

    Hi gurus.
    I'm using BAPI_SALESORDER_CREATEFROMDAT2 to create sales orders and it works almost fine ...
    I've only one problem: is it possible to get automatically the storage?
    If I set the field STORE_LOC in the item, I get that storage in my order, otherwise the storage in the row order is empty.
    But if I insert rows by the transactionVA01/02 I get automatically the storage, I don't need to force it.
    Thanks for your help ...

    Hi
    If Storage Location is assigned against the particular Plant and Shipping point functionally, then using VA01 transaction, it will
    pick the storage location automatically. So when using your BAPI try with passing PLANT or SHIPPING POINT and see whether
    storage location getting populated or not.
    Regards,
    Murali

  • Order quantity in BAPI BAPI_SALESORDER_CREATEFROMDAT2

    Hi,
    I'm using BAPI 'BAPI_SALESORDER_CREATEFROMDAT2' to create a sale order.
    But the order quantity isn't upadate when I check the sales order number.
    The field I used is target_qty in BAPISDITM.
    Is the field wrong or some other problems?
    Best Regards,
    Rachel

    Hi,
    I created SO using BAPI_SALESDOCU_CREATEFROMDATA1. while filling the header and item data, i used to do the following,
    If you are passing some value to 'target_qty', make sure that you are filling the sales_items_inx-req_qty with 'X'. then pass them to the tables import parameters. Please refer the following code.
      fs_sorder-doc_type  = w_auart.
      fs_sorderx-doc_type = c_flag.
      fs_sorder-sales_org  = w_vkorg.
      fs_sorderx-sales_org = c_flag.
      fs_sorder-distr_chan  = w_vtweg.
      fs_sorderx-distr_chan = c_flag.
      fs_sorder-division  = w_spart.
      fs_sorderx-division = c_flag.
      fs_sorderx-updateflag = c_flag.
      fs_partner-partn_role = c_pship.
      fs_partner-partn_numb = w_pship.
      APPEND fs_partner TO t_partner.
      fs_partner-partn_role = c_psold.
      fs_partner-partn_numb = w_psold.
      APPEND fs_partner TO t_partner.
      loop at t_mdata into fs_mdata.
        fs_item-itm_number  = fs_mdata-posnr.
        fs_itemx-itm_number = c_flag.
        fs_item-material    = fs_mdata-matnr.
        fs_itemx-material   = c_flag.
        fs_item-target_qty  = fs_mdata-kwmeng.
        fs_itemx-target_qty = c_flag.
        fs_item-item_categ  = fs_mdata-pstyv.
        fs_itemx-item_categ = c_flag.
        fs_itemx-updateflag = c_flag.
          APPEND fs_item TO t_item.
          APPEND fs_itemx TO t_itemx.
        fs_sline-ITM_NUMBER  = fs_mdata-posnr.
        fs_slinex-ITM_NUMBER = c_flag.
        fs_sline-SCHED_LINE  = c_sline.
        fs_slinex-SCHED_LINE = c_flag.
        fs_sline-REQ_QTY     = fs_mdata-kwmeng.
        fs_slinex-REQ_QTY    = c_flag.
          APPEND fs_sline TO t_sline.
          APPEND fs_slinex TO t_slinex.
      endloop.                             " Loop t_mdata
    ENDFORM.                               " data_fill
    *  FORM CREATE_SO                                                     *
    *  This subroutine calls a BAPI BAPI_SALESDOCU_CREATEFROMDATA1 for    *
    *  creating a sales document.                                         *
    *  There are no interface parameters to be passed to this subroutine. *
    FORM create_so .
      CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
        EXPORTING
          sales_header_in     = fs_sorder
          sales_header_inx    = fs_sorderx
        IMPORTING
          salesdocument_ex    = w_sonum
        TABLES
          return              = t_return
          sales_items_in      = t_item
          sales_items_inx     = t_itemx
          sales_partners      = t_partner
          sales_schedules_in  = t_sline
          sales_schedules_inx = t_slinex.
    ENDFORM.                               " create_SO
    Hope this helps.

  • Sale order item text through BAPI_SALESORDER_CREATEFROMDAT2

    Hi,
    We are creating a sale order through a 'Zprogram'. Uploading the required details from a excel sheet and  passing to a BAPI_SALESORDER_CREATEFROMDAT2.
    We are using the 'order_text' parameter to create the item text. If there are multiple lines in the same item text likes this
    (we are passing it in a single line)
    Order type ORDER_ID   PO number u2026u2026 Item Note - Zi01
    STD                   2                   10                Currency - RS
                                                                       Test order -1
                                                                       Test item - 2                                                                               
    It is creating the sale order with the item text  and the item text when viewed normally its appears one below one. But if we click the 'detail' button and view it through the editor mode it is appearing in the same line with # characters in between.
    TAX_CURRENCY = Rupees #TAX_UNIT_PRICE =0.0000# Test order = 1
    It is replacing the enter statement with '#.' We can split the text where # appears and pass it as a separate line .but this will create a problem when the data itself contains a  # character.
    Please advise how we can avoid this and can create the sale order item text correctly.
    Regards,
    Charumathi Balachandran

    As you said, How are creating single line text from the multi line text.
    I hope you are using a CONTACTENATE statemetn to do so. Please the SEPARATOR being used for this.
    I hope you have copied texts from excel sheet to SE38 editor. Please copy text from Excel to Notepad, then Notepad to SE38.
    Edited by: Priyanka Chowdry on Dec 20, 2010 11:21 AM

  • Clear WBS field in sales order using bapi_salesorder_createfromdat2.

    Hi,
    Situation is this, I have a sales order, where the WBS element in the line item is populated. I want to clear that field to blank and save the sales order.
    When I try to do that using the bapi_salesorder_createfromdat2, it says that it is successful, but when I go back to the sales order and see that field is still populated and not cleared. But the same field if I clear it through VA02 it works fine.
    Header level update flag is set as 'U'.
    I have tried setting up 'D' 'U' and 'I' for the update flag for the line item. Still no luck.
    Given below is the sample code, did anybody else also faced the same issue.
    Data Section.
    data : sal_t_in type standard table of BAPISDHD1,
           sal_s_in like line of sal_t_in.
    *data : sal_t_in type standard table of BAPISDH1,
    *       sal_s_in like line of sal_t_in.
    data : ret_t type standard table of bapiret2,
           ret_s like line of ret_t.
    data : partner_t type standard table of bapiparnr,
           partner_s like line of partner_t.
    data : item_t type standard table of bapisditm,
           item_s like line of item_t.
    data : item_t_inx type standard table of BAPISDITMX,
           item_s_inx like line of item_t_inx.
    data : schdl_t type standard table of BAPISCHDL,
           schdl_s like line of schdl_t.
    data : schdl_t_inx type standard table of BAPISCHDLX,
           schdl_s_inx like line of schdl_t_inx.
    data : ord_view type order_view.
    data : sal_t_key type standard table of sales_key,
           sal_s_key like line of sal_t_key.
    data : ord_t_hdr type standard table of bapisdhd,
           ord_s_hdr like line of ord_t_hdr.
    data : ord_t_itm type standard table of bapisdit,
           ord_s_itm like line of ord_t_itm.
    data : hdr_inx type BAPISDHD1X.
    data : hdr2_inx type BAPISDH1X.
    data : qty type DZMENG.
    data : logic_switch type BAPISDLS.
    data : sd_doc_out type BAPIVBELN-VBELN.
    data : sd_hdr_out type BAPISDHD.
    data : sd_hdr_stat type BAPISDHDST.
    Logic Section.
    sal_s_in-doc_type = 'ZOR'.
    hdr_inx-updateflag = 'U'.
    ord_view-header = 'X'.
    ord_view-item = 'X'.
    sal_s_key-vbeln = '0000001067'.
    append sal_s_key to sal_t_key.
    call function 'BAPISDORDER_GETDETAILEDLIST'
      exporting
        i_bapi_view                   = ord_view
    *   I_MEMORY_READ                 =
      tables
        sales_documents               = sal_t_key
       ORDER_HEADERS_OUT             = ord_t_hdr
       ORDER_ITEMS_OUT               = ord_t_itm
    *   ORDER_SCHEDULES_OUT           =
    *   ORDER_BUSINESS_OUT            =
    *   ORDER_PARTNERS_OUT            =
    *   ORDER_ADDRESS_OUT             =
    *   ORDER_STATUSHEADERS_OUT       =
    *   ORDER_STATUSITEMS_OUT         =
    *   ORDER_CONDITIONS_OUT          =
    *   ORDER_COND_HEAD               =
    *   ORDER_COND_ITEM               =
    *   ORDER_COND_QTY_SCALE          =
    *   ORDER_COND_VAL_SCALE          =
    *   ORDER_CONTRACTS_OUT           =
    *   ORDER_TEXTHEADERS_OUT         =
    *   ORDER_TEXTLINES_OUT           =
    *   ORDER_FLOWS_OUT               =
    *   ORDER_CFGS_CUREFS_OUT         =
    *   ORDER_CFGS_CUCFGS_OUT         =
    *   ORDER_CFGS_CUINS_OUT          =
    *   ORDER_CFGS_CUPRTS_OUT         =
    *   ORDER_CFGS_CUVALS_OUT         =
    *   ORDER_CFGS_CUBLBS_OUT         =
    *   ORDER_CFGS_CUVKS_OUT          =
    *   ORDER_BILLINGPLANS_OUT        =
    *   ORDER_BILLINGDATES_OUT        =
    *   ORDER_CREDITCARDS_OUT         =
    *   EXTENSIONOUT                  =
    loop at ord_t_itm into ord_s_itm.
    move-corresponding ord_s_itm to item_s.
    call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
      exporting
        input         = item_s-WBS_ELEM
    IMPORTING
       OUTPUT        = item_s-WBS_ELEM
    *move space to item_s-WBS_ELEM.
    append item_s to item_t.
    endloop.
    clear item_s_inx.
    item_s_inx-updateflag = 'D'.
    item_s_inx-wbs_elem = 'X'.
    append item_s_inx to item_t_inx.
    call function 'BAPI_SALESORDER_CREATEFROMDAT2'
      exporting
        SALESDOCUMENTIN               = '0000001067'
        order_header_in               = sal_s_in
        ORDER_HEADER_INX              = hdr_inx
    *   SENDER                        =
    *   BINARY_RELATIONSHIPTYPE       =
    *   INT_NUMBER_ASSIGNMENT         =
    *   BEHAVE_WHEN_ERROR             =
    *   LOGIC_SWITCH                  =
    *   TESTRUN                       =
    *   CONVERT                       = ' '
    * IMPORTING
    *   SALESDOCUMENT                 =
      tables
        RETURN                        = ret_t
       ORDER_ITEMS_IN                = item_t
       ORDER_ITEMS_INX               = item_t_inx
        order_partners                = partner_t
    *   ORDER_SCHEDULES_IN            =
    *   ORDER_SCHEDULES_INX           =
    *   ORDER_CONDITIONS_IN           =
    *   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                    =
    *   ORDER_KEYS                    =
    *   EXTENSIONIN                   =
    *   PARTNERADDRESSES              =
    call function 'BAPI_TRANSACTION_COMMIT'
    * EXPORTING
    *   WAIT          =
    * IMPORTING
    *   RETURN        =
    Result I get when I execute is
    S     V4     233     SALES_HEADER_IN has been processed successfully     VBAKKOM
    S     V4     233     SALES_ITEM_IN has been processed successfully          VBAPKOM     000001
    S     V1     311     Standard order 1067 has been saved          Standard order     1067
    Which means it says it save successfully..but data is not changed.
    Any Ideas??
    Thanks and Regards,
    Mahesh.

    Hi,
    The problem is fixed. The item inx table I was not passing the item number field, so the bapi was not knowing which line item to update.
    It was a stupid overlook on my part.
    Thanks and Regards,
    Mahesh.

  • Order schedule lines not created using BAPI_SALESORDER_CREATEFROMDAT2

    Hi experts,
      I am creating sales order using BAPI_SALESORDER_CREATEFROMDAT2. I want to update the Order quantity in VBAP-KWMENG.I got the information from SDN when including the Schedule line in BAPI 'BAPI_SALESORDER_CREATEFROMDAT2  '.
      I tried by using Update flag = 'I'.I am not able to update, what are the values to be passed and how to update the field.
    Is there any other way..Please suggest me..
    Thanks&Regards,
    Karthik.

    Hi, In the BAPI if you look at the tables parameter you will find ORDER_ITEMS_IN and ORDER_ITEMS_INX as well as ORDER_SCHEDULES_IN and ORDER_SCHEDULES_INX. To update KWMENG you will have to pass that value to ORDER_ITEMS_IN-TARGET_QTY and update the same in the table ORDER_ITEMS_INX (ORDER_ITEMS_INX-TARGET_QTY) with 'X'.
    For updating schedule line go for ORDER_SCHEDULES_IN-SCHED_LINE and update X for the same in ORDER_SCHEDULES_INX.
    Try looking into the following code, I am filling in both the Item data as well as the Schedule line data.
      loop at t_mdata into fs_mdata.
        fs_item-itm_number  = fs_mdata-posnr.
        fs_itemx-itm_number = c_flag.
        fs_item-material    = fs_mdata-matnr.
        fs_itemx-material   = c_flag.
        fs_item-target_qty  = fs_mdata-kwmeng.
        fs_itemx-target_qty = c_flag.
        fs_item-item_categ  = fs_mdata-pstyv.
        fs_itemx-item_categ = c_flag.
        fs_itemx-updateflag = c_flag.
          APPEND fs_item TO t_item.
          APPEND fs_itemx TO t_itemx.
        fs_sline-ITM_NUMBER  = fs_mdata-posnr.
        fs_slinex-ITM_NUMBER = c_flag.
        fs_sline-SCHED_LINE  = c_sline.
        fs_slinex-SCHED_LINE = c_flag.
        fs_sline-REQ_QTY     = fs_mdata-kwmeng.
        fs_slinex-REQ_QTY    = c_flag.
          APPEND fs_sline TO t_sline.
          APPEND fs_slinex TO t_slinex.
      endloop.                             " Loop t_mdata
    c_flag contains 'X'.
    fs_item is of structure ORDER_ITEMS_IN.
    fs_sline is of structure ORDER_SCHEDULES_IN.

  • Quantity is not updating while using BAPI_SALESORDER_CREATEFROMDAT2

    Hi all,
    i am Creating Sales Order using BAPI_SALESORDER_CREATEFROMDAT2 BAPI,
    Here i am passing all required fields. Sales order also created, but in the created order; quantiy value is updating as 0 only. Even though i passed the value.(BAPISDITM-ARGET_QTY)
    My bapi is returning...
    SALES_HEADER_IN has been processed successfully
    SALES_ITEM_IN has been processed successfully
    The sales document is not yet complete: Edit data
    Standard Order 12323 has been saved
    Help me to solve it.
    Thanks
    Regards

    You cannot update quantinty from that field
    use the REQ_QTY field in  ORDER_SCHEDULES_IN
    and set its corresponding flag in  ORDER_SCHEDULES_INX to X
    It will work

  • How to gen Schedule line automatical.y by BAPI_SALESORDER_CREATEFROMDAT2

    Dears,
       I am using BAPI_SALESORDER_CREATEFROMDAT2 to create Sales Order,
    everything goes on well, but the only problem is i have to input the schedule line myself by providing the   SCHEDULE_LINES& SCHEDULE_LINESX parameter.
      Just wondering...is there any way to let 
      BAPI_SALESORDER_CREATEFROMDAT2  create schedule line automatically,
      just like what we do in frontend, after we input the order quantity in line item , the
      schedule line will be generated automatically...

    Hello,
    You can use FM: BAPI_SALESORDER_CHANGE with update indicator I (insert)
      call function 'BAPI_SALESORDER_CHANGE'
        exporting
          salesdocument    = l_vbeln
          order_header_inx = l_wa_order_header_inx
          simulation       = l_simulation
        tables
          return           = l_i_return
          order_item_in    = l_i_order_item
          order_item_inx   = l_i_order_item_inx
          partners         = l_i_partners
          schedule_lines   = l_i_schedule_lines
          schedule_linesx  = l_i_schedule_linesx
          extensionin      = l_i_extensionin.
    Thanks
    Subhankar

  • Error while creating a sales order BAPI_SALESORDER_CREATEFROMDAT2

    Hi All,
    I am using the BAPI BAPI_SALESORDER_CREATEFROMDAT2 to create a sales order.
    I am passing all the required fields and also the rejection code at the item level.
    Also I am using a variant configuration material and hence ai am filling the VC config tables.
    When I execute this BAPI it is giving me the error 'Item 000010's configuration can no longer be changed' although configuration is maintained for this material.
    When I try the same case with no rejection code and with VC configuration, the sales order is created.
    When I try the same case again with rejection code and NO VC configuration, the sales order is created.
    When I maintain both the rejection code and VC configuration I am getting the error.
    Does anyone have any idea what is causing this error or I am supposed to populate any flag in ORDER_ITEMS_INX to get this correctly.
    Any answers will be greatly apppreciated!
    Thanks
    Sandeep

    Sandeep,
    There are a few SAP Notes that you should investigate, some of which you may have already seen.  First, I'd suggest you look at [Note 481102|https://service.sap.com/sap/support/notes/481102] and its three related Notes: [774346|https://service.sap.com/sap/support/notes/774346], [550431|https://service.sap.com/sap/support/notes/550431], [366265|https://service.sap.com/sap/support/notes/366265].
    If these Notes do not help then check if [Note 1099414|https://service.sap.com/sap/support/notes/1099414] has been applied in your system.  If it has been applied, then [Note 1116144|https://service.sap.com/sap/support/notes/1116144] might solve your issue.  If neither of these two notes are applied, then it could be that they both need to be applied.  However, if both notes are already applied, then you may want to consider opening a customer message with SAP.  Since these two SAP Notes are relatively new, it makes me think that you might have discovered a related error that has not been reported to SAP yet.
    Best Regards,
    Jamie

  • BAPI_SALESORDER_CREATEFROMDAT2 & Confirmed Qty NOT being set

    Good day!
    Creating orders via BAPI_SALESORDER_CREATEFROMDAT2.  Orders are being created successfully. However, CONFIRMED QTY is set to 0, and NOT triggering.
    The following settings have been confirmed.
    - Majority of all communication field settings are set to "X" at Header, Item, schedule, and condition.
    - All itm_number are set accordingly to respective posnr
    - All updateflag are set accordingly
    - Set comp_dlv and part_dlv to ' '.
    From a functional perspective, what configurations HAVE to be completed to ensure Deliveries are triggered via respective BAPI?  I understand, availability check is performed in background so screens cannot be performed--thus, no partial or full delivery can be filled.
    Any pointers will be appreciative. Thanks in advance.

    I seem to remember having that issue before.  I believe the fix in that particular case was that the storage location was not specified in the BAPI call for items that were ATP-relevant.  Of course, if your ATP check is at the shipping point level, if you don't specify the shipping point, you won't get a confirmation either.  As usual, I believe I tracked it down with the good old debugger.

Maybe you are looking for