on 05-18-2004 11:46 AM
HI
I had written the following code but it is giving me a NullPointerException. Can anyone help me to locate how and wre is this error is commng from.
The error is <b>creation error java.lang.NullPointerException</b>
try {
String PartnerNumber = "";
String DocType = "";
String SalesOrg = "";
String DistrChan = "";
String Division = "";
String PurchOrder = "";
String SalesOrderNum = "";
int c = 0;
Object[][] itemData = new Object[5][2];
PartnerNumber = request.getParameter("Customer");
DocType = request.getParameter("OrderType");
SalesOrg = request.getParameter("SalesOrg");
DistrChan = request.getParameter("DistChan");
Division = request.getParameter("Division");
PurchOrder = request.getParameter("PONum");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 2; j++) {
c++;
itemData<i>[j] = request.getParameter("t" + c);
}
}
try {
mRepository = new JCO.Repository("Nikhil", mConnection);
pw.print("Repository object crested - " + mRepository);
} catch (Exception e) {
pw.print("Repository error ");
}
try {
IFunctionTemplate ftemplate =
mRepository.getFunctionTemplate(
"BAPI_SALESORDER_CREATEFROMDATA2");
pw.print("Functon Template object crested - " + ftemplate);
jcoFunction = new JCO.Function(ftemplate);
pw.print("Function object crested - " + jcoFunction);
} catch (Exception e) {
pw.print("function templet error ");
}
try {
JCO.Table ORDER_PARENERS =
jcoFunction.getTableParameterList().getTable(
"ORDER_PARTNERS");
pw.print("order partner table not loaded ");
ORDER_PARENERS.appendRow();
ORDER_PARENERS.setValue("SP", "PART_ROLE");
ORDER_PARENERS.setValue(PartnerNumber, "PART_NUMB");
JCO.Structure order_header_inx =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_INX");
pw.print("order header INX table not loaded ");
order_header_inx.setValue("I", "UPDATEFLAG");
order_header_inx.setValue("X", "DCO_TYPE");
order_header_inx.setValue("X", "SALES_ORG");
order_header_inx.setValue("X", "DISTR_CHAN");
order_header_inx.setValue("X", "DIVISION");
order_header_inx.setValue("I", "PURCH_NO_C");
JCO.Structure order_header_in =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_IN");
pw.print("order header IN table not loaded ");
order_header_in.setValue(DocType, "DOC_TYPE");
order_header_in.setValue(SalesOrg, "SALES_ORG");
order_header_in.setValue(DistrChan, "DISTR_CHAN");
order_header_in.setValue(Division, "DIVISION");
order_header_in.setValue(PurchOrder, "PURCH_NO_C");
JCO.Table ORDER_ITEM_INX =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEM_INX");
pw.print("order item INX table not loaded ");
JCO.Table ORDER_ITEM_IN =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEM_IN");
pw.print("order item IN table not loaded ");
for (int i = 0; i < 5; i++) {
if (itemData[0]<i> != null) {
ORDER_ITEM_INX.appendRow();
ORDER_ITEM_IN.appendRow();
ORDER_ITEM_INX.setValue("X", "MATERIAL");
ORDER_ITEM_IN.setValue(itemData<i>[0], "MATERIAL");
ORDER_ITEM_INX.setValue("X", "COMP_QUANT");
ORDER_ITEM_IN.setValue(itemData<i>[1], "COMP_QUANT");
ORDER_ITEM_INX.setValue("X", "UPDATEFLAG");
}
}
JCO.Field SalesDocumentField =
jcoFunction.getExportParameterList().getField(
"SALESDOCUMENT");
SalesOrderNum = SalesDocumentField.getValue().toString();
pw.print(" The sales order " + SalesOrderNum + " created ");
} catch (Exception ex) {
PrintWriter pw = response.getWriter();
pw.print("data error ");
}
} catch (Exception e) {
PrintWriter pw = response.getWriter();
pw.print(" creation error " + e);
}
Thanks
Nikhil
Hello Nikhil,
I am also facing a similar problem as you faced years back.
For the bapi BAPI_SALESORDER_CREATEFROMDAT1,
In the ORDER_HEADER_IN import structure, I am setting the field DOC_TYPE as "OR". I am getting a message in RETURN table as "Sales document type OR is not valid".
The field DOC_TYPE is supposed to be of 4 characters in the Bapi. I tried passing "OR " (OR followed by 2 spaces) but the spaces are getting trimmed and I am getting the same error message.
Kindly provide me with the solution to this problem.
Thanks and regards,
Mayuresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I was able to create the sales order with BAPI_SALESORDER_CREATEFROMDAT2, and now have to change the configuration data with BAPI_SALESORDER_CHANGE - for example: SIM CARD, which is a second position in the Sales order has to have configuration: variant conditions - 24 months.
I have tried the OSS - Sap notes and found the list of the fields to be filled, but no examples:
possibly data for the configuration, below you find the fields you
must fill at least:
-
BAPICUCFG, configuration: Reference data
- POSEX External Item Number
- CONFIG_ID External configuration ID (temporary)
- ROOT_ID Instance number in the configuration
BAPICUINS: Configuration: Instances
- CONFIG_ID External configuration ID (temporary)
- INST_ID Instance number in the configuration
- OBJ_TYPE Object type
- CLASS_TYPE Class type
- OBJ_KEY Object key
- QUANTITY Instance quantity
BAPICUVAL Configuration: Characteristic values
- CONFIG_ID External configuration ID (temporary)
- INST_ID Instance number in the configuration
- CHARC Characteristic name
- VALUE Value of a characteristic
Configuration data during the creation/change, the characteristic
value assignment must be entered completely here.
-
If somebody can provide this data, it would be great, since SAP obviously didn't think that it would be useful (as with many other functionalities) )
Thanks,
Jury
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
following is the error i got
start processcom.sap.mw.jco.JCO$Client@4865eedata error com.sap.mw.jco.JCO$Exception: (127) JCO_ERROR_FIELD_NOT_FOUND: Field PART_ROLE not a member of BAPIPARTNR at com.sap.mw.jco.JCO$MetaData.indexOf(JCO.java:7803) at com.sap.mw.jco.JCO$Record.setValue(JCO.java:13022) at conect.TestCon.doGet(TestCon.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:151) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:373) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:250) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:319) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:297) at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:696) at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:221) at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92) at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:146) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37) at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140)
Can you please look into this .
thanks
Nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
another error. help please
start processcom.sap.mw.jco.JCO$Client@1a51ac0data error com.sap.mw.jco.JCO$Exception: (127) JCO_ERROR_FIELD_NOT_FOUND: Field ORDER_HEADER_INX not a member of INPUT at com.sap.mw.jco.JCO$MetaData.indexOf(JCO.java:7803) at com.sap.mw.jco.JCO$Record.getStructure(JCO.java:12370) at conect.TestCon.doGet(TestCon.java:96) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:151) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:373) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:250) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:319) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:297) at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:696) at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:221) at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92) at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:146) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37) at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140)
Thanks
Nikhil
Hi Nikhil,
i can't find the BAPI bapi_salesorder_createfromdata2 you are using. Did you copy it from this one?
function bapi_salesorder_createfromdat2.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(SALESDOCUMENTIN) LIKE BAPIVBELN-VBELN OPTIONAL
*" VALUE(ORDER_HEADER_IN) LIKE BAPISDHD1 STRUCTURE BAPISDHD1
*" VALUE(ORDER_HEADER_INX) LIKE BAPISDHD1X STRUCTURE BAPISDHD1X
*" OPTIONAL
*" VALUE(SENDER) LIKE BAPI_SENDER STRUCTURE BAPI_SENDER OPTIONAL
*" VALUE(BINARY_RELATIONSHIPTYPE) LIKE BAPIRELTYPE-RELTYPE
*" OPTIONAL
*" VALUE(INT_NUMBER_ASSIGNMENT) LIKE BAPIFLAG-BAPIFLAG OPTIONAL
*" VALUE(BEHAVE_WHEN_ERROR) LIKE BAPIFLAG-BAPIFLAG OPTIONAL
*" VALUE(LOGIC_SWITCH) LIKE BAPISDLS STRUCTURE BAPISDLS OPTIONAL
*" VALUE(TESTRUN) LIKE BAPIFLAG-BAPIFLAG OPTIONAL
*" VALUE(CONVERT) LIKE BAPIFLAG-BAPIFLAG DEFAULT SPACE
*" EXPORTING
*" VALUE(SALESDOCUMENT) LIKE BAPIVBELN-VBELN
*" TABLES
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
*" ORDER_ITEMS_IN STRUCTURE BAPISDITM OPTIONAL
*" ORDER_ITEMS_INX STRUCTURE BAPISDITMX OPTIONAL
*" ORDER_PARTNERS STRUCTURE BAPIPARNR
*" ORDER_SCHEDULES_IN STRUCTURE BAPISCHDL OPTIONAL
*" ORDER_SCHEDULES_INX STRUCTURE BAPISCHDLX OPTIONAL
*" ORDER_CONDITIONS_IN STRUCTURE BAPICOND OPTIONAL
*" ORDER_CFGS_REF STRUCTURE BAPICUCFG OPTIONAL
*" ORDER_CFGS_INST STRUCTURE BAPICUINS OPTIONAL
*" ORDER_CFGS_PART_OF STRUCTURE BAPICUPRT OPTIONAL
*" ORDER_CFGS_VALUE STRUCTURE BAPICUVAL OPTIONAL
*" ORDER_CFGS_BLOB STRUCTURE BAPICUBLB OPTIONAL
*" ORDER_CFGS_VK STRUCTURE BAPICUVK OPTIONAL
*" ORDER_CFGS_REFINST STRUCTURE BAPICUREF OPTIONAL
*" ORDER_CCARD STRUCTURE BAPICCARD OPTIONAL
*" ORDER_TEXT STRUCTURE BAPISDTEXT OPTIONAL
*" ORDER_KEYS STRUCTURE BAPISDKEY OPTIONAL
*" EXTENSIONIN STRUCTURE BAPIPAREX OPTIONAL
*" PARTNERADDRESSES STRUCTURE BAPIADDR1 OPTIONAL
*"----------------------------------------------------------------------
This structure is missing in the IMPORTING list of your BAPI interface:
JCO.Structure order_header_inx =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_INX");
Regards
Stefan
Hi
The BAPI name i had put was wrong
I corrected it and executed the code again
I am getting the following error again
data error com.sap.mw.jco.JCO$Exception: (127) JCO_ERROR_FIELD_NOT_FOUND: Field ORDER_ITEM_INX not a member of TABLES at com.sap.mw.jco.JCO$MetaData.indexOf(JCO.java:7803) at com.sap.mw.jco.JCO$Record.getTable(JCO.java:12358) at conect.TestCon.doGet(TestCon.java:115) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:151) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:373) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:250) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:319) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:297) at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:696) at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:221) at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92) at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:146) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37) at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140
I saw the structure of the function mobule too, out there ORDER_ITEM_INX is stated as a table.
Can you please help me to locate the problem.
Thanks
Nikhil
Hi Stefan,
I was an\ble to locate that, Thanks for the advice it is working now.
But it is giving me another error
java.lang.ArrayIndexOutOfBoundsException: 2 at conect.TestCon.doGet(TestCon.java:124) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:151) .......
The array to have 5 rows and 2 columns . and i dont see it voilating the index rules.
Can yo please help me on this too.
Thanks a lot
Nikhil
Hi Stefan,
I think this may be the last question to u in this problem.
I have got the message <b>The sales order created</b>
but i cant see the sales order number
As per the code it should have even printed the sales order number, but it does not do that .
is it due to the reason that the transaction has not COMMIT.
Will this BAPI not take care of the transaction COMMIT implisitly.
Do I have to call the BAPI_TRANSACTION_COMMIT to comit this transaction.
Please advice.
Thanks & Regards
Nikhil
Hi Nikhil,
one question: Are there specific reasons for you to use the JCO..stuff directly? As you've seen, most of the errors resulted from the "unsafe" usage of the BAPI interface on the Java side (wrong parameter names etc.). There's a proxy generator included in the Developer Studio, which can generate classes for remote functions (including BAPIs) providing type-safe access to those interfaces.
Regards
Stefan
Hi Stefan,
There is no specific reason to use the JCO. stuff.
I was planning to try that also but was unable to get a nack of it.
Can you please let me know from where can i get the help on that.
Can you please provide me with a solution to the above problem too.
Sorry to bother you so much
Thanks
Nikhil
Hi Stefan
Need confirmation on one more point.
I think i need to add a code as follows also
<b>mConnection.execute(jcoFunction);</b>
to execute the function module of the bapi.and a similar thing for COMMIT bapi too.
Thanks a million
It would really have been hard for me without your expert help.
Can i have you contact please
Nikhil
nikhil.mahajan@capgemini.com
Hi Nikhil,
first of all yes, you have to call mConnection.execute(function);
Detailed documentation about JCO client programming and proxy generation (i would prefer the latter) is available here:
JCO Client Programming:
http://help.sap.com/saphelp_nw04/helpdata/en/35/42e13d82fcfb34e10000000a114084/content.htm
Example of creating proxies for BAPI access:
http://help.sap.com/saphelp_nw04/helpdata/en/ed/897483ea5011d6b2e800508b6b8a93/content.htm
Regards
Stefan
Hi Stefan,
The final code in place i have pu is as follows.
I think it is not creating a order.
it is giving a blank browser screen. even checked in SAP it does not show up out there too.
public class TestCon extends HttpServlet {
private IRepository mRepository;
private JCO.Function jcoFunction;
private JCO.Function jcoCommit;
public JCO.Client mConnection = null;
String a = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
mConnection =
JCO.createClient(
"010",
"nmahajan",
"passme",
"EN",
"erps021.vtcdb.visteon.com",
"25");
mConnection.connect();
} catch (Exception ex) {
PrintWriter pw = response.getWriter();
pw.print("error connection ");
}
try {
String PartnerNumber = "";
String DocType = "";
String SalesOrg = "";
String DistrChan = "";
String Division = "";
String PurchOrder = "";
String SalesOrderNum = "";
int c = 0;
Object[][] itemData = new Object[5][2];
PartnerNumber = request.getParameter("Customer");
DocType = request.getParameter("OrderType");
SalesOrg = request.getParameter("SalesOrg");
DistrChan = request.getParameter("DistChan");
Division = request.getParameter("Division");
PurchOrder = request.getParameter("PONum");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 2; j++) {
c++;
itemData<i>[j] = request.getParameter("t" + c);
}
}
try {
mRepository = new JCO.Repository("Nikhil", mConnection);
} catch (Exception e) {
PrintWriter pw = response.getWriter();
pw.print("Repository error ");
}
try {
IFunctionTemplate ftemplate =
mRepository.getFunctionTemplate(
"BAPI_SALESORDER_CREATEFROMDAT2");
jcoFunction = new JCO.Function(ftemplate);
} catch (Exception e) {
PrintWriter pw = response.getWriter();
pw.print("function templet error ");
}
try {
PrintWriter pw = response.getWriter();
JCO.Table ORDER_PARENERS =
jcoFunction.getTableParameterList().getTable(
"ORDER_PARTNERS");
ORDER_PARENERS.appendRow();
ORDER_PARENERS.setValue("SP", "PARTN_ROLE");
ORDER_PARENERS.setValue(PartnerNumber, "PARTN_NUMB");
JCO.Structure order_header_inx =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_INX");
order_header_inx.setValue("I", "UPDATEFLAG");
order_header_inx.setValue("X", "DOC_TYPE");
order_header_inx.setValue("X", "SALES_ORG");
order_header_inx.setValue("X", "DISTR_CHAN");
order_header_inx.setValue("X", "DIVISION");
order_header_inx.setValue("X", "PURCH_NO_C");
JCO.Structure order_header_in =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_IN");
order_header_in.setValue(DocType, "DOC_TYPE");
order_header_in.setValue(SalesOrg, "SALES_ORG");
order_header_in.setValue(DistrChan, "DISTR_CHAN");
order_header_in.setValue(Division, "DIVISION");
order_header_in.setValue(PurchOrder, "PURCH_NO_C");
JCO.Table ORDER_ITEM_INX =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEMS_INX");
JCO.Table ORDER_ITEM_IN =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEMS_IN");
for (int i = 0; i < 5; i++) {
if (itemData<i>[0] != null) {
ORDER_ITEM_INX.appendRow();
ORDER_ITEM_IN.appendRow();
ORDER_ITEM_INX.setValue("X", "MATERIAL");
ORDER_ITEM_IN.setValue(itemData<i>[0], "MATERIAL");
ORDER_ITEM_INX.setValue("X", "COMP_QUANT");
ORDER_ITEM_IN.setValue(itemData<i>[1], "COMP_QUANT");
ORDER_ITEM_INX.setValue("X", "UPDATEFLAG");
}
}
try{
mConnection.execute(jcoFunction);
}
catch(Exception e)
{
e.printStackTrace(pw);
}
try{
IFunctionTemplate ftemplate =
mRepository.getFunctionTemplate(
"BAPI_TRANSACTION_COMMIT");
jcoCommit = new JCO.Function(ftemplate);
JCO.Field commitField = jcoCommit.getImportParameterList().getField("WAIT");
commitField.setValue("X");
}
catch (Exception e){
e.printStackTrace(pw);
}
try{
mConnection.execute(jcoCommit);
}
catch(Exception e)
{
e.printStackTrace(pw);
}
JCO.Field SalesDocumentField =
jcoFunction.getExportParameterList().getField(
"SALESDOCUMENT");
SalesOrderNum = SalesDocumentField.getValue().toString();
pw.print( SalesOrderNum );
} catch (Exception ex) {
PrintWriter pw = response.getWriter();
pw.print("data error ");
ex.printStackTrace(pw);
}
} catch (Exception e) {
PrintWriter pw = response.getWriter();
e.printStackTrace(pw);
}
}
Can you please advice
Thanks
Nikhil
Hi Nikhil,
the fact, that there's no exception does not have to mean, that the call succeeded. You have to check the entries of the RETURN table after the function call, if there are messages of type 'E' (error) or 'W' (warning) since this indicates more logical errors (missing parameters or not properly filled structures).
Hope that helps.
Regards
Stefan
Hi Nikhil,
you have to check the valid sales document types in the R/3 system. The easiest way to do this is creating a salesorder using the corresponding online transaction in R/3 and to "remember" the parameters you specified online. If you use this parameters for the BAPI call, it should succeed. Another possibility is to use transaction SE37. Input the bapi name there and use the testing environment (by pressing F8). You can specify all of the import and table parameters. If the call succeeds internally it should also succeed externally.
Hope that helps.
Regards
Stefan
Hi Stefan,
I am able to create the sales order now. and it is showing up in SAP too.
But i have one more problem.
The sales order is created with a 0 quantity.
I was passing quantity in the field TARGET_QTY of the table ORDER_ITEMS_IN.
Can you please help me with this, as to what field of the table ORDER_ITEMS_IN should be updated to show the quantity in the sales order
Thanks
Nikhil
Hi Nikhil,
well the reason for that is hard to tell from my side, since it's an "logical error" resulting from the data you are providing for the call. So maybe the best solution is to check whether the call succeeds if you try it in the R/3 system with the same parameters.
Just one idea: Please assure, you have set the corresponding 'X'-field parameter in the ORDER_ITEMS_IN table structure to 'X' (should be named TARGET_QTYX).
Regards
Stefan
Hi
Following is the code i have written in a servlet.
public class TestCon extends HttpServlet {
private IRepository mRepository;
private JCO.Function jcoFunction;
private JCO.Function jcoCommit;
public PrintWriter pw = null;
public static JCO.Client mConnection = null;
String a = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
PrintWriter pw = response.getWriter();
pw.print("start process");
mConnection =
JCO.createClient(
"010",
"nmahajan",
"passme",
"EN",
"erps021.vtcdb.visteon.com",
"25");
mConnection.connect();
pw.print( mConnection );
} catch (Exception ex) {
pw.print("error connection ");
}
try {
pw.print("start data processing");
String PartnerNumber = "";
String DocType = "";
String SalesOrg = "";
String DistrChan = "";
String Division = "";
String PurchOrder = "";
String SalesOrderNum = "";
int c = 0;
Object[][] itemData = new Object[5][2];
PartnerNumber = request.getParameter("Customer");
DocType = request.getParameter("OrderType");
SalesOrg = request.getParameter("SalesOrg");
DistrChan = request.getParameter("DistChan");
Division = request.getParameter("Division");
PurchOrder = request.getParameter("PONum");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 2; j++) {
c++;
itemData<i>[j] = request.getParameter("t" + c);
}
}
try {
mRepository = new JCO.Repository("Nikhil", mConnection);
pw.print("Repository object crested - " + mRepository);
} catch (Exception e) {
pw.print("Repository error ");
}
try {
IFunctionTemplate ftemplate =
mRepository.getFunctionTemplate(
"BAPI_SALESORDER_CREATEFROMDATA2");
pw.print("Functon Template object crested - " + ftemplate);
jcoFunction = new JCO.Function(ftemplate);
pw.print("Function object crested - " + jcoFunction);
} catch (Exception e) {
pw.print("function templet error ");
}
try {
JCO.Table ORDER_PARENERS =
jcoFunction.getTableParameterList().getTable(
"ORDER_PARTNERS");
pw.print("order partner table not loaded ");
ORDER_PARENERS.appendRow();
ORDER_PARENERS.setValue("SP", "PART_ROLE");
ORDER_PARENERS.setValue(PartnerNumber, "PART_NUMB");
JCO.Structure order_header_inx =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_INX");
pw.print("order header INX table not loaded ");
order_header_inx.setValue("I", "UPDATEFLAG");
order_header_inx.setValue("X", "DCO_TYPE");
order_header_inx.setValue("X", "SALES_ORG");
order_header_inx.setValue("X", "DISTR_CHAN");
order_header_inx.setValue("X", "DIVISION");
order_header_inx.setValue("I", "PURCH_NO_C");
JCO.Structure order_header_in =
jcoFunction.getImportParameterList().getStructure(
"ORDER_HEADER_IN");
pw.print("order header IN table not loaded ");
order_header_in.setValue(DocType, "DOC_TYPE");
order_header_in.setValue(SalesOrg, "SALES_ORG");
order_header_in.setValue(DistrChan, "DISTR_CHAN");
order_header_in.setValue(Division, "DIVISION");
order_header_in.setValue(PurchOrder, "PURCH_NO_C");
JCO.Table ORDER_ITEM_INX =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEM_INX");
pw.print("order item INX table not loaded ");
JCO.Table ORDER_ITEM_IN =
jcoFunction.getTableParameterList().getTable(
"ORDER_ITEM_IN");
pw.print("order item IN table not loaded ");
for (int i = 0; i < 5; i++) {
if (itemData[0]<i> != null) {
ORDER_ITEM_INX.appendRow();
ORDER_ITEM_IN.appendRow();
ORDER_ITEM_INX.setValue("X", "MATERIAL");
ORDER_ITEM_IN.setValue(itemData<i>[0], "MATERIAL");
ORDER_ITEM_INX.setValue("X", "COMP_QUANT");
ORDER_ITEM_IN.setValue(itemData<i>[1], "COMP_QUANT");
ORDER_ITEM_INX.setValue("X", "UPDATEFLAG");
}
}
JCO.Field SalesDocumentField =
jcoFunction.getExportParameterList().getField(
"SALESDOCUMENT");
SalesOrderNum = SalesDocumentField.getValue().toString();
pw.print(" The sales order " + SalesOrderNum + " created ");
} catch (Exception ex) {
PrintWriter pw = response.getWriter();
pw.print("data error ");
}
} catch (Exception e) {
e.printStackTrace();
}
}
The output i am getting on the browser this time is -
start processcom.sap.mw.jco.JCO$Client@f5e0f0
Can you please help me to locate where is the processing stopping
Thanks
Nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nikhil,
please change the last
} catch (Exception e) {
e.printStackTrace();
}
to
} catch (Exception e) {
PrintWriter pw = response.getWriter();
e.printStackTrace(pw);
}
or you won't see output from this catch block in the browser.
Another thing: You declared the JCO.Client mConnection as static. This is not a good idea, remove the static keyword or you're getting in trouble if your servlet is accessed by more than one request at the same time.
Regards
Stefan
Hi
Can you please explain to me the reason for doing this as i am not so good at it
Thanks
Nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to replace:
itemData[j] = request.getParameter("t" + c);
with:
itemData [ i ] [j] = request.getParameter("t" + c);
This will be the error.
Lucky!
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Very weird.
The problem which Antonio noticed is that you are trying to assing a value to a 2-d array, with only giving the first index.
However, this should not give an nullpointerexception,rather the code should not compile.
If you still have the problem, encapsulate the code between a try catch clause, and call printStackTrace() on the exception object
try {
//old code
}catch(Exception e){
e.printStackTrace()
}catch(RuntimeException runE){
runE.printStackTrace();
}
Hi all,
this is a problem of the forum output. The code compiles since the itemData[ i ][ j ] without spaces around the 'i' is interpreted as printing the following text <i>Italic</i> as itemData<i>[j] can be seen here.</i>
The problem must be something different.
@Nikhil, please have a look at the exception, which class and line number is displayed, sample:
java.lang.NullPointerException
at com.sap.tc.webdynpro.progmodel.context.Paths.createAttributePointer(<b>Paths.java:129</b>)
at com.sap.tc.webdynpro.progmodel.context.MappedAttribute.getDataPointer(MappedAttribute.java:62)
more...
Please locate the line in your source code (class name and line will be different of course) and post it here.
Hope that helps.
Regards
Stefan
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.