Sei sulla pagina 1di 10

How to Handle Import and Export

Parameters of ABAP Function


Module (RFC Enabled) In Java

Applies to:
This applies to SAP NetWeaver, SAP-Java, SAP Java Connector (Jco). For more information, visit the Java
homepage.

Summary
This article will help you understand the ways in which you can handle and use the import and export
parameters of a ABAP function module (RFC enabled) in your Java code. This will help you in interacting
with ABAP with simple JCo calls & teach you how to use the different types of ABAP function module
parameters in Java. This article is written from Java’s prespective and teaches how to handle the different
type of values passed and returned to/from a ABAP function module in Java.
Author: Vikram Kharata
Company: Steria
Created on: 9 July 2009

Author Bio
Vikram Kharata is working as a Senior Engineer with Steria. He is primarily a Java developer
and his current work area involves creating and supporting applications in the SAP-Java
domain using SAP Netweaver Platform. He also has a good working knowledge of SAP
Enterprise Portal and a little knowledge of ABAP programming.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 1
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

Table of Contents
ABAP Function vs Java method ......................................................................................................................... 3 
Prerequisites ................................................................................................................................................... 3 
Concept ........................................................................................................................................................... 3 
Handling Import Parameters in Java .................................................................................................................. 3 
Prerequisites ................................................................................................................................................... 3 
Concept ........................................................................................................................................................... 3 
Handling Export Parameters in Java .................................................................................................................. 5 
Prerequisites ................................................................................................................................................... 5 
Concept ........................................................................................................................................................... 5 
Complete Example ............................................................................................................................................. 8 
Related Content .................................................................................................................................................. 9 
Disclaimer and Liability Notice .......................................................................................................................... 10 

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 2
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

ABAP Function vs Java method


Prerequisites
You should have a working knowledge of Java programming language.

Concept
An ABAP function module is very similar in concept to a function or method written in Java.
Conceptually, both take a set of parameters as input, process data and return a set of parameters as output.
The values that are passed to a function are called Import Parameters in ABAP, and are called input
parameters in Java. The values that a function returns are called Export Parameters in ABAP, and are
called a return value in Java.

Note: While a Java method can return only single value or multiple values of the same data type, an ABAP function
module can return any number of export parameters which can be of same or different data types.

Handling Import Parameters in Java


Prerequisites
You should have knowledge of making simple JCo calls from Java to ABAP.

Concept
In order to execute a ABAP function module successfully in Java, you must set the values of the import
parameters in your Java code. How to set the import parameter’s value depends upon its type.
Import Parameters can be broadly classified into the following three categories on the basis of their data
types.
1. Simple/Elementary Data Types:
The following diagram shows the mapping between Java and ABAP.

SAP JCo automatically performs the conversion between ABAP and Java data types.
To set the import parameters of these types use the code as under,

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 3
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

In the above code snippet,


Z_DISPLAY_HELLO_WORLD is the name of the ABAP Function Module
NAME1 is the name of the import parameter of simple data type (as stated above)

2. Structure:
A structure is a sequence of any elementary types, reference types, or complex data types. To set a
value in the import parameter of type structure, follow the code sample given below,

In the above code snippet,


Z_DISPLAY_HELLO_WORLD is the name of the ABAP Function Module
FULL_NAME is the name of import parameter of type structure.
FNAME, LNAME are the structure’s field names.

3. Table:
A table is used to store rows of data where each row has the same data type, which can be
elementary or complex.
To set values in the import parameter of type table, follow the code sample given below,

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 4
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

In the above code snippet,


Z_DISPLAY_HELLO_WORLD is the name of the ABAP Function Module
ADDRESSES is the name of the import parameter of type table.
COL1, COL2, COL3 are the table’s column names.

Handling Export Parameters in Java


Prerequisites
You should have knowledge of making simple JCo calls from Java to ABAP.

Concept
Like import parameters, the export parameters are also of different types and have to be handled accordingly
in Java.
Export Parameters can be broadly classified into the following three categories on the basis of their data
types.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 5
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

1. Simple/Elementary Data Types:


The following diagram shows the mapping between Java and ABAP.

SAP JCo automatically performs the conversion between ABAP and Java data types.
Retrieving the values from the export parameters of these types is quite simpler as shown in the
code as under,

In the above code snippet,


RETURNCODE is the name of the export parameter of simple data type (as stated above)
MESSAGE is the name of the export parameter of simple data type (as stated above)
2. Structure:
To retrieve the values that are returned as export parameters of type structure, use the code as under,

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 6
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

In the above code snippet,


RETURN_STRUCTURE is the name of the export parameter of type structure.
FIELD_NAME1, FIELD_NAME2 are the structure’s field names.
3. Table:
As we know by now, that tables contains rows of data, so to retrieve these values from the export
parameters of type table use the code as under,

In the above code snippet,


TEST_TABLES is the name of the export parameter of type table.
COL_NAME1, COL_NAME2 are the table’s column names.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 7
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

The above example uses HashMap to store the results in Java. You can choose your own object
type to store the values.

Complete Example
Please find the entire code sample below for your easy reference,

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 8
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

Related Content
SAP JCo
ABAP Function Modules
Java References
For more information, visit the Java homepage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 9
How to Handle Import and Export Parameters of ABAP Function Module (RFC Enabled) In Java

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 10

Potrebbero piacerti anche