05-24-2006 8:27 AM
Hi all,
My cousin is working on uploading Sales Order Document
from java server to R/3.
for that he is having a code from JCO jar.
the below is the file from which one can upload his SO details from JAVA to R/3.
But in this program he is just able to upload one Item detail for one Sales document.
but requirement is to upload 'n' item details for one Sales document.
Here is the Java code.
**********************
/**
@author pega
*
TODO To change the template for this generated type comment go to
Window - Preferences - Java - Code Style - Code Templates
*/
/*
Created on Jun 24, 2004
*
To change the template for this generated file go to
Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.sap.satyam.salesorder;
import java.sql.Timestamp;
import java.util.Calendar;
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
public class SalesOrder {
static final String SID = "R3";
static final String errorID = "E";
IRepository repository;
//String orderNumber = orderCreation("M-01","3000","0002",3,"ST");
int counter;
public SalesOrder()
{
try {
// Add a connection pool to the specified system
JCO.addClientPool(SID, // Alias for this pool
10, // Max. number of connections
"800", // SAP client
"develop", // userid
"bslabap", // password
"EN", // language
"172.18.33.20", // host name
"00");
// Create a new repository
repository = JCO.createRepository("MYRepository", SID);
}
catch (JCO.Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
// Retrieves and sales order Create
public void createSalesOrder(String PO_NO, String MAT,String RQTY,String CUSTMAT, String SOLD_NAME, String SOLD_STREET,String SOLD_COUNTRY, String SOLD_POST_CODE,String SHIP_NAME, String SHIP_STREET,String SHIP_COUNTRY, String SHIP_POST_CODE)
{
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_CREATEFROMDAT1");
JCO.MetaData so_metadata = new JCO.MetaData("BAPI_SALESORDER_CREATEFROMDAT1");
// 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
// Header
JCO.ParameterList input = function.getImportParameterList();
JCO.ParameterList tables = function.getTableParameterList();
JCO.Structure input_header = input.getStructure("ORDER_HEADER_IN");
// Item details
JCO.Table table_item = tables.getTable("ORDER_ITEMS_IN");
//JCO.Structure input_item = table_item.getStructure("ORDER_ITEMS_IN");
// Partner details
JCO.Table table_partner = tables.getTable("ORDER_PARTNERS");
// Populate the header details
input_header.setValue("ZAD5","DOC_TYPE"); // Document Type
input_header.setValue("3000","SALES_ORG"); // Sales Organization
input_header.setValue("10","DISTR_CHAN"); // Distribution Channel
input_header.setValue("00","DIVISION"); // Distribution Channel
input_header.setValue("20041212","REQ_DATE_H");// can be changed in yyyymmdd (Requested date)
input_header.setValue(PO_NO,"PURCH_NO_C");// can be changed ( Customer PO Number )
//Populate the item detalis
table_item.appendRow();
table_item.setRow(1);
table_item.setValue("000010","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
table_item.appendRow();
table_item.setRow(2);
table_item.setValue("000020","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
//Populate the Partner details
// Sold to Party
table_partner.appendRow();
table_partner.setRow(1);
table_partner.setValue("AG","PARTN_ROLE");
//table_partner.setValue("0000002007","PARTN_NUMB");
table_partner.setValue("0000100067","PARTN_NUMB");
table_partner.setValue(SOLD_NAME,"NAME"); // can be changed
table_partner.setValue(SOLD_STREET,"STREET"); // can be changed
table_partner.setValue(SOLD_COUNTRY,"COUNTRY");
table_partner.setValue(SOLD_POST_CODE,"POSTL_CODE"); // can be changed
// Ship to party
table_partner.appendRow();
table_partner.setRow(2);
table_partner.setValue("WE","PARTN_ROLE");
table_partner.setValue("0000100067","PARTN_NUMB");
table_partner.setValue(SHIP_NAME,"NAME");// can be changed
table_partner.setValue(SHIP_STREET,"STREET"); // can be changed
table_partner.setValue(SHIP_COUNTRY,"COUNTRY");
table_partner.setValue(SHIP_POST_CODE,"POSTL_CODE");// can be changed
// Call the remote system
client.execute(function);
// Print return message
JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
System.out.println("BAPI_SALES_ORDER_GETLIST RETURN: " + ret.getString("MESSAGE"));
// Get table containing the orders
//JCO.Table sales_orders = function.getTableParameterList().getTable("SALES_ORDERS");
JCO.Field sales_order = function.getExportParameterList().getField("SALESDOCUMENT");
// Print results
String so = sales_order.getString();
String message = ret.getString("MESSAGE");
String message_type = ret.getString("TYPE");
if (message_type.equalsIgnoreCase("E")) {
System.out.println("Error in Sales Order Creation:" + message);
}
else{
System.out.println("Sales Order " + so + " Created Succesfully");
}
// Release the client into the pool
JCO.releaseClient(client);
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
// Retrieves and sales order Create
public void listSalesOrders()
{
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_GETLIST");
// 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();
//input.setValue("0000002007", "CUSTOMER_NUMBER" );
input.setValue( "3000", "SALES_ORGANIZATION");
//input.setValue( "0", "TRANSACTION_GROUP" );
//input.setValue("PO_NUMBER_JAVA01","PURCHASE_ORDER_NUMBER");
// Call the remote system
client.execute(function);
// Print return message
JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
System.out.println("BAPI_SALES_ORDER_GETLIST RETURN: " + ret.getString("MESSAGE"));
// Get table containing the orders
JCO.Table sales_orders = function.getTableParameterList().getTable("SALES_ORDERS");
// Print results
if (sales_orders.getNumRows() > 0) {
// Loop over all rows
do {
counter++;
System.out.println("--
");
// Loop over all columns in the current row
for (JCO.FieldIterator e = sales_orders.fields(); e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
System.out.println(field.getName() + ":\t" + field.getString());
}//for
} while(sales_orders.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);
}
}
public static void main(String[] argv) {
SalesOrder so = new SalesOrder();
//
so.createSalesOrder("PO_NUMBER_JAVA02", "","0000000020000","121-223-2332-1231", "SOFTWARE SYSTEME GMBH-WE", "STREET-SH","US", "53125","SOFTWARE SYSTEME GMBH-WE", "STREET-SH","US", "53125");
//so.listSalesOrders();
}
}
>>>>Please if any of SDN users can help in resolving this issue. It will be very helpful to my cousin.
05-24-2006 4:14 PM
Before:
//Populate the item detalis
table_item.appendRow();
table_item.setRow(1);
table_item.setValue("000010","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
table_item.appendRow();
table_item.setRow(2);
table_item.setValue("000020","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
Try to add:
//Populate the item detalis
table_item.appendRow();
table_item.setRow(2);
table_item.setValue("000020","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
table_item.appendRow();
table_item.setRow(2);
table_item.setValue("000020","ITM_NUMBER");
table_item.setValue("AA01","PO_ITM_NO");// can be changed
table_item.setValue("IAD-SC3000","MATERIAL");
table_item.setValue(CUSTMAT,"CUST_MAT");// can be changed
table_item.setValue("20041212","REQ_DATE");// can be changed in yyyymmdd
table_item.setValue(RQTY,"REQ_QTY");// can be changed Qty * 1000
Regards.