cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI

Former Member
0 Kudos
73

I need to create a sales order with reference to billing document using a BAPI.

It's possible?

Any help appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi joel corral,

0006                           Sales organization                                                        
 
BAPI_SALESGROUP_GET_DETAIL     Sales Group: Display Name                                                 
 
BAPI_SALESOFFICE_GET_DETAIL    Sales Office: Display Name                                                
 
BAPI_SALESOFFICE_GRP_EXIST     Sales Office / Sales Group: Existence Check                               
 
BAPI_SALESORG_EXIST            Sales Organization: Existence Check                                       
 
BAPI_SALESORG_GET_DETAIL       Sales Organization: Display Data                                          
 
BAPI_SALESORG_OFFICE_EXIST     Sales Organization / Sales Office: Existence Check                        

I hope these links will solve your problem.

1.LSMW - BAPI

2.Creating Billing Plan data for sales order using BAPI_SALESORDER_CREATEFROM

3.BAPI - SALES ORDER CREATE

4.Deleting Sales Order Details using BAPI_SALESORDER_CHANGE And Reinserting

Hope it helps.

Kindly reward points if it helps by clicking the star on the left hand side of the screen.

Regards,

Maheswaran.B

Answers (2)

Answers (2)

Former Member
0 Kudos

I haven't ever heard of a sales order being created with reference to a billing document. There is no provision in configuration IMG to configure a copy procedure for billing document to sales order. It is not possible.

What is the business process that needs this?

Former Member
0 Kudos

Hi joel,

Yes, its possible. You can use FM BAPI_SALESORDER_CREATEFROMDAT1

You can populate Order Header internal table (TYPE bapisdhead) with the relevant data along with other internal tables populated and call the FM

like for eg:

LOOP AT it_data.

CLEAR v_index.

v_index = sy-tabix.

*- New SalesOrder

AT NEW order.

READ TABLE it_data INDEX v_index.

CLEAR: it_orderh, it_item, it_partner,

order, soldto, shipto, return,

it_item[], it_partner[].

v_total = v_total + 1. "Increment Total SalesOrders counter

CLEAR l_itemno.

l_itemno = '10'.

*- Covert date fields into Internal format

CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'

EXPORTING

datum = it_data-date

dtype = 'DATS'

IMPORTING

idate = it_data-date.

*- Populate SalesOrder header data.

CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'

EXPORTING

input = it_data-auart

IMPORTING

output = it_data-auart.

it_orderh-doc_type = it_data-auart.

it_orderh-sales_org = it_data-vkorg.

it_orderh-distr_chan = it_data-vtweg.

it_orderh-division = it_data-spart.

it_orderh-purch_no = 'DEPOT'.

it_orderh-price_date = it_data-date. "Doc Dt

it_orderh-req_date_h = it_data-date. "Del.Dt

it_orderh-purch_no_s = it_data-order.

*- Partner data

CLEAR: l_partner, l_kunnr.

*- Convert Partner type into internal format

l_partner = 'SP'. "SoldTo Party

CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'

EXPORTING

input = l_partner

IMPORTING

output = l_partner.

*- Convert Customer into internal format

l_kunnr = it_data-kunnr.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = l_kunnr

IMPORTING

output = l_kunnr.

it_partner-partn_role = l_partner.

it_partner-partn_numb = l_kunnr.

APPEND it_partner.

CLEAR it_partner.

ENDAT.

*- Item data

it_item-itm_number = l_itemno.

*- Convert material number into internal format

CLEAR l_matnr.

l_matnr = it_data-matnr.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = l_matnr

IMPORTING

output = l_matnr

EXCEPTIONS

length_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

it_item-material = l_matnr.

it_data-qty = it_data-qty * 1000.

it_item-req_qty = it_data-qty.

it_item-sales_unit = it_data-uom.

it_item-req_date = it_data-date.

*- Pricing data

  • it_item-cond_type = it_data-kschl. "Pricing condition

  • CLEAR l_kbetr.

  • l_kbetr = it_data-kbetr / 10. "Price (Rate)

  • it_item-cond_value = l_kbetr.

APPEND it_item.

CLEAR it_item.

*- Increment Item counter.

l_itemno = l_itemno + 10.

*- At end of SalesOrder

AT END OF order.

READ TABLE it_data INDEX v_index.

*- Call the BAPI for SalesOrder creation

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'

EXPORTING

order_header_in = it_orderh

IMPORTING

salesdocument = order

sold_to_party = soldto

ship_to_party = shipto

return = return

TABLES

order_items_in = it_item

order_partners = it_partner.

IF sy-subrc = 0.

COMMIT WORK.

ENDIF.

v_return = return+0(1).

IF v_return = 'E'.

v_error = v_error + 1.

CLEAR l_mesg.

l_mesg = return.

CONDENSE l_mesg.

ELSE.

v_correct = v_correct + 1.

CLEAR l_mesg.

CONCATENATE 'Salesorder'(007) order 'successfully created.'(008)

INTO l_mesg SEPARATED BY space.

CONDENSE l_mesg.

ENDIF.

*- Populate the output table

CLEAR it_out.

it_out-order = it_data-order.

it_out-mesg = l_mesg.

APPEND it_out.

CLEAR it_out.

ENDAT.

ENDLOOP.

Regards,

Raj