Application Development 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: 

Check user name on selection screen

Former Member
0 Kudos

Dear all,

I have been able to make a field mandatory on a selection screen. This is field username. However, the system does not check if the user exists.

What I have done is made a copy of the program behind LX16: RLINV015

Now I have ZLX16 and ZRLINV015

I know the SAP users are found in tabel USR02, so I have added this table under data definition where the other tables are mentioned.

How do I enforce that only existing usernames are entered?

Thanks,

Nick

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Hi,

Using this, you are not only provided with input help where you can pick the user from the list, but also your are checking user existence manually and if not found system prompts to correct the entry.


TABLES: usr02.

PARAMETERS: pa_user TYPE usr02-bname.

AT SELECTION-SCREEN.
  SELECT SINGLE bname FROM usr02 INTO usr02-bname
                                 WHERE bname = pa_user.
  IF sy-subrc ne 0.
    MESSAGE 'No such user in the system, please correct your entry' TYPE 'E'.
  ENDIF.

Regards

Marcin

6 REPLIES 6

alex_m
Active Contributor
0 Kudos

You have to check explicitely in AT SELECTION SCREEN event, if you declare a parameter with obligatory option, it only checks whether the fild is not empty it wont check with possible values with table.

Former Member
0 Kudos

Hi Nick,

check the code,

At selection-screen on <ur fld name>.

select single * from usr02 into <workarea> where bname = <fld name value >

if sy-subrc ne 0.

error msg.

else.

proceed with further actions.

endif.

MarcinPciak
Active Contributor
0 Kudos

Hi,

Using this, you are not only provided with input help where you can pick the user from the list, but also your are checking user existence manually and if not found system prompts to correct the entry.


TABLES: usr02.

PARAMETERS: pa_user TYPE usr02-bname.

AT SELECTION-SCREEN.
  SELECT SINGLE bname FROM usr02 INTO usr02-bname
                                 WHERE bname = pa_user.
  IF sy-subrc ne 0.
    MESSAGE 'No such user in the system, please correct your entry' TYPE 'E'.
  ENDIF.

Regards

Marcin

0 Kudos

Marcin,

I really appreciate your answer, it brought me somewhere. However, the code I pasted is addeing a new field, whereas I really need the user name in field LINK-UNAME, otherwise my inventory document is not getting the user name.

I have tried the following to achieve this:

AT SELECTION-SCREEN.

SELECT SINGLE bname FROM usr02 INTO link-uname

WHERE bname = pa_user

This was however not doing the job.

Do you have any more suggestions?

Thanks,

Nick

0 Kudos

No problem. What I understand is that you want user name back in LINK-UNAME field, but validate it on selection screen, right? So this should help.


PARAMETERS: pa_user TYPE usr02-bname. "for validation

tables: link, "first declare work area for LINK table
             usr02. "USR02 used for fetching data (as LINK-UNAME and USR02-BNAME has different type)

AT SELECTION-SCREEN.
SELECT SINGLE bname FROM usr02 INTO usr02  
WHERE bname = pa_user.  "here validation first
if sy-subrc ne 0.
   message ...
else.
   "user correct, transport your data
    LINK-UNAME = USR02-BNAME.
endif.

Regards

Marcin

0 Kudos

Dear Marcin,

You are my hero.

Have a wonderful day,

Nick