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: 

sample Bapi code for creating orders

Former Member
0 Kudos

HI all,

ive been working on creating an order using idoc_input_orders and couldnt do it because of 2 fields. now changed my decission and thinking of writing a bapi to do the same. has anybody got the sample code for mapping and filling in the bapis before calling bapi for creating an order. Could somebody help me with a sample code and i could use it as a reference before starting coding.

thanks,

Kiran

2 REPLIES 2

former_member181962
Active Contributor
0 Kudos

See if this helps.

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

0 Kudos

thanks ravi,

will start coding. might ask for some help if i get stuck somewhere.