If you wish to generate a passowrd in SAP, it can be easily done using the following function Module.
Function Module to generate a Password in SAP ABAP.
RSEC_GENERATE_PASSWORD
For generating the password the following parameters need to be passed to the Function Module.ALPHABET TYPE C With the help of these letters the password is generated.
ALPHABET_LENGTH TYPE I The total length of the above mentioned field. This can be calculated with the
help of STRLEN or can be hard coded.
FORCE_INIT TYPE C CAN be left blank
OUTPUT_LENGTH TYPE I SAP password are usually 8 characters in lenght. So this can be defaulted to 8.
If you are using PARAMETER for inputting the 'ALPHABET' then you should use the addition LOWER CASE to take care of the Lower Case characters. Please see the code given below.
REPORT ZEX_PASSWORD .
Parameter: p_char(100) LOWER CASE.
Data: d_password(8),
d_len type i.
d_len = STRLEN( p_char ).
CALL FUNCTION 'RSEC_GENERATE_PASSWORD'
EXPORTING
ALPHABET = p_char
ALPHABET_LENGTH = d_len
FORCE_INIT = ' '
OUTPUT_LENGTH = 8
IMPORTING
OUTPUT = d_password
EXCEPTIONS
SOME_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Parameter: p_char(100) LOWER CASE.
Data: d_password(8),
d_len type i.
d_len = STRLEN( p_char ).
CALL FUNCTION 'RSEC_GENERATE_PASSWORD'
EXPORTING
ALPHABET = p_char
ALPHABET_LENGTH = d_len
FORCE_INIT = ' '
OUTPUT_LENGTH = 8
IMPORTING
OUTPUT = d_password
EXCEPTIONS
SOME_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write:/ d_password.