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: 

Regarding - BAPI_SALESORDER_CREATEFROMDAT1

Former Member
0 Kudos

Hello All,

I am having a flat file which contains data for creating sales order. But I am unable to create sales order using BAPI.

Here first I have created a demo program after wards I will conver it to final program.

Following is my demo source code. Kindly let me know what I am missing.

Regards,

Dilip

data : iBAPISDHEAD like BAPISDHEAD occurs 10 with header line,

iBAPIITEMIN like BAPIITEMIN occurs 10 with header line,"Item data input

iBAPIPARTNR like BAPIPARTNR occurs 10 with header line."partners

iBAPISDHEAD-DOC_NUMBER = '1'.

iBAPISDHEAD-doc_type = 'BV'.

iBAPISDHEAD-SALES_ORG = '1000'.

iBAPISDHEAD-DISTR_CHAN = '10'.

iBAPISDHEAD-DIVISION = '10'.

append iBAPISDHEAD.

*clear iBAPISDHEAD.

*****Item details

iBAPIITEMIN-ITM_NUMBER = '10'.

iBAPIITEMIN-MATERIAL = 'SMB_FERT04'.

append iBAPIITEMIN.

*clear iBAPIITEMIN.

          • End Item details

*****Partner functions

iBAPIPARTNR-PARTN_ROLE = 'AA'.

iBAPIPARTNR-PARTN_NUMB = '1'.

iBAPIPARTNR-ITM_NUMBER = '10'.

append iBAPIPARTNR.

*clear iBAPIPARTNR.

*****end partner functions

***NEW ADDITION

data : iBAPI_VBELN like BAPIVBELN-VBELN.

data : iBAPISOLDTO like BAPISOLDTO occurs 10 with header line."SOLD TO PARTY

data : iBAPISHIPTO like BAPISHIPTO occurs 10 with header line."SHIP TO PARTY

***pass data to BAPISOLDTO

iBAPISOLDTO-SOLD_TO = '1'.

iBAPISOLDTO-NAME = 'Test customer1'.

append iBAPISOLDTO.

***end pass data to BAPISOLDTO

***pass data to iBAPISHIPTO

iBAPISHIPTO-SHIP_TO = '1'.

iBAPISHIPTO-NAME = 'Test customer1'.

append iBAPISHIPTO.

***end pass data to BAPISOLDTO

***end addition

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'

EXPORTING

ORDER_HEADER_IN = iBAPISDHEAD

WITHOUT_COMMIT = 'X'

CONVERT_PARVW_AUART = 'X'

IMPORTING

SALESDOCUMENT = iBAPI_VBELN

SOLD_TO_PARTY = iBAPISOLDTO

SHIP_TO_PARTY = iBAPISHIPTO

  • BILLING_PARTY = '1'

  • RETURN =

TABLES

ORDER_ITEMS_IN = iBAPIITEMIN

ORDER_PARTNERS = iBAPIPARTNR

  • ORDER_ITEMS_OUT =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CCARD =

  • ORDER_CFGS_BLOB =

  • ORDER_SCHEDULE_EX =

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

  • IMPORTING

  • RETURN =

.

9 REPLIES 9

FredericGirod
Active Contributor
0 Kudos

Hi Diliip,

use the return structure or table to know the messages from your BAPI. Maybe there will be the solution of your problem.

Rgd

Frédéric

0 Kudos

Hello Frédéric,

Thanks for your informative reply. When I use RETURN table there I am getting error

'Please enter sold-to party or ship-to party '

. But if you have look at the code the values of sold to party & ship to party are there in the internal table's header line.

Regards,

Dilip

0 Kudos

Hello

SOLD_TO_PARTY and SHIP_TO_PARTY are <u>exporting</u>parameters of the BAPI. if you want to set SOLD_TO_PARTY and / or SHIP_TO_PARTY explicit, you'll have to do that via ORDER_PARTNERS.

Regards Wolfgang

0 Kudos

Dilip,

You are passing 'AA' for partner role. It should be 'AG'. Pass customer number with leading zeroes. Also, populate iBAPIPARTNR with SHIP TO PARTY number(with leading zeroes).

Importing parameters - 'salesdocument', 'SOLD_TO_PARTY',

'SHIP_TO_PARTY' are retuned by BAPI after successful creation of sales order. Do not populate them.

Hope this solves your problem.

Satyanarayana Kotte

0 Kudos

Hello,

As per your suggestions I have made the changes but still I am unable to create the sales document.

Regards,

Dilip

REPORT ZTESTDB01.

data : iBAPISDHEAD like BAPISDHEAD occurs 10 with header line,

iBAPIITEMIN like BAPIITEMIN occurs 10 with header line,"Item data input

iBAPIPARTNR like BAPIPARTNR occurs 10 with header line."partners

iBAPISDHEAD-doc_type = 'BV'.

iBAPISDHEAD-SALES_ORG = '1000'.

iBAPISDHEAD-DISTR_CHAN = '10'.

iBAPISDHEAD-DIVISION = '10'.

append iBAPISDHEAD.

*****Item details

iBAPIITEMIN-ITM_NUMBER = '10'.

*HG_LV_ITEM = ''.

*PO_ITM_NO = ''.

iBAPIITEMIN-MATERIAL = 'SMB_FERT04'.

append iBAPIITEMIN.

*clear iBAPIITEMIN.

          • End Item details

*****Partner functions

iBAPIPARTNR-PARTN_ROLE = 'AG'.

iBAPIPARTNR-PARTN_NUMB = '0000000001'.

iBAPIPARTNR-ITM_NUMBER = '10'.

iBAPIPARTNR-TITLE ='Company'.

iBAPIPARTNR-name = 'Test Customer1'.

iBAPIPARTNR-street = 'kandivali'.

iBAPIPARTNR-country ='IN'.

iBAPIPARTNR-POSTL_CODE = '400101'.

append iBAPIPARTNR.

*clear iBAPIPARTNR.

*****end partner functions

data : iBAPI_VBELN like BAPIVBELN-VBELN." value '0020000054'.

data : iBAPISOLDTO like BAPISOLDTO occurs 10 with header line."SOLD TO PARTY

data : iBAPISHIPTO like BAPISHIPTO occurs 10 with header line."SHIP TO PARTY

data iBAPIRETURN1 like BAPIRETURN occurs 10 with header line.

***end addition

loop at iBAPISOLDTO.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'

EXPORTING

ORDER_HEADER_IN = iBAPISDHEAD

WITHOUT_COMMIT = space

  • CONVERT_PARVW_AUART = 'X'

IMPORTING

SALESDOCUMENT = iBAPI_VBELN

SOLD_TO_PARTY = iBAPISOLDTO

SHIP_TO_PARTY = iBAPISHIPTO

  • BILLING_PARTY = '1'

RETURN = iBAPIRETURN1

TABLES

ORDER_ITEMS_IN = iBAPIITEMIN

ORDER_PARTNERS = iBAPIPARTNR

  • ORDER_ITEMS_OUT =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CCARD =

  • ORDER_CFGS_BLOB =

  • ORDER_SCHEDULE_EX =

.

append iBAPIRETURN1.

endloop.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = ' '

  • IMPORTING

  • RETURN =

.

write 10 sy-subrc color 7 inverse on.

write :/2 ibapi_vbeln color 5.

loop at iBAPIRETURN1.

write :/2 iBAPIRETURN1-type,5 iBAPIRETURN1-message,iBAPI_VBELN.

endloop.

0 Kudos

What messages are you getting? Also, you have to use BAPI_TRANSACTION_COMMIT after the call if you don't have any errors.

Former Member
0 Kudos

Your partner numbers may need to be in internal format and should already exist in the system. If it is one time customer order that you are creating, then you need to pass the entire address information of the partners.

Former Member
0 Kudos

The Sold-To party Function is 'AG'.

I don't see Ship-To in your code i.e. Partner function 'WE'.

Regards

Mahendra

0 Kudos

Hi Diliip,

Check below code. I used BAPI_SALESORDER_CREATEFROMDAT2.

Dont forget to call BAPI_TRANSACTION_COMMIT.

*-- Order header

x_order_header_in-doc_type = it_file-auart.

x_order_header_in-sales_org = it_file-vkorg.

x_order_header_in-distr_chan = it_file-vtweg.

x_order_header_in-division = it_file-spart.

x_order_header_in-ord_reason = it_file-augru.

x_order_header_in-purch_no_c = it_file-pohead.

*-- Partners data

*-- Sold to party

it_order_partners-partn_role = 'AG'.

it_order_partners-partn_numb = it_file-soldto.

append it_order_partners.

clear it_order_partners.

*-- Ship to party

it_order_partners-partn_role = 'WE'.

it_order_partners-partn_numb = it_file-shipto.

append it_order_partners.

clear it_order_partners.

*-- Item Details

it_orders_items_in-itm_number = g_itemno.

it_orders_items_in-material = it_file-matnr.

it_orders_items_in-target_qty = it_file-zmeng.

it_orders_items_in-target_qu = it_file-zieme.

it_orders_items_in-plant = it_file-werks.

append it_orders_items_in.

clear it_orders_items_in.

*-- Schedule Lines

it_order_schedules_in-itm_number = g_itemno.

it_order_schedules_in-sched_line = c_0001.

it_order_schedules_in-req_qty = it_file-zmeng.

append it_order_schedules_in.

clear it_order_schedules_in.

Thanks,

Rajesh.