Hallo,
den Funktionsbaustein hatte ich noch nicht auf dem Schirm. Die Info ist etwas anders als die aus RSUSR200.
Ich bin nicht so der Freund von vielen IF..ELSE-Konstrukten, daher hätte ich hier folgendes Testprogramm als Vorschlag. Meiner Ansicht nach etwas "more clean", insbesondere bzgl. der Übersichtlichkeit der einzelnen Rückgabewerte bzw. SY-SUBRC's aus dem Funktionsbaustein.
report z_pw_state.
data: f4Bname like usr02-bname.
parameters: pClient type mandt default '100'.
select-options: sBname for f4Bname.
types: begin of ValueAndText,
value type int4,
text type char80,
end of ValueAndText,
ValuesAndTexts type standard table of ValueAndText with key value.
types: begin of UserResult,
bname type xubname,
value type int4,
text type char80,
end of UserResult,
UserResults type standard table of UserResult with empty key.
" An RFC destination for testing
data: rfcDest type rfcdest value 'SAPQX1100',
" Importing parameter from SUSR_USER...
pwdstate type int4,
" Result from FM SUSR... and the explaining text
result type ValueAndText,
" Result for a single user and a table for all results.
userResult type UserResult,
userResults type UserResults.
" A table for all possible password status and their meanings
" from FM SUSR_USER_PASSWORD_STATUS_GET, taken from the documentation
data(pwStatusInfos) = value ValuesAndTexts(
( value = -2 text = 'Password cannot (generally) be changed' )
( value = -1 text = 'Password cannot be changed until the end of the wait period' )
( value = 0 text = 'Password can be changed, but does not have to be changed' )
( value = 1 text = 'Password is initial and must be changed' )
( value = 2 text = 'Password has expired and must be changed' )
( value = 3 text = 'Password must be changed because it no longer meets the new rules' ) ).
" A table for all possible SUBRC's and their meanings from FM SUSR_USER...
data(subrcs) = value ValuesAndTexts(
( value = 1 text = 'User does not exist' )
( value = 2 text = 'Internal error' )
( value = 3 text = 'Password logon disabled' )
( value = 4 text = 'User has no password' )
( value = 5 text = 'Not authorized for other user' )
( value = 6 text = 'Unknown error when calling SUSR_USER_PASSWORD_STATUS_GET' ) ).
data: resultTable type ref to ValuesAndTexts,
resultValue type int4.
" Get all users in the specified client of this system.
select bname from usr02 client specified into table @data(users)
where mandt = @pClient and bname in @sBname.
" Get the password status for each user.
loop at users reference into data(user).
call function 'SUSR_USER_PASSWORD_STATUS_GET' destination rfcDest
exporting
USERNAME = user->*
PASSWORD_LOGON = 'X '
importing
pwdstate = pwdstate
exceptions
username_not_exists = 1
internal_error = 2
password_logon_disabled = 3
user_has_no_password = 4
not_authorized_for_other_user = 5
others = 6.
if ( sy-subrc = 0 ).
resultValue = pwdstate.
resultTable = ref #( pwStatusInfos ).
else.
resultValue = sy-subrc.
resultTable = ref #( subrcs ).
endif.
try.
result = resultTable->*[ value = resultValue ].
catch CX_SY_ITAB_LINE_NOT_FOUND.
result-value = resultValue.
result-text = '*** Unknown ***'.
endtry.
userResult = corresponding #( result ).
userResult-bname = user->*.
insert UserResult into table userResults.
endloop.
cl_demo_output=>display_data( userResults ).
Viele Grüße
Shortcut IT