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 - quantity

former_member534411
Participant
0 Kudos

Hi,

I am using BAPI <b>'BAPI_SALESORDER_CREATEFROMDAT2'</b> to create sales orders, I could able to create order successfully but quantity of the line item is not coming in the order. If any idea which field should i use to populate the <b>quantity</b> in the <b>sales order</b> items please lemme know.

thanks in advance

//suresh

15 REPLIES 15

Former Member
0 Kudos

Fill the following fields of ORDER_ITEMS_IN for Quantity

<b>TARGET_QTY</b> - Quantity

<b>TARGET_QU</b> - Unit of Measure

and in ORDER_ITEMS_INX fill

<b>UPDATEFLAG</b> = 'U'

<b>TARGET_QTY</b> = 'X'

<b>TARGET_QU</b> = 'X'

Regards,

Subramanian V.

former_member534411
Participant
0 Kudos

Hi Subramanian,

thanks a lot for your answer, i am just coding according to your suggestion and let you in 30mins.

//suresh

former_member534411
Participant
0 Kudos

Hello Subramanian,

I could not able to create sales order after modifying the code. some different problem is coming. if you have any sample code on sales order creation please mail me <b>suresh_karan@yahoo.com</b>

//suresh

0 Kudos

Instead of update_flag = 'U', put 'I'

U - Update

I - Create

D - Delete

Regards,

Subramanian V.

P.S. In case it still does not work, kindly post your code

and also post what paramaeters that you are passing to your respective input(table included) parameters.

Regards,

Subramanian V.

former_member534411
Participant
0 Kudos

Hi subramanian,

I am coping the code below. please see and lemme know the problem .

Loop at it_mat_grp.

on change of it_mat_grp-kunnr.

loop at it_temp1 where kunnr eq it_mat_grp-kunnr.

it_items-bcode = it_temp1-bcode.

it_items-matnr = it_temp1-matnr.

it_items-quantity = it_temp1-quantity.

it_items-posnr = v_posnr1.

*=====> bapi line items table

it_bapi_items-itm_number = v_posnr1.

it_bapi_items-material = it_temp1-matnr.

it_bapi_items-comp_quant = it_temp1-quantity.

it_bapi_items-sales_unit = 'KG'.

append it_bapi_items.

*=====> bapi quantity structures

  • it_bapi_order_inx-itm_number = v_posnr1.

  • it_bapi_order_inx-updateflag = 'I'.

  • it_bapi_order_inx-target_qty = 'X'.

  • it_bapi_order_inx-target_qu = 'X'.

  • append it_bapi_order_inx.

append it_items.

v_posnr1 = v_posnr1 + 10.

clear it_items.

endloop.

endon.

*=====> bapi customer structure

it_bapi_customer-partn_role = 'AG'.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = it_mat_grp-kunnr

importing

output = it_mat_grp-kunnr.

it_bapi_customer-partn_numb = it_mat_grp-kunnr.

it_bapi_customer-itm_number = '000000'.

append it_bapi_customer.

*=====> bapi pricing condition structure

sort it_conditions by barcode.

sort it_items by posnr.

on change of it_mat_grp-kunnr.

loop at it_items.

loop at it_conditions where barcode = it_items-bcode.

it_pricing-price = it_conditions-condition.

it_bapi_conditions-itm_number = v_posnr.

it_bapi_conditions-cond_type = it_conditions-condition.

append it_bapi_conditions.

endloop.

v_posnr = v_posnr + 10.

endloop.

endon.

at end of kunnr.

*====> bapi function module to create an order

call function 'BAPI_SALESORDER_CREATEFROMDAT2'

exporting

order_header_in = it_bapi_header

tables

return = bapi_return

order_items_in = it_bapi_items

order_items_inx = it_bapi_order_inx

order_partners = it_bapi_customer

order_conditions_in = it_bapi_conditions.

*====> bapi to commit to the order

if l_obj_key ne '$'.

call function 'BAPI_TRANSACTION_COMMIT' .

endif.

endloop.

//suresh

0 Kudos

There are a few things, which I would share with you before analysing your code:

a) In 4.6C, very good documentation is already provided for each of the parameters that needs to be entered in the various input/table parameters

b) For every parameter that you fill, there usually exists a *X structure as well. This indicates that , what parameters that you need to insert in the Sales Order.

For e.g.

ORDER_HEADER_IN and ORDER_HEADER_INX, in ORDER_HEADER_INX you need to indicate which parameters are to be inserted and therefore you need to mark UPDATE_FLAG = 'I' and mark the parameters such as SALES_ORG = 'X' and DISTR_CHAN = 'X'. 'X' indicates these values are to be inserted in the given sales order document.

Also refer to note 93091 at http://service.sap.com

In the last line of your code , you have put l_obj_key ne '$', I am not sure why you are doing this. The only thing perhaps you need to do is, if you obtain the sales document number, then commit, otherwise, no need.

I have a sample code for BAPI_SALESORDER_CHANGE, however, you are looking for BAPI_SALESORDER_CREAT2. There are some differences in these two, but essentially the filling of data in structures/tables remains the same. If you find the pattern, you can do it similarly for your BAPI_SALESORDER_CREAT2


parameters: p_vbeln type bapivbeln-vbeln default '7226'.

*** Header Structure
data: ls_order_header_in   type bapisdh1.
data: ls_order_header_inx  type bapisdh1x.

*** Line Item Table
data: lt_order_item_in     type table of bapisditm.
data: lt_order_item_inx    type table of bapisditmx.

*** Schedule Lines Table
data: lt_schedule_lines    type table of bapischdl.
data: lt_schedule_lines_x  type table of bapischdlx.

*** Schedule Lines Structure
data: ls_schedule_lines    type bapischdl.
data: ls_schedule_lines_x  type bapischdlx.

*** Return Table
data: lt_return type table of bapiret2.
data: ls_return type bapiret2.


*** Header Information
ls_order_header_in-sales_org = '1000'.
ls_order_header_in-distr_chan = '10'.
ls_order_header_in-division   = '00'.
*ls_order_header_in-sales_grp  = '110'.
*ls_order_header_in-sales_off  = '1010'.

***To update
ls_order_header_inx-updateflag = 'U'.

*** Schedule Line Information
ls_schedule_lines-itm_number = '000010'.
ls_schedule_lines-sched_line = '0003'.
*ls_schedule_lines-req_date   = '20050401'.
ls_schedule_lines-date_type  = '1'.
ls_schedule_lines-req_qty    = '105.000'.
append ls_schedule_lines to lt_schedule_lines.
*
ls_schedule_lines-itm_number = '000010'.
ls_schedule_lines-sched_line = '0003'.
*ls_schedule_lines-req_date   = '20050401'.
ls_schedule_lines-date_type  = '1'.
ls_schedule_lines-req_qty    = '130.000'.
append ls_schedule_lines to lt_schedule_lines.

ls_schedule_lines_x-itm_number = '000010'.
ls_schedule_lines_x-sched_line = '0003'.
ls_schedule_lines_x-updateflag = 'U'.
ls_schedule_lines_x-req_date   = 'X'.
ls_schedule_lines_x-date_type  = 'X'.
ls_schedule_lines_x-req_qty    = 'X'.
append ls_schedule_lines_x to lt_schedule_lines_x.

*ls_schedule_lines-itm_number = '000010'.
*ls_schedule_lines-sched_line = '0039'.
*ls_schedule_lines-req_date   = '20050401'.
*ls_schedule_lines-date_type  = '1'.
*ls_schedule_lines-req_qty    = '80.000'.
*append ls_schedule_lines to lt_schedule_lines.
*
*ls_schedule_lines_x-itm_number = '000010'.
*ls_schedule_lines_x-sched_line = '0039'.
*ls_schedule_lines_x-updateflag = 'I'.
*ls_schedule_lines_x-req_date   = 'X'.
*ls_schedule_lines_x-date_type  = 'X'.
*ls_schedule_lines_x-req_qty    = 'X'.
*append ls_schedule_lines_x to lt_schedule_lines_x.
*

call function 'BAPI_SALESORDER_CHANGE'
  exporting
    salesdocument               = p_vbeln
    order_header_in             = ls_order_header_in
    order_header_inx            = ls_order_header_inx
*   SIMULATION                  =
*   BEHAVE_WHEN_ERROR           = ' '
*   INT_NUMBER_ASSIGNMENT       = ' '
*   LOGIC_SWITCH                =
  tables
    return                      = lt_return
    order_item_in               = lt_order_item_in
    order_item_inx              = lt_order_item_inx
*   PARTNERS                    =
*   PARTNERCHANGES              =
*   PARTNERADDRESSES            =
*   ORDER_CFGS_REF              =
*   ORDER_CFGS_INST             =
*   ORDER_CFGS_PART_OF          =
*   ORDER_CFGS_VALUE            =
*   ORDER_CFGS_BLOB             =
*   ORDER_CFGS_VK               =
*   ORDER_CFGS_REFINST          =
    schedule_lines              = lt_schedule_lines
    schedule_linesx             = lt_schedule_lines_x
*   ORDER_TEXT                  =
*   ORDER_KEYS                  =
*   CONDITIONS_IN               =
*   CONDITIONS_INX              =
*   EXTENSIONIN                 =
          .

call function 'BAPI_TRANSACTION_COMMIT'
 exporting
   wait          = 'X'
* IMPORTING
*   RETURN        =

Regards,

Subramanian V.

0 Kudos

Thank you .. I too got same issue. it is manadatory that we should pass schedule details.

former_member534411
Participant
0 Kudos

Hi Subramanian,

Thanks a lot spending time on this issue. If you have free time can you please write sample code on <b>'BAPI_SALESORDER_CREATEFROMDAT2'</b> add logic for quantity of the order.

i have't pass structure for ORDER_HEADER_INX to update line item data even order is creating.

If you need i will send my total code of my program.

//suresh

former_member534411
Participant
0 Kudos

Hi subramanian,

Thanks a lot try to help me in all aspects, now i sort out the issue about order quantity.

schedule line items structure having a field called order quantity. i just passed that stucture also as internal table to the BAPI. so now it was updating the quantity.

In normal practice line item data is copied to the <b>schedule line</b> items here it was in the <b>reverse process </b>.

//suresh

0 Kudos

Hi Suresh,

Good to know that you were able to solve your problem and thank you for sharing the information , how you went about it.

Kindly mark the thread as answered, so that others can benefit out of this.

Regards,

Subramanian V.

former_member534411
Participant
0 Kudos

Hi Subramanian,

I could not able to see any quantity field in <b>BAPISDITM</b> but i can see in <b>BAPISCHDL</b>. we have nearly 8 fields which had name with quantity in <b>BAPISDITM</b> , i given values to all those fields

1,2,...8 to test but it was not updating. so i try to search other structures.

//suresh

0 Kudos

Hi Suresh,

I am not sure if your problem is solved or you are still having problem. I see in one post you mentioned that you were able to pass the quantities, but in your last response you still seems to be asking about quantity fields.

The quantity field in BAPISDITM is TARGET_QTY and you need to fill in the TARGET_QU along with it. As Subramanian already pointed out, you need to fill in the corresponding 'X' structures and the fields with 'X'.

I am not sure if you are able to create the sales order or not. If not your error messages will be returned in the RETURN table of your BAPI call. Look at those messages and see if that gives you a hint. If not, post the messages here so that someone will help.

Srinivas

former_member534411
Participant
0 Kudos

Hi Srinivas,

I have resolved the problem, had problem in the <b>order quantity</b> not in <b>Target quantity</b> . that has been resolved using the <b>schedule line sturctures</b>. we need not to fill in the corresponding 'X' structures and the fields with 'X', i guess i.e. needed when you are changing the sales orders.

//suresh

Former Member
0 Kudos

Hi Suresh,

can you please elobarate on ur explanation as I am also facing the same problem and I need the solution urgently.

I am able to upload the material information but unable to upload the corresponding quantity info.

Expecting ur reply at the earliest.

regards,

Daya.

former_member534411
Participant
0 Kudos

Hi Daya shankar,

sales order <b>BAPI_SALESORDER_CREATEFROMDAT2</b> there is structure called <b>BAPISCHDL</b> for <b>schedule line items</b>, just fill that structure as like <b>BAPISDITM</b> along with item position number in order to populate the quantity for your material.

still you are not clear please post the code i will try explain where you have to add the code.

//suresh