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: 

bapi sales order

Former Member
0 Kudos

Respected Members

i am executing the Bapi for creating SALES ORDER and it is working fine.

but there are two problems .

First Problem:

in my flat file i have two sales order

sno description quantity

1 abc 50

2 xyz 70

when i am executing the program two sales order are creating but thing is that for second sales order it is taking the quantity 50 only that is of first order.

But when i debug the program it is taking 70 upto when it is calling the BAPI function module .

I am not getting where it is going back in bapi function module and taking the qunatity 50 for second sales order also.

Please give me your answers.

Second thing is that suppose for sales order 1 i have five or six line items then how to make the flat file for this type of requirement.

Thanks give me your solutions.

3 REPLIES 3

former_member200338
Active Contributor
0 Kudos

Hi,

Are u using the BAPI with in the loop? make sure you clear the work area before you assign them.

You can create a flat file for item by adding more coloum in the flat file. This coloumn will help u in finding the sales order which it belongs to.

Regards,

Niyaz

Former Member
0 Kudos

Hi

for multiple orders you have to run this BAPI in LOOP of the data table

and use BAPI_transaction_commit at the end.

see the sample code and do it

SALES ORDER INPUT CREATION.

PARAMETERS: p_auart TYPE auart OBLIGATORY.

PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.

PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.

PARAMETERS: p_spart TYPE vtweg OBLIGATORY.

PARAMETERS: p_sold TYPE kunnr OBLIGATORY.

PARAMETERS: p_ship TYPE kunnr OBLIGATORY.

*ITEM

PARAMETERS: p_matnr TYPE matnr OBLIGATORY.

PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.

PARAMETERS: p_plant TYPE werks_d OBLIGATORY.

PARAMETERS: p_itcat TYPE pstyv OBLIGATORY.

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

  • HEADER DATA

header-doc_type = p_auart.

headerx-doc_type = 'X'.

header-sales_org = p_vkorg.

headerx-sales_org = 'X'.

header-distr_chan = p_vtweg.

headerx-distr_chan = 'X'.

header-division = p_spart.

headerx-division = 'X'.

headerx-updateflag = 'I'.

  • PARTNER DATA

partner-partn_role = 'AG'.

partner-partn_numb = p_sold.

APPEND partner.

partner-partn_role = 'WE'.

partner-partn_numb = p_ship.

APPEND partner.

  • ITEM DATA

itemx-updateflag = 'I'.

item-itm_number = '000010'.

itemx-itm_number = 'X'.

item-material = p_matnr.

itemx-material = 'X'.

item-plant = p_plant.

itemx-plant = 'X'.

item-target_qty = p_menge.

itemx-target_qty = 'X'.

item-target_qu = 'EA'.

itemx-target_qu = 'X'.

item-item_categ = p_itcat.

itemx-item_categ = '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

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 WORK AND WAIT.

WRITE: / 'Document ', v_vbeln, ' created'.

ENDIF

Regards

Anji

0 Kudos

Respected Members

i have a problem in creating sales order through BAPI

i will explain you.

My flat file structure is

doc_type sales_org dis_Ch division part_num pono itm_num material short_text qty plant price

OR 1000 20 10 1000 123 10 100-100 abc 50 1000 500

OR 1000 20 10 1000 254 10 100-200 XYZ 70 1000 800

Now when i am executing my program with this flat file data , everything is coming but problem is that in second sales order which is getting create is also having the quantity and price value of the first sales order ie 50 and 500 and it is not taking quantity as 70 and price as 800.

Rest everything is getting changed .

For eg Material is getting changed and description is getting changed for second po.

for second sales order it is taking material 100-200 and description XYZ only.

Then why it is taking values for quantity and price same as first sales order.

i m using the bapi function module in the loop only and thats why two sales order are getting generated.

also at the debugging when the values are passed to BAPI function module it is passing the correct values ie 70 and 800 but finally when i am going to tcode VA02 and seeing the sales order then it is showing the values of the previous order.

Please give me the solution as soon as possible.

Thanks