Warning: Deprecated articles
You are using the old version of the knowledge base for ERPConnect.
Make sure to use the samples within the new HelpCenter for ERPConnect.
This sample shows how to use structures between SAP and .NET with a RFC server.
About #
A structure with the name NUMBERS is added to the Z_ADD_2 function and the table is being deleted (see also RFC Server with tables). Now we rename the function to Z_ADD_3. The structure is build with 2 columns named NUMB1 and NUMB2. Add the 2 columns to the RFCTableColumnCollection. Then add the Structure NUMBERS with the Columns Collection to the IMPORT definition.
Both columns are filled in ABAP and should be added by the .NET program.
Initialize RFCServer #
The following sample code shows how to initialize the RFCServer object:
[C#]
Now as always we add the 2 Columns from the Structure in the .NET programm. The result is returned in the scalar export parameter RES.
[C#]
Call the Function #
The following sample ABAP code calls the function in a foreign destination.
REPORT ZADDTEST3
DATA res TYPE i.
DATA numbs LIKE zaddstruc2.
numbs-numb1 = '1'.
numbs-numb2 = '2'.
CALL FUNCTION 'Z_ADD_3' DESTINATION 'ERPTEST'
EXPORTING
NUMBERS = numbs
IMPORTING
RES = res.
WRITE: / 'Result: ', res.
The same sample here with import and export structure. A dd a structure to the EXPORTS-Collection on the SAP side. Remove the RES Parameter. The .NET programm is modified also with a structure to the EXPORTS-Collection with 2 added Columns (NUMB1 and NUMB2). The ABAP Coding is also getting modified see Coding below.
[C#]
The Values from the IMPORTS-Collection are set in variables. Then different values are added to them and are written back to the EXPORTS-Collection.
[C#]
And here is the little modified sample ABAP code.
REPORT ZADDTEST4 .
.
DATA numbs LIKE zaddstruc2.
DATA exnumbers like zaddstruc2.
numbs-numb1 = '1'.
numbs-numb2 = '2'.
CALL FUNCTION 'Z_ADD_4' DESTINATION 'ERPTEST'
EXPORTING
NUMBERS = numbs
IMPORTING
EXNUMBERS = exnumbers.
WRITE: / 'First result is (added 1): ', exnumbers-numb1 .
WRITE: / 'Second result is (added 98): ', exnumbers-numb2 .