SELECTION SCREEN PROGRAMMING
Selection texts are texts which are used to replace technical field names on selection-screen with custom names.
In real-time business no business user(end user) can understand technical names, they just uses the applications for the business, when ever we print a input field on selection-screen, we get technical field names by default.
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input
The above code will generate below screen
Selection texts in SAP ABAP
But we need to replace P_MTART with our custom name, follow the below steps to change technical name.
Go to Program Source,Select Goto-Text Elements-Selectin Texts
Selection texts in SAP ABAP
Replace question mark with your custome text.
Selection texts in SAP ABAP
Selection texts in SAP ABAP
Selection-screen texts in SAP ABAP
In the same way you can replace radio button text, selection-options text, parameters text etc.
* Selection Screen Format:
*
* This block of code is responsible with declaring the form fields to be used
* by the user and any othe parameters he wishes to have.
*
* Selection Screen : GoTo -> Text Elements -> Selection Texts
*
* Parameters:
* Syntax:
* PARAMETERS: <nameofparameter> LIKE basetable-field DEFAULT space. (optional)
* Parameters sets a singular field in the form, that takes values
* Values are preset from those that exist in the table
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
*
* Select-Options:
* Select-Options syntax:
* Select options creates two fields in the form, for start/end value
* also allows exclusion of values and queries for specific lists of values.
SELECT-OPTIONS: s_vrefer FOR ever-vrefer,
s_kofiz FOR ever-kofiz,
s_vkonto FOR ever-vkonto
Radio Button Group: is a group of radio buttons, one one radio button can be selected in on radio button group. To print radio button in SAP screen we use below syantax.
PARAMETERS : RADIOBUTTON GROUP .
*Example program of using Radio Button in SAP
*The below is the example of using radio button in SAP, the below code prints two radio buttons.Select and Execute for testing.
*Using radio button in SAP ABAP
REPORT ZSAPN_RADIO_BUTTON.
PARAMETERS : P_RAD1 RADIOBUTTON GROUP RB1.
PARAMETERS : P_RAD2 RADIOBUTTON GROUP RB1.
START-OF-SELECTION.
IF P_RAD1 = 'X'.
WRITE:/ 'Radio Button1 is selected '.
ELSEIF P_RAD2 = 'X'.
WRITE:/ 'Radio Button2 Is selectd'.
ENDIF.
*Some times we may need to print drop down on selection-screen, and need to
*catch the selected value for execution logic, the below example will
*explain how to use drop-down in selection-screen in SAP ABAP.
*To display drop down list we have to use type-group VRM as type-pools.
*Drop Down list on Selection Screen in SAP ABAP
REPORT ZSAPN_DROP_DOWN_SS.
TYPE-POOLS: VRM. " Use type group VRM for list
DATA: IT_LIST TYPE VRM_VALUES.
DATA: WA_LIST TYPE VRM_VALUE.
DATA: IT_VALUES TYPE TABLE OF DYNPREAD,
WA_VALUES TYPE DYNPREAD.
DATA: LV_SELECTED_VALUE(10) TYPE C.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
PARAMETERS: COLORS TYPE C AS LISTBOX VISIBLE LENGTH 20. "Parameter
*--------------------------------------------------------------*
*Initialization
*--------------------------------------------------------------*
INITIALIZATION. "initialize values to drop down list
WA_LIST-KEY = '1'.
WA_LIST-TEXT = 'Green'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '2'.
WA_LIST-TEXT = 'Blue'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '3'.
WA_LIST-TEXT = 'Orange'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '4'.
WA_LIST-TEXT = 'Gray'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '5'.
WA_LIST-TEXT = 'White'.
APPEND WA_LIST TO IT_LIST.
WA_LIST-KEY = '6'.
WA_LIST-TEXT = 'Yellow'.
APPEND WA_LIST TO IT_LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'COLORS'
VALUES = IT_LIST
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2.
*--------------------------------------------------------------*
*At Selection Screen
*--------------------------------------------------------------*
AT SELECTION-SCREEN ON COLORS.
CLEAR: WA_VALUES, IT_VALUES.
REFRESH IT_VALUES.
WA_VALUES-FIELDNAME = 'COLORS'.
APPEND WA_VALUES TO IT_VALUES.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
TRANSLATE_TO_UPPER = 'X'
TABLES
DYNPFIELDS = IT_VALUES.
READ TABLE IT_VALUES INDEX 1 INTO WA_VALUES.
IF SY-SUBRC = 0 AND WA_VALUES-FIELDVALUE IS NOT INITIAL.
READ TABLE IT_LIST INTO WA_LIST
WITH KEY KEY = WA_VALUES-FIELDVALUE.
IF SY-SUBRC = 0.
LV_SELECTED_VALUE = WA_LIST-TEXT.
ENDIF.
ENDIF.
*--------------------------------------------------------------*
*Start of Selection
*--------------------------------------------------------------*
START-OF-SELECTION.
WRITE:/ LV_SELECTED_VALUE.
*******************************************************************************
* Selection Screen Format:
*
* This block of code is responsible with declaring the form fields to be used
* by the user and any othe parameters he wishes to have.
*
* Selection Screen : GoTo -> Text Elements -> Selection Texts
*
* Parameters:
* Syntax:
* PARAMETERS: <nameofparameter> LIKE basetable-field DEFAULT space. (optional)
* Parameters sets a singular field in the form, that takes values
* Values are preset from those that exist in the table
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
*
* Select-Options:
* Select-Options syntax:
* Select options creates two fields in the form, for start/end value
* also allows exclusion of values and queries for specific lists of values.
SELECT-OPTIONS: s_vrefer FOR ever-vrefer,
s_kofiz FOR ever-kofiz,
s_vkonto FOR ever-vkonto.
*
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path TYPE string LOWER CASE. "File path
SELECTION-SCREEN END OF BLOCK b4.
* Value of chosen path is stored in p_path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*
*
******************************************************************************
* Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
* window_title = ' '
default_extension = 'txt'
default_file_name = 'file_name'
initial_directory = 'C:\'
CHANGING
filename = gv_filename
path = gv_path
fullpath = p_path
user_action = gv_result.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path TYPE string LOWER CASE. "File path
SELECTION-SCREEN END OF BLOCK b4.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*
*
******************************************************************************
* Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
* window_title = ' '
default_extension = 'txt'
default_file_name = 'file_name'
initial_directory = 'C:\'
CHANGING
filename = gv_filename
path = gv_path
fullpath = p_path
user_action = gv_result.
******************************************************************************
* File path variable
* File path is stored in p_path.
*******************************************************************************
* Selection Screen Format:
*
* This block of code is responsible with declaring the form fields to be used
* by the user and any othe parameters he wishes to have.
*
* Selection Screen : GoTo -> Text Elements -> Selection Texts
*
* Parameters:
* Syntax:
* PARAMETERS: <nameofparameter> LIKE basetable-field DEFAULT space. (optional)
* Parameters sets a singular field in the form, that takes values
* Values are preset from those that exist in the table
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
SELECTION-SCREEN END OF BLOCK b2.
*
* Select-Options:
* Select-Options syntax:
* Select options creates two fields in the form, for start/end value
* also allows exclusion of values and queries for specific lists of values.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-004.
SELECT-OPTIONS: s_vrefer FOR ever-vrefer,
s_kofiz FOR ever-kofiz,
s_vkonto FOR ever-vkonto.
SELECTION-SCREEN END OF BLOCK b3.
*
* Parameters : This is how we add a Checkbox
PARAMETERS : P_CHK AS CHECKBOX .
START-OF-SELECTION.
IF P_CHK = 'X'.
WRITE:/ 'Check box is selected'.
ELSE.
WRITE: / 'Check Box is not selected'.
ENDIF.
* PARAMETERS: File Dialog Insert
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path TYPE string LOWER CASE. "File path
SELECTION-SCREEN END OF BLOCK b4.
* Then we need to call:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*
*
******************************************************************************
* Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
* window_title = ' '
default_extension = 'txt'
default_file_name = 'file_name'
initial_directory = 'C:\'
CHANGING
filename = gv_filename
path = gv_path
fullpath = p_path
user_action = gv_result.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
* Syntax:
* SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
* ( content ..... )
* ( content ..... )
* SELECTION-SCREEN END OF BLOCK b2.
*
* Notes: By clicking on text-004 it takes us to the Text Symbols Screen
* alternatively we can do GoTo -> Text Elements -> Text Symbols
* We can set the content of text-004 there.
* Example:
* Single parameter choice embedded in block named b2
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
SELECTION-SCREEN END OF BLOCK b2.
* Example:
* Parameter and Selection Block embedded in block named b2
* Notes : We can add any sort of structure between the beginning and the end of the block
* It just paints a block on the screen.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
SELECT-OPTIONS: s_bstus FOR ever-bstatus.
SELECTION-SCREEN END OF BLOCK b2.
* Example:
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
PARAMETERS: p_bstat LIKE ever-bstatus DEFAULT space. " '' or ' '
SELECT-OPTIONS: s_bstus FOR ever-bstatus.
SELECTION-SCREEN END OF BLOCK b2.
*
* Select-Options:
* Select-Options syntax:
* Select options creates two fields in the form, for start/end value
* also allows exclusion of values and queries for specific lists of values.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-002.
SELECT-OPTIONS: s_vrefer FOR ever-vrefer,
s_kofiz FOR ever-kofiz,
s_vkonto FOR ever-vkonto.
SELECTION-SCREEN END OF BLOCK b3.
* Second block is just text / comments
SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-007
SELECTION-SCREEN: SKIP.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 01(30) text-005.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
* Third block is a file dialog window
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_path TYPE string LOWER CASE. "File path
SELECTION-SCREEN END OF BLOCK b4.
* Necessary add-on for file dialog window.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
*
*
******************************************************************************
* Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
* window_title = ' '
default_extension = 'txt'
default_file_name = 'file_name'
initial_directory = 'C:\'
CHANGING
filename = gv_filename
path = gv_path
fullpath = p_path
user_action = gv_result.
1. Simple selection screen with one parameter, and one select options - selscreensimple.abap
2. Simple selection screen with parameter/seloptions and file save dialog - selscreenfilesave.abap
3. Selection Screen (Parameter/SelOptions/Blocks/Checkbox/FileDialog) - selscreencombi1.abap
4. Selection Screen (Blocks + Titles) - selscreenblockstitles
5. Selection Screen (File Dialogs) - selscreenfiledialog(save)
6. Selection Screen (Checkboxes) - selscreencheckboxes
7. Selection Screen (Text Elements + Uline + SKIP + Titles) - selscreentextelements (TO DO)
8. Selection Screen (Load File Dialog)
9. Selection Screen (Parameters)
10. Selection Screen (Select Options)
11. Selection Screen (Radio Buttons) - selscreenradiobutton
12. Selection Screen (List Boxes) - selscreenlistbox
* Syntax:
* SELECTION-SCREEN: Setting up the block
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
" Declaring the checkbox
PARAMETERS : P_CHK AS CHECKBOX .
* SELECTION-SCREEN: Ending the block
SELECTION-SCREEN END OF BLOCK b4.
*
*
*In main code, after START-OF-SELECTION:
START-OF-SELECTION.
IF P_CHK = 'X'.
WRITE:/ 'Check box is selected'.
ELSE.
WRITE: / 'Check Box is not selected'.
ENDIF.
*