BAPI - Sales Order
Hello all,
This is a simple question in regards to the sales order bapi. If I have an external program call the bapi and it has 10 line items will the sales order be created if one of the line items is in valid. For example, 10 line items are passed and line item 8 has an invalid material. Will the order be created with 9 items or will the bapi call fail due to the error.
Thanks,
Chris
I just made a quick test with an existing upload report where I am using 'BAPI_SALESDOCU_CREATEFROMDATA'. In case you pass in a material which doesn't exist, the BAPI errors out completely and no order is created at all. In your example you would not get the 9 valid items created but the whole order will fail.
In my case we might get invalid ISBN numbers which we translate into materials before we call the BAPI. At this point I do a check to MARA to make sure that the material is valid. If not I am not even passing it to the BAPI.
Your example again, my check would find out that one of the materials is invalid and only pass the 9 valid items to the BAPI which will then successfully create the order.
Hope that helps,
Michael
Similar Messages
-
Error in JCo while connecting BAPI SALES ORDER.
package com.sap;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.Exception;
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
public class DirectBAPI extends AbstractPortalComponent
public void doContent(IPortalComponentRequest request,
IPortalComponentResponse response)
JCO.Client mConnection;
JCO.Repository mRep;
response.write("Connecting..........");
try
// Change the logon information to your own system/user
mConnection = JCO.createClient("<client number>", "<user Id>", "password",
null, // language
"application server number", "<system no..>");
response.write("Reached");
mConnection.connect(); // connecting JCo...
mRep = new JCO.Repository("SAPJCo", mConnection); //use JCo Repository....
response.write("Connected Succesfully");
//response.write( mConnection.getAttributes() );
// mConnection.disconnect();
catch (Exception ex)
ex.printStackTrace();
response.write(ex.getMessage());
JCO.Function function = null;
JCO.FunctionTemplate ftp = null;
JCO.Table codes = null;
try
ftp = mRep.getFunctionTemplate();
function = ftp.getFunction();
function = this.createFunction("BAPI_SALESORDER_GETSTATUS");
// Accessing SALES_ORDER_GETSTATUS.
if (function == null)
response.write("BAPI_COMPANYCODE_GETLIST" + " not found in SAP.");
catch (Exception exx)
response.write(exx.getmessage() );
In the above code while while connecting to the BAPI SALES ORDER GET_STATUS an error is coming for JCO connection for the JCo Repository.
The method createFunction() is undefined for the type of Project.
plz guide how to rectify this so as to connect BAPI SALES ORDER thru JCo connection.
Thanx in advance.
Regards:
HanifHi,
The below Code is helpful for Calling BAPI's Using JCO .
public class TestJCO {
JCO.Client mConnection;
JCO.Repository mRepository;
public TestJCO() {
try {
// Change the logon information to your own system/user
// mConnection =
// JCO.createClient("800", // SAP client
// "USERID", // userid
// "password", // password
// null, // language
// "appserver hostname", // application server host name
// "00"); // system number
mConnection =
JCO.createClient("002", // SAP client
"userid", // userid
"password", // password
null, // language
"app server host name", // application server host name
"00"); // system number
mConnection.connect();
mRepository = new JCO.Repository("companyname", mConnection);
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
JCO.Function function = null;
JCO.Table codes = null;
try {
function = this.createFunction("BAPI_COMPANYCODE_GETLIST");
if (function == null) {
System.out.println("BAPI_COMPANYCODE_GETLIST" +
" not found in SAP.");
System.exit(1);
mConnection.execute(function);
JCO.Structure returnStructure =
function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S")) ) {
System.out.println(returnStructure.getString("MESSAGE"));
System.exit(1);
codes =
function.getTableParameterList().getTable("COMPANYCODE_LIST");
for (int i = 0; i < codes.getNumRows(); i++) {
codes.setRow(i);
System.out.println(codes.getString("COMP_CODE") + '\t' +
codes.getString("COMP_NAME"));
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
try {
codes.firstRow();
for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {
function = this.createFunction("BAPI_COMPANYCODE_GETDETAIL");
if (function == null) {
System.out.println("BAPI_COMPANYCODE_GETDETAIL" +
" not found in SAP.");
System.exit(1);
function.getImportParameterList().
setValue(codes.getString("COMP_CODE"), "COMPANYCODEID");
function.getExportParameterList().setActive(false, "COMPANYCODE_ADDRESS");
mConnection.execute(function);
JCO.Structure returnStructure =
function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S") ||
returnStructure.getString("TYPE").equals("W")) ) {
System.out.println(returnStructure.getString("MESSAGE"));
JCO.Structure detail =
function.getExportParameterList().
getStructure("COMPANYCODE_DETAIL");
System.out.println(detail.getString("COMP_CODE") + '\t' +
detail.getString("COUNTRY") + '\t' +
detail.getString("CITY"));
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
mConnection.disconnect();
public JCO.Function createFunction(String name) throws Exception {
try {
IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());
if (ft == null)
return null;
return ft.getFunction();
catch (Exception ex) {
throw new Exception("Problem retrieving JCO.Function object.");
public static void main(String[] args) {
TestJCO app = new TestJCO();
Please Check your code with above code.
Thanks,
SubbaRao Chinta -
Userexit in BAPI sales order creation
HI all,
My requirement is one SERIALNUMBER field add BAPI salesorder creation.
That field not existed in satndard BAPI structures.BAPI input XML file.
Salesorder>extras(menu)>Technical object->serialmumber[RIPW0SERNR).
please give any enhancement serial number BAPI sales order creation.
Thanks.
Edited by: sreddy GPs on Sep 23, 2008 5:59 AMHello,
Whatever the Structure that you are refering to in the BAPI for Sales Order Creation, use an Append Structure to add the SERIALNUMBER field to the existing Standard BAPI Structure.
For your information, the following are the BAPIs that can be used for Sales Order Creation.
BAPI_SALESORDER_CREATEFROMDAT1
BAPI_SALESORDER_CREATEFROMDAT2
BAPI_SALESORDER_CREATEFROMDATA
BAPI_SALESORDER_CREATEBOS
Hope it would serve your purpose.
Thanks and Regards,
Venkat Phani Prasad Konduri -
Updating a child of a BOM material using bapi sales order change
Hi, Appreciate your thoughts on the following issue..
We have a batch program which uses a bapi sales order change and updates the plant at the line items of the sales order. when this plant is assigned.. if any of the line item is a BOM item, it explodes and the data from the parent ( like payment terms, fixed val date ) should get copied to the child items same as the parent. This is happening fine if manual mode using va01 and va02 but when plant is updated using bapi the childs are not getting the data from the parent ( which comes through config )...
Appreciate your inputs and any additional information to be passed to the bapi for the BOM materials to get the same config data as parent to the child when exploded...
Thanks and will reward helpful answers..Hi, Appreciate your thoughts on the following issue..
We have a batch program which uses a bapi sales order change and updates the plant at the line items of the sales order. when this plant is assigned.. if any of the line item is a BOM item, it explodes and the data from the parent ( like payment terms, fixed val date ) should get copied to the child items same as the parent. This is happening fine if manual mode using va01 and va02 but when plant is updated using bapi the childs are not getting the data from the parent ( which comes through config )...
Appreciate your inputs and any additional information to be passed to the bapi for the BOM materials to get the same config data as parent to the child when exploded...
Thanks and will reward helpful answers.. -
BAPI SALES ORDER & Copy with reference
Hello,
I'm creating sales order copied with reference to an invoice. My problem is that the data item is empty. When I create the sales order manually and use the option 'Create with reference' and choose an invoice, the sales order is created with all data item. I don't know how I can get to copy the data item from the invoice in the new sales order. The code that I'm using is the following:
DATA: order_header_in LIKE bapisdhd1,
order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,
order_text LIKE bapisdtext OCCURS 0 WITH HEADER LINE,
order_header_inx LIKE bapisdhd1x,
order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,
order_schedules_in LIKE bapischdl OCCURS 0 WITH HEADER LINE,
order_conditions_in LIKE bapicond OCCURS 0 WITH HEADER LINE,
extensionin LIKE bapiparex OCCURS 0 WITH HEADER LINE,
partneraddresses LIKE bapiaddr1 OCCURS 0 WITH HEADER LINE,
order_cfgs_ref like BAPICUCFG occurs 0 with header line.
DATA: salesdocument LIKE bapivbeln-vbeln.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
order_header_in-doc_type = 'ZA09'.
order_header_in-sales_org = '1700'.
order_header_in-distr_chan = '01'.
order_header_in-division = '01'.
order_header_in-BILL_DATE = '20060701'.
order_header_in-ref_doc = '0900000019'.
order_header_in-refdoc_cat = 'M'.
*order_header_in-REF_DOC_L_LONG = '0900000019'.
order_header_in-purch_no_c ='prueba'.
*order_header_in-ord_reason = '003'.
*order_header_in-pmnttrms = '0002'.
*order_header_in-sales_off = '2800'.
order_header_in-ref_doc_l = 'FACTURA ES'.
*order_header_in-fix_val_dy = '20060701'.
*order_header_in-currency = 'USD'.
*order_header_in-exchg_rate = '1.2'.
order_partners-partn_role = 'AG'.
order_partners-partn_numb = '0000000001'.
order_partners-langu = 'EN'.
order_partners-name = 'El corte aleman'.
order_partners-country = 'ES'.
APPEND order_partners.
order_partners-partn_role = 'RE'.
order_partners-partn_numb = 'ARR000'.
order_partners-addr_link = '0000030044'.
APPEND order_partners.
CALL FUNCTION 'ADDR_GET_COMPLETE_ALL_TYPES'
EXPORTING
addrnumber = order_partners-addr_link
PERSNUMBER =
address_object_type = '1'
IV_CURRENT_COMM_DATA = 'X'
IMPORTING
ADDR1_COMPLETE =
ADDR2_COMPLETE =
ADDR3_COMPLETE =
ADDR1_COMPLETE_BAPI = partneraddresses
ADDR2_COMPLETE_BAPI =
ADDR3_COMPLETE_BAPI =
EXCEPTIONS
PARAMETER_ERROR = 1
ADDRESS_NOT_EXIST = 2
PERSON_NOT_EXIST = 3
INTERNAL_ERROR = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
data: vl_texto(40) value 'NUEVOOOOO'.
partneraddresses-name = vl_texto. clear vl_texto.
partneraddresses-name_2 = vl_texto.
partneraddresses-name_3 = vl_texto.
partneraddresses-name_4 = vl_texto.
partneraddresses-langu = 'E'.
APPEND partneraddresses.
DATA: vl_cantidad LIKE bapisditm-target_qty.
vl_cantidad = 1.
order_item_in-itm_number = 10.
order_item_in-material = 'HONORARIOS'.
order_item_in-ref_doc = '0900000019'.
order_item_in-ref_doc_it = 10.
order_item_in-ref_doc_ca = 'M'.
APPEND order_item_in.
order_schedules_in-itm_number = 10.
order_schedules_in-req_qty = vl_cantidad.
APPEND order_schedules_in.
order_text-text_id = 'Z001'.
order_text-ITM_NUMBER = ''.
order_text-langu = 'EN'.
order_text-text_line = 'Hola, CARACOLAcola'.
APPEND order_text.
order_text-text_id = 'Z001'.
order_text-langu = 'EN'.
order_text-text_line = 'Adios caracol'.
APPEND order_text.
order_text-itm_number = '000010'.
order_text-text_id = '0001'.
order_text-langu = 'EN'.
order_text-text_line = 'Hola, POSICIÓN'.
APPEND order_text.
extensionin-structure = 'BAPE_VBAK'.
extensionin-valuepart1 = ' BCL 7'.
APPEND extensionin.
order_cfgs_ref-posex = '10'.
order_cfgs_ref-config_id = '10'.
order_cfgs_ref-root_id = '00000001'.
append order_cfgs_ref.
CALL FUNCTION 'ZBAPI_SALESORDER_CREATEFROMDT2'
EXPORTING
SALESDOCUMENTIN = salesdocument
order_header_in = order_header_in
ORDER_HEADER_INX = order_header_inx
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
IMPORTING
salesdocument = salesdocument
TABLES
return = return
order_items_in = order_item_in
ORDER_ITEMS_INX =
order_partners = order_partners
order_schedules_in = order_schedules_in
ORDER_SCHEDULES_INX =
order_conditions_in = order_conditions_in
ORDER_CONDITIONS_INX =
ORDER_CFGS_REF = order_cfgs_ref
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
ORDER_CCARD =
order_text = order_text
ORDER_KEYS =
extensionin = extensionin
partneraddresses = partneraddresses
PERFORM report TABLES return.
*DATA: salesdocument LIKE bapivbeln-vbeln.
*DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*refresh return.
*CALL FUNCTION 'BAPI_SALESDOCUMENT_COPY'
EXPORTING
salesdocument = '0400000191'
documenttype = 'ZA04'
TESTRUN = ' '
IMPORTING
SALESDOCUMENT_EX = salesdocument
TABLES
RETURN = return
*PERFORM report TABLES return.
*write: / salesdocument.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
*& Form report
text
-->P_MENSAJE text
FORM report TABLES p_mensaje STRUCTURE bapiret2.
DATA: vl_mensaje TYPE string.
LOOP AT return.
CLEAR vl_mensaje.
MESSAGE ID return-id
TYPE return-type
NUMBER return-number
INTO vl_mensaje
WITH return-message_v1
return-message_v2
return-message_v3
return-message_v4.
WRITE: / vl_mensaje.
ENDLOOP.
ENDFORM. " reportHi Manuel,
There are some function modules which is there to copy the order details. I am not sure about the function module name. But you can search in SE37. But bapi for creating the sales order does not have the functionality of copying the data from one document to another document.
You can try using this function module.
BAPI_SALESDOCUMENT_COPY
Data will be copied based on the copy control routines that is set between the two document types.
Thanks,
Arun -
Error in bapi sales order creation
hi..
I m creating sales order using bapi fm, It was working fine, but all of a sudden it is giving error 'NO OBJECT STATUS AVAILABLE FOR SDI 0.' and Sales order is not gettign created. Any idea why the problem occurs?Hi Cynthia,
This is probably caused by a COMMIT WORK in a user exit during sales order processing. This COMMIT WORK triggers FM BUFFER_STATUS_REFRESH which in turn causes this problem.
You can easily find out by putting a break-point in this FM and then take a look in the call-stack to find out where the commit work occurred.
Regards.
John. -
LSMW-BAPI Sales order creation
Hi All,
I was trying to create sales order through the LSMW BAPI method.
For the first line item i'm getting the correct quantity that i''m passing.
But from second line item onwards quantity field is appearing as 0 (zero) even though i pass the different quantity values.
i'm assiging the quantity to the REQ_QTY field in the schedule line items structure.
Please suggest any solution for this.
Thanking you.
with regards,
BharathHi,
Can u tell me the steps to create a sales order using idoc, i've created a bapi but thats a temprory use. I wanted to created a sales order automatically when a purchase order is saved.
Please let me know if u can help me, i wanted to do it using idoc
Regards
Sanju -
Bapi sale order Reason for rejection
hi,
i want to update "Reason for rejection" of sale order
through BAPI ,
So how should i find it in BAPI_SALESORDER_CHANGE .
in which table of this bapi ?
ThanksHi
Re: update sales orders
http://abap.wikiprog.com/wiki/BAPI_SALESORDER_CHANGE
regards
Pavan -
Hi folks,
Can anybody tell me the BAPI name to update the plant, route and storage location in the sales order.
if possible please tell me BAPI name in general which updates the sales order values...
thanks in advanceHi,
Use the bapi'S 'BAPI_SALESORDER_CHANGE'
and 'BAPI_TRANSACTION_COMMIT' to update the sales orders.
Regards,
Sudheer Kumar -
hi folks,
iam doing LSMW Bapi method for sales order creation do we need to create mandatorly header and item structure for in source structure creation in LSMW ?points will be rewarded for useful answers.Yes u need to create two structures one for header and the other for line item. Within Src structure first create Structure for Header Data then create another structure UNDER Header Data (LOWER LEVEL).
~Sid -
BAPI Sales order create with reference
Hi
I need to use BAPI to create sales order with reference to Quantity Contract. The line item material quantity would be less than or equal to quantity contract quantity.
Sales order needs to be created with new quantity.
Quantity contract quantity change needs to be maintained.
Document flow needs to be maintained.
Is any one aware if this is possible using BAPI_SALESORDER_CREATEFROMDAT2. If yes, how?
Any insights would be highly appreciated.Hi Maninder,
The BAPI does not allow the Pricing Conditions to be sourced from the Contract. I debugged the BAPI and it uses a piece of code (don't recall which subroutine though) from SAPMV45A which is relevant for dialog processing where it reads from the VBAP and *VBAP structures. Well this structure is only populated when you are using the Front End transaction (VA41, VA42, etc). Because this structure is empty, pricing conditions do not flow across.
Here is a little prototype program I whipped up to test my method of creating a Sales order and then changing the Sales Order:
REPORT ypat_salesorder_create LINE-SIZE 256.
* This program will create a ZOC Sales Order with Reference to Contract
* 20000720 / 10. This will be done via BAPI. There are 2 BAPi calls,
* BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE. We need to
* perform 2 BAPI calls as the BAPI to create the Sales Order does not
* bring across the Pricing Conditions properly. To get around this we
* create the Order with reference to the Contract, then we get the
* related Pricing Conditions from the COntract and then update the newly
* created Order.
* Constants
CONSTANTS: c_contract LIKE vbak-vbeln VALUE '0020000720',
c_item LIKE vbap-posnr VALUE '000010'.
* Structures
* Structure to hold BAPI Header
DATA: st_bapisdhd1 LIKE bapisdhd1.
* Internal Tables
* Sales Order Create BAPI Return Messages
DATA: tbl_return TYPE STANDARD TABLE OF bapiret2
WITH HEADER LINE.
* Sales Order BAPI Line Item
DATA: tbl_bapisditm TYPE STANDARD TABLE OF bapisditm
WITH HEADER LINE.
* Sales Order BAPI Line Item
DATA: tbl_bapisditmx TYPE STANDARD TABLE OF bapisditmx
WITH HEADER LINE.
* Sales Order BAPI Pricing Conditions
DATA: tbl_bapicond TYPE STANDARD TABLE OF bapicond
WITH HEADER LINE.
* Sales Order BAPI Partner Functions
DATA: tbl_bapiparnr TYPE STANDARD TABLE OF bapiparnr
WITH HEADER LINE.
* Sales Order BAPI Schedule Lines
DATA: tbl_bapischdl TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.
* Sales Order BAPI Schedule Lines
DATA: tbl_bapischdlx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
* Sales Order BAPI Pricing Conditions
DATA: tbl_bapicondx TYPE STANDARD TABLE OF bapicondx
WITH HEADER LINE.
* Customer Enhancement for VBAK, VBAP, VBEP
DATA: tbl_bapiparex TYPE STANDARD TABLE OF bapiparex
WITH HEADER LINE.
* Table to hold BAPI Detail Conditions
DATA: tbl_bapisdcond TYPE STANDARD TABLE OF bapisdcond
WITH HEADER LINE.
* Table to hold Return Messages from Sales Order Change BAPI
DATA: tbl_return_chg TYPE STANDARD TABLE OF bapiret2
WITH HEADER LINE.
* Variables
DATA: g_vbeln_created LIKE vbak-vbeln,
g_valid_contract TYPE c,
g_cont_price_date TYPE d.
* Start of Selection
START-OF-SELECTION.
PERFORM validate_contract.
PERFORM create_sales_ord.
PERFORM update_sales_ord.
* End of Selection
END-OF-SELECTION.
PERFORM write_output_report.
* Subroutines
*& Form create_sales_ord
* Create the Sales Order
FORM create_sales_ord .
PERFORM populate_bapi_tables.
PERFORM call_create_sales_ord_bapi.
ENDFORM. " create_sales_ord
*& Form populate_bapi_tables
* Fill up the BAPI Tables
FORM populate_bapi_tables .
PERFORM populate_bapi_header.
PERFORM build_bapi_partners.
PERFORM build_bapi_items.
PERFORM build_bapi_sched_lines.
ENDFORM. " populate_bapi_tables
*& Form populate_bapi_header
* Build BAPI Header Details
FORM populate_bapi_header .
CLEAR st_bapisdhd1.
st_bapisdhd1-doc_type = 'ZOC'. "Order type
st_bapisdhd1-sales_org = '026'. "Sales Org
st_bapisdhd1-distr_chan = '00'. "Dist Channel
st_bapisdhd1-division = '00'. "Division
st_bapisdhd1-purch_no_c = 'Cust Po No'. "Cust PO No
st_bapisdhd1-name = 'Orderer'. "Name of Orderer
st_bapisdhd1-ord_reason = ''. "Order Reason
st_bapisdhd1-sales_off = '3001'. "Sales Office
st_bapisdhd1-sales_grp = '301'. "Market Area
IF g_valid_contract = 'X'.
st_bapisdhd1-price_date = g_cont_price_date.
ENDIF.
ENDFORM. " populate_bapi_header
*& Form build_bapi_partners
* Build BAPI Partner Functions
FORM build_bapi_partners .
CLEAR tbl_bapiparnr.
tbl_bapiparnr-partn_role = 'AG'.
tbl_bapiparnr-partn_numb = '0000100750'.
APPEND tbl_bapiparnr.
CLEAR tbl_bapiparnr.
tbl_bapiparnr-partn_role = 'WE'.
tbl_bapiparnr-partn_numb = '0000504472'.
APPEND tbl_bapiparnr.
ENDFORM. " build_bapi_partners
*& Form build_bapi_items
* Build The BAPI Line Items
FORM build_bapi_items .
DATA: l_matnr LIKE mara-matnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '10000072'
IMPORTING
output = l_matnr.
CLEAR tbl_bapisditm.
tbl_bapisditm-itm_number = c_item.
IF g_valid_contract = 'X'.
tbl_bapisditm-ref_doc = c_contract.
tbl_bapisditm-ref_doc_it = c_item.
tbl_bapisditm-ref_doc_ca = 'G'. "Contract
ENDIF.
tbl_bapisditm-material = l_matnr.
tbl_bapisditm-plant = '3012'.
tbl_bapisditm-target_qty = '5.000'.
tbl_bapisditm-target_qu = 'M3'.
tbl_bapisditm-item_categ = 'ZZOC'.
tbl_bapisditm-sales_dist = '301'.
tbl_bapisditm-dlv_prio = '02'.
tbl_bapisditm-prc_group5 = '080'.
tbl_bapisditm-cust_mat35 = 'kdmat'.
tbl_bapisditm-route = 'TESYS'.
tbl_bapisditm-usage_ind = 'CIV'.
APPEND tbl_bapisditm.
CLEAR tbl_bapisditmx.
tbl_bapisditmx-itm_number = c_item.
tbl_bapisditmx-ref_doc = 'X'.
tbl_bapisditmx-ref_doc_it = 'X'.
tbl_bapisditmx-ref_doc_ca = 'X'.
tbl_bapisditmx-material = 'X'.
tbl_bapisditmx-updateflag = 'I'.
tbl_bapisditmx-plant = 'X'.
tbl_bapisditmx-target_qty = 'X'.
tbl_bapisditmx-target_qu = 'X'.
tbl_bapisditmx-item_categ = 'X'.
tbl_bapisditmx-sales_dist = 'X'.
tbl_bapisditmx-dlv_prio = 'X'.
tbl_bapisditmx-prc_group5 = 'X'.
tbl_bapisditmx-cust_mat35 = 'X'.
tbl_bapisditmx-usage_ind = 'X'.
tbl_bapisditmx-route = 'X'.
APPEND tbl_bapisditmx.
ENDFORM. " build_bapi_items
*& Form build_bapi_sched_lines
* Build the BAPI Schedule Lines
FORM build_bapi_sched_lines .
CLEAR tbl_bapischdl.
tbl_bapischdl-itm_number = c_item.
tbl_bapischdl-req_qty = '1'.
tbl_bapischdl-req_date = sy-datum.
APPEND tbl_bapischdl.
ENDFORM. " build_bapi_sched_lines
*& Form build_bapi_conditions
* Pull the BAPI Pricing Conditions from the Contract
FORM build_bapi_conditions .
LOOP AT tbl_bapisdcond.
CLEAR tbl_bapicond.
MOVE-CORRESPONDING tbl_bapisdcond TO tbl_bapicond.
APPEND tbl_bapicond.
CLEAR tbl_bapicondx.
tbl_bapicondx-itm_number = tbl_bapicond-itm_number.
tbl_bapicondx-cond_st_no = tbl_bapicond-cond_st_no.
tbl_bapicondx-cond_count = tbl_bapicond-cond_count.
tbl_bapicondx-cond_type = tbl_bapicond-cond_type.
tbl_bapicondx-updateflag = 'I'.
tbl_bapicondx-cond_value = 'X'.
tbl_bapicondx-currency = 'X'.
tbl_bapicondx-cond_unit = 'X'.
tbl_bapicondx-cond_p_unt = 'X'.
tbl_bapicondx-varcond = tbl_bapicond-varcond.
APPEND tbl_bapicondx.
ENDLOOP.
ENDFORM. " build_bapi_conditions
*& Form call_create_sales_ord_bapi
* Call the Sales Order Create BAPI
FORM call_create_sales_ord_bapi .
CLEAR g_vbeln_created.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = st_bapisdhd1
IMPORTING
salesdocument = g_vbeln_created
TABLES
return = tbl_return
order_items_in = tbl_bapisditm
order_items_inx = tbl_bapisditmx
order_partners = tbl_bapiparnr
order_schedules_in = tbl_bapischdl.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDFORM. " call_create_sales_ord_bapi
*& Form update_sales_ord
* Update the newly created Sales Order with the Pricing Conditions
* from the Contract
FORM update_sales_ord .
CHECK g_valid_contract EQ 'X'.
PERFORM get_contract_details.
PERFORM build_bapi_conditions.
PERFORM call_change_sales_ord_bapi.
ENDFORM. " update_sales_ord
*& Form get_contract_details
* Get Contract Details
FORM get_contract_details .
* Need to manually get the relevant Pricing Conditions as the BAPI
* BAPISDORDER_GETDETAILEDLIST causes problems when we call the BAPI
* BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE (I think
* this is due to the fact that these BAPIs belong to the same Function
* Group and there must be some common structures that are not cleared
* causing us all sorts of grief when we try and call the next BAPI)
DATA: tbl_konv TYPE STANDARD TABLE OF konv WITH HEADER LINE.
DATA: tbl_komv TYPE STANDARD TABLE OF komv WITH HEADER LINE.
DATA: tbl_vbak TYPE STANDARD TABLE OF vbak WITH HEADER LINE.
* Pricing Condition Master
DATA: BEGIN OF tbl_t685a OCCURS 0,
kschl LIKE t685a-kschl,
kaend_wrt LIKE t685a-kaend_wrt,
END OF tbl_t685a.
SELECT *
INTO TABLE tbl_vbak
FROM vbak
WHERE vbeln = c_contract.
READ TABLE tbl_vbak INDEX 1.
SELECT *
INTO TABLE tbl_konv
FROM konv
WHERE knumv = tbl_vbak-knumv AND
kposn = c_item.
CHECK sy-subrc EQ 0.
* We now need to make sure we only bring across the Condition Types that
* are EDITABLE. If we bring across non editable conditions (such as
* 'ZPR1') the Change Sales Order BAPI will fail
SELECT kschl kaend_wrt
INTO TABLE tbl_t685a
FROM t685a
FOR ALL ENTRIES IN tbl_konv
WHERE kappl EQ 'V' AND "Sales
kschl EQ tbl_konv-kschl AND
kaend_wrt EQ 'X' AND "Value is Editable
kmanu NE 'D'. "Process manually
* Prepare for Binary Search
SORT tbl_t685a BY kschl.
LOOP AT tbl_konv.
READ TABLE tbl_t685a WITH KEY kschl = tbl_konv-kschl BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING tbl_konv TO tbl_komv.
APPEND tbl_komv.
ENDIF.
ENDLOOP.
CHECK NOT tbl_komv[] IS INITIAL.
* Map KOMV into the more BAPI friendly BAPISDCOND structure
CALL FUNCTION 'MAP_INT_TO_EXT_STRUCTURE'
TABLES
fxvbak = tbl_vbak
fxkomv = tbl_komv
fxbapikomv = tbl_bapisdcond
EXCEPTIONS
entry_missing = 1
OTHERS = 2.
ENDFORM. " get_contract_details
*& Form call_change_sales_ord_bapi
* Call the Change Sales Order BAPI
FORM call_change_sales_ord_bapi .
DATA: st_head_chg LIKE bapisdh1x,
st_logic_switch TYPE bapisdls.
CHECK NOT g_vbeln_created IS INITIAL.
CHECK g_valid_contract EQ 'X'.
st_head_chg-updateflag = 'U'.
st_logic_switch-cond_handl = 'X'.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = g_vbeln_created
order_header_inx = st_head_chg
logic_switch = st_logic_switch
TABLES
return = tbl_return_chg
conditions_in = tbl_bapicond
conditions_inx = tbl_bapicondx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDFORM. " call_change_sales_ord_bapi
*& Form write_output_report
* Produce Output Report
FORM write_output_report .
IF NOT g_vbeln_created IS INITIAL.
WRITE:/ 'Success! Sales Order', g_vbeln_created, 'was created!'.
ELSE.
WRITE:/ 'Failure! Sales Order was not created!'.
ENDIF.
SKIP.
WRITE:/ 'Sales Order Create Log'.
LOOP AT tbl_return.
WRITE:/ tbl_return-type, tbl_return-id, tbl_return-number,
tbl_return-message.
ENDLOOP.
SKIP.
WRITE:/ 'Sales Order Change Log'.
LOOP AT tbl_return_chg.
WRITE:/ tbl_return_chg-type, tbl_return_chg-id,
tbl_return_chg-number, tbl_return_chg-message.
ENDLOOP.
ENDFORM. " write_output_report
*& Form validate_contract
* Make sure that the Contract is Valid
FORM validate_contract .
DATA: l_gueen LIKE vbak-gueen,
l_prsdt LIKE vbkd-prsdt.
SELECT SINGLE vbak~gueen vbkd~prsdt
INTO (l_gueen, l_prsdt)
FROM vbak
INNER JOIN vbkd
ON vbak~vbeln = vbkd~vbeln
WHERE vbak~vbeln = c_contract AND
vbkd~posnr = '000000'.
IF sy-datum LE l_gueen.
* Contract is valid! Set Order Price Date
g_valid_contract = 'X'.
g_cont_price_date = l_prsdt.
ENDIF.
ENDFORM. " validate_contract
Hope this helps.
Cheers,
Pat. -
BAPI SALES ORDER CHANGE CUSTOM FIELD
Hello Gurus,
I am trying to update a custom field for sales order. The field name is zfield1 in vbak. The field is added to vbakkom, vbakkomx, vbakkoz, vbakkozx, BAPE_VBAK, BAPE_VBAKX. I guess i need to use the EXTENSIONIN table to populate this field's values to change it with the BAPI. But I not sure exactly how to populate the fields. Can someone tell me how exactly i need to do this?
Also the documentation says fill Extensionin this way.
STRUCTURE VALUEPART1 1234561234567890123
BAPE_VBAP 0000004711000020 XYZ
BAPE_VBAPX 0000004711000020 X
What is the 1234561234567890123? Is it a field?
Thanks,
KBHi,
Check this example..I am updating the VBAP field..Instead you can replace it for VBAK..
PARAMETERS: P_VBELN TYPE VBAK-VBELN.
DATA: T_LINE LIKE BAPISDITM OCCURS 0 WITH HEADER LINE.
DATA: T_LINEX LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA: T_EXTEN LIKE BAPIPAREX OCCURS 0 WITH HEADER LINE.
DATA: T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: BAPE_VBAP LIKE BAPE_VBAP.
DATA: BAPE_VBAPX LIKE BAPE_VBAPX.
DATA: ORDER_HEADERX LIKE BAPISDH1X.
ORDER_HEADERX-UPDATEFLAG = 'U'.
T_LINE-ITM_NUMBER = '000010'.
APPEND T_LINE.
T_LINEX-ITM_NUMBER = '000010'.
T_LINEX-UPDATEFLAG = 'U'.
APPEND T_LINEX.
BAPE_VBAP-VBELN = P_VBELN.
BAPE_VBAP-POSNR = '000010'.
<b>BAPE_VBAP-<b>YYFREETEXT</b> = '02'.</b>
T_EXTEN-STRUCTURE = 'BAPE_VBAP'.
T_EXTEN+30 = BAPE_VBAP.
APPEND T_EXTEN.
BAPE_VBAPX-VBELN = P_VBELN.
BAPE_VBAPX-POSNR = '000010'.
<b>BAPE_VBAPX-YYFREETEXT = 'X'.</b>
T_EXTEN-STRUCTURE = 'BAPE_VBAPX'.
T_EXTEN+30 = BAPE_VBAPX.
APPEND T_EXTEN.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_vbeln
order_header_inx = ORDER_HEADERX
tables
return = T_RETURN
ORDER_ITEM_IN = T_LINE
ORDER_ITEM_INX = T_LINEX
EXTENSIONIN = T_EXTEN.
COMMIT WORK.
Thanks,
Naren -
Hello,
I am using BAPI_SALESORDER_CREATEFROMDAT2 to create sales order. The system is configured to automatically generate the item numbers. I can create an order alright for simple materials.
For this I am populating both Line items and Schedule Line item structures - ORDER_ITEMS_IN and ORDER_SCHEDULES_IN respectively, without passing the line item number(ITM_NUMBER field).
The problem is when I create an order which has a KIT as a line item.
So SAP explodes the Kit correctly, but the quantity information goes all wrong for the subsequent lines after the kit. Hence order does not get correctly created.
Any hints on how to solev this? I want to create the order with Kit and simple materials and without provising the line item numbers.hello,
Please check the following code in case its a bill of material
FORM CHECK_SALES_BOM TABLES ORDER_ITEMS_IN STRUCTURE BAPIITEMIN
ORDER_PARTNERS STRUCTURE ZBAPISHIP1.
CLEAR FLAG_CANCEL_CREATE.
CLEAR V_LINES1.
LOOP AT ORDER_ITEMS_IN.
V_ITM_NUMBER = ORDER_ITEMS_IN-ITM_NUMBER.
ORDER_ITEMS_IN-PO_ITM_NO = ORDER_ITEMS_IN-ITM_NUMBER. " DEVK942749
ORDER_ITEMS_IN-ITM_NUMBER = 10 * SY-TABIX + 10 * V_LINES1.
MODIFY ORDER_ITEMS_IN.
LOOP AT ORDER_PARTNERS WHERE ITEM_NUMB = V_ITM_NUMBER.
ORDER_PARTNERS-ITEM_NUMB = ORDER_ITEMS_IN-ITM_NUMBER.
MODIFY ORDER_PARTNERS.
ENDLOOP.
SELECT SINGLE KNUMH FROM KOTD001 INTO KOTD001-KNUMH
WHERE KAPPL = 'V'
AND KSCHL = 'A001'
AND MATWA = ORDER_ITEMS_IN-MATERIAL
AND DATBI GE SY-DATUM
AND DATAB LE SY-DATUM.
IF SY-SUBRC = 0.
SELECT SINGLE SMATN FROM KONDD INTO KONDD-SMATN
WHERE KNUMH = KOTD001-KNUMH.
ORDER_ITEMS_IN-MATERIAL = KONDD-SMATN.
ELSE.
ORDER_ITEMS_IN-MATERIAL = ORDER_ITEMS_IN-MATERIAL.
ENDIF.
CLEAR V_WERKS.
SELECT SINGLE DWERK MTPOS INTO (V_WERKS, MVKE-MTPOS) FROM MVKE
WHERE MATNR = ORDER_ITEMS_IN-MATERIAL
AND VKORG = WWW_ORDER_HEADER_EXP-VKORG
AND VTWEG = WWW_ORDER_HEADER_EXP-VTWEG.
IF MVKE-MTPOS EQ 'LUMF' OR MVKE-MTPOS EQ 'ZLUM'.
READ TABLE ORDER_PARTNERS WITH KEY ITEM_NUMB = V_ITM_NUMBER
PARTN_ROLE = 'WE'.
REFRESH : DA_MASTB,
DA_STKOB,
DA_STZUB.
CALL FUNCTION 'CS_ALT_SELECT_MAT'
EXPORTING
ALL = ' '
CAPID = 'SD01'
DATUV = SY-DATUM
DIALF = ' '
LOSGR = 0
MATNR = ORDER_ITEMS_IN-MATERIAL
NOTAB = 'X'
NRFDC = ' '
STLAL = ' '
STLAN = ' '
VPRIO = ' '
WERKS = V_WERKS
TABLES
MASTB_WA = DA_MASTB
STKOB_WA = DA_STKOB
STZUB_WA = DA_STZUB
EXCEPTIONS
ALT_NOT_FOUND = 1
BOM_NOT_ACTIVE = 2
BOM_NOT_FOUND = 3
CALL_INVALID = 4
NO_ALT_FOUND = 5
NO_BOM_FOUND = 6
OTHERS = 7.
READ TABLE DA_MASTB INDEX 1.
IF SY-SUBRC = 0.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'SD01'
DATUV = SY-DATUM
EMENG = 1
MEHRS = 'X'
MTNRV = ORDER_ITEMS_IN-MATERIAL
RNDKZ = '2'
STLAL = '01'
WERKS = V_WERKS
IMPORTING
TOPMAT = CSTMAT
TABLES
STB = TSTB
MATCAT =
EXCEPTIONS
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
OTHERS = 8.
DESCRIBE TABLE TSTB LINES V_LINES.
ENDIF.
V_LINES1 = V_LINES + V_LINES1 .
CLEAR V_LINES.
ENDIF.
ENDLOOP.
hope this will help you.
Reward points if it helps
regards,
krishna -
BAPI Sales order create - Ship to party Error
Dear All,
I have an issue with BAPI_SALESDOCU_CREATEFROMDATA1.
I need different ship to party's on the items , irresspective of the header ship to party. Currently the order is getting created with the same ship to party for all the items , same as the header ship to party. Please refer the code below and help.
Sales document type
IF zdemmast-doc_type = 'X'.
header-doc_type = 'ZDMM'.
ELSEIF zdemmast-doc_type = 'ZDME'.
headerx-doc_type = 'X'.
ENDIF.
Sales organization
header-sales_org = '1000'.
headerx-sales_org = 'X'.
Distribution channel
header-distr_chan = '10'.
headerx-distr_chan = 'X'.
Division
header-division = '10'.
headerx-division = 'X'.
headerx-updateflag = 'I'.
Sold to
partner-partn_role = 'AG'.
partner-partn_numb = zdemmast-kunnr.
APPEND partner.
Ship to
partner-partn_role = 'WE'.
partner-partn_numb = zdemmast-kunnr.
APPEND partner.
LOOP AT it_zdem_item INTO wa_zdem_item.
itemx-updateflag = 'I'.
item-itm_number = wrk_item_number.
itemx-itm_number = 'X'.
item-material = '000000000000000016'. "wa_zdem_item-matnr.
itemx-material = 'X'.
item-plant = '1000'.
itemx-plant = 'X'.
item-target_qty = wa_zdem_item-cret.
itemx-target_qty = 'X'.
lt_schedules_in-itm_number = wrk_item_number.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = wa_zdem_item-cret.
lt_schedules_inx-itm_number = wrk_item_number.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
partner-partn_role = 'WE'.
partner-partn_numb = wa_zdem_item-kunnr.
partner-itm_number = wrk_item_number.
APPEND item.
APPEND itemx.
APPEND lt_schedules_in.
APPEND lt_schedules_inx.
APPEND partner.
wrk_item_number = wrk_item_number + 10.
ENDLOOP.
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.
Please suggest.
Thanks in advanceHi,
try the following:
Fill tables parameter SALES_PARTNERS (BAPIPARTNR).
For header don't fill field ITM_NUMBER.
For position fill field ITM_NUMBER.
For example (BAPIPARTNR):
SP | 0000010000 | 000000 | ...
SP | 0000009034 | 000001 | ...
At header the ship to will be "10000" and at item 1 it will be "9034".
Regards -
BAPI Sales Order create with reference Invoice document
Hi
I am using BAPI ''SD_SALESDOCUMENT_CREATE'' to create debit memo request with reference Invoice document.
First time its successfully created with reference Invoice.When i am going to create 2nd time debit memo request with same reference Invoice and item
no its giving following error.
Reference quantity:
10 EA (total referenced:
40 EA)
Error in SALES_ITEM_IN 000010
Condition ZSLS is not allowed as header condition
Sales document was not changed
Please help any one to resolved this issue.
Regards
ShyamSD_SALESDOCUMENT_CREATE is not a BAPI. Is there any specific reason you're using this FM when the actual BAPI exists?
ZSLS is a custom condition. There might as well be some user exit that attempts to add it [possibly incorrectly], how would we know this on SCN? There is enough information in the error message to troubleshoot on your own, it seems. What kind of analysis have you done before posting on SCN?
Maybe you are looking for
-
Inbound calls to response group - failed
Hi! I have a problem with inbound calls to Response group from external phones. But calls from Lync client to Response Group are working without problem. And calls from external phones to Lync users perfectly working too. I found this alert in event
-
Having trouble connecting my Canon MX 870 Printer wirelessly to my MacBook Pro. The instructions ask for me to enter the "access point" from the router (I use Time Machine). Right now, it's set to "My Network", but that won't work any more. What is t
-
Raw pictures not sharp in photoshop
when I open a raw file in other programs like "ACDSee" it is sharp. when I open the same picture in photoshop it is not sharp.
-
Report Customization Form Question
How do you display the report customization before the report is rendered?
-
Opening file using JFileChooser with File filtering
ok guys I am trying set a file filter object to my file chooser it compile but i have a run time error, the error says: Exception in thread "AWT-EventQueue-0" java.land.IllegalArgurmentException: Extension must be non-null and not empty at javax.swin