sapdev logo background
sapdev logo sapdev logo
Comments

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.



comments powered by Disqus