参考SAP ABAP 随机字符串生成 三种方式_abap随机生成字符串-CSDN博客
思路
1、分别产生 大写字符 小写字符 数字字符 固定长度-3的3种的综合字符串
2、产生随机数字
3、对综合字符串指定位置分别插入 大写字符,小写字符,数字字符
代码如下
*--------------------------------------------------------------------*
*function:
*changer:
*note:根据字符串产生随机指定长度字符串
*--------------------------------------------------------------------*
FORM FRM_GET_PWDCHAR USING PALBET TYPE C PLEN TYPE I CHANGING PWDCHAR TYPE C.
CALL FUNCTION 'RSEC_GENERATE_PASSWORD'
EXPORTING
ALPHABET = PALBET
OUTPUT_LENGTH = PLEN
IMPORTING
OUTPUT = PWDCHAR
EXCEPTIONS
SOME_ERROR = 1.
ENDFORM.
*--------------------------------------------------------------------*
*function:
*changer:
*note:PLEN 必须大于3
*--------------------------------------------------------------------*
FORM FRM_GET_PWDCHAR_DGT_ULAHPHA USING PLEN TYPE I CHANGING PWDCHAR TYPE C.
DATA: L_NO(40) TYPE C,
LU TYPE C,
LL TYPE C,
LD TYPE C,
LSUBCT TYPE I,
L_INDEX TYPE I,
ALBET(80).
DATA: UALPHA(26) TYPE C,
LALPHA(26) TYPE C,
DIGSTR(10) TYPE C.
CLEAR:L_NO,L_INDEX.
UALPHA = 'ABCDEFGHJKLMNPQRSTUVWXYZ'.
LALPHA = 'abcdefghijklmnopqrstuvwxyz'.
DIGSTR = '123456789'.
ALBET = UALPHA && LALPHA && DIGSTR.
LSUBCT = PLEN - 3.
PERFORM FRM_GET_PWDCHAR USING UALPHA 1 CHANGING LU.
PERFORM FRM_GET_PWDCHAR USING LALPHA 1 CHANGING LL.
PERFORM FRM_GET_PWDCHAR USING DIGSTR 1 CHANGING LD.
PERFORM FRM_GET_PWDCHAR USING ALBET LSUBCT CHANGING L_NO.
DATA: CL_RANDOM TYPE REF TO CL_RANDOM_NUMBER,
M TYPE I.
CREATE OBJECT CL_RANDOM.
CALL METHOD CL_RANDOM->IF_RANDOM_NUMBER~INIT.
CALL METHOD CL_RANDOM->IF_RANDOM_NUMBER~GET_RANDOM_INT
EXPORTING
I_LIMIT = LSUBCT
RECEIVING
R_RANDOM = M.
IF M = 0.
CONCATENATE LU L_NO INTO L_NO.
ELSEIF M = LSUBCT.
CONCATENATE L_NO LU INTO L_NO.
ELSE.
L_INDEX = LSUBCT - M.
CONCATENATE L_NO+0(M) LU L_NO+M(L_INDEX) INTO L_NO.
ENDIF.
LSUBCT = LSUBCT + 1.
CALL METHOD CL_RANDOM->IF_RANDOM_NUMBER~GET_RANDOM_INT
EXPORTING
I_LIMIT = LSUBCT
RECEIVING
R_RANDOM = M.
IF M = 0.
CONCATENATE LL L_NO INTO L_NO.
ELSEIF M = LSUBCT.
CONCATENATE L_NO LL INTO L_NO.
ELSE.
L_INDEX = LSUBCT - M.
CONCATENATE L_NO+0(M) LL L_NO+M(L_INDEX) INTO L_NO.
ENDIF.
LSUBCT = LSUBCT + 1.
CALL METHOD CL_RANDOM->IF_RANDOM_NUMBER~GET_RANDOM_INT
EXPORTING
I_LIMIT = LSUBCT
RECEIVING
R_RANDOM = M.
IF M = 0.
CONCATENATE LD L_NO INTO L_NO.
ELSEIF M = LSUBCT.
CONCATENATE L_NO LD INTO L_NO.
ELSE.
L_INDEX = LSUBCT - M.
CONCATENATE L_NO+0(M) LD L_NO+M(L_INDEX) INTO L_NO.
ENDIF.
PWDCHAR = L_NO.
ENDFORM.