Dynamic Parameter Texts in Selection Screen – 2

By | August 10, 2009 | Tricks | 12,429 | 5

Selection Screen Parameter Text by coding using Function Modules SELECTION_TEXTS_MODIFY.

In the last post Dynamic Parameter Texts in Selection Screen (which was so many weeks ago), we discussed how we can change the selection screen parameter by changing the values of some selection screen specific variables. Enno suggested to use the FM SELECTION_TEXTS_MODIFY to handle the selection screen parameters more easily and in standard way.

Some of the readers also left comment on the previous post about the use of this trick. One scenario I came in my mind: Certain Parameter Texts based on the Radio button selection. E.g. We have some radio buttons like Sales Order, Credit Memo, Debit Memo and so on. Based on this radiobutton selection, we want to display the Date’s parameter text.

This code snippet will realize this scenario using the FM SELECTION_TEXTS_MODIFY.

*&---------------------------------------------------------------------*
*& Report  ZTEST_NP_HELPER
*&
*&---------------------------------------------------------------------*

REPORT  ztest_np_helper.

*----------------------------------------------------------------------*
* Selection Screen Class definition
*----------------------------------------------------------------------*
CLASS lcl_selscr DEFINITION.

  PUBLIC SECTION.
    CLASS-DATA:
      f_date_text TYPE char30.

    CLASS-METHODS:
      set_text
        IMPORTING
          if_name TYPE char8
          if_type TYPE char1
          if_text TYPE char30,

      change_screen.

  PRIVATE SECTION.
    CLASS-DATA:
      t_text TYPE STANDARD TABLE OF rsseltexts.

ENDCLASS.                    "lcl_selscr DEFINITION

*.... Selection Screen
SELECTION-SCREENBEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
PARAMETERSp_so   RADIOBUTTON GROUP rd1 DEFAULT 'X' USER-COMMAND usr1,
            p_cre  RADIOBUTTON GROUP rd1,
            p_deb  RADIOBUTTON GROUP rd1.
PARAMETERSp_date TYPE datum.
SELECTION-SCREENEND OF BLOCK blk1.

*.... Initialization
INITIALIZATION.
  aaa 'Select an option to continue'.

*.... At Selection-Screen Output
AT SELECTION-SCREEN OUTPUT.
* text for Radiobuttons
  lcl_selscr=>set_textif_name 'P_SO'
                        if_type 'P' if_text 'Sales Order' ).
  lcl_selscr=>set_textif_name 'P_CRE'
                        if_type 'P' if_text 'Credit memo' ).
  lcl_selscr=>set_textif_name 'P_DEB'
                        if_type 'P' if_text 'Debit memo' ).

* determine the text for the P_DATE
  CASE 'X'.
    WHEN p_so.    lcl_selscr=>f_date_text 'Sales Order Entry Date'.
    WHEN p_cre.   lcl_selscr=>f_date_text 'Credit Memo Entry Date'.
    WHEN p_deb.   lcl_selscr=>f_date_text 'Debit Memo Entry Date'.
  ENDCASE.
  lcl_selscr=>set_textif_name 'P_DATE'
                        if_type 'P'
                        if_text lcl_selscr=>f_date_text ).

* Change the Selection Screen
  lcl_selscr=>change_screen).

*.... Start of selection
START-OF-SELECTION.
  WRITE'Date Text'lcl_selscr=>f_date_text.

*----------------------------------------------------------------------*
* Selection Screen Class definition
*----------------------------------------------------------------------*
CLASS lcl_selscr IMPLEMENTATION.

  METHOD set_text.
    DATAla_text LIKE LINE OF t_text.

    la_text-name if_name.
    la_text-kind if_type.
    la_text-text if_text.
    APPEND la_text TO t_text.

  ENDMETHOD.                    "set_text

  METHOD change_screen.
    CALL FUNCTION 'SELECTION_TEXTS_MODIFY'
      EXPORTING
        program  sy-cprog
      TABLES
        seltexts t_text.
  ENDMETHOD.                    "change_screen

ENDCLASS.                    "lcl_selscr IMPLEMENTATION

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

5 Comments

  • HI Naimesh,
    I used this feature for several INCLUDES, which are in use in several different programs.
    If you use a parameter in an include, you will have to specify the parameter text in the program, not in the include.

    So I put into each INCLUDE:

    parameters: P_par1.

    initialization.
    clear $t_dtel.
    $s_dtel-name = 'P_PAR1'.
    $s_dtel-kind = 'P'.
    $s_dtel-datenelment = 'VBELN'.
    append $s_dtel to $t_dtel.
    call function 'SELECTION_TEXTS_MODIFY_DTEL'
    exporting program = sy-cprog
    tables sel_dtel = $t_dtel
    exceptions others = 1.

    $t_dtel and $s_dtel have to be defined in another include.

    INITIALIZATION section can exist mor than one time in a program…

    so it helps me to have in every program the same parameters description.

    Only reasonable if there are many programs which need the same include…
      _.Enno._

  • thanks

  • hello… hapi blogging… have a nice day! just visiting here….

  • a litlle enhancement: The selection type will be retrieved by method itself:

    LCL_SELSCR

     
    CLASS lcl_selscr IMPLEMENTATION.
     
      METHOD set_text.
        DATA: la_text LIKE LINE OF t_text.
     
        DATA lr_descr TYPE REF TO cl_abap_typedescr.
        FIELD-SYMBOLS <lfs_any> TYPE ANY.
        ASSIGN (if_name) TO <lfs_any>.
        lr_descr = cl_abap_datadescr=>describe_by_data( <lfs_any> ).
        CASE lr_descr->type_kind.
          WHEN cl_abap_datadescr=>typekind_struct1.
    *== Structure => SELECT-OPTIONS
            la_text-kind = 'S'.
          WHEN OTHERS.
    *== Others   => PARAMETERS        
            la_text-kind = 'P'.
        ENDCASE.
     
        la_text-name = if_name.
        la_text-text = if_text.
        APPEND la_text TO t_text.
     
      ENDMETHOD.                    "set_text
     
  • Hello Enno,

    Thanks for adding the method to make it more dynamic 🙂

    Btw, when you use the ABAP_CODE short code, you don’t need to convert HTML symbols to its entity. The short code logic should be able to convert it properly.

    Regards,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.