cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed with BAPI_SALESORDER_CREATEFROMDAT1 parameters

Former Member
0 Kudos

Dear all,

I am trying to execute BAPI_SALESORDER_CREATEFROMDAT1 from Java.

I am passing all mandatory parameters.

I am setting the DOC_TYPE as "OR".

However in the Return structure I get the message

Sales document type OR is not defined.

This works fine from the ECC system.

The DOC_TYPE field has 4 characters.

So I have tried passing "OR ". (OR followed by 2 spaces.)

But the string passed is getting trimmed and te reult is the same return message.

Can anyone please help me in this matter.

Thanks and regards,

Mayuresh.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear All,

This is my code.


import com.sap.mw.jco.*;
import java.io.StringWriter;
public class Test {

	public static void main(String[] args) {
		
			String result = "";
		
			try {
				JCO.Client mConnection;
				JCO.Repository mRepository;
				JCO.Function mFunction;		   
				JCO.Table mTable; 

				mConnection =
								JCO.createClient( "100" , "user" , "password" , "en" , "host-ip" , "10" ); 
					   
							mConnection.connect();		   
							mRepository = new JCO.Repository("myRep", mConnection);
							mFunction = mRepository.getFunctionTemplate( "BAPI_SALESORDER_CREATEFROMDAT1").getFunction();
							
							
							JCO.Structure mStructure = mFunction.getImportParameterList().getStructure("ORDER_HEADER_IN");
							
							String doc = "OR  ";
							System.out.println(doc);
							System.out.println(doc.length());
							mStructure.setValue(doc,"DOC_TYPE");
							
							System.out.println(doc);
							System.out.println(doc.length());
							
							mStructure.setValue("1000","SALES_ORG");
							mStructure.setValue("10","DISTR_CHAN");
							mStructure.setValue("01","DIVISION");
							
							mTable = mFunction.getTableParameterList().getTable("ORDER_PARTNERS");
							mTable.appendRow();
							mTable.setValue("SP","PARTN_ROLE");
							mTable.setValue("AMIT","PARTN_NUMB");
															
							mTable = mFunction.getTableParameterList().getTable("ORDER_ITEMS_IN");
							mTable.appendRow();
							mTable.setValue("58","MATERIAL");
							mTable.setValue("6","REQ_QTY");
								
							
							mConnection.execute(mFunction);
							
							//mFunction = mRepository.getFunctionTemplate("BAPI_TRANSACTION_COMMIT").getFunction();
							//mConnection.execute(mFunction);
							
							mStructure = mFunction.getExportParameterList().getStructure( "RETURN" );
							
							StringWriter writer = new StringWriter();
							mStructure.writeXML(writer);
							result = writer.getBuffer().toString();		   		   
							
							mConnection.disconnect();		 		   
			}
			catch (Exception ex) {
				ex.printStackTrace();
				result = ex.getMessage();
			}

			System.out.println(result);

	}
}

I hope now someone will be able to help.

Thanks and regards,

Mayuresh

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Mayuresh,

When you set the String parameter (OR) followed by two empty space, length will be 4 but check with your BAPI programmer how they are handling in backend?.

Regards, Suresh KB