ABAP 产生必须包含 大写 小写 数字的固定长度字符串的算法

参考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.
相关推荐
草莓熊Lotso3 小时前
unordered_map/unordered_set 使用指南:差异、性能与场景选择
java·开发语言·c++·人工智能·经验分享·python·网络协议
编程小Y4 小时前
Android应用的架构演进
经验分享
weixin_537217067 小时前
少儿编程资源合集
经验分享
weixin_5372170613 小时前
harmonyos开发教程资源合集
经验分享
AI科技星14 小时前
为什么宇宙无限大?
开发语言·数据结构·经验分享·线性代数·算法
岁岁的O泡奶15 小时前
DVWA_Vulnerability: Command Injection
经验分享·安全·web安全
adjusttraining16 小时前
毁掉孩子视力不是电视和手机,两个隐藏很深因素,很多家长并不知
深度学习·其他
雾岛听蓝1 天前
C++ 类和对象(一):从概念到实践,吃透类的核心基础
开发语言·c++·经验分享·笔记
小屋主人2 天前
【实用软件】UninstallTool:一个小巧、安全、快速、强大的卸载软件
经验分享·其他·软件·软件卸载