Dynamically alter a selection screen based on user

The following ABAP code demonstrates how you can dynamically alter a selection screen based on which user is running it. This particular report checks if the current user is the person who created it and show different fields depending on result.


*&--------------------------------------------------------------*
*& Report  ZDYNAMIC_SELSCREEN                                   *
*&                                                              *
*&--------------------------------------------------------------*
*&  Change selection screen layout based on user name           *
*&  Created by SAPDev                                           *
*&--------------------------------------------------------------*

REPORT  zdynamic_selection NO STANDARD PAGE HEADING.
TABLES: ekpo.
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME
                                     TITLE text-001.
SELECT-OPTIONS: p_field1 FOR ekpo-ebeln,
                p_field2 FOR ekpo-ebelp,
                p_filed3 FOR ekpo-matnr,
                p_field4 FOR ekpo-werks,
                p_field5 FOR ekpo-bstyp.
SELECTION-SCREEN END OF BLOCK block1.
*data declaration
data: wa_trdir type trdir.
************************************************************************
*AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN OUTPUT.
*Get report details including who created it.
  SELECT single *
      from TRDIR
      into wa_trdir
    where NAME eq sy-cprog
      and SUBC eq '1'.
*Check if current user created report
  if wa_trdir-cnam eq sy-uname. "
    loop at screen.
      if screen-name CS 'P_FIELD1' or
         screen-name CS 'P_FIELD2'.
        screen-active = 1.
      else.
        screen-active = 0.
      endif.
      modify screen.
    endloop.
  else.
    loop at screen.
      if screen-name CS 'P_FIELD1' or
         screen-name CS 'P_FIELD2'.
        screen-active = 0.
      else.
        screen-active = 1.
      endif.
      modify screen.
    endloop.
  endif.

Related Articles

Adding buttons to an ABAP report selection screen within SAP
Add buttons to Application toolbar of selection screen
Add buttons with icon to selection screen
Add buttons to dynamically change the selection screen entry fields
ABAP parameter as checkbox plus initiate 'AT selection-screen' EVENT to unselect other checkboxes
Initiate the 'AT selection-screen' EVENT from a checkbox
SAP dropdown list box for an ABAP report selection screen
Initiate the 'AT selection-screen' EVENT from a LISTBOX within an ABAP report sel screen
ABAP Radiobutton to Initiate the 'AT selection-screen' EVENT on SAP report
ABAP Begin of Block to group selection-screen fields plus add title and frame
Report Selection Screen - Example code and information on various sel screen processing techniques
Selection screen push buttons
F4 search help manually called from report selection screen
Modify Selection Screen(LOOP AT SCREEN)
Restrict select-options to only allow specific restrictions
Radiobutton (inc desc) and entry field on same line of SAP selection screen
Add blank line to SAP report selection screen
Add Tab strip to Selection Screen