背景:项目中,批次号的最后两位是顺序号,最后两位顺序号累加超过99会引起批次号重复,需要和字母结合生成批次号,比如:AAAAAA00、AAAAAA01、AAAAAA02、AAAAAA03......AAAAAA09、AAAAAA0A、AAAAAA0B......AAAAAA0Z、AAAAAA10,以下是利用ASC码进行数字字母组合的函数,希望对用到的TX有帮助。
FUNCTION ZFUNC_GET_NEW_CHARG.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_CHARG) LIKE MCHA-CHARG OPTIONAL
*" EXPORTING
*" VALUE(O_CHARG) LIKE MCHA-CHARG
*" VALUE(O_MESSAGE) TYPE CHAR20
*"----------------------------------------------------------------------
TYPES: BEGIN OF TY_ASC,
W1 TYPE I,
W2 TYPE I,
END OF TY_ASC.
* 0~9 对应48~57,A~Z 对应65~90
DATA: IT_ASC TYPE TY_ASC,
IT_ASC1 TYPE TY_ASC.
DATA: C1 TYPE C,
C2 TYPE C.
O_CHARG = I_CHARG.
IT_ASC-W1 = CL_ABAP_CONV_OUT_CE=>UCCPI( I_CHARG+6(1) ).
IT_ASC-W2 = CL_ABAP_CONV_OUT_CE=>UCCPI( I_CHARG+7(1) ).
IT_ASC1 = IT_ASC.
IT_ASC1-W2 = IT_ASC1-W2 + 1.
IF IT_ASC1-W2 = 58.
IT_ASC1-W2 = 65.
ELSEIF IT_ASC1-W2 = 91.
IT_ASC1-W2 = 48.
IT_ASC1-W1 = IT_ASC1-W1 + 1.
IF IT_ASC1-W1 = 58.
IT_ASC1-W1 = 65.
ELSEIF IT_ASC1-W1 = 91.
O_MESSAGE = ‘该批次号段已满!‘.
RETURN.
ENDIF.
ENDIF.
C1 = CL_ABAP_CONV_IN_CE=>UCCPI( IT_ASC1-W1 ).
C2 = CL_ABAP_CONV_IN_CE=>UCCPI( IT_ASC1-W2 ).
CONCATENATE C1 C2 INTO O_CHARG+6(2).
ENDFUNCTION.
版权声明:本文为博主原创文章,未经博主允许不得转载。