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

create sales order with BAPI_SALESORDER_CREATEFROMDAT2 example

Former Member
0 Likes
2,542

Hi, does anyone have a working example of how to create a sales order using BAPI_SALESORDER_CREATEFROMDAT2?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
701

hi Robert,

Check this code...try to map.

  • one order with total sum of effort

clear: l_order_header,

l_salesdocument,

l_order_partners,

l_order_items,

l_order_schdl.

refresh: it_order_items,

it_order_partners,

it_order_schdl,

it_return.

  • ???????? get from material ...

  • Order header

l_order_header-doc_type = 'ZQBV'.

l_order_header-distr_chan = '10'.

l_order_header-division = '00'.

if g_qals-werk eq '1100'.

l_order_header-sales_org = '1000'.

else.

if g_qals-werk eq '3100'.

l_order_header-sales_org = '3000'.

else.

message i001(00) with text-005.

endif.

endif.

l_order_header-purch_no_c = g_qals-prueflos. " <= lot

  • Partner data

l_order_partners-partn_role = 'AG'.

l_order_partners-partn_numb = g_qals-kunnr.

append l_order_partners to it_order_partners.

  • Order items => only one

l_order_items-itm_number = 10.

l_order_items-material = g_qals-matnr.

l_order_items-target_qty = 1.

append l_order_items to it_order_items.

  • Schedules for quantity

l_order_schdl-itm_number = 10.

l_order_schdl-req_qty = 1. " <= only 1 !

append l_order_schdl to it_order_schdl.

  • Conditions for value

l_order_conditions-itm_number = 10.

l_order_conditions-cond_type = 'PR00'.

l_order_conditions-cond_value = g_effort_sum.

l_order_conditions-currency = g_effort_unit.

append l_order_conditions to it_order_conditions.

  • BAPI to create sales order

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENTIN =

ORDER_HEADER_IN = l_order_header

  • ORDER_HEADER_INX =

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

SALESDOCUMENT = l_salesdocument

TABLES

RETURN = it_return

ORDER_ITEMS_IN = it_order_items

  • ORDER_ITEMS_INX =

ORDER_PARTNERS = it_order_partners

ORDER_SCHEDULES_IN = it_order_schdl

  • ORDER_SCHEDULES_INX =

ORDER_CONDITIONS_IN = it_order_conditions

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

.

if not l_salesdocument is initial.

  • order successfully created

message i001(00) with text-001 l_salesdocument.

endif.

endif.

for more info check the below link also

Regards,

Naveen

1 REPLY 1
Read only

Former Member
0 Likes
702

hi Robert,

Check this code...try to map.

  • one order with total sum of effort

clear: l_order_header,

l_salesdocument,

l_order_partners,

l_order_items,

l_order_schdl.

refresh: it_order_items,

it_order_partners,

it_order_schdl,

it_return.

  • ???????? get from material ...

  • Order header

l_order_header-doc_type = 'ZQBV'.

l_order_header-distr_chan = '10'.

l_order_header-division = '00'.

if g_qals-werk eq '1100'.

l_order_header-sales_org = '1000'.

else.

if g_qals-werk eq '3100'.

l_order_header-sales_org = '3000'.

else.

message i001(00) with text-005.

endif.

endif.

l_order_header-purch_no_c = g_qals-prueflos. " <= lot

  • Partner data

l_order_partners-partn_role = 'AG'.

l_order_partners-partn_numb = g_qals-kunnr.

append l_order_partners to it_order_partners.

  • Order items => only one

l_order_items-itm_number = 10.

l_order_items-material = g_qals-matnr.

l_order_items-target_qty = 1.

append l_order_items to it_order_items.

  • Schedules for quantity

l_order_schdl-itm_number = 10.

l_order_schdl-req_qty = 1. " <= only 1 !

append l_order_schdl to it_order_schdl.

  • Conditions for value

l_order_conditions-itm_number = 10.

l_order_conditions-cond_type = 'PR00'.

l_order_conditions-cond_value = g_effort_sum.

l_order_conditions-currency = g_effort_unit.

append l_order_conditions to it_order_conditions.

  • BAPI to create sales order

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENTIN =

ORDER_HEADER_IN = l_order_header

  • ORDER_HEADER_INX =

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

SALESDOCUMENT = l_salesdocument

TABLES

RETURN = it_return

ORDER_ITEMS_IN = it_order_items

  • ORDER_ITEMS_INX =

ORDER_PARTNERS = it_order_partners

ORDER_SCHEDULES_IN = it_order_schdl

  • ORDER_SCHEDULES_INX =

ORDER_CONDITIONS_IN = it_order_conditions

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

.

if not l_salesdocument is initial.

  • order successfully created

message i001(00) with text-001 l_salesdocument.

endif.

endif.

for more info check the below link also

Regards,

Naveen