cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_BUPA_CREATE_FROM_DATA + PARTNERCATEGORY

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

gregorw
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

gregorw
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

gregorw
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

gregorw
Active Contributor
0 Kudos

Hello Marek,

type in the Function Module Name and press F8. Then you start the Test. You can enter test data and also save it. Press F8 again and the Function Module will start.

Regards

Gregor

Former Member
0 Kudos

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.

gregorw
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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 !

gregorw
Active Contributor
0 Kudos

Hello Marek,

i think that the RETURN Table is only filled when an Error occurs. The table is empty when the function was called successfully.

Regards

Gregor

gregorw
Active Contributor
0 Kudos

Hello Marek,

it is also possible to test BAPI's which require a BAPI_TRANSACTION_COMMIT to write to the Database in SE37. Look at SAP Note 178338.

Regards

Gregor

Former Member
0 Kudos

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

gregorw
Active Contributor
0 Kudos

Hello Marek,

you're welcome. But not only thank in words. Give points for the solutions. If you have problems doing this, look at the .

Regards

Gregor

Former Member
0 Kudos

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

gregorw
Active Contributor
0 Kudos

Hello Marek,

please post a new thread, to that also other SDN Users can contribute.

Regards

Gregor

Former Member
0 Kudos

hi Gregor,

yes, I have post new thread for this problem, and I will make this question as answered!

Thanks!

With Regards,

Answers (0)