Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_SALESORDER_CREATEFROMDAT2

Former Member
0 Likes
1,570

Hi everyone,

I'm a abap beginner who's trying bravely to create a sales order with this bapi: BAPI_SALESORDER_CREATEFROMDAT2

but it always reject my demand with this message: "Condition PR00 is not allowed as header condition" and "Sales document was not changed" although I'm trying to create one.

how i loaded the header:

IF t_header-doc_type IS NOT INITIAL.
    s_so_header-doc_type = t_header-doc_type.
    s_so_headerx-updateflag = 'I'.
    s_so_headerx-doc_type = 'X'.
  ENDIF.

  IF t_header-sales_org IS NOT INITIAL.
    s_so_header-sales_org = t_header-sales_org.
    s_so_headerx-sales_org = 'X'.
  ENDIF.

  IF t_header-distr_chan IS NOT INITIAL.
    s_so_header-distr_chan = t_header-distr_chan.
    s_so_headerx-distr_chan = 'X'.
  ENDIF.

  IF t_header-division IS NOT INITIAL.
    s_so_header-division = t_header-division.
    s_so_headerx-division = 'X'.
  ENDIF.

  IF t_header-req_date_h NE '00000000'.
    s_so_header-req_date_h = t_header-req_date_h.
    s_so_headerx-req_date_h = 'X'.
  ENDIF.

  IF t_header-purch_no_c IS NOT INITIAL.
    s_so_header-purch_no_c = t_header-purch_no_c.
    s_so_headerx-purch_no_c = 'X'.
  ENDIF.

  IF t_header-purch_date NE '00000000'.
    s_so_header-purch_date = t_header-purch_date.
    s_so_headerx-purch_date = 'X'.
  ENDIF.

  IF t_header-ref_1 IS NOT INITIAL.
    s_so_header-ref_1 = t_header-ref_1.
    s_so_headerx-ref_1 = 'X'.
  ENDIF.

  IF t_header-partn_numb_sh IS NOT INITIAL.
    t_so_partners-partn_role = 'WE'. "Ship to party SH -> WE
    t_so_partners-partn_numb = t_header-partn_numb_sh.
    APPEND t_so_partners.
  ENDIF.

  IF t_header-partn_numb_sp IS NOT INITIAL.
    t_so_partners-partn_role = 'AG'. "Sold to party SP -> AG
    t_so_partners-partn_numb = t_header-partn_numb_sp.
    APPEND t_so_partners.
  ENDIF.

  IF t_header-ord_reason IS NOT INITIAL.
    s_so_header-ord_reason = t_header-ord_reason.
    s_so_headerx-ord_reason = 'X'.
  ENDIF.

  IF t_header-price_date NE '00000000'.
    s_so_header-price_date = t_header-price_date.
    s_so_headerx-price_date = 'X'.
  ENDIF.

  IF t_header-dlv_block IS NOT INITIAL.
    s_so_header-dlv_block = t_header-dlv_block.
    s_so_headerx-dlv_block = 'X'.
  ENDIF.

  IF t_header-bill_block IS NOT INITIAL.
    s_so_header-bill_block = t_header-bill_block.
    s_so_headerx-bill_block = 'X'.
  ENDIF.

how i fed the items:

IF s_t_items-itm_number IS NOT INITIAL.
    t_so_items-itm_number = s_t_items-itm_number.
    t_so_itemsx-itm_number = s_t_items-itm_number.
    t_so_itemsx-updateflag = 'I'.
    t_so_itemsx-po_itm_no = s_t_items-itm_number.
  ENDIF.

  IF s_t_items-material IS NOT INITIAL.
    t_so_items-material = s_t_items-material.
    t_so_itemsx-material = 'X'.
  ENDIF.

  IF s_t_items-short_text IS NOT INITIAL.
    t_so_items-short_text = s_t_items-short_text.
    t_so_itemsx-short_text = 'X'.
  ENDIF.

  IF s_t_items-item_categ IS NOT INITIAL.
    t_so_items-item_categ = s_t_items-item_categ.
    t_so_itemsx-item_categ = 'X'.
  ENDIF.

  IF s_t_items-comp_quant IS NOT INITIAL.
    t_so_items-comp_quant = s_t_items-comp_quant.
    t_so_itemsx-comp_quant = 'X'.
  ENDIF.

  IF s_t_items-sales_unit IS NOT INITIAL.
    t_so_items-sales_unit = s_t_items-sales_unit.
    t_so_itemsx-sales_unit = 'X'.
  ENDIF.

  IF s_t_items-cond_type IS NOT INITIAL.
    t_so_cond-cond_type  = s_t_items-cond_type.
    t_so_condx-cond_type  = 'X'.
  ENDIF.

  IF s_t_items-cond_value IS NOT INITIAL.
    t_so_cond-cond_value = s_t_items-cond_value.
    t_so_condx-cond_value = 'X'.
  ENDIF.

  IF s_t_items-currency IS NOT INITIAL.
    t_so_cond-currency = s_t_items-currency.
    t_so_condx-currency = 'X'.
  ENDIF.
  t_so_cond-itm_number = s_t_items-itm_number.
  t_so_condx-updateflag = 'I'.
  t_so_condx-itm_number = s_t_items-itm_number.
  APPEND: t_so_cond, t_so_condx.

  IF s_t_items-profit_ctr IS NOT INITIAL.
    t_so_items-profit_ctr = s_t_items-profit_ctr.
    t_so_itemsx-profit_ctr = 'X'.
  ENDIF.

  IF s_t_items-dlv_date NE '00000000'.
    t_so_schdl-itm_number = s_t_items-itm_number.
    t_so_schdl-dlv_date = s_t_items-dlv_date.
    t_so_schdlx-itm_number = s_t_items-itm_number.
    t_so_schdlx-updateflag = 'I'.
    t_so_schdlx-dlv_date = 'X'.
    APPEND: t_so_schdl, t_so_schdlx.
  ENDIF.

  IF s_t_items-plant IS NOT INITIAL.
    t_so_items-plant = s_t_items-plant.
    t_so_itemsx-plant = 'X'.
  ENDIF.

  IF s_t_items-bill_date NE '00000000'.
    t_so_items-bill_date = s_t_items-bill_date.
    t_so_itemsx-bill_date = 'X'.
  ENDIF.

  IF s_t_items-cust_mat35 IS NOT INITIAL.
    t_so_items-cust_mat35 = s_t_items-cust_mat35.
    t_so_itemsx-cust_mat35 = 'X'.
  ENDIF.
  APPEND: t_so_items, t_so_itemsx.

and finally called my bapi:

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
      order_header_in               = s_so_header
      order_header_inx              = s_so_headerx
   IMPORTING
      salesdocument                 = v_salesorder
    TABLES
      return                        = t_return
      order_items_in                = t_so_items
      order_items_inx               = t_so_itemsx
      order_partners                = t_so_partners
      order_schedules_in            = t_so_schdl
      order_schedules_inx           = t_so_schdlx
      order_conditions_in           = t_so_cond
      order_conditions_inx          = t_so_condx

.

thks a lot,

5 REPLIES 5
Read only

Former Member
0 Likes
1,155

First try to create sales order manually in VA01 ,if no issues ,the use same data in FM ..

Check with sample program:

REPORT z_bapi_salesorder_create.

  • 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 OBLIGATORY.

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.

  • 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'.

  • 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'.

  • 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'.

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.

  • 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.

Read only

Former Member
0 Likes
1,155

PR00/PB00-generally are unit price conditions, not allowed at header and allowed only at item level.

in t_so_cond-populate item no.

Siva

Read only

former_member186078
Active Participant
0 Likes
1,155

Hi Jin,

Can you check whether the Item number is passing to the condition records at the place:

t_so_cond-itm_number = s_t_items-itm_number.

t_so_condx-updateflag = 'I'.

t_so_condx-itm_number = s_t_items-itm_number.

APPEND: t_so_cond, t_so_condx.

Please put the break points and check. Because, if the item number is initial in the condition records, the BAPI will treat it as a header condition and will try to insert. Actually, the PR00 condition will generally be configured for items. So, you might be getting the problem. Just check once and pass the item number if it is not passing.

Thanks,

Adithya K

askSAP@googlegroups.com

Note: Dont forget to reward points if it is useful

Read only

dev_parbutteea
Active Contributor
0 Likes
1,155

Hi,

I used this code to create a sales order:

MOVE: lv_refobjecttype TO lwa_sales_header_in-refobjecttype,

<lf_output_tab>-ordtp TO lwa_sales_header_in-doc_type,

<lf_output_tab>-slorg TO lwa_sales_header_in-sales_org,

<lf_output_tab>-dstch TO lwa_sales_header_in-distr_chan,

<lf_output_tab>-divsn TO lwa_sales_header_in-division,

<lf_output_tab>-invdt TO lwa_sales_header_in-req_date_h,

lc_cons_1 TO lwa_sales_header_in-date_type,

space TO lwa_sales_header_in-bill_block,

<lf_output_tab>-ordre TO lwa_sales_header_in-ord_reason,

<lf_output_tab>-ordkey TO lwa_sales_header_in-purch_no_c,

<lf_output_tab>-invdt TO lwa_sales_header_in-doc_date,

lc_cons_i TO lwa_sales_header_inx-updateflag,

lc_cons_x TO lwa_sales_header_inx-doc_type,

lc_cons_x TO lwa_sales_header_inx-sales_org,

lc_cons_x TO lwa_sales_header_inx-distr_chan,

lc_cons_x TO lwa_sales_header_inx-division,

lc_cons_x TO lwa_sales_header_inx-req_date_h,

lc_cons_x TO lwa_sales_header_inx-date_type,

lc_cons_x TO lwa_sales_header_inx-bill_block,

lc_cons_x TO lwa_sales_header_inx-ord_reason,

lc_cons_x TO lwa_sales_header_inx-purch_no_c,

lc_cons_x TO lwa_sales_header_inx-doc_date .

MOVE:<lf_output_tab>-itm_number TO lwa_sales_items_in-itm_number,

<lf_output_tab>-matnr TO lwa_sales_items_in-material,

<lf_output_tab>-batch TO lwa_sales_items_in-batch,

<lf_output_tab>-usage TO lwa_sales_items_in-usage_ind, <lf_output_tab>-plant TO lwa_sales_items_in-plant,

<lf_output_tab>-quant TO lwa_sales_items_in-target_qty , <lf_output_tab>-stloc TO lwa_sales_items_in-store_loc,

<lf_output_tab>-ounit TO lwa_sales_items_in-sales_unit,

<lf_output_tab>-shppt TO lwa_sales_items_in-ship_point,

<lf_output_tab>-itm_number TO lwa_sales_items_inx-itm_number,

lc_cons_i TO lwa_sales_items_inx-updateflag,

lc_cons_x TO lwa_sales_items_inx-material,

lc_cons_x TO lwa_sales_items_inx-batch,

lc_cons_x TO lwa_sales_items_inx-usage_ind, lc_cons_x TO lwa_sales_items_inx-plant,

lc_cons_x TO lwa_sales_items_inx-target_qty , lc_cons_x TO lwa_sales_items_inx-store_loc,

lc_cons_x TO lwa_sales_items_inx-sales_unit,

lc_cons_x TO lwa_sales_items_inx-ship_point.

MOVE <lf_output_tab>-itmct TO lwa_sales_items_in-item_categ.

MOVE lc_cons_x TO lwa_sales_items_inx-item_categ.

APPEND lwa_sales_items_in TO li_sales_items_in.

APPEND lwa_sales_items_inx TO li_sales_items_inx.

MOVE: lc_cons_ag TO lwa_sales_partners-partn_role,

<lf_output_tab>-sold2 TO lwa_sales_partners-partn_numb,

<lf_output_tab>-itm_number TO lwa_sales_schedules_in-itm_number ,

<lf_output_tab>-quant TO lwa_sales_schedules_in-req_qty ,

<lf_output_tab>-itm_number TO lwa_sales_schedules_inx-itm_number,

lc_cons_i TO lwa_sales_schedules_inx-updateflag,

lc_cons_x TO lwa_sales_schedules_inx-req_qty.

APPEND lwa_sales_partners TO li_sales_partners.

APPEND lwa_sales_schedules_in TO li_sales_schedules_in .

APPEND lwa_sales_schedules_inx TO li_sales_schedules_inx.

MOVE:<lf_output_tab>-itm_number TO lwa_sales_conditions_in-itm_number,

<lf_output_tab>-contp TO lwa_sales_conditions_in-cond_type,

<lf_output_tab>-contp TO lwa_sales_conditions_in-condtype,

<lf_output_tab>-value TO lwa_sales_conditions_in-cond_value,

<lf_output_tab>-value TO lwa_sales_conditions_in-condvalue,

<lf_output_tab>-pcurr TO lwa_sales_conditions_in-currency.

APPEND lwa_sales_conditions_in TO li_sales_conditions_in.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENT =

sales_header_in = lwa_sales_header_in

sales_header_inx = lwa_sales_header_inx

  • SENDER =

binary_relationshiptype = lc_bin_rltnshtp

int_number_assignment = lwa_int_number_assignment

IMPORTING

salesdocument_ex = lv_salesdocument

TABLES

return = li_salesorder_return

sales_items_in = li_sales_items_in

sales_items_inx = li_sales_items_inx

sales_partners = li_sales_partners

sales_schedules_in = li_sales_schedules_in

sales_schedules_inx = li_sales_schedules_inx

sales_conditions_in = li_sales_conditions_in

  • SALES_CFGS_REF =

  • SALES_CFGS_INST =

  • SALES_CFGS_PART_OF =

  • SALES_CFGS_VALUE =

  • SALES_CFGS_BLOB =

  • SALES_CCARD =

  • KEY_TABLE =

.

Revert back in case of queries!

Regards,

Sooness

Read only

Former Member
0 Likes
1,155

so happy to receive so much replies,

and it works, so thanks to all of you.;-D