Application Development 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: 

How to create sales order using BAPI.

Former Member
0 Kudos

Hi all,

I am trying to create sales order using standard BAPI

"BAPI_SALESORDER_CREATEFROMDAT2". But, even I had entered all mandatory fields, I am unable to create sales order sucessfully.

I had gone through the documentaion of this BAPI and entered these fields.

These are the mandatory fields that which I had tried to create,

ORDER_HEADER_IN :

DOC_TYPE Sales document type

SALES_ORG Sales organization

DISTR_CHAN Distribution channel

DIVISION Division

ORDER_PARTNERS..:

PARTN_ROLE Partner role, SP sold-to party

PARTN_NUMB Customer number

ORDER_ITEMS_IN..:

MATERIAL Material number

Do we have anymore fields to give as inputs? I am getting this error message as below :

Msg: Personal number 00007176 does not exit.

But, I am not giving any personal number manually. This personal number was having connection with partner role field,

I had reffered this from the VBPA (Sales Document: Partner Table). Now, please suggest me how to solve this?

Can anyone tell me how to solve this problem and create sales order sucessfully.

Thanks in advance,

Surender Batlanki.

11 REPLIES 11

bpawanchand
Active Contributor
0 Kudos

hi

Check this [Sample Code|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-Simpleprogramtocreatesalesorderusing+BAPI]

Regards

pavan

0 Kudos

Hi Pavan,

Actually, I have to give some test data to our MB intergration team. For them, I have to give what all the mandatory fields and example inputs as just to create sales order.

For them, our standard BAPI parameters only will be viseble,

Now, we have to give some test data with all the fields mostly needed. But, while I am trying in SE37 itself I am unable to create it sucessfully.

This is my actual issue. thats why i need only test data which can be create sucessfully. I am trying this from IDES trial version not on client version. Is thats the problem lack of proper data in database..?

Can you suggest me ?

Former Member
0 Kudos

Hi,

Create that employee number using PA40 tcode (HR).

kathir.

0 Kudos

Hi,

Thanks for your reply,

I had reffered to PA40 T.Code, We are having some information/data of that perticular employee with that person number.

Can we do any more than this..?

Thanks,

Surender Batlanki.

0 Kudos

I also have the same problem , can any one tell me correct way to create sales order?

Former Member
0 Kudos

hi,

you goto to se16n and put vbpa check entries that partner function for example 'SE' - sales employee.if u execute some records will come and double clk on single record.it will two set of values for same field parvw .use the internally saved partner function in ur bapi.

it will work.

check this code

LOOP AT it_head INTO wa_head.

bapi_head-DOC_TYPE = wa_head-auart.

bapi_head-SALES_ORG = wa_head-vkorg.

bapi_headx-BILL_SCHED = 'X'.

bapi_headx-REF_1 = 'X'.

bapi_headx-PURCH_NO_C = 'X'.

bapi_headx-PMNTTRMS = 'X'.

bapi_headx-INCOTERMS1 = 'X'.

bapi_headx-NAME = 'X'.

bapi_headx-BILL_BLOCK = 'X'.

if wa_head-payer IS NOT INITIAL.

wa_parnr-PARTN_ROLE = 'RG'.

wa_parnr-PARTN_NUMB = wa_head-payer.

APPEND wa_parnr to it_parnr.

ENDIF.

if wa_head-pernr IS NOT INITIAL.

wa_parnr-PARTN_ROLE = 'VE'.

wa_parnr-PARTN_NUMB = wa_head-pernr.

APPEND wa_parnr to it_parnr.

ENDIF.

LOOP AT it_data1 INTO wa_Data1 WHERE bstnk = wa_head-bstnk.

wa_item-MATERIAL = wa_data1-matnr .

wa_item-TARGET_QTY = wa_data1-zmeng.

wa_item-PLANT = wa_data1-werks.

wa_item-BILL_BLOCK = wa_data1-faksp.

wa_item-STORE_LOC = wa_data1-lgort.

APPEND wa_item to it_item.

wa_itemx-MATERIAL = 'X' .

wa_itemx-TARGET_QTY = 'X'.

wa_itemx-PLANT = 'X'.

wa_itemx-BILL_BLOCK = 'X'.

wa_itemx-STORE_LOC = 'X'.

APPEND wa_itemx to it_itemx.

wa_sched-REQ_QTY = wa_data1-zmeng.

APPEND wa_sched to it_sched.

wa_schedx-REQ_QTY = 'X'.

APPEND wa_schedx to it_schedx.

ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

ORDER_HEADER_IN = bapi_head

ORDER_HEADER_INX = bapi_headx

IMPORTING

SALESDOCUMENT = SALESDOCUMENT

TABLES

RETURN = it_ret1

ORDER_ITEMS_IN = it_item

ORDER_ITEMS_INX = it_itemx

ORDER_PARTNERS = it_parnr

ORDER_SCHEDULES_IN = it_sched

ORDER_SCHEDULES_INX = it_schedx .

Regards,

Manesh.R

Edited by: manesh ramachandran on Dec 31, 2009 1:22 PM

uwe_schieferstein
Active Contributor
0 Kudos

Hello Surender

Using PA40 is complete nonsense because you want to create a sales order for a CUSTOMER and not an EMPLOYEE.

Working on an IDES test system simply go to VA01 and create a sales order in dialog. As soon as you have saved the order successfully you know all mandatory data you need to feed your BAPI with.

By the way, I prefer to use RFC-enabled SD_SALESORDER_CREATE (which is internally called by the BAPI) because it is less restrictive regarding order types.

Regards

Uwe

0 Kudos

SD_SALESDOCUMENT_CREATE instead of SD_SALESORDER_CREATE

Former Member
0 Kudos

hi surendra ,

chech with below code.

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.

let us know if you have any qauistions.

~linganna

Former Member
0 Kudos

Hi,

Check this development as reference:

http://wiki.sdn.sap.com/wiki/display/ABAP/SalesOrderInterface

cheers

Aveek

jj
Active Contributor
0 Kudos

order_header_in-doc_type = 'OR'.

order_header_in-sales_org = 'BP01'.

order_header_in-distr_chan = '01'.

order_header_in-purch_date = '20090513'.

order_header_in-pmnttrms = '0001'.

order_header_in-purch_no_c = '111'.

order_header_in-division = '01'.

order_items_in-itm_number = '10'.

order_items_in-material = 'RAW MATERIAL1'.

order_items_in-plant = 'BP01'.

APPEND order_items_in.

order_partners-partn_role = 'AG'. "SP (internally) --- Sold-to party

order_partners-partn_numb = 'C58000'.

APPEND order_partners.

order_partners-partn_role = 'RE'. " BP----


Bill-to party

order_partners-partn_numb = 'C58000'.

APPEND order_partners.

order_schedules_in-itm_number = '10'.

order_schedules_in-req_qty = 100.

APPEND order_schedules_in.

call function 'BAPI_SALESORDER_CREATEFROMDAT2'

exporting

  • SALESDOCUMENTIN =

order_header_in = order_header_in

  • ORDER_HEADER_INX =

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

convert = 'X' "for Conversion of Partner Function + Order Type

importing

salesdocument = wrk_salesdocno

tables

return = t_return

order_items_in = order_items_in

  • order_items_inx =

order_partners = order_partners

order_schedules_in = 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 = 'X'

importing

return = t_return.

check the conversion for BP