Field value request (F4) with filter

The easiest way to provide a value request (F4) for a field is to use appropriate search help from the dictionary. If you need a dynamic behavior of the value list you can develop it using standard function module F4IF_INT_TABLE_VALUE_REQUEST.

You can pass some parameters to this function module, but using the more advanced settings is a bit tricky. You have to set it in a callback form. An example of such functionality could be preseting a restriction, a filter for the value list.
It can be very usefull in programs which deal with CUA (Central User Administration). Usually you have an internal table with all users in all managed systems, but you want to give a choice of users from a particular system. You can set a restriction on the system and filter the users by them.
Here a list of systems and users without restriction.
screenshot
Here a list of users filterd by a particular system. System is set as restriction and the column with system is hidden.
screenshot
As you can see, system is inserted as the restriction.
screenshot
Here the coding.
REPORT zf4value.

TYPES:
  BEGIN OF ts_user,
    system    TYPE sysysid,
    user      TYPE xubname,
    text      TYPE ad_namtext,
  END OF ts_user.

DATA:
  gv_dynpprog LIKE sy-repid,
  gv_dynpnr   LIKE sy-dynnr,
  gv_system   TYPE sysysid,
  gt_user     TYPE TABLE OF ts_user,
  ls_user     TYPE ts_user.

DEFINE append_user.
  ls_user-system = &1.
  ls_user-user   = &2.
  ls_user-text   = &3.
  append ls_user to gt_user.
END-OF-DEFINITION.

append_user 'A01_100' 'SMITHJ'  'John Smith'.
append_user 'A01_100' 'MORGANT' 'Tom Morgan'.
append_user 'B01_150' 'WHITEA'  'Amy White'.
append_user 'B01_150' 'LEEH'    'Henry Lee'.

gv_dynpprog = sy-repid.
gv_dynpnr   = sy-dynnr.

* Set the restriction to filter the entries
gv_system = 'B01_150'.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  EXPORTING
    retfield         = 'USER'
    dynpprog         = gv_dynpprog
    dynpnr           = gv_dynpnr
    dynprofield      = 'GS_NOTFALL-ENDUSER'
    value_org        = 'S'
    callback_program = gv_dynpprog
    callback_form    = 'F4_CALLBACK'
  TABLES
    value_tab        = gt_user.

*&---------------------------------------------------------------------*
*&      Form  f4_callback
*&---------------------------------------------------------------------*
FORM f4_callback TABLES   record_tab  STRUCTURE seahlpres
                 CHANGING shlp        TYPE      shlp_descr
                          callcontrol LIKE      ddshf4ctrl.

  DATA:
    ls_selopt TYPE ddshselopt.

  FIELD-SYMBOLS:
    <fs_fieldprop> TYPE ddshfprop.

* Set the restriction for first field
  ls_selopt-shlpfield = 'F0001'.
  ls_selopt-sign      = 'I'.
  ls_selopt-option    = 'EQ'.
  ls_selopt-low       = gv_system.
  APPEND ls_selopt TO shlp-selopt.

* Hide the first field
  READ TABLE shlp-fieldprop WITH KEY fieldname = 'F0001'
    ASSIGNING <fs_fieldprop>.
  CLEAR <fs_fieldprop>-shlplispos.

ENDFORM.                    "f4_callback
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2010 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.