用se37创建函数znumc4_initial。
源代码如下:
FUNCTION znumc4_initial.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(TOYEAR) TYPE INRI-TOYEAR
*" VALUE(SUBOBJECT) OPTIONAL
*" TABLES
*" LT_NRIV STRUCTURE NRIV OPTIONAL
*"----------------------------------------------------------------------
DATA: mod TYPE i ,
str TYPE string,
xstrc TYPE x,
xstr TYPE xstring ,
days TYPE i,
range_nr TYPE inri-nrrangenr.
DO 366 TIMES.
CLEAR: str,xstr,xstrc.
days = sy-index .
WHILE days > 0 .
mod = days MOD 26 .
days = days DIV 26 .
IF mod = 0.
mod = 26.
days = days - 1.
ENDIF.
xstrc = mod + 64 .
CONCATENATE xstrc xstr INTO xstr IN BYTE MODE.
IF days < 26 AND days > 0 .
xstrc = days + 64 .
CONCATENATE xstrc xstr INTO xstr IN BYTE MODE.
EXIT.
ENDIF.
ENDWHILE.
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
im_xstring = xstr
im_encoding = '8400'
IMPORTING
ex_string = str.
range_nr = str.
IF strlen( range_nr ) = 1.
range_nr = '0' && range_nr.
ENDIF.
lt_nriv-object = 'ZNUM4'.
lt_nriv-subobject = subobject.
lt_nriv-nrrangenr = range_nr.
lt_nriv-toyear = toyear.
lt_nriv-fromnumber = '0001'.
lt_nriv-tonumber = '9999'.
lt_nriv-nrlevel = 0 .
APPEND lt_nriv.
ENDDO.
MODIFY nriv FROM TABLE lt_nriv.
ENDFUNCTION.
用se37创建函数ZNUMC4_GET_NEXT。
源代码如下:
FUNCTION znumc4_get_next.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(DATUM) TYPE SY-DATUM DEFAULT SY-DATUM
*" VALUE(SUBOBJECT)
*" EXPORTING
*" REFERENCE(NUMBER)
*" EXCEPTIONS
*" INTERVAL_NOT_FOUND
*" NUMBER_RANGE_NOT_INTERN
*" OBJECT_NOT_FOUND
*" QUANTITY_IS_0
*" QUANTITY_IS_NOT_1
*" INTERVAL_OVERFLOW
*" BUFFER_OVERFLOW
*" TOYEAR_NOT_FOUND
*"----------------------------------------------------------------------
DATA: mod TYPE i ,
str TYPE string,
xstrc TYPE x,
xstr TYPE xstring ,
days TYPE i,
day01 TYPE d,
range_nr TYPE inri-nrrangenr.
IF datum IS INITIAL .
datum = sy-datum.
ENDIF.
SELECT SINGLE * FROM nriv
WHERE object = 'ZNUM4' AND
subobject = subobject AND
toyear = datum+0(4) .
IF sy-subrc <> 0.
RAISE toyear_not_found.
ENDIF.
day01 = datum+0(4) && '0101'.
days = datum - day01 + 1.
WHILE days > 0 .
mod = days MOD 26 .
days = days DIV 26 .
IF mod = 0.
mod = 26.
days = days - 1.
ENDIF.
xstrc = mod + 64 .
CONCATENATE xstrc xstr INTO xstr IN BYTE MODE.
IF days < 26 AND days > 0 .
xstrc = days + 64 .
CONCATENATE xstrc xstr INTO xstr IN BYTE MODE.
EXIT.
ENDIF.
ENDWHILE.
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
im_xstring = xstr
im_encoding = '1106'
IMPORTING
ex_string = str.
range_nr = str.
IF strlen( range_nr ) = 1.
range_nr = '0' && range_nr.
ENDIF.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = range_nr
object = 'ZNUM4'
subobject = subobject
toyear = datum+0(4)
IMPORTING
number = number
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
OTHERS = 8.
CASE sy-subrc.
WHEN 1.
RAISE interval_not_found.
WHEN 2.
RAISE number_range_not_intern.
WHEN 3.
RAISE object_not_found.
WHEN 4.
RAISE quantity_is_0.
WHEN 5.
RAISE quantity_is_not_1.
WHEN 6.
RAISE interval_overflow.
WHEN 7.
RAISE buffer_overflow.
WHEN OTHERS.
ENDCASE.
ENDFUNCTION.
使用方法:
DATA: numc(4) TYPE n.
CALL FUNCTION 'ZNUMC4_GET_NEXT'
EXPORTING
subobject = '02'
IMPORTING
number = numc
EXCEPTIONS
OTHERS = 9.
网友评论