cancel
Showing results for 
Search instead for 
Did you mean: 

Calling RFC from Java Program?

former_member462539
Participant
0 Kudos

Hello Experts,

I'm trying to call a simple RFC from ERP backend in my java program. I did all the setup in my local eclipse tool and able to run sample programs provided by SAP (i.e StepByStepClient.java & StepByStepServer.java) and got familiar a little bit on how it works.

I'm having bit trouble in understanding JCo API and coding it appropriately. Would anyone please provide me the code for my requirement.

This is my RFC:

RFC Name: Z_ASTU_GET_SUBSCRIPTIONS

Export Parameters:

Parameter Name: ELIGIBLE_LIST

Typing: TYPE

Associated Type: ZSU_EXISTING_SUBSCRIPTIONS (Table Type)

Line type: ZSSU_EXISTINGSUBSCRIPTIONS

Structure: ZSSU_EXISTSUBS; again it has some 50 fields.

Tables:

BLANK

How do I read/iterate this RFC into my java code? Please help with some code snippet on iterating or looping through this Export parameters.

This is what I tried but No Luck.

System.out.println(" List Details: " + function.getExportParameterList().getListMetaData().); 

OUTPUT:  

ELIGIBLE_LIST,ZSU_EXISTING_SUBSCRIPTIONS,h,0,0,290,574,0, ,Existing Subscriptions Table Type,EXPORT,OPTIONAL

JCoTable exportTable1 = function.getTableParameterList().getTable("ELIGIBLE_LIST");

OUTPUT: NullPointerException. I suspect such as this might not be a tabletype or incompatiable type.

System.out.println("Export Table1 " + exportTable1.getMetaData() + ":\n"); 

JCoStructure exportStructure = function.getExportParameterList().getStructure("ZSU_EXISTING_SUBSCRIPTIONS");

OUTPUT: Cannot convert Table type to Structure Record. I suspect such as this also related to incompatiable types.  

System.out.println("System info for " + exportStructure.getMetaData().getFieldCount() + ":\n"); 

Check attached screenshot of RFC. When I double click on ZSU_EXISTING_SUBSCRIPTIONS, It is opening a Dictionary screen with some info. Particularly a tab called "Line Type" is having "ZSSU_EXISTSUBS", when I double clik on it, then it is displaying a Structure screen with some fields info.

Thanks

VB

Accepted Solutions (1)

Accepted Solutions (1)

SridharRaju
Product and Topic Expert
Product and Topic Expert
0 Kudos

It seems very simple.Try the following and let me know.

JCoTable table = function.getExportParameterList().getTable("ELIGIBLE_LIST");

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

{

    table.setRow(i);

    System.out.println(table.getValue(0) + '\t' + table.getValue(1)+..........); // Check & verify how many columns you have in each record and get it displayed accordingly.

}

Thanks

MSR

former_member462539
Participant
0 Kudos

Perfect answer. Thanks a lot Sridhar. Much appreciated.

Regards,

VB

Answers (1)

Answers (1)

Sharathmg
Active Contributor
0 Kudos

Follow the steps in my blog to first create the proxy classes for your backend RFC.

Then, once the proxy classes are available it has the necessary getter and setter classes. Then, the main class has the method execute to trigger the RFC call and get the data into the variables.

If you are familiar with Java, then on execution you should be able to find your way through the setters and getters to view the resulting data.

Regards,

Sharath

former_member462539
Participant
0 Kudos

Thank you sharath for your response. I'm Java savvy and familiar with NWDS plug-in Enterprise connector. In current situation I have to use it in Eclipse only as there is other dependencies.

just I need technical logic in iterating the loop of blackend RFC as I quite did not understood this API on which getter's exactly needs to be used. I'm able to use setter's for IMPORT parameters as they are very simple fields/components in RFC. In case of EXPORT parameters, this RFC has combination of Table & Structure & within , fields/ components. I just need technical logic on using this RFC EXPORT fields.

Thanks

VB

Sharathmg
Active Contributor
0 Kudos

RFC export parameters?

The example in this link explains in detail about setting the input and getting the output and looping through it.

Example: Using Generated Proxies to Call Function Modules (SAP Library - Development Manual)

Regards,

Sharath

former_member462539
Participant
0 Kudos

Hello Sharath,

Unfortunately, it doesnt have any code related to on how to read Table Type from RFC for EXPORT parameters.

Regards

VB.

former_member462539
Participant
0 Kudos

Hello Experts,

Would anyone please help with some snippet? I'm getting followin error at JCoTable object codes. It seems I'm trying to intanitate the object with incorrect one.

 

Exception in thread "main"  java.lang.NullPointerException

JCoTable codes = function.getTableParameterList().getTable("ZSU_EXISTING_SUBSCRIPTIONS ");

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

        {

             

            JCoStructure detail = codes.getStructure("ZSSU_EXISTSUBS");

            System.out.println(detail.getString("CONTRACT_NUMBER") + '\t' +

                               detail.getString("MATERIAL_NUMBER") + '\t' +

                               detail.getString("MATERIAL_DESC"));

        }

Regards

VB
P.S. Plz.,Refer attached screenshot.

Sharathmg
Active Contributor
0 Kudos

Which line of the code, do you get the Null Pointer Exception?

No screenshot attached with your post. Reattach.

Regards,

Sharath

former_member462539
Participant
0 Kudos

I'm getting error at this line of code as mentioned in my previous thread. JCoTable object called "codes" is might be getting NULL value. so throwing NullPointerException.

JCoTable codes = function.getTableParameterList().getTable("ZSU_EXISTING_SUBSCRIPTIONS ");


RFC screenshot had been attached to the initial thread. However here with again I'm attaching.