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

Error while creating Salesorder using BAPI

Former Member
0 Likes
3,317

hello frnds,

I m new to abap and tryin to make use of BAPI_SALESORDER_CREATEFROMDAT1 to create Sales Order

I have used the progrtam below.

&----


*& Report ZSALESBAPITRIAL

*&

&----


*&

*&

&----


REPORT zsalesbapitrial.

TABLES : vbak , vbap.

  • Parameter Screen.

  • Sales Document Type.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

  • Sales document type.

PARAMETERS: p_auart TYPE vbak-auart OBLIGATORY.

  • Sales Organisation.

PARAMETERS: p_vkorg TYPE vbak-vkorg OBLIGATORY.

  • Distribution channel.

PARAMETERS: p_vtweg TYPE vbak-vtweg OBLIGATORY.

  • Division.

PARAMETERS: p_spart TYPE vbak-spart OBLIGATORY.

SKIP 1.

  • Sold to.

PARAMETERS: p_sold TYPE vbak-kunnr OBLIGATORY.

  • Ship to.

PARAMETERS: p_ship TYPE vbak-kunnr OBLIGATORY.

SKIP 1.

  • Material(Article No).

PARAMETERS: p_matnr TYPE vbap-matnr OBLIGATORY.

  • Quantity (Cummulative quantity of sales Order)

PARAMETERS: p_menge type vbap-kwmeng obligatory.

  • Plant(Site )

parameters: p_plant type vbap-werks obligatory.

SELECTION-SCREEN END OF BLOCK b1.

  • 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

  • Sales document type

header-doc_type = p_auart.

headerx-doc_type = 'X'.

  • Sales organization

header-sales_org = p_vkorg.

headerx-sales_org = 'X'.

  • Distribution channel

header-distr_chan = p_vtweg.

headerx-distr_chan = 'X'.

  • Division

header-division = p_spart.

headerx-division = 'X'.

headerx-updateflag = 'I'.

  • Partner data

  • Sold to

partner-partn_role = 'AG'.

partner-partn_numb = p_sold.

APPEND partner.

  • Ship to

partner-partn_role = 'WE'.

partner-partn_numb = p_ship.

APPEND partner.

  • ITEM DATA

itemx-updateflag = 'I'.

  • Line item number.

item-itm_number = '000010'.

itemx-itm_number = 'X'.

  • Material

item-material = p_matnr.

itemx-material = 'X'.

  • Plant

item-plant = p_plant.

itemx-plant = 'X'.

  • Quantity

item-target_qty = p_menge.

itemx-target_qty = '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 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.

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

ENDIF.

but its giving 'Error in creating document' I m unable to figure wat i m missing . Is it tht i m gving wrong parameters.

Please help !!!

11 REPLIES 11
Read only

Former Member
0 Likes
1,877

How can i get what the return error is ????

Read only

0 Likes
1,877

All the data that is given to the Salesorder while creating sales order in normal transaction needs to be filled when calling the BAPI.

Please verify that all the data including the ones automatically filled and mandatory data is passed to the BAPI.

To see the exact error include the coding below :

loop at return.

write : / return-type,

return-id,

return-number,

return-message,

return-message_v1,

return-message_v2,

return-message_v3,

return-message_v4.

endloop.

Read only

0 Likes
1,877

Hello Rachana

The <b>return </b>table contains all the messages due to errors that similarly would occur in the dialog transaction. Because BAPIs are usually called via RFC they collect errors and do not raise any exception otherwise the RFC connection would break down.

Thus, look carefully through the E-messages in the return table.

Regards

Uwe

Read only

Former Member
0 Likes
1,877

Thanks a lot

I was able to track error and error was due to wrong data.

Now i have one more concern , if my SO is having multiple items then wat chnges do i need to make .

Do i need to use BAPI_SALESDOCU_CREATEFROMDATA2 ???

Whats the difference between BAPI_SALESDOCU_CREATEFROMDATA1 and BAPI_SALESDOCU_CREATEFROMDATA2.

Read only

0 Likes
1,877

For multiple line items, you have to append the same in the table ORDER_ITEMS_IN and in ORDER_ITEMS_INX and in the schdule lines related table.

reward points.

krishna

Read only

Former Member
0 Likes
1,877

Does tht mean i need to add the following code

  • Line item number.

item-itm_number = '000010'.

itemx-itm_number = 'X'.

  • Material

item-material = p_matnr.

itemx-material = 'X'.

  • Plant

item-plant = p_plant.

itemx-plant = 'X'.

  • Quantity

item-target_qty = p_menge.

itemx-target_qty = 'X'.

APPEND item.

APPEND itemx.

  • For second item.

  • Line item number.

item-itm_number = '000020'.

itemx-itm_number = 'X'.

  • Material

item-material = '600020001'.

itemx-material = 'X'.

  • Plant

item-plant = p_plant.

itemx-plant = 'X'.

  • Quantity

item-target_qty = p_menge.

itemx-target_qty = '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 lines

lt_schedules_in-itm_number = '000020'.

lt_schedules_in-sched_line = '0002'.

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.

  • Fill schedule line flags

lt_schedules_inx-itm_number = '000020'.

lt_schedules_inx-sched_line = '0002'.

lt_schedules_inx-updateflag = 'X'.

lt_schedules_inx-req_qty = 'X'.

APPEND lt_schedules_inx.

But i guess it is overwritting my frst material..

Also i m gettin a error

For object rv_beleg, number range interval doesnot exist

Pls suggest

Read only

0 Likes
1,877

Hello Rachana

If you initially create your sales order there is no need to fill the <i>change-indicator </i>structures (e.g. ITEMX).

If there are higher "versions" of the BAPI are available in your system (e.g. <b>BAPI_SALESDOCU_CREATEFROMDATA2</b>) then go for this BAPI.

Finally, if you experience problems with certain document types (BAPI does not create them) then you can use the underlying RFC-enabled function module SD_SALESDOCUMENT_CREATE directly. If you look at the coding of BAPI_SALESDOCU_CREATEFROMDATA2 it calls fm SD_SALESDOCUMENT_CREATE with IMPORTING parameter

BUSINESS_OBJECT         = 'BUS2032'

This business object is restricted to certain document types. For more details please refer to:

Regards

Uwe

Read only

Former Member
0 Likes
1,877

i m still getting this error

Also i m gettin a error

<b>For object rv_beleg, number range interval doesnot exist</b>

Please suggest

Read only

Former Member
0 Likes
1,877

Thanks a lot ... I was able to Make SO successfully .

Read only

Former Member
0 Likes
1,877

Now i want to create Purchase order using BAPI....

Please suggest

Read only

0 Likes
1,877

Hello Rachana

In this case you have to use the famous <b>BAPI_PO_CREATE1</b>.

Regards

Uwe