Exercise 2: Implementing a Local Function Call
Use
In all R/3 systems the CALL FUNCTION statement is an integral part of the ABAP language. This statement calls a function module locally in the same system. Write a program that calls the function module RFC_READ_SPFLI locally.
Prerequisites
To execute the program, you must have created the function group and function module described in Exercise 1.
In the procedure below we assume that you create a new APAB program using the Object Navigator. The procedure generally applies to creating new programs, even if no Programs object node exists in the object list.
Procedure
Create a Local Function Call:
- Call the Object Navigator (SE80).
- In the window Object Selection select the listbox entry Program and enter XX_RFC_Tutorial as name. Remember to replace XX with the initials of your name.
- Since the program XX_RFC_Tutorial does not exist, the system asks you whether to create it. Confirm with Yes.
The Create programs dialog window appears.
- Deactivate the With Top include option and choose Continue to leave the window.
A dialog window appears on which you can determine other program attributes.
- Enter the required attributes for your program and choose Save.
- Create the program as a Local object.
The system adds the program to the object list of the assigned development class and displays it under the Programs object node.
- Double-click on the program name.
The ABAP Editor appears in the tools window. It contains the program in display mode.
- Choose Display <-> Change ( STRG+F1 ).
- Write a calling program like the one below:
REPORT XX_RFC_Tutorial.
* Global Data Declaration
TABLES: spfli.
PARAMETERS: p_carrid LIKE spfli-carrid DEFAULT 'LH',
p_connid LIKE spfli-connid DEFAULT '400'.
DATA: SYSTEM LIKE SY-SYSID.
* Calling the Function
CALL FUNCTION 'XX_RFC_READ_SPFLI'
EXPORTING
carrid = p_carrid
connid = p_connid
IMPORTING
ex_spfli = spfli
sys = system
EXCEPTIONS
invalid_data = 1.
* Handling Exceptions
CASE sy-subrc.
WHEN 1.
WRITE 'No data available'.
EXIT.
ENDCASE.
* Displaying Results
WRITE: spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-cityto,
spfli-deptime,
spfli-arrtime.
- Save the program ( STRG+S ).
- Check the syntax ( STRG+F2 ) and activate the program ( STRG+F3 ).
If the system did not encounter any syntax errors, you can execute the program ( F8 ). To test it, you can use the pre-set values.
Result
You implemented a local function call.