How to add pushbutton in a Selection screen?

In this tutorial, I will discuss two methods on how to add push button to a standard report selection screen. A push button is used to trigger an action executed by a user such as altering the selection screen dynamically, calling another program or report. The first way is using the statement FUNCTION KEY which syntax appears below.

SELECTION-SCREEN: FUNCTION KEY 1.
SELECTION-SCREEN: FUNCTION KEY 2..up to..7



Using this method let you add up to seven (7) function keys. The command code for these  function keys corresponds to their number such that for function key 1, it is set to  'FC01'. And for function key 2 it is set to 'FC02' and so on and so forth. These function keys are displayed in the application toolbar just besides the execute button. Add your logic on the event AT SELECTION-SCREEN. The second method is using the statement SELECTION-SCREEN PUSHBUTTON. Its syntax appears below:
SELECTION-SCREEN PUSHBUTTON [/][pos](len)button_text USER-COMMAND fcode [VISIBLE LENGTH vlen][MODIF ID modid]

This statement creates a pushbutton on the current selection screen. The text on the pushbutton is determined by the content of button_text. The rules that apply to text also apply to button_text when creating an output field. In order to position the button on the selection screen, use the parameter /[pos][len]. The syntax and meaning of [/][pos](len) are the same as when creating horizontal lines although in this case, len defines the length of the pushbutton on the selection screen. If a pushbutton extends beyond position 83 or beyond the edge of a block with a frame, it is cut off at the right hand side. 


If you specify the USER-COMMAND addition, the pushbutton must be assigned a function code fcode. The function code fcode must be specified directly and can only contain a maximum of 20 characters. If the user selects the pushbutton on the selection screen, the runtime environment triggers the event AT SELECTION-SCREEN and the function code fcode is transferred to the ucomm component in the interface work area sscrfields. 


Below are sample codes between the two:
1. Using the FUNCTION KEY statement

TYPE-POOLS icon.
TABLES sscrfields.
DATA functxt TYPE smp_dyntxt.

PARAMETERS: p_carrid TYPE s_carr_id,
p_cityfr TYPE s_from_cit.

SELECTION-SCREEN: FUNCTION KEY 1,
FUNCTION KEY 2.

INITIALIZATION.
functxt-icon_id = icon_ws_plane.
functxt-quickinfo = 'Preselected Carrier'.
functxt-icon_text = 'LH'.
sscrfields-functxt_01 = functxt.
functxt-icon_text = 'UA'.
sscrfields-functxt_02 = functxt.

AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01'.
p_carrid = 'LH'.
p_cityfr = 'Frankfurt'.
WHEN 'FC02'.
p_carrid = 'UA'.
p_cityfr = 'Chicago'.
WHEN OTHERS. 
... 
ENDCASE.

START-OF-SELECTION.
... 

2. Using the PUSHBUTTON statement
TABLES sscrfields.
TYPE-POOLS icon.

SELECTION-SCREEN:
BEGIN OF SCREEN 500 AS WINDOW TITLE title,
PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
PUSHBUTTON 12(30) but2 USER-COMMAND cli2
VISIBLE LENGTH 10,
END OF SCREEN 500.

AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'CLI1'.
...
WHEN 'CLI2'.
...
ENDCASE.

START-OF-SELECTION.
title = 'Push button'.
but1 = 'Button 1'.

CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = icon_information
text = 'Button 2'
info = 'My Quickinfo'
IMPORTING
RESULT = but2
EXCEPTIONS
OTHERS = 0.

CALL SELECTION-SCREEN '0500' STARTING AT 10 10.

No comments:

Post a Comment

How to download the data structure of tables in SE11?

Good morning people around the world. Its me again doing some blogs. Sharing to you some tips and tricks in the SAP world. Well, before I s...