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: 

Quantity In BAPI_SALESORDER_CREATEFROMDAT2 Not Updating

Former Member
0 Kudos

Hi All,

I have a requirement to create Sales order(VA01), PGI(VL02N) and Billing(VF01) automatically when I enter customer material and Quantity. All the above should be done programatically.

So I am using the BAPI BAPI_SALESORDER_CREATEFROMDAT2 in creating a sales Order. In Standard Transaction VA01 when I am giving Cust No, material and Quantity, it is creating a sales order and delevery and giving the Success message 19 has been saved (80000456 Delivery created)

If Delivery No is there only I can make PGI with another BAPI. But Delivery is not Creating with the BAPI I BAPI_SALESORDER_CREATEFROMDAT2.

When I use the BAPI with parameters Doc type, Cust no, Partner Type(AG), Material and Quantity, Sales Order is Creating but Quantity is not Updating..I am also passing the header X and Item X values.

I am Getting the below Return Messages

SALES_HEADER_IN has been processed successfully

SALES_ITEM_IN has been processed successfully

The sales document is not yet complete: Edit data

19 has been saved (no delivery created)

Can any One help me in this Regard..

Should I nee to paas More Parameters?

Or Can any one tell me in detail about the Parameters to be Passed To the above BAPI to get its Correct Functionality.

Thanks in Advance.

Regards

Avinash.

Edited by: Avinash on Feb 4, 2010 3:24 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

CLEAR lwa_bapiitemsb.

lw_posnr = lw_posnr + 10.

lwa_bapiitemsb-plant = lw_bapi-werks.

lwa_bapiitemsb-itm_number = lw_posnr.

lwa_bapiitemsb-material = lwa_outtab-matnr.

lwa_bapiitemsb-target_qty = ABS( lwa_outtab-kwmeng_f ). "Quantity passed

lwa_bapiitemsb-item_categ = 'ZFRE'.

lwa_bapiitemsb-cust_mat35 = lwa_outtab-no.

lwa_bapiitemsb-dlvschduse = lwa_outtab-vkaus.

APPEND lwa_bapiitemsb TO lit_bapiitemsb.

After every item you will have to have to pass the schedule line item also as follows,

CLEAR lwa_bapischdl.

lwa_bapischdl-req_qty = lwa_outtab-kwmeng_f. "Quantity passed

lwa_bapischdl-itm_number = lw_posnr.

APPEND lwa_bapischdl TO lit_bapischdl.

then the next item can be appended,

and finally passed to the BAPI as follows,

CALL FUNCTION 'ISM_SALESORDER_CREATEFROMDAT2'

EXPORTING

order_header_in = lw_bapiheaderb

IMPORTING

salesdocument = lw_docnob

TABLES

return = lit_returnb

order_items_in = lit_bapiitemsb

order_partners = lit_bapiparnrb

order_schedules_in = lit_bapischdl

order_conditions_in = lit_bapicondsb.

  • CLEAR level1.

IF NOT lw_docnob IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

This will do it ,

Hope this helps you,

Regards,

Abhijit G. Borkar

4 REPLIES 4

Former Member
0 Kudos

Hi,

CLEAR lwa_bapiitemsb.

lw_posnr = lw_posnr + 10.

lwa_bapiitemsb-plant = lw_bapi-werks.

lwa_bapiitemsb-itm_number = lw_posnr.

lwa_bapiitemsb-material = lwa_outtab-matnr.

lwa_bapiitemsb-target_qty = ABS( lwa_outtab-kwmeng_f ). "Quantity passed

lwa_bapiitemsb-item_categ = 'ZFRE'.

lwa_bapiitemsb-cust_mat35 = lwa_outtab-no.

lwa_bapiitemsb-dlvschduse = lwa_outtab-vkaus.

APPEND lwa_bapiitemsb TO lit_bapiitemsb.

After every item you will have to have to pass the schedule line item also as follows,

CLEAR lwa_bapischdl.

lwa_bapischdl-req_qty = lwa_outtab-kwmeng_f. "Quantity passed

lwa_bapischdl-itm_number = lw_posnr.

APPEND lwa_bapischdl TO lit_bapischdl.

then the next item can be appended,

and finally passed to the BAPI as follows,

CALL FUNCTION 'ISM_SALESORDER_CREATEFROMDAT2'

EXPORTING

order_header_in = lw_bapiheaderb

IMPORTING

salesdocument = lw_docnob

TABLES

return = lit_returnb

order_items_in = lit_bapiitemsb

order_partners = lit_bapiparnrb

order_schedules_in = lit_bapischdl

order_conditions_in = lit_bapicondsb.

  • CLEAR level1.

IF NOT lw_docnob IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

This will do it ,

Hope this helps you,

Regards,

Abhijit G. Borkar

Former Member
0 Kudos

Thanks For The Great Help.

Now I am able to Create all the above said documents correctly.

One more clarification needed.

While doing sales, delivery, and billing, where exactly we need to lock the material.Can any one tell me the exact Enque Function Module to lock the material.

For Sales Document Only I am Using the above BAPI,

For Deliver and Billing I am using BDC.

Some times all documents are creating Perfectly and some times not.

So I think the Issue is with locking.

So any one Please help me on this.

Regards

Avinash

0 Kudos

Hi Avinash,

I have same requirement as yours, and getting same problem i.e sales order getting created without delivery.

Please let me know how you solved this problem. I have also tired using FM ISM_SALESORDER_CREATEFROMDAT2 as suggested by Abhijit but still getting same error.

Please help.

Thanks,

Siddhesh

myominkhaing
Explorer
0 Kudos

Below Code are not working as well

public static void BAPI_SALESORDER_CREATEFROMDAT2() throws JCoException { int P_ITM_NUMBER=1; int P_Quantity=1; BigDecimal P_COND_VALUE = new BigDecimal("1000.00"); JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem"); JCoFunction function = destination.getRepository().getFunction("BAPI_SALESORDER_CREATEFROMDAT2"); JCoContext.begin(destination); if (function == null) { throw new RuntimeException("Function not found in SAP."); } else { JCoParameterList importParameterList = function.getImportParameterList(); System.out.println(importParameterList); JCoStructure input_header3 = importParameterList.getStructure("ORDER_HEADER_IN"); input_header3.setValue("DOC_TYPE", "Z201"); input_header3.setValue("SALES_ORG", "1000"); input_header3.setValue("DISTR_CHAN", "10"); input_header3.setValue("DIVISION", "00"); input_header3.setValue("PURCH_DATE", new Date()); JCoParameterList tables = function.getTableParameterList(); System.out.println(tables); JCoTable table1 = tables.getTable("ORDER_ITEMS_IN"); table1.appendRow(); table1.setRow(1); table1.setValue("ITM_NUMBER","000001"); table1.setValue("MATERIAL","000000000050000002"); table1.setValue("PLANT","1100"); table1.setValue("STORE_LOC","1102"); table1.setValue("TARGET_QTY",1); table1.setValue("TARGET_QU","CAR"); table1.appendRow(); table1.setRow(2); table1.setValue("ITM_NUMBER","000002"); table1.setValue("MATERIAL","000000000050000001"); table1.setValue("PLANT","1100"); table1.setValue("STORE_LOC","1102"); table1.setValue("TARGET_QTY",1); table1.setValue("TARGET_QU","CAR"); JCoTable table2 = tables.getTable("ORDER_PARTNERS"); table2.appendRow(); table2.setRow(1); table2.setValue("PARTN_ROLE","AG");//AG table2.setValue("PARTN_NUMB","0001000206"); table2.setValue("ITM_NUMBER","000000"); table2.appendRow(); table2.setRow(2); table2.setValue("PARTN_ROLE","WE");//AG table2.setValue("PARTN_NUMB","0001000206"); table2.setValue("ITM_NUMBER","000000"); JCoTable table_SCHEDULES_IN = tables.getTable("ORDER_SCHEDULES_IN"); table_SCHEDULES_IN.appendRow(); table_SCHEDULES_IN.setRow(1); table_SCHEDULES_IN.setValue("ITM_NUMBER","000001"); table_SCHEDULES_IN.setValue("REQ_DATE",new Date()); table_SCHEDULES_IN.setValue("REQ_QTY",1); table1.appendRow(); table_SCHEDULES_IN.setRow(2); table_SCHEDULES_IN.setValue("ITM_NUMBER","000002"); table_SCHEDULES_IN.setValue("REQ_DATE",new Date()); table_SCHEDULES_IN.setValue("REQ_QTY",1); JCoTable table_SCHEDULES_INX = tables.getTable("ORDER_SCHEDULES_INX"); table_SCHEDULES_INX.appendRow(); table_SCHEDULES_INX.setRow(1); table_SCHEDULES_INX.setValue("ITM_NUMBER","000001"); table_SCHEDULES_INX.setValue("REQ_DATE","X"); table_SCHEDULES_INX.setValue("REQ_QTY","X"); table_SCHEDULES_INX.setValue("REQ_TIME","X"); table_SCHEDULES_INX.appendRow(); table_SCHEDULES_INX.setRow(2); table_SCHEDULES_INX.setValue("ITM_NUMBER","000002"); table_SCHEDULES_INX.setValue("REQ_DATE","X"); table_SCHEDULES_INX.setValue("REQ_QTY","X"); table_SCHEDULES_INX.setValue("REQ_TIME","X"); JCoTable table3 = tables.getTable("ORDER_CONDITIONS_IN"); table3.appendRow(); table3.setRow(1); table3.setValue("ITM_NUMBER","000001"); table3.setValue("COND_TYPE","ZP00"); table3.setValue("COND_VALUE",P_COND_VALUE); table3.setValue("CURRENCY","MMK"); table3.appendRow(); table3.setRow(2); table3.setValue("ITM_NUMBER","000002"); table3.setValue("COND_TYPE","ZP00"); table3.setValue("COND_VALUE",P_COND_VALUE); table3.setValue("CURRENCY","MMK"); try { function.execute(destination); JCoParameterList exportParameterList = function.getExportParameterList(); System.out.println(exportParameterList); String value = exportParameterList.getValue("SALESDOCUMENT").toString(); System.out.println("SalesOrder:"+ value); JCoParameterList tables1 = function.getTableParameterList(); System.out.println(tables1); JCoTable table_R = tables1.getTable("RETURN"); System.out.println(table_R); System.out.println(table_R.getString("MESSAGE")); System.out.println(table_R.getString("TYPE")); System.out.println(table_R.getString("MESSAGE_V1")); System.out.println(table_R.getString("MESSAGE_V2")); System.out.println(table_R.getString("MESSAGE_V3")); System.out.println(table_R.getString("MESSAGE_V4")); TRANSACTION_COMIT(); } catch (AbapException e) { System.out.println(e.toString()); return; } } } }