cancel
Showing results for 
Search instead for 
Did you mean: 

How to get/print all return values of an ABAP call with java

Former Member
0 Kudos

Hi!

I have just started to use java instead of c code and rfc. My problem is to read all return values and (for example) print them to stdout. I now how to call the ABAP and I now how to print an export-value or a table if I know its name and type. But how can I built a generic solutions which can print all export parameters, tables and exceptions which are returned by the ABAP function. Does anybody have a demo example for me or is there a good documentation/book where I can find a solution? A few lines to put me on the right path would be great!

Thanks,

Konrad

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use metadata to get structure and getValue() instead of a specific type getter.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Konrad,

I think creating a generic program to find all tables and fields is very complicated, and i never tried that before. Please give me your mail id, incase i get something relavent i will update you.

Thanks & Regards,

Kathirvel

Former Member
0 Kudos

Thanks for the nice offer!

Konrad

Former Member
0 Kudos

Hi Konrad,

After executing the function, you can get the contents of the table as shown below,

<b> codes =myFunction.getTableParameterList().getTable("REQUISITION_ITEMS");

size =codes.getNumRows();

if (size == 0)

{

System.out.println("No value matches the selection criteria");

}</b>

Here Size will give the number of records in the Table returned,

The you can get the values as shown below,

<b> for (int i = 0; i < size; i++)

{

codes.setRow(i); // This will used to fetch the value from ith row

purchaseRequisitionNo<i> = codes.getString("PREQ_NO") ;

item<i> = codes.getString("PREQ_ITEM") ;

creatorName<i> = codes.getString("CREATED_BY");

purchaseRequisitionDate<i> = codes.getString("PREQ_DATE");

description<i> = codes.getString("SHORT_TEXT");

plant<i>=codes.getString("PLANT");

}</b>

Now you can print or take it from here ar per your need. Hope this solve your problem.

Thanks

Kathirvel

Message was edited by: Kathirvel Balakrishnan

Former Member
0 Kudos

Thanks!

Can you show me a generic example which grabs all tables and all fields in those tables. What is if I do not know the name of the fields or even if there are tables at all. Maybe there are just normal export parameters (fields). Or the BAPI exports a structure...

This is the reason why I want a generic function which prints out all return values of a function.

Thanks again!

Konrad

Former Member
0 Kudos

Hi Konrad,

Please check the following link..

http://manuals.sybase.com/onlinebooks/group-iaw/iag0203e/iadgen2/@Generic__BookTextView/24685

This details how to read export values after invoking BAPI. Hope this help you.

Regards,

Uma

Message was edited by: Uma Maheswari

Former Member
0 Kudos

I'm using SAP JavaConnector JCO. There is no Factory Object...

In the code I'm doing something like this:

(oFunktionHandler and oConnection are Helper Classes)

JCO.Function function = null;

function = oFunktionHandler.createFunction("BAPI_MATERIAL_GET_DETAIL");

function.getImportParameterList().setValue("P-100", "MATERIAL");

oConnection.getConnection().execute(function);

OK, now the function is executed and I can start to receive the result (and here starts my problem):

for( int i = 0; i < function.getExportParameterList().getNumFields(); i++ ) {

/*

I need to loop over each export parameter, each structure and each field for this structures and print out the field name and its value...

*/

System.out.println("fieldname: xxx; value: yyy");

}

Maybe somebody can halp me with this code?

Thanks,

Konrad

Former Member
0 Kudos

To add, if you are using a JSP or servlet to access the function, then all you have to do is add the code

functionname.writeHTML(out);

This method stops the request at this line, so no other line below gets called. It would be like calling a requestDispatcher.forward.

Former Member
0 Kudos

What I need is the following:

I want to call a function (e. g. BAPI_MATERIAL_GETDETAIL) and then have some kind of a loop which allows me to print all values of the given material. Therefor I need loop which reads all export parameters, all tables, each field for each table... How can I asked for these values?

Thanks again,

Konrad

Former Member
0 Kudos

There is also a method that prints all the data to a outputstream in HTML format. It shows the tables, imput parameters, basically everything.

void writeHTML(java.lang.String html_filename)

Dump the function and all parameters and tables to the specified HTML file.

void writeHTML(java.io.Writer writer)

Dump the function and all parameters and tables to the specified HTML file.