cancel
Showing results for 
Search instead for 
Did you mean: 

Passing more complex data between JAVA and SAP

Former Member
0 Kudos

Hi,

now that my RFC connection works, i'm trying to pass some data between Java and SAP.

First time i've tried with simple objects like strings and integers and it worked fine. But i do have some problems with more complex structures like tables or one table row. Is it possible to send complete tables filled with data between the two systems? and if yes, how can i achieve it?

I did define a new parameter in the "Tables" tab within the function modul and then tried to access it in JAVA with

JCoTable zrksUsers = function.getTableParameterList().getTable("T_EXAMPLE_TABLE"); but i didnt get any data, only the column definitions.

Do i have to define an export parameter? (of which kind?)

I've tried that too:


FUNCTION ZFB_TEST01.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(IM_USERID) TYPE  STRING
*"  EXPORTING
*"     VALUE(EX_ZRKS) TYPE  ZRKS
*"  TABLES
*"      T_RETURN STRUCTURE  ZRKS
*"----------------------------------------------------------------------

DATA temp TYPE ZRKS.

SELECT * FROM ZRKS INTO temp WHERE USRID = IM_USERID.
ENDSELECT.

EX_ZRKS = temp.

ENDFUNCTION.

but then i get a conversion error in Java:

"122) JCO_ERROR_CONVERSION: Cannot convert field EX_ZRKS of type STRUCTURE to TableRecord"

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
Former Member
0 Kudos

Ok i already did what is explained in this document, but on page 7 is this statement:

"TEST_TABLES is the name of the export parameter of type table."

if i add an export parameter of type table, i get the error that generic types arent allowed!

Is the "tables" tab only for internal passing of tables and not for Java <-> SAP connections?

Former Member
0 Kudos

As far as this error is concerned :

generic types arent allowed

You can have a understanding from below link :

http://www.sap-press.de/download/dateien/657/sappress_interface_programming.pdf

Goto page 10 : Section Generic Data types....

As far as your original error is concerned :

JCO_ERROR_CONVERSION: Cannot convert field EX_ZRKS of type STRUCTURE to TableRecord"

You have cearly mentioned below as an export parameter..

*" EXPORTING

*" VALUE(EX_ZRKS) TYPE ZRKS

Now your errror suggests that EX_ZRKS which is actually of type ZRKS is an structure and not a Table.

In Java code you are trying to call it as a table....Right !!

Infact if you can paste here the piece of code that you have written...it would be easy for me to help you out of this....

Former Member
0 Kudos

	public static void main(String[] args)
	{
		// SAP System
		SapSystem system = new SapSystem("***", "*****.net", 
										 "***", "00", "******", "********");
		
		Connection connect = new Connection(system);
		

		JCoFunction function = connect.getFunction("ZFB_TEST01");
		
		String UserID = "d5rbrank";
		
		function.getImportParameterList().setValue("IM_USERID", UserID);
		connect.execute(function);

		JCoStructure struct = function.getExportParameterList().getStructure("EX_ZRKS");
		
		System.out.println(struct.getString("NAME"));
                                    
	}

I can compile this without errors, but my struct is empty, there are no values in the variable struct.

In general:

The doc you've sent me is very good, but there is nothing explained about the ABAP function module side.

I would be more interested how the ABAP source code would look like for these examples and how to define the import/export parameter etc.

Thanks

Former Member
0 Kudos

At runtime you are getting error on which line of above code...

If if you can get some idea from below URL: (they contain both abap and java code)

http://www.sapdev.co.uk/java/jco/bapi_jco.pdf

Former Member
0 Kudos

Ok, now i got it!

My Java code is almoste the same as before but i changed my ABAP code a litle bit.

I defined an import parameter and one table parameter, with the same type as my query table.

Instead of the code above, i wrote only this one single line of code:


FUNCTION ZVENDFUN.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(IM_USERID) TYPE  STRING
*"  TABLES
*"      ITAB STRUCTURE  ZRKS OPTIONAL
*"----------------------------------------------------------------------


SELECT * FROM ZRKS INTO TABLE ITAB WHERE USRID = IM_USERID.


ENDFUNCTION.

and now it workds perfect!

Thanks a lot, the last doc you've posted helped very much.

I've one more "design pattern" question, but i'm gonna open a new thread

Answers (0)