Learn Parameters in SAP ABAP: Syntax, Types & Examples

Parameters in SAP ABAP: Complete Guide with Syntax & Examples
If you're creating strong SAP applications, knowing the parameters in SAP ABAP is non-negotiable. Parameters enable programs, function modules and methods to exchange information by passing values into and out, returning the results and changing objects on the fly.
No matter if you're a newbie ABAP developer or a seasoned consultant who is brushing up on the best methods, this guide will cover the entire gamut: parameters declaration in SAP ABAP and parameters IDs, import/export mechanisms including the CHANGING and RETURNING terms and how to utilize parameters using Call Transaction. In the end you'll have a complete knowledge of each parameter type within the ABAP world.
What Are Parameters in SAP ABAP?
Parameters are placeholders named by name that are used to transfer data between a program that calls it and a program unit that is called -- like subroutines (FORM) function module, a subroutine, or a method. They are what is the connection of a unit that can be called.
There are five major categories:
| Parameter Type | Direction | Used In |
|---|---|---|
| IMPORTING | Caller → Callee | Function Modules, Methods |
| EXPORTING | Callee → Caller | Function Modules, Methods |
| CHANGING | Both directions | Function Modules, Methods, FORMs |
| RETURNING | Callee → Caller (single value) | Methods |
| TABLES | Both directions | Function Modules (legacy) |
Parameters Declaration in SAP ABAP
Declaring Parameters in Selection Screens
A PARAMETERS statement in ABAP can be used to specify input fields on an option screen. This is different from the function module parameters — creating a single-value input field that users can use to fill in a report.
Parameters Syntax in SAP ABAP
PARAMETERS: p_name TYPE data_type [DEFAULT value]
[OBLIGATORY]
[LOWER CASE]
[AS CHECKBOX]
[RADIOBUTTON GROUP grp].
Example:
PARAMETERS: p_matnr TYPE matnr, " Material Number
p_werks TYPE werks_d, " Plant
p_check AS CHECKBOX, " Checkbox
p_flag TYPE c DEFAULT 'X'. " Flag with default
How to Declare Parameter in SAP ABAP — Key Rules
- Names of parameters must begin with "P_" (by convention).
- The maximum length is 8 characters for the parameter name.
- Make use of OBLIGATORY to create a mandatory field on the screen of selection.
- Make use of DEFAULT to fill in values.
- Make use of LOWER CASE to take lowercase input with no automatic conversion into uppercase.
PARAMETERS: p_email TYPE ad_smtpadr LOWER CASE OBLIGATORY.
Actual and Formal Parameters in SAP ABAP
This is an essential concept that every ABAP developer must understand.
- Formal parameters are the names of parameters specified within the unit of program called (the function module, the FORM, or method definition). They are placeholders.
- Actual parameters are the actual variables that are sent by the program that calls it when it invokes the unit.
Example — Actual and Formal Parameters in SAP ABAP
" ---- Subroutine Definition (Formal Parameters) ----
FORM calculate_discount
USING fv_price TYPE p DECIMALS 2 " Formal
fv_percent TYPE i " Formal
CHANGING cv_discount TYPE p DECIMALS 2. " Formal
cv_discount = fv_price * fv_percent / 100.
ENDFORM.
" ---- Calling Program (Actual Parameters) ----
DATA: lv_price TYPE p DECIMALS 2 VALUE '500.00',
lv_percent TYPE i VALUE 10,
lv_discount TYPE p DECIMALS 2.
PERFORM calculate_discount
USING lv_price " Actual
lv_percent " Actual
CHANGING lv_discount." Actual
The mapping is positional — lv_price is then passed to fv_price, and so on.
Import and Export Parameters in SAP ABAP
Function modules employ the importing and exporting parameters to produce an uncluttered, directional interface.
IMPORTING Parameters
Information flows through the calling party into the function module. The function module reads this data but does not alter it.
EXPORTING Parameters
Data is transferred through the function module towards the user. The function module sets these and they are read out by the caller.
Import and Export Parameters in SAP ABAP — Full Example
FUNCTION z_get_material_details
IMPORTING
im_matnr TYPE matnr
im_werks TYPE werks_d
EXPORTING
ex_maktx TYPE maktx
ex_meins TYPE meins
EXCEPTIONS
material_not_found = 1
plant_not_found = 2
OTHERS = 3.
SELECT SINGLE maktx meins
INTO (ex_maktx, ex_meins)
FROM mara
INNER JOIN makt ON mara~matnr = makt~matnr
WHERE mara~matnr = im_matnr
AND makt~spras = sy-langu.
IF sy-subrc <> 0.
RAISE material_not_found.
ENDIF.
ENDFUNCTION.
Calling the function module:
CALL FUNCTION 'Z_GET_MATERIAL_DETAILS'
IMPORTING
im_matnr = lv_matnr
im_werks = lv_werks
EXPORTING
ex_maktx = lv_maktx
ex_meins = lv_meins
EXCEPTIONS
material_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Material not found.' TYPE 'E'.
ENDIF.
Changing Parameter in SAP ABAP
The CHANGING keyword specifies parameters that can be both written and read. The caller inputs a value; the function module or FORM alters it, and the result will be returned back to the caller.
Changing Parameter in SAP ABAP — Example
FUNCTION z_apply_tax
IMPORTING
im_tax_rate TYPE p DECIMALS 2
CHANGING
ch_amount TYPE p DECIMALS 2.
ch_amount = ch_amount + ( ch_amount * im_tax_rate / 100 ).
ENDFUNCTION.
Calling:
DATA: lv_amount TYPE p DECIMALS 2 VALUE '1000.00',
lv_tax_rate TYPE p DECIMALS 2 VALUE '18.00'.
CALL FUNCTION 'Z_APPLY_TAX'
IMPORTING
im_tax_rate = lv_tax_rate
CHANGING
ch_amount = lv_amount.
WRITE: / 'Amount after tax:', lv_amount. " Output: 1180.00
Returning Parameter in SAP ABAP
The RETURNING parameter is used only in ABAP object methods (not function modules). It lets a method return exactly one value directly, which allows functional-style programming as well as method chaining.
Rules for Returning Parameter in SAP ABAP
- A limit of one RETURNING parameter can be used per method.
- It has to be transferred by value (VALUE(...)).
- If RETURNING is defined, you are not able to also define EXPORTING parameters.
Returning Parameter in SAP ABAP — Example
CLASS zcl_math DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
square_root
IMPORTING im_number TYPE f
RETURNING VALUE(rv_result) TYPE f.
ENDCLASS.
CLASS zcl_math IMPLEMENTATION.
METHOD square_root.
rv_result = sqrt( im_number ).
ENDMETHOD.
ENDCLASS.
" Calling the method
DATA: lv_result TYPE f.
lv_result = zcl_math=>square_root( im_number = '144' ).
WRITE: / lv_result. " Output: 12.0
The RETURNING parameter allows for a clean, inline call without the requirement to assign a variable separately prior to using the result.
Parameter ID in SAP ABAP
A Parameter ID (PID) is a key used to store and retrieve data in SAP user memory (also known as the global memory buffer). This permits values to be shared among different programs and transactions within the exact same SAP session.
Parameter IDs are specified in transaction SU20 (maintain parameter IDs) and are assigned to screen fields by using the field's technical attributes in Screen Painter.
Set Parameter ID in SAP ABAP
The SET PARAMETER statement creates a value in the user memory under a specified parameter ID.
Syntax:
SET PARAMETER ID 'param_id' FIELD variable.
Example — Set Parameter ID in SAP ABAP:
DATA: lv_bukrs TYPE bukrs VALUE '1000'.
SET PARAMETER ID 'BUK' FIELD lv_bukrs.
This stores the company code 1000 under the ID BUK in the user's memory.
Get Parameter ID in SAP ABAP
The GET PARAMETER statement retrieves an earlier stored value from the user's memory.
Syntax:
GET PARAMETER ID 'param_id' FIELD variable.
Example — Get Parameter ID in SAP ABAP:
DATA: lv_bukrs TYPE bukrs.
GET PARAMETER ID 'BUK' FIELD lv_bukrs.
IF sy-subrc = 0.
WRITE: / 'Company Code:', lv_bukrs.
ELSE.
WRITE: / 'No value found for PID BUK.'.
ENDIF.
Following a successful GET PARAMETER, sy-subrc is set to 0. If no value is found for the PID, the value of sy-subrc is set to 4.
Clear Parameter ID in SAP ABAP
To erase the value from memory for a specific parameter ID, use SET PARAMETER with an empty or initial field.
Example — Clear Parameter ID in SAP ABAP:
DATA: lv_empty TYPE bukrs. " Initial/empty value
SET PARAMETER ID 'BUK' FIELD lv_empty.
Setting a PID to its initial value will effectively remove it from memory, so that old values don't get carried over into the next processing step.
CALL TRANSACTION in SAP ABAP with Parameter
CALL TRANSACTION can be used to trigger another SAP transaction inside an ABAP program. It is possible to pass values to the transaction you want to call by using the parameter IDs or BDC (Batch Data Communication) sessions.
Basic CALL TRANSACTION Syntax
CALL TRANSACTION 'tcode' [AND SKIP FIRST SCREEN]
[MODE mode]
[UPDATE update_type]
[MESSAGES INTO itab].
Call Transaction with Parameters in SAP ABAP — Using Parameter IDs
The most commonly used method to pre-fill fields prior to an incoming transaction is to set the appropriate parameter IDs before calling.
DATA: lv_matnr TYPE matnr VALUE 'MATERIAL-001',
lv_werks TYPE werks_d VALUE '1000'.
" Set parameter IDs to pre-fill fields in the target transaction
SET PARAMETER ID 'MAT' FIELD lv_matnr.
SET PARAMETER ID 'WRK' FIELD lv_werks.
" Call transaction and skip the first screen (fields pre-filled)
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
Call Transaction in SAP ABAP with Parameter — Using BDC
To perform automated data entry (batch processing), make use of a BDC table to pass parameters:
DATA: lt_bdcdata TYPE TABLE OF bdcdata,
ls_bdcdata TYPE bdcdata,
lt_messages TYPE TABLE OF bdcmsgcoll.
" Screen 1 - Initial screen of MM01
CLEAR ls_bdcdata.
ls_bdcdata-program = 'SAPLMGMM'.
ls_bdcdata-dynpro = '0060'.
ls_bdcdata-dynbegin = 'X'.
APPEND ls_bdcdata TO lt_bdcdata.
CLEAR ls_bdcdata.
ls_bdcdata-fnam = 'RMMG1-MATNR'.
ls_bdcdata-fval = 'NEW-MATERIAL-01'.
APPEND ls_bdcdata TO lt_bdcdata.
" Call the transaction with BDC data
CALL TRANSACTION 'MM01'
USING lt_bdcdata
MODE 'N' " N = No display (background)
UPDATE 'S' " S = Synchronous update
MESSAGES INTO lt_messages.
IF sy-subrc = 0.
WRITE: / 'Material created successfully.'.
ELSE.
WRITE: / 'Error during material creation.'.
ENDIF.
MODE Options:
- A — Display all screens
- E — Display screens with errors only
- N — No display (background mode)
Parameter Passing: By Reference vs. By Value
ABAP provides two methods to transfer parameters:
Pass by Reference (Default)
The program that is called works directly with the caller's memory address. Any changes made are immediately reflected in the variable of the caller. This is quicker, but more risky.
FORM modify_value USING pv_data TYPE i.
pv_data = pv_data * 2. " Directly alters the caller's variable
ENDFORM.
Pass by Value
A copy is created. The changes inside the called unit do not affect the caller unless they are explicitly returned via CHANGING or RETURNING.
FORM modify_value USING VALUE(pv_data) TYPE i.
pv_data = pv_data * 2. " Modifies only the local copy
ENDFORM.
Complete Reference: Parameters in SAP ABAP Cheat Sheet
" ===== SELECTION SCREEN PARAMETERS =====
PARAMETERS: p_field TYPE data_type
DEFAULT value
OBLIGATORY
LOWER CASE
AS CHECKBOX
RADIOBUTTON GROUP grp.
" ===== FUNCTION MODULE PARAMETERS =====
FUNCTION z_example
IMPORTING VALUE(im_input) TYPE type " Pass by value
EXPORTING VALUE(ex_output) TYPE type " Pass by value
CHANGING ch_data TYPE type " Pass by reference
TABLES t_itab TYPE table_type " Internal table
EXCEPTIONS error_case = 1
OTHERS = 2.
ENDFUNCTION.
" ===== METHOD PARAMETERS (OOP) =====
METHODS my_method
IMPORTING im_input TYPE type
EXPORTING ex_output TYPE type
CHANGING ch_value TYPE type
RETURNING VALUE(rv_result) TYPE type
RAISING zcx_my_exception.
" ===== PARAMETER IDs =====
SET PARAMETER ID 'PID' FIELD lv_variable. " Store value
GET PARAMETER ID 'PID' FIELD lv_variable. " Retrieve value
SET PARAMETER ID 'PID' FIELD lv_empty. " Clear value
" ===== CALL TRANSACTION WITH PARAMETERS =====
SET PARAMETER ID 'PID' FIELD lv_value.
CALL TRANSACTION 'TCODE' AND SKIP FIRST SCREEN.
Common Mistakes to Avoid
- Disambiguating the direction of IMPORTING/EXPORTING when calling function modules — it's from the point of view of the caller, not the function module.
- Using RETURNING and EXPORTING in the same method — this is not permitted.
- Not checking sy-subrc immediately following GET PARAMETER ID — the PID may not have been set yet.
- Forgetting VALUE(...) for importing parameters — passing by reference could result in unexpected side effects.
- Utilizing general types (c, n, i) in declarations of parameters without defining the length or precision.
- Not clearing the Parameter IDs after use, causing old values to persist throughout transaction calls.
Conclusion
Understanding the parameters in SAP ABAP is the foundation to creating clean, reusable, and efficient SAP programs. From the declarations of PARAMETERS on selection screens to import and export parameters in function modules, as well as CHANGING parameters which alter data on-the-fly, and RETURNING parameters within OOP techniques — every type has an individual purpose within the ABAP programming model.
The process of mastering parameter IDs (SET, GET, and clearing them) makes it possible to have seamless cross-transaction information passing, particularly when used with CALL TRANSACTION using parameters in SAP ABAP. Knowing the distinction between formal and actual parameters will allow you to troubleshoot interfaces without fear.
Make use of the cheat sheet above for quick reference and ensure that you keep these most effective practices in mind when you develop production-quality SAP solutions.
Frequently Asked Questions (FAQs)
Q1: What is the difference between IMPORTING and EXPORTING parameters in SAP ABAP?
IMPORTING parameters pass information into the function module from the caller. EXPORTING parameters transfer information back to the caller from the function module. The naming is always from the perspective of the function module.
Q2: How do I create a mandatory field on a selection screen in SAP ABAP?
Make use of the OBLIGATORY addition: PARAMETERS: p_field TYPE matnr OBLIGATORY.
Q3: Can a method have both RETURNING and EXPORTING parameters?
No. When using ABAP OOP, if a method specifies a RETURNING parameter it is not able to also define EXPORTING parameters. Choose either one or the other.
Q4: What is a Parameter ID (PID) in SAP ABAP?
A Parameter ID is a short key (defined in transaction SU20) used to save values in SAP user memory using SET PARAMETER ID and retrieve them using GET PARAMETER ID. This allows pre-filling of screen fields across transactions.
Q5: What does CALL TRANSACTION with AND SKIP FIRST SCREEN do?
It makes a transaction call and skips the initial screen, as long as the mandatory fields on that screen have been filled out using parameter IDs or BDC data.
Related SAP Training Courses
Tags
Share this article
Help others discover this valuable SAP content


