0% found this document useful (0 votes)
235 views9 pages

Creating and Handling Buttons in Sap Abap

creating and handling buttons in sap abap (1)

Uploaded by

saikumar satya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views9 pages

Creating and Handling Buttons in Sap Abap

creating and handling buttons in sap abap (1)

Uploaded by

saikumar satya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Add buttons to dynamically change the selection screen entry fields

report this ad

The following code demonstrates how to add user defined push buttons to a standard
report selection screen. Push buttons are used to trigger user functions within the
program to make them interactive with the user. The example below shows how
buttons can allow you to dynamically alter a selection screen depending on which
button is pressed. But they can be used for many other applications from displaying a
window to calling other reports.

*&--------------------------------------------------------------*
*& Report ZSSCRBUTTON *
*& *
*&--------------------------------------------------------------*
*& Adds buttons to selection screen. *
*& Demonstrates alteration of selection screen layout *
*& depending on which button is pressed. *
*&--------------------------------------------------------------*
REPORT zsscrbutton NO STANDARD PAGE HEADING.
TABLES: t030, skat, sscrfields.
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME
TITLE text-001.
SELECT-OPTIONS: p_ktopl FOR t030-ktopl,
p_komok FOR t030-komok,
p_ktosl FOR t030-ktosl.
SELECTION-SCREEN SKIP.
*SELECTION-SCREEN FUNCTION KEY 1. "Adds button to application toolbar
* Declaration of sel screen buttons
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (20) w_button USER-COMMAND BUT1.
SELECTION-SCREEN PUSHBUTTON (25) w_but2 USER-COMMAND BUT2.
SELECTION-SCREEN END OF LINE.
SELECT-OPTIONS: p_konts FOR t030-konts,
p_bklas FOR t030-bklas.
PARAMETER: gd_ucomm like sy-ucomm default 'BUT1' no-display.
SELECTION-SCREEN END OF BLOCK block1.
TYPES: BEGIN OF t_t030,
ktopl TYPE t030-ktopl,
konts TYPE t030-konts,
txt20 TYPE skat-txt20,
bklas TYPE t030-bklas,
bkbez TYPE t025t-bkbez,
END OF t_t030.
DATA: it_t030 TYPE STANDARD TABLE OF t_t030 INITIAL SIZE 0,
wa_t030 TYPE t_t030.
DATA: gd_repsize TYPE i VALUE '83'.
************************************************************************
*INITIALIZATION.
INITIALIZATION.
* Add displayed text string to buttons
w_button = 'GL account selection'.
w_but2 = 'Valuation class selection'.
************************************************************************
*AT SELECTION-SCREEN.
AT SELECTION-SCREEN.
* Check if buttons have been
if sscrfields-ucomm eq 'BUT1'.
gd_ucomm = 'BUT1'.
clear: p_BKLAS.
refresh: p_BKLAS.
elseif sscrfields-ucomm eq 'BUT2'.
clear: p_KONTS.
refresh: p_KONTS.
gd_ucomm = 'BUT2'.
endif.
************************************************************************
*AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN OUTPUT.
if gd_ucomm eq 'BUT1'.
loop at screen.
if screen-name CS 'P_KONTS'.
screen-active = 1.
elseif screen-name CS 'P_BKLAS'.
screen-active = 0.
endif.
modify screen.
endloop.
elseif gd_ucomm eq 'BUT2'.
loop at screen.
if screen-name CS 'P_KONTS'.
screen-active = 0.
elseif screen-name CS 'P_BKLAS'.
screen-active = 1.
endif.
modify screen.
endloop.
endif.

We can create pushbuttons on ABAP selection screen using the statement SELECTION-SCREEN
PUSHBUTTON. The event that gets triggered when the pushbutton is pressed is handled in the AT
SELECTION-SCREEN event.
TABLES sscrfields.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
SELECTION-SCREEN:
PUSHBUTTON /2(40) button1 USER-COMMAND but1,
PUSHBUTTON /2(40) button2 USER-COMMAND but2.
*--------------------------------------------------------------*
*At Selection-Screen
*--------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'BUT1'.
MESSAGE 'Button 1 was clicked' TYPE 'I'.
WHEN 'BUT2'.
MESSAGE 'Button 2 was clicked' TYPE 'I'.
ENDCASE.
*--------------------------------------------------------------*
*Initialization
*--------------------------------------------------------------*
INITIALIZATION.
button1 = 'Button 1'.
button2 = 'Button 2'.
Selection Screen Output

If Button 1 is clicked then we get the following popup.

Even we can add icons to the pushbuttons on selection screen.

TYPE-POOLS: icon.
TABLES sscrfields.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
SELECTION-SCREEN:
PUSHBUTTON /2(40) button1 USER-COMMAND but1,
PUSHBUTTON /2(40) button2 USER-COMMAND but2.
*--------------------------------------------------------------*
*At Selection-Screen
*--------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'BUT1'.
MESSAGE 'Button 1 was clicked' TYPE 'I'.
WHEN 'BUT2'.
MESSAGE 'Button 2 was clicked' TYPE 'I'.
ENDCASE.
*--------------------------------------------------------------*
*Initialization
*--------------------------------------------------------------*
INITIALIZATION.
button1 = 'Button 1'.
button2 = 'Button 2'.

CALL FUNCTION 'ICON_CREATE'


EXPORTING
name = icon_okay
text = 'Continue'
info = 'Click to Continue'
IMPORTING
RESULT = button1
EXCEPTIONS
OTHERS = 0.

CALL FUNCTION 'ICON_CREATE'


EXPORTING
name = icon_cancel
text = 'Exit'
info = 'Click to Exit'
IMPORTING
RESULT = button2
EXCEPTIONS
OTHERS = 0.
Selection Screen Output
This article teach you how to add buttons on ABAP Selection screen. so you just copy and
paste ABAP Code to your ABAP Workbench and change as you need.

1 TABLES : sscrfields.
2
3 SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-b02.
4 SELECTION-SCREEN:
5 BEGIN OF LINE,
6 PUSHBUTTON 2(30) text-bt1 USER-COMMAND bt1,
7 END OF LINE,
8 BEGIN OF LINE,
9 PUSHBUTTON 2(30) text-bt2 USER-COMMAND bt2,
1 END OF LINE,
0 BEGIN OF LINE,
1 PUSHBUTTON 2(30) text-bt3 USER-COMMAND bt3,
1 END OF LINE,
1 BEGIN OF LINE,
2 PUSHBUTTON 2(30) text-bt4 USER-COMMAND bt4,
1 END OF LINE,
3 BEGIN OF LINE,
1 PUSHBUTTON 2(30) text-bt5 USER-COMMAND bt5,
4 END OF LINE.
1 SELECTION-SCREEN END OF BLOCK b2.
5
1 AT SELECTION-SCREEN.
6
1 IF sscrfields-ucomm CP 'BT*'.
7 PERFORM f_call_transaction USING sscrfields-ucomm.
1 EXIT.
8 ENDIF.
1
9 START-OF-SELECTION.
2 *&---------------------------------------------------------------------*
0 *& Form F_CALL_TRANSACTION
2 *&---------------------------------------------------------------------*
1 * text
2 *----------------------------------------------------------------------*
2 * -->P_SSCRFIELDS_UCOMM text
2 *----------------------------------------------------------------------*
3 FORM f_call_transaction USING fu_ucomm.
2
4 CASE fu_ucomm.
2 WHEN 'BT1'.
5 "add your abap code for this event command
2 ENDCASE.
6
2
7 ENDFORM. " F_CALL_TRANSACTION
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5

SELECTION-SCREEN - PUSHBUTTON
Quick Reference
Syntax
SELECTION-SCREEN PUSHBUTTON [/][pos|POS_LOW|POS_HIGH](len) button_text
USER-COMMAND fcode
[VISIBLE LENGTH vlen]
[ MODIF ID modid]
[ldb_additions].

Extras:

1. ... [/][pos|POS_LOW|POS_HIGH](len)

2. ... USER-COMMAND fcode

3. ... VISIBLE LENGTH vlen

Effect

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 in the
addition COMMENT. The addition MODIF ID assigns the pushbutton to the modification group modid.

The additions ldb_additions can only be used in the selection include of a logical database.

Notes

 The function module ICON_CREATE can be used to assign an icon, a tooltip, and a text to a
pushbutton. Enough length, len, must be assigned to the pushbutton so that the icon can be
displayed internally and the visible length must be modified using VISIBLE LENGTH.

 Once the event block in AT SELECTION-SCREEN has been processed, the system usually returns to
displaying the selection screen. To exit selection screen processing and continue executing the
program, either Execute or Cancel must be chosen. This means pushbuttons on selection screens are
intended primarily for use for dynamic modifications to the selection screen rather than to control the
program.

Addition 1

... [/][pos|POS_LOW|POS_HIGH](len)

Effect

The position of the pushbutton must be specified using this addition. The syntax and meaning of are the same
as when creating horizontal lines, although in this case len defines the length of the pushbutton in the dynpro
of the selection screen. If a pushbutton extends beyond position 83 or beyond the margin of a block with a
frame, it is cut off on the right.

Addition 2

... USER-COMMAND fcode


Effect

If the addition USER-COMMAND is specified, 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.

To enable the pushbutton, the statement TABLES must be used to declare an interface work area of the
structure SSCRFIELDS from ABAP Dictionary.

If the user selects the pushbutton on the selection screen, the runtime environment raises the event AT
SELECTION-SCREEN and the function code fcode is passed to the component ucomm in the interface work
area sscrfields.

Notes

 If the function code of a pushbutton corresponds to a function code used in the GUI status of the
selection screen, the selection screen processing is influenced accordingly.

 It is not recommended that the system field sy-ucomm instead of sscrfields-ucomm is evaluated,
since this does not guarantee that sy-ucomm is always given the correct value in selection screen
processing.

Addition 3

... VISIBLE LENGTH vlen

Effect

The addition VISIBLE LENGTH defines the visible length vlen of the pushbutton and its text. The syntax and
meaning of this addition are the same as when creating output fields, although a pushbutton is never displayed
as shorter than the text defined for it.

Example

Defines and accesses a standalone selection screen 500 with two pushbuttons in an executable program. An
icon and a tooltip are created for the second pushbutton.

TABLES sscrfields.

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 quick info'
IMPORTING
RESULT = but2
EXCEPTIONS
OTHERS = 0.

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

You might also like