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.

最近更新

  1. redis时间环结构-时序特征

    2024-07-10 08:00:05       0 阅读
  2. 欢迎来到 Mint Expedition:Web3 和 NFT 的新时代开始

    2024-07-10 08:00:05       0 阅读
  3. MySQL运算符

    2024-07-10 08:00:05       0 阅读
  4. 【gradle中如何不使用插件将依赖打进jar包】

    2024-07-10 08:00:05       0 阅读
  5. web前端面向对象面试25题

    2024-07-10 08:00:05       0 阅读
  6. 【编程语言】C++和C的异同点

    2024-07-10 08:00:05       0 阅读

热门阅读

  1. Django 实现子模版继承父模板

    2024-07-10 08:00:05       6 阅读
  2. [面试爱问] https 的s是什么意思,有什么作用?

    2024-07-10 08:00:05       8 阅读
  3. Docker

    2024-07-10 08:00:05       7 阅读
  4. Vue中v-for和v-if优先级(2、3)

    2024-07-10 08:00:05       6 阅读
  5. 晚上定时编译android系统

    2024-07-10 08:00:05       7 阅读
  6. 摒弃传统分页:移动端开发中的无限滚动实现

    2024-07-10 08:00:05       6 阅读
  7. 程序人生 - (002)

    2024-07-10 08:00:05       8 阅读
  8. MacOS隐藏文件打开指南

    2024-07-10 08:00:05       7 阅读