Preface – This post is part of the ABAP Beginner series.
Table of Contents
Parameters in SAP ABAP Report
Have you ever worked on HTML tags where we use <INPUT> tag to get single input OR C/C++ tag where we use SCANF/CIN statement to take single input. Just like that, in ABAP PARAMETERS are used to take single input.
Definition
PARAMETERS are ABAP statements which are used to declare input ABAP variables in ABAP Programs/Report, variables are just like DATA statements. For every PARAMETER variable declared, an input box becomes visible on selection screen.
Syntax
PARAMETERS <NAME OF YOUR PARAMETER> [ TYPE/LIKE ] <DATA ELEMENT/ABAP PREDEFINED DATA TYPE/REFERENCE to ABAP Table, Structure or View Field>
Examples
Case 01: TYPE/LIKE to DATA ELEMENT.
PARAMETERS P_BARRY TYPE ZBARRY_NAME. //Here P_BARRY is a Parameter with property same as ZBARRY_NAME which is a Data Element. PARAMETERS P_ALLEN LIKE P_BARRY. //Here P_ALLEN is a Parameter with Property same as Parameter P_BARRY i.e. ZBARRY_NAME.
Case 02: TYPE/LIKE to ABAP PREDEFINED DATA TYPE.
PARAMETERS P_BARRY(10) TYPE C. //Here P_BARRY is a Parameter with property of a character and length 10. PARAMETERS P_ALLEN LIKE P_BARRY. //Here P_ALLEN is a Parameter with Property same as Parameter P_BARRY i.e. character and length 10.
Case 03: REFERENCE to ABAP Table, Structure or View Field.
DATA CARR_ID(40) TYPE c. CARR_ID = ‘SFLIGHT-CARRID’. PARAMETERS P_BARRY LIKE (CARR_ID).
*NOTE: In the above statement, the PARAMETER is just like field CARRID of table SFLIGHT. It will have all the properties (length, data type, decimal places, etc) and search help of that field.
DEFAULT Values of a PARAMETER
Syntax:
PARAMETERS <NAME OF YOUR PARAMETER> [TYPE/LIKE] <DATA ELEMENT/ ABAP DATA TYPES/ DDIC Field> DEFAULT <YOUR DEFAULT VALUE>.
Example:
PARAMETERS P_NAME(20) TYPE C DEFAULT ‘BARRY ALLEN’.
Setting PARAMETER value from Memory
We can store values in SAP Memory. To learn more about Memories click here.
From these memories we can get the values and set it as default in PARAMETER.
Have you ever wondered that after viewing your table name when you come back again to SE11, its name still appears? This is possible because every time we open anything in SE11, the value of Parameter is set into memory and when we revisit the DDIC/SE11, it get the Parameter value back from memory. Let us see how we can do it too in our program.
To Set PARAMETER value in SAP Memory:
SET PARAMETER ID <NAME OF YOUR Memory ID> FIELD <Name of the field whose value will be saved>.
Example:
SET PARAMETER ID pid_barry FIELD lv_barry.
To Get PARAMETER value from SAP Memory:
GET PARAMETER ID <NAME OF YOUR Memory ID> FIELD <Name of the field which will get the value>.
Example:
GET PARAMETER ID pid_barry FIELD lv_barry.
To Give Default value to Parameter from SAP Memory:
PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> MEMORY ID <NAME OF YOUR Memory ID> .
Example:
PARAMETER P_NAME(20) TYPE C MEMORY ID pid_barry .
*NOTE: IF any of the above operation fails, SY-SUBRC becomes 4.
Allow PARAMETER to Accept LOWER and Upper Case
The default value of Parameter is upper case that means all input changes to upper case. You can allow lower cases using given syntax.
Syntax: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> LOWER CASE.
Example:
PARAMETER P_NAME(20) TYPE C LOWER CASE .
Reduce Visible Length
You can allow as many lengths of Parameter you want and also restrict the length visible to the end user using given syntax.
Syntax: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> VISIBLE LENGTH <Your Length>.
Example:
PARAMETER P_NAME(20) TYPE C VISIBLE LENGTH 5 .
Define Required/Mandatory/Obligatory Field
Suppose you want an input the will be saved in the table as a Primary key, it means it is a required field and it cannot be left blank. To tell user that it is mandatory to fill some values in this field you will use given syntax.
Syntax: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> OBLIGATORY.
Example:
PARAMETER P_NAME(20) TYPE C OBLIGATORY.
Attach Search Help to Parameters
Search Help were earlier called Match Code Objects in SAP ABAP. To know more about Search Help Click Here.
A search help provides the possible values for a given parameter. To attach a search help to a parameter use the syntax given below:
Syntax: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> MATCHCODE OBJECT <Name of your Search Help>.
Example:
PARAMETER P_NAME(20) TYPE C MATCHCODE OBJECT ZBARRY_SHELP.
Check Parameter Input against Check Table or Fixed Value
If you want a Parameter to have input only that value that is present in the Check Table. Then you need to do three things:
- Make the Parameter Obligatory: The Empty value will not be in check table and hence it will be a required field.
- DATA TYPE will be a field from table having Check-Value Relationship.
- Attach a Check: A Check will ensure the presence of valid value.
Syntax: PARAMETERS <Name of your parameter> [TYPE/LIKE] < DDIC REFERENCE> OBLIGATORY VALUE CHECK.
Example:
PARAMETER P_CARRID TYPE SFLIGHT-CARRID OBLIGATORY VALUE CHECK.
The check will compare data with check table; if not present will throw an error.
Define Checkbox
A Parameter can be a simple field as well as a checkbox with given syntax.
Syntax:
PARAMETERS <Name of your parameter> AS CHECKBOX.
Example:
PARAMETER: P_CHECK1 AS CHECKBOX . P_CHECK2 AS CHECKBOX DEFAULT ‘X’ .
Here P_CHECK2 has default value ‘X’ which means it is checked.
Define Radio Button
A Parameter can be a simple field, a checkbox and even a radio button.
Syntax: PARAMETERS <Name of your parameter> RADIOBUTTON GROUP <Name of Radio button Group> .
Example:
PARAMETER: P_rad1 RADIOBUTTON GROUP rad1 DEFAULT ‘X’ , P_rad2 RADIOBUTTON GROUP rad1 , P_rad3 RADIOBUTTON GROUP rad1 .
The radio buttons comes under a group with one of them as a default value. A radio button group here can have maximum length four. If you do not assign the default value, the first radio button is assigned automatically. Here ‘X’ means radio button is pressed.
Modify Input Fields
To modify appearance of a field or a Parameter, we assign it a MODIF ID whose length can be maximum 3 characters. Now these fields will behave as a single group. And using Modify Screen statements we can modify their appearance on screen.
SYNTAX: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> MODIF ID <Name of your MODIF ID>.
Example:
PARAMETERS: P_First_name(20) TYPE C MODIF ID md1, P_Last_name(20) TYPE C MODIF ID md1.
Hide a Parameter
Sometimes you need a parameter but you don’t need to display it. In such case you can pass default value, or a value via INITIALIZATION, or via another Program.
SYNTAX: PARAMETERS <Name of your parameter> [TYPE/LIKE] <DATA TYPE/DATA ELEMENT/DDIC REFERENCE> NO-DISPLAY.
please change font color for sample code it’s mixed with background color.
Done. Thanks for recommendation.