on 09-16-2004 10:36 AM
Hello Friends,
I am trying to create the Business Partner through the BAPI BAPI_BUPA_CREATE_FROM_DATA. Here is the code.
template = repository.getFunctionTemplate("BAPI_BUPA_CREATE_FROM_DATA");
template1 = repository.getFunctionTemplate("BAPI_TRANSACTION_COMMIT");
function = template.getFunction();
function1 = template.getFunction();
str = function.getImportParameterList().getStructure("CENTRALDATAPERSON");
str.setValue("Raza","FIRSTNAME");
mConnection.execute(function);
mConnection.execute(function1);
though above code does not give me any exception, but still it does not create any new business partner. Then I come to know that It is mandatory to enter the partner category.
Now problem which I am facing is that, the PARTNERCATEGORY is not the structure, cause when I execute this line of code,
function.getImportParameterList().getStructure("PARTNERCATEGORY");
It gives me exception, that cant convert PARTNERCATEGORY of type char to structure.
So I tried to set the PARTNERCATEGORY in this way,
function.getImportParameterList().setValue(1, "PARTN_CAT");
But ofcourse it gives me exception, this feild is not the input-
Please advise me, how I can set the PARTNERCATEGORY , or in general how I can create the Business Partner!
Many thanks,
Marek
Hello Marek,
you have to use
function.getImportParameterList().setValue("1", "PARTNERCATEGORY");
because the PARTNERCATEGORY is not a Structure. It is a simple Character Field with length 1.
Regards
Gregor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Gregor,
Many thanks for your reply, But I did already tried like this, but still some problem comes,
function.getImportParameterList().setValue(1, "PARTNERCATEGORY");
and then when I try to get the return table, to check the TYPE, it give me exception, that not row accesable !
PLEASE HELP!
With Best Regards,
Marek.
Hello Marek,
here is the code I'm using:
// Set up Import Parameters
JCO.ParameterList imports = function.getImportParameterList();
JCO.Structure centralDataPerson = imports.getStructure("CENTRALDATAPERSON");
centralDataPerson.setValue("Stadler","FIRSTNAME");
centralDataPerson.setValue("Markus","LASTNAME");
function.getImportParameterList().setValue("1", "PARTNERCATEGORY");
// Get a client from the pool
JCO.Client client = JCO.getClient(SID);
// We can call 'RFC_SYSTEM_INFO' directly since it does not need any input parameters
client.execute(function);
// Get table containing the return
JCO.Table returntab = function.getTableParameterList().getTable("RETURN");
// Print results
if (returntab.getNumRows() > 0) {
// Loop over all rows
do {
System.out.println("-----------------------------------------");
// Loop over all columns in the current row
for (JCO.FieldIterator e = returntab.fields(); e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
System.out.println(field.getName() + ":t" + field.getString());
}//for
} while(returntab.nextRow());
}
else {
System.out.println("No results found");
}//if
// Read new BUSINESSPARTNER Number
String bpNumber = function.getExportParameterList().getString("BUSINESSPARTNER");
System.out.println("New Business Partner Number: " + bpNumber);
Take note that I don't do a commit because it's only a test.
Regards
Gregor
Hallo Gregor,
Many many thanks for your kind reply, I am getting kind of nervous now, cause I dont know where is the problem, from your guidence any my thinking code should do what it intend to do, but some how its not :)!
Here is my code,
repository = new JCO.Repository("call" , mConnection);
template = repository.getFunctionTemplate("BAPI_BUPA_CREATE_FROM_DATA");
template1 = repository.getFunctionTemplate("BAPI_TRANSACTION_COMMIT");
function = template.getFunction();
function1 = template.getFunction();
str = function.getImportParameterList().getStructure("CENTRALDATAPERSON");
str.setValue("Raza","FIRSTNAME");
function.getImportParameterList().setValue(1, "PARTNERCATEGORY");
mConnection.execute(function);
mConnection.execute(function1);
JCO.Table returnTab = function.getTableParameterList().getTable("RETURN");
System.out.println(returnTab.getNumRows());
When I print here no.of rows, its 0 !
However, when I print the partnerno, it prints one number,
String bpNumber = function.getExportParameterList().getString("BUSINESSPARTNER");
System.out.println("New Business Partner Number: " + bpNumber);
And then when I try to call the BAPI, BAPI_BUPA_CENTRAL_GETDETAIL, and write the following code:
JCO.Repository repository = new JCO.Repository("call" , mConnection);
IFunctionTemplate template = repository.getFunctionTemplate("BAPI_BUPA_CENTRAL_GETDETAIL");
JCO.Function function = template.getFunction();
function.getImportParameterList().setValue("0000000025", "BUSINESSPARTNER");
mConnection.execute(function);
JCO.Table table = function.getTableParameterList().getTable("RETURN");
JCO.Structure str = function.getExportParameterList().getStructure("CENTRALDATAPERSON");
System.out.println("Here is the name:" + str.getString("FIRSTNAME"));
It does not print any name, however the BP which I have created from SAP GUI, it prints that name !
I would appreciate, if you please help me in identifiny the problem, that why not it creates the new row in table?
Many many, thanks
Marek
Message was edited by: Marek Jöricke
Hello Marek,
do you see the difference between your line
function.getImportParameterList().setValue(1, "PARTNERCATEGORY");
and mine:
function.getImportParameterList().setValue("1", "PARTNERCATEGORY");
The two " are the problem I think. The 1 in your code is interpreted as a Number and the "1" in my code is transfered as a String.
Regards
Gregor
Hello Gregor,
Thanks once again for your kind reply,
Yes that was a silly mistake that I did not put 1 under", But still when I write this line
function.getImportParameterList().setValue("1", "PARTNERCATEGORY");
and print the rows in return table, it gives me 0, however it always return the new BUSINESSPARTNER no.
Dont know, where is the problem!
Any suggestions,
Thanks again !
Marek
Hello Marek,
have you tested the Function Module in Function Builder Transaction SE37? It must work with your Data. When this is done, then do the next step and test your Java Application. I've extended my Example now and do a Commit also. After the commit, I read the Data with BAPI_BUPA_CENTRAL_GETDETAIL. On my R/3 Enterprise 4.70 it works perfect:
public void BupaCreateFromData()
{
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_BUPA_CREATE_FROM_DATA");
IFunctionTemplate ftemplatecommit = repository.getFunctionTemplate("BAPI_TRANSACTION_COMMIT");
IFunctionTemplate ftemplateread = repository.getFunctionTemplate("BAPI_BUPA_CENTRAL_GETDETAIL");
// if the function definition was found in backend system
if(ftemplate != null) {
// Create a function from the template
JCO.Function function = ftemplate.getFunction();
JCO.Function commit = ftemplatecommit.getFunction();
JCO.Function read = ftemplateread.getFunction();
// Set up Import Parameters
JCO.ParameterList imports = function.getImportParameterList();
JCO.Structure centralDataPerson = imports.getStructure("CENTRALDATAPERSON");
centralDataPerson.setValue("Stadler","FIRSTNAME");
centralDataPerson.setValue("Markus","LASTNAME");
function.getImportParameterList().setValue("1", "PARTNERCATEGORY");
// Get a client from the pool
JCO.Client client = JCO.getClient(SID);
// We can call 'RFC_SYSTEM_INFO' directly since it does not need any input parameters
client.execute(function);
// Get table containing the return
JCO.Table returntab = function.getTableParameterList().getTable("RETURN");
// Print results
if (returntab.getNumRows() > 0) {
// Loop over all rows
do {
System.out.println("-----------------------------------------");
// Loop over all columns in the current row
for (JCO.FieldIterator e = returntab.fields(); e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
System.out.println(field.getName() + ":t" + field.getString());
}//for
} while(returntab.nextRow());
}
else {
System.out.println("No results found");
// Read new BUSINESSPARTNER Number
String bpNumber = function.getExportParameterList().getString("BUSINESSPARTNER");
System.out.println("New Business Partner Number: " + bpNumber);
// Commit
client.execute(commit);
// Set
read.getImportParameterList().setValue(bpNumber, "BUSINESSPARTNER");
// Commit
client.execute(read);
// Read Export
JCO.ParameterList readExport = read.getExportParameterList();
JCO.Structure readCentralDataPerson = readExport.getStructure("CENTRALDATAPERSON");
System.out.println("Firstname: " + readCentralDataPerson.getString("FIRSTNAME"));
System.out.println("Lastname : " + readCentralDataPerson.getString("LASTNAME"));
}//if
// Release the client into the pool
JCO.releaseClient(client);
}
else {
System.out.println("Function BAPI_BUPA_CREATE_FROM_DATA not found in backend system.");
}
}
catch (Exception ex) {
System.out.println("Caught an exception: n" + ex);
}
}
Regards
Gregor
Hello Gregor,
Many thanks for such a kind favour!
I am now going to test the application according to your code, with in next few hours, I will definately let you know the result!
So nice of you again!
As far as know, in Functin builder with Transaction SE37 u just can see, if FM exists and its details (source-code and etc), ? pls let me know what exactly should I check in Transaction SE37.
With Best Regards,
Marek
Hi Gregor,
Now I have tested the FM (BAPI_BUPA_CREATE_FROM_DATA) in se37, i have provided the test data, and it has given me the ExportParameter (BUSINESSPARTNER), but when I put this BUSINESSPARTNER no, in Tran BP to find the BP, it does not find this new created BP.?
And one thing more, do I need to mention RFC target SYS:
in se37.
one thing more, in se37 when I execute the test, the return table is empty ( no errors,or no msgs) which indicates the test is succesful ? or.
With Regards,
Marek.
Hello Marek,
the successful test of the FM is indicated by the returned BP Number. You won't find this number in the system because you've not done a Commit.
So try now my code with the Commit.
You don't have to provide a target system if the function should be called on the system on which you logged on.
Regards
Gregor
Hi Gregor,
now I have tested with your code, and still there is no row in Table, however,now when i call the getDetail bapi, it provides me the relevent information of the newly created BP!
yes, u are right, there is somewher problem in my commit , but I am doing this , i need to debug it once again !
Hello Gregor,
Thanks you very much for your kind help!
My problem was from the begining that return table shows me 0 rows, when I call it! but I think u are right when u have successful call, then there is no row in table!,
Now I am a step a head, to construct a J2EE application and do this all stuff with JSP, and then same work using BSP and WAS. let see!
I am using Eclipe and JBOSS env for J2EE and SAP JCO stuff, dont know if its really a adviseable stuff to go on! however I have a chance to do the stuff with Netweaver as well, but not yet looked into it.
Thanks once again for your kind reply!
With Regards,
Marek
Message was edited by: Marek Jöricke
Hi Gregor,
I have already given the points to the answer ! was really very helpful,
I am doing this project as my final thesis,
Now I am getting one another problem, when I try to connect the SAP system using JCO in my servlet, it gives me following error!
HTTP ERROR: 500 com/sap/mw/jco/JCO
However I have put sapjco.jar in WEB-ING\lib folder and to buildpath as well, ? any idea what is possibly wronge ? what is the evn, u are using?
With Regards,
Marek
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.