cancel
Showing results for 
Search instead for 
Did you mean: 

JCO.Structure NullPointerException

Former Member
0 Kudos

Hi All,

I am having a java.lang.NullPointerException when I try to call an RFC, that my ABAP colleague makes for me..

The execption happends when I try to get the Structure "RETURN".

I think, the suspect is the data type thah the rFC returns, if returns something.

I have executed the RFC in the SAP workbecnh, it seems to run Ok.

Sicne I am foraigner in the SAP land, I am not sure if I am going in the wrong way, or in the correct way but with the worng map....

Thanks in advance

/----


/

JCO.Function function = null;

JCO.Table codes = null;

try {

function = this.createFunction("YFH_INTERFACE_DADOS_MESTR");

if (function == null) {

System.out.println("BAPI " +

" not found in SAP.");

System.exit(1);

}

mConnection.execute(function);

JCO.Structure returnStructure =

function.getExportParameterList().getStructure("RETURN"); // The ERROR happends here

if (! (returnStructure.getString("TYPE").equals("") ||

returnStructure.getString("TYPE").equals("S")) ) {

System.out.println("DADOS= "+returnStructure.getString("MESSAGE"));

System.exit(1);

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Luis,

This return is the name of the return parameter. But check what is the structure type of that return table.

You have to pass there actual structure name instead of "RETURN".

So, check at SAP R/3 side and get the structure type and pass in : function.getExportParameterList().getStructure("<structure type>");

Regards,

Bhavik

Former Member
0 Kudos

Hi Bhavik,

I follow your advice, an look at the SAP side.

I realzie that I need to send a table as input parameter,

and this RRFC returns me another table.

So, I think, I need to create a METADATA, a try to pass the parameters.

After that, I guess I am goint to need to call:

function.getExportParameterList().getStructure("NAME_OUTPUT_TABLE");

Tthe code that I am trying right now is, let me know what do you think:

/----


PARAMETRO DE ENTRADA -
/

// Create metadata definition of the input parameter list

JCO.MetaData input_md = new JCO.MetaData("INPUT");

input_md.addInfo("PERNR", JCO.TYPE_NUM, 8, 35, 0);

input_md.addInfo("ENDDA", JCO.TYPE_DATE, 8, 35, 0);

input_md.addInfo("BEGDA", JCO.TYPE_DATE, 8, 35, 0);

// Create the input parameter list from the metadata object

JCO.ParameterList input = JCO.createParameterList(input_md);

// Set the first (and only) input parameter

input.setValue("0080055", "PERNR");

input.setValue("09062005", "ENDDA");

input.setValue("09062005", "BEGDA");

/----


FIM PARAMETROS DE ENTRADA -
/

JCO.Function function = null;

JCO.Table codes = null;

try {

function = this.createFunction(strFunction);

if (function == null) {

System.out.println("RFC " +strFunction +

" not found in SAP.");

System.exit(1);

}

System.out.println("RFC "+ strFunction + " EXISTE=OK.....\n");

// Here we go...

mConnection.execute(function);

System.out.println("Debug:.. executou...");

JCO.Structure returnStructure =

function.getExportParameterList().getStructure("DM_END");

System.out.println("Debug:.. antes del IF..");

if (! (returnStructure.getString("TYPE").equals("") ||

returnStructure.getString("TYPE").equals("S")) ) {

System.out.println("DADOS= "+returnStructure.getString("MESSAGE"));

System.out.println("sAINDO....abort..");

System.exit(1);

}

codes = function.getTableParameterList().getTable("DM_END");

for (int i = 0; i < codes.getNumRows(); i++) {

codes.setRow(i);

System.out.println(codes.getString("CNAME") + '\t' +

codes.getString("FATXT"));

}

}

catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

Former Member
0 Kudos

Hi Bhavik Devisha,

Regarding

function.getExportParameterList().getStructure("<structure type>");

I sorry, I have no idea of how to know what structure type is supposed to invoke.

I see the RFC details in the SAP GUI, but it doenst have the RETURN structure as the BAPI_COMPANYCODE_GETLIST does.

In the case of the COMPANYCODE function, the return structure is listed in the "importation"(I dont know the exact name in englis, my version is in portuguese) column, when browsing in the "Fucntion Builder".

My RFC only return Tables, but this tables are not listed in the exportation table, neither the input tables in the importation column.

Also, I delete the code lines refering the getStruture (works better without ...ehehehe) and the program runs, but I get "empty" tables, no rows. But in the SAP GUI, I can see the table has data.

Thans in advance by any help!!

Former Member
0 Kudos

Hi Luis,

No need to create this metadata.

The structure name for the "RETURN" parameter, you can give "BAPIRETURN". This is the actual structure.

Give this in gteStructure() and continue with the privious coding without doing this metadata thing.

Let me know the status if it works for you.

regards,

Bhavik

Former Member
0 Kudos

Oi (=hi in protuguese) Bhavik,

I try, but this line brings me the NullPointer Exception.

JCO.Structure returnStructure =

function.getExportParameterList().getStructure("BAPIRETURN");

System.out.println("RETURN= "+returnStructure.getString("MESSAGE"));

Also, I dont know why I am calling this getStructure method, ?is this necessary in order to know if the RFC goes well???

Remember, my code runs without this line code, but I no rows in the output table.

Former Member
0 Kudos

Hi luis,

Have tried executing the same BAPI with same input parameters in SAP r/3 system?

Is it giving any values in this Return table or in COMPANYCODE_LIST table?

And it is not required to write this step for checking RFC goes well.

Regrds,

Bhavik

Former Member
0 Kudos

Yes, I do. In the SAP GUI I get some ouput tables.

I thnik, I will forget about the getStrucutre, a deal with my problem of getting empty output tables.

As far as you help me with this, I wil lrecognize your deserved points, an post an new question regardig the empty tables.

Muito Obrigado!! (thanks very much in portuguese)

Former Member
0 Kudos

First before executing the function you should be able to retrieve the input parameters and get the table.

From the table add the row, get the structure , fill it,

add next row and so on. Check out the JCO Doc...

Execute the function,

Get the export parms

Display the results....

After the initial fetch of the function from the repository you should be able to manipulate the function and its objects to get at all the tables, structures and parameters you need.

Enjoy