Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

F4 function (drop down list) with limited values/selections

Former Member
0 Likes
2,205

Hi Everyone,

I would like to ask if this is possible, and if yes, then how:

I would like create a selection screen where the user will select a certain UNAME from the drop down list. This selection field will have possible values taken from SU01 user names. But here's the twist; the selection field should not allow users to type on it or select a blank value. The user is obliged to select from the drop down list. Is this possible? If yes, please tell me how to do this or you may share some links for me to follow.

Thank you very much in advance.

Regards,

RE

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,206

Hi Reymar,

Using listbox automatically restricts user with the input, he/she can only pick a value. Furthermore, simply adding OBLIGATORY addition will force selection by user on this field. Check this code:


TYPES: t_c30(12) TYPE c.

PARAMETERS: pa_uname TYPE t_c30 AS LISTBOX VISIBLE LENGTH 40 USER-COMMAND f_code OBLIGATORY .

DATA: BEGIN OF it_users OCCURS 0,
        bname TYPE usr01-bname,
        name_textc TYPE user_addr-name_textc,
       END OF it_users.

"fill the table only once
INITIALIZATION.
  SELECT usr01~bname user_addr~name_textc INTO CORRESPONDING FIELDS OF TABLE it_users
           FROM usr01 INNER JOIN user_addr
                              ON usr01~bname = user_addr~bname.

"on F4 (input help) return user id (BNAME) 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_uname.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'BNAME'
      value_org       = 'S'
    TABLES
      value_tab       = it_users
    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.
  ELSE.
     "<- here just react accordingly, user id is stored in  pa_uname
  ENDIF.

The list will show only user names (not ids), but when you pick one, his/her id will be returned to PA_UNAME. If you want to see both user name and id, in standard toolbar of any SAP window choose last icon ( Customize Local Layout->Options->Expert-> select Show all keys in dropdown lists ). But please be aware that this setting is global one, hence is applicable to all lists accross the system.

Regards

Marcin

3 REPLIES 3
Read only

Former Member
0 Likes
1,206

Check this demo program:

DEMO_DROPDOWN_LIST_BOX

Regards,

Ravi

Read only

Former Member
0 Likes
1,206

List Box will not allow user to enter any values and you can some logic in PAI.

FIELD fld MODULE chek_empty

Read only

MarcinPciak
Active Contributor
0 Likes
1,207

Hi Reymar,

Using listbox automatically restricts user with the input, he/she can only pick a value. Furthermore, simply adding OBLIGATORY addition will force selection by user on this field. Check this code:


TYPES: t_c30(12) TYPE c.

PARAMETERS: pa_uname TYPE t_c30 AS LISTBOX VISIBLE LENGTH 40 USER-COMMAND f_code OBLIGATORY .

DATA: BEGIN OF it_users OCCURS 0,
        bname TYPE usr01-bname,
        name_textc TYPE user_addr-name_textc,
       END OF it_users.

"fill the table only once
INITIALIZATION.
  SELECT usr01~bname user_addr~name_textc INTO CORRESPONDING FIELDS OF TABLE it_users
           FROM usr01 INNER JOIN user_addr
                              ON usr01~bname = user_addr~bname.

"on F4 (input help) return user id (BNAME) 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_uname.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'BNAME'
      value_org       = 'S'
    TABLES
      value_tab       = it_users
    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.
  ELSE.
     "<- here just react accordingly, user id is stored in  pa_uname
  ENDIF.

The list will show only user names (not ids), but when you pick one, his/her id will be returned to PA_UNAME. If you want to see both user name and id, in standard toolbar of any SAP window choose last icon ( Customize Local Layout->Options->Expert-> select Show all keys in dropdown lists ). But please be aware that this setting is global one, hence is applicable to all lists accross the system.

Regards

Marcin