function: ZGET_SERIAL_NUMBER
importing:
IM_NR_NAME LIKE TNRO-OBJECT Number Range的名字
IM_BEGIN_VALUE LIKE INRI-NRRANGENR Number Range的起始值
changing:
CH_SERIAL_NUMBER LIKE TNRO-OBJECT 10位流水号
tables:
RETURN LIKE BAPIRET2 Return Messages
FUNCTION ZGET_SERIAL_NUMBER.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(IM_NR_NAME) LIKE TNRO-OBJECT
*" VALUE(IM_BEGIN_VALUE) LIKE INRI-NRRANGENR
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*" CHANGING
*" VALUE(CH_SERIAL_NUMBER) LIKE TNRO-OBJECT
*"----------------------------------------------------------------------
data: return1 like BAPIRET2.
DATA: last_id TYPE numc10,
quant LIKE inri-quantity, "dummy分配的编号数
code LIKE inri-returncode. "returncode返回代码
DO.
CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
EXPORTING
object = IM_NR_NAME
EXCEPTIONS
foreign_lock = 1
object_not_found = 2
system_failure = 3
OTHERS = 4.
IF sy-subrc <> 0 AND sy-index < 10.
CONTINUE.
ELSEIF sy-subrc EQ 0.
EXIT.
ELSEIF sy-subrc <> 0 AND sy-index = 10.
RETURN.
ENDIF.
ENDDO.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = IM_BEGIN_VALUE
object = IM_NR_NAME
IMPORTING
number = last_id
quantity = quant
returncode = code
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.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
CLEAR CH_SERIAL_NUMBER .
ELSE.
CH_SERIAL_NUMBER = last_id.
ENDIF.
CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
EXPORTING
object = IM_NR_NAME
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
RETURN.
ENDIF.
if CH_SERIAL_NUMBER is INITIAL .
RETURN1-type = 'E' .
APPEND RETURN1 to RETURN.
else.
return1-type = 'S'.
APPEND RETURN1 to RETURN.
endif.
ENDFUNCTION.
阅读(895) | 评论(0) | 转发(0) |