Various Ways to implement F4 Value Request

By | Last Updated on June 19, 2014 | 39,689

Overview of various different options to implement the ABAP F4 help which is Value request for any given field using SALV, ALV, F4 std FMs.

Using SALV to show F4 in Popup

CLASS lcl_f4 DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      msgnr_salv
        RETURNING value(rv_msgnr) TYPE t100-msgnr.
  PRIVATE SECTION.
    TYPES:
      BEGIN OF lty_t100,
        msgnr TYPE t100-msgnr,
        text  TYPE t100-text,
      END   OF lty_t100.
    CLASS-DATA: t_t100 TYPE STANDARD TABLE OF lty_t100.
ENDCLASS.                    "lcl_f4 DEFINITION
*
CLASS lcl_f4 IMPLEMENTATION.
  METHOD msgnr_salv.
 
    DATA: o_salv_f4 TYPE REF TO cl_salv_table.
    DATA: lo_functions TYPE REF TO cl_salv_functions_list.
    DATA: lo_selections TYPE REF TO cl_salv_selections.
    DATA: lt_rows TYPE salv_t_row,
          lv_row  TYPE i.
 
    DATA: ls_t100 LIKE LINE OF t_t100.
 
    SELECT msgnr text
      INTO TABLE t_t100
      FROM t100
      UP TO 10 ROWS
      WHERE arbgb = '00'
      AND   sprsl = sy-langu.
 
    cl_salv_table=>factory(
       IMPORTING
         r_salv_table   = o_salv_f4
      CHANGING
        t_table        = t_t100 ).
 
*
    lo_functions = o_salv_f4->get_functions( ).
    lo_functions->set_default( 'X' ).
 
    lo_selections = o_salv_f4->get_selections( ).
    lo_selections->set_selection_mode( if_salv_c_selection_mode=>single ).
 
* ALV as Popup
    o_salv_f4->set_screen_popup(
      start_column = 80
      end_column   = 140
      start_line   = 3
      end_line     = 10 ).
 
* Display
    o_salv_f4->display( ).
 
* Get the result
    lt_rows = lo_selections->get_selected_rows( ).
    READ TABLE lt_rows INTO lv_row INDEX 1.
    IF sy-subrc EQ 0.
      READ TABLE t_t100 INTO ls_t100 INDEX lv_row.
      rv_msgnr = ls_t100-msgnr.
    ENDIF.
 
  ENDMETHOD.                    "msgnr_salv
ENDCLASS.                    "lcl_f4 IMPLEMENTATION
 

Using ALV Popup

 
    CLASS-METHODS:
      msgnr_alv
        RETURNING value(rv_msgnr) TYPE t100-msgnr.
***
  METHOD msgnr_alv.
    TYPE-POOLS: slis.
    DATA:  lt_fcat  TYPE STANDARD TABLE OF slis_fieldcat_alv.
    DATA:  ls_fcat  TYPE slis_fieldcat_alv.
    DATA:  ls_tabix TYPE slis_selfield.
 
    DATA: ls_t100 LIKE LINE OF t_t100.
 
    SELECT msgnr text
      INTO TABLE t_t100
      FROM t100
      UP TO 10 ROWS
      WHERE arbgb = '00'
      AND   sprsl = sy-langu.
 
    ls_fcat-fieldname = 'MSGNR'.
    ls_fcat-tabname   = 'T_T100'.
    ls_fcat-reptext_ddic = 'Message'.
    ls_fcat-outputlen = '10'.
    APPEND ls_fcat TO lt_fcat.
 
    ls_fcat-fieldname = 'TEXT'.
    ls_fcat-tabname   = 'T_T100'.
    ls_fcat-reptext_ddic = 'Message Text'.
    ls_fcat-outputlen = '50'.
    APPEND ls_fcat TO lt_fcat.
 
    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
      EXPORTING
        i_title              = 'Popup To Select'
        i_allow_no_selection = 'X'
        i_zebra              = 'X'
        i_tabname            = 'T_T100'
        it_fieldcat          = lt_fcat
      IMPORTING
        es_selfield          = ls_tabix
      TABLES
        t_outtab             = t_t100.
 
    IF ls_tabix IS NOT INITIAL.
      READ TABLE t_t100 INTO ls_t100 INDEX ls_tabix-tabindex.
      rv_msgnr = ls_t100-msgnr.
    ENDIF.
 
  ENDMETHOD.                    "msgnr_alv
 

Using FM F4IF_INT_TABLE_VALUE_REQUEST

 
    CLASS-METHODS:
      msgnr_f4fm
        RETURNING value(rv_msgnr) TYPE t100-msgnr.
***
  METHOD msgnr_f4fm.
 
 
    SELECT msgnr text
      INTO TABLE t_t100
      FROM t100
      UP TO 10 ROWS
      WHERE arbgb = '00'
      AND   sprsl = sy-langu.
 
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
        retfield        = 'MSGNR'
        dynpprog        = sy-repid
        dynpnr          = sy-dynnr
        dynprofield     = 'P_MSGNR'
        window_title    = 'Select Value'
        value_org       = 'S'
        display         = ' '
      TABLES
        value_tab       = t_t100
      EXCEPTIONS
        parameter_error = 1
        no_values_found = 2
        OTHERS          = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
 
  ENDMETHOD.                    "msgnr_f4FM
 

Using FM F4IF_INT_TABLE_VALUE_REQUEST with one column table

 
    CLASS-METHODS:
      msgnr_f4fm_column
        RETURNING value(rv_msgnr) TYPE t100-msgnr.
***
  METHOD msgnr_f4fm_column.
 
    SELECT msgnr text
      INTO TABLE t_t100
      FROM t100
      UP TO 10 ROWS
      WHERE arbgb = '00'
      AND   sprsl = sy-langu.
 
    TYPES:
      BEGIN OF lty_char100,
        value TYPE char100,
      END OF lty_char100.
    DATA: lt_values TYPE STANDARD TABLE OF lty_char100.
    DATA: ls_values LIKE LINE OF lt_values.
    DATA: ls_t100   LIKE LINE OF t_t100.
 
    DATA: lt_ftab TYPE STANDARD TABLE OF dfies  ,
          ls_ftab LIKE LINE OF lt_ftab.
 
    DATA: lt_ret_tab TYPE STANDARD TABLE OF ddshretval,
          ls_ret_tab LIKE LINE OF lt_ret_tab.
 
    LOOP AT t_t100 INTO ls_t100.
      ls_values = ls_t100-msgnr.
      APPEND ls_values TO lt_values.
 
      ls_values = ls_t100-text.
      APPEND ls_values TO lt_values.
    ENDLOOP.
 
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        tabname        = 'T100'
      TABLES
        dfies_tab      = lt_ftab
      EXCEPTIONS
        not_found      = 1
        internal_error = 2
        OTHERS         = 3.
    IF sy-subrc <> 0.
 
    ENDIF.
 
    DELETE lt_ftab WHERE fieldname NE 'MSGNR'
                     AND fieldname NE 'TEXT'.
 
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
        retfield        = 'MSGNR'
        dynpprog        = sy-repid
        dynpnr          = sy-dynnr
*       dynprofield     = 'P_MSGNR'
        window_title    = 'Select Value'
        value_org       = 'C'
        display         = ' '
      TABLES
        value_tab       = lt_values
        field_tab       = lt_ftab
        return_tab      = lt_ret_tab
      EXCEPTIONS
        parameter_error = 1
        no_values_found = 2
        OTHERS          = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
 
    READ TABLE lt_ret_tab INTO ls_ret_tab INDEX 1.
    rv_msgnr = ls_ret_tab-fieldval.
 
  ENDMETHOD.                    "msgnr_f4FM_Column
 

HELP_START

There is a wrapper FM HELP_START which calls various FMs based on the parameters being passed. Since there are many different variants, I’m not gonna mention it here. If you have already some existing code base, let me know, I can update this post.

Demo Call

 
PARAMETERS: p_msgnr TYPE t100-msgnr OBLIGATORY.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_msgnr.
  p_msgnr = lcl_f4=>msgnr_salv( ).
  "p_msgnr = lcl_f4=>msgnr_alv( ).
  "p_msgnr = lcl_f4=>msgnr_f4FM( ).
  "p_msgnr = lcl_f4=>msgnr_f4fm_column( ).
 

Do you have a Code Snippet which you want to share, Submit Code Snippet here

Tags

Share It!

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

1 Comment

  • Clemens Li

    Hey, thank you for the compilation.

    Regarding SALV, there is a big glitch in SAP standard: If you don’t use a dictionary structure for the table displayed but a local type with fields with dictionary reference ( defined as field TYPE tabname-fieldname), you won’t get F1 or F4 Help even as the F4 dropdown symbol is displayed.

    I think in 99 % of all applications you won’t have to define your own F4 code – SAP standard provides it.

    Use this code to activate it (Though it does not work for domain fixed values):

    Enable F1 and F4 in SALV

     
    METHOD salv_set_ref_tab_field_f1_f4.
      DATA:
        lo_columns        TYPE REF TO cl_salv_columns_list,
        lt_column_ref     TYPE salv_t_column_ref,
        lr_data           TYPE REF TO data,
        lv_help_id        TYPE string,
        ls_ddic_reference TYPE salv_s_ddic_reference.
      FIELD-SYMBOLS:
             <ft> TYPE ANY TABLE,
             <fs>  TYPE ANY,
             <ff>  TYPE ANY,
             <fs_col>  TYPE LINE OF salv_t_column_ref.
     
    * get columns object
      lo_columns = mo_salv-&gt;get_columns( ).
    * get table of columns
      lt_column_ref = lo_columns-&gt;get( ).
      LOOP AT lt_column_ref ASSIGNING <fs_col>.
        AT FIRST.
    * assign data table
          ASSIGN mr_salv_data->* TO <ft>.
          CREATE DATA lr_data LIKE LINE OF <ft>."!
          ASSIGN lr_data->* TO <fs>.
        ENDAT.
        IF <fs_col>-r_column->get_ddic_reference( ) IS INITIAL.
          ASSIGN COMPONENT  <fs_col>-columnname OF STRUCTURE <fs> TO <ff>.
          DESCRIBE FIELD  HELP-ID lv_help_id.
          CHECK lv_help_id CA '-'.
          SPLIT lv_help_id AT '-'
            INTO ls_ddic_reference-table ls_ddic_reference-field.
          <fs_col>-r_column->set_ddic_reference( ls_ddic_reference ).
        ENDIF.
      ENDLOOP.
     
     

    Call the method after initiating the SALV object before call of method DIDPLAY( ).
    I’m still looking for a simple method enabling F4 for domain fixed values.

    Regards, Clemens

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