on 06-21-2006 8:26 AM
Hi All
Does anyone have the code in Java to create a Sales Order by using BAPI_SALESORDER_CREATEFROMDAT2.
Thanks in advance
Sree Ramya
Hi,
fill it out with the real values and try it:
.....
// Create sales orders
public void CreateSalesOrders()
{
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_CREATEFROMDAT2");
// Create a function from the template
JCO.Function function = new JCO.Function(ftemplate);
// Get a client from the pool
JCO.Client client = JCO.getClient(SID);
// Fill in input parameters
JCO.ParameterList input = function.getImportParameterList();
JCO.Structure order = function.getImportParameterList().getStructure("ORDER_HEADER_IN");
order.setValue("TA","DOC_TYPE");
order.setValue("0000000000","REF_1_S");
order.setValue("0000","SALES_ORG");
order.setValue("00","DISTR_CHAN");
order.setValue("00","DIVISION");
order.setValue("0000","SALES_OFF");
order.setValue("20060620","REQ_DATE_H");
order.setValue("20060620","PURCH_DATE");
order.setValue("LOC","INCOTERMS1");
order.setValue("0000","PMNTTRMS");
order.setValue("00000","PURCH_NO_C");
order.setValue("00","SHIP_COND");
order.setValue("USD","CURRENCY");
order.setValue("USD","CURR_ISO");
order.setValue("0000000000","COMPL_DLV");
order.setValue("0000000000","COMP_CDE_B");
order.setValue("000000000","NAME");
JCO.Table partners = function.getTableParameterList().getTable("ORDER_PARTNERS");
partners.deleteAllRows();
partners.appendRow();
partners.setValue("AG","PARTN_ROLE");
partners.setValue("0000000000","PARTN_NUMB");
partners.setValue("00010","ITM_NUMBER");
// Call the remote system
client.execute(function);
// Print return message
JCO.Table returns = function.getTableParameterList().getTable("RETURN");
// Print results
if (returns.getNumRows() > 0) {
// Loop over all rows
do {
system.out.println("----
");
// Loop over all columns in the current row
for (JCO.FieldIterator e = returns.fields(); e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
system.out.println(field.getName() + ":\t" + field.getString());
}//for
} while(returns.nextRow());
}
else {
System.out.println("No results found");
}//if
// Release the client into the pool
JCO.releaseClient(client);
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
......
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin ,
I m using ur solution for fill RFC table but i m not able to get data in table.Actually I am storing mail contents in ABAP table through JAVA program which r i m geting in byte string.My requirement is to call java function from ABAP.I m able to read a single value through import parameter but i want to read values in table.
This is my code please correct it by which it will pass mail(byte string) value through table to ABAP.
import com.sap.mw.jco.*;
import java.util.*;
import com.sap.mw.jco.JCO.ParameterList;
public class Example_Test implements JCO.ServerExceptionListener, JCO.ServerStateChangedListener {
static public class Repository extends JCO.BasicRepository implements IRepository {
public Repository(String name)
{
super(name);
System.out.println("\n T his is in the Repoistry passing");
}
}
protected static IRepository repository;
static {
System.out.println("I am in the second static ");
repository = new Repository("TestRepository");
JCO.MetaData fmeta = new JCO.MetaData("CONNECTION");
fmeta.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.IMPORT_PARAMETER, null);
fmeta.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
fmeta.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);
fmeta.addInfo("RFCTABLE", JCO.TYPE_TABLE, 150, 0, 0, 0, "RFCTABLE");
repository.addFunctionInterfaceToCache(fmeta);
JCO.MetaData smeta = new JCO.MetaData("RFCTABLE");
smeta.addInfo("FIELD", JCO.TYPE_STRING , 256 );
repository.addStructureDefinitionToCache(smeta);
System.out.println("\n I create table interface \n");
}
static public class Server extends JCO.Server {
public Server(String gwhost, String gwserv, String progid, IRepository repository)
{
super(gwhost,gwserv,progid,repository);
}
protected JCO.Function getFunction(String function_name)
{
JCO.Function function = super.getFunction(function_name);
//System.out.println("\n\n I have read the function name--" + function_name);
return function;
}
protected boolean checkAuthorization(String function_name, int authorization_mode,
String authorization_partner, byte[] authorization_key)
{
System.out.println("\n I am in authioruiwerter \n");
return true;
}
protected void handleRequest(JCO.Function function)
{
//System.out.println("\n I am in handle request \n");
JCO.ParameterList input = function.getImportParameterList();
JCO.ParameterList output = function.getExportParameterList();
// JCO.ParameterList tables = function.getTableParameterList();
// JCO.ParameterList tables = function.getTableParameterList().getTable("RFCTABLE");
JCO.Table tables = function.getTableParameterList().getTable("RFCTABLE");
tables.appendRow();
//tables.setValue(CONNECTION.mimeType, "FIELD");
System.out.println("handleRequest(" + function.getName() + ")");
FetchMailUsage CONNECTION = new FetchMailUsage();
CONNECTION.readMail();
//output.setValue(CONNECTION.mimeType,"RESPTEXT");
//output.setValue("This is a response from Example5.java","RESPTEXT");
//output.setValue(CONNECTION.mimeType,"RESPTEXT");
for (int i = 0; i <CONNECTION.count3 ; i++)
{
tables.setValue(CONNECTION.array<i>,"RFCTABLE");
}
}
}
JCO.Server srv[] = new JCO.Server[1];
public Example_Test()
{
System.out.println("\n I am in Example_test constructor \n");
JCO.addServerExceptionListener(this);
JCO.addServerStateChangedListener(this);
System.out.println("\n I out of Example_test constructor \n");
}
public void startServers()
{
srv[0] = new Server("192.168.1.74","sapgw00","JCOSERVER01",repository);
System.out.println("\n I am in start server \n");
for (int i = 0; i < srv.length; i++) {
try {
System.out.println("i m in fo loop");
srv<i>.setTrace(true);
srv<i>.start();
}
catch (Exception ex) {
System.out.println("Could not start server " + srv<i>.getProgID() + ":\n" + ex);
}//try
}//for
System.out.println("\n I out of server \n");
}
public void serverExceptionOccurred(JCO.Server server, Exception ex)
{
System.out.println("Exception in server " + server.getProgID() + ":\n" + ex);
ex.printStackTrace();
}
public void serverStateChangeOccurred(JCO.Server server, int old_state, int new_state)
{
System.out.print("Server " + server.getProgID() + " changed state from [");
if ((old_state & JCO.STATE_STOPPED ) != 0) System.out.print(" STOPPED ");
if ((old_state & JCO.STATE_STARTED ) != 0) System.out.print(" STARTED ");
if ((old_state & JCO.STATE_LISTENING ) != 0) System.out.print(" LISTENING ");
if ((old_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSACTION ");
if ((old_state & JCO.STATE_BUSY ) != 0) System.out.print(" BUSY ");
System.out.print("] to [");
if ((new_state & JCO.STATE_STOPPED ) != 0) System.out.print(" STOPPED ");
if ((new_state & JCO.STATE_STARTED ) != 0) System.out.print(" STARTED ");
if ((new_state & JCO.STATE_LISTENING ) != 0) System.out.print(" LISTENING ");
if ((new_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSACTION ");
if ((new_state & JCO.STATE_BUSY ) != 0) System.out.print(" BUSY ");
System.out.println("]");
}
public static void main(String[] argv)
{
Example_Test obj = new Example_Test();
obj.startServers();
}
}
This type of byte string i m geting by my class FetchMailUsage.
boundary="----=_Part_67397_32729369.1156399213563"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.