‎2006 Nov 02 6:59 AM
‎2006 Nov 02 7:02 AM
hi
data: number type c.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'AUFTRAG'
IMPORTING
number = number.
Here number cud b any type of number which will fil ur requirement.
Hope this helps u.
Regds,
Seema.
‎2006 Nov 02 7:03 AM
Create a serial number range object in SNRO transaction(give 01 in starting number) and every time you want a new number you can call the NUMBER_GET_NEXT function.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01' (or pass the Variable)
object = 'ObjectName'
IMPORTING
number = number.http://www.erpgenie.com/sap/abap/code/abap33.htm
<b>ex----</b>
General - Number Range Generation
In the 4.6x environment, SAP have included a number range generation
program just like those used for Purchase Order, Sales Order etc.
*
This SAP number range generation is an include program.
*
INCLUDE ZRANGENO.
*
* Always have to be included in the main program data declaration
*
* data: wnorange like INRI-NRRANGENR, "number range,
* wsubobj like inri-SUBOBJECT, "sub object
* wdocno(12).
*
* Steps :-
* 1. Number range Sub Object must be maintain in table ZSGRP
* You can used transaction SE16 to create a table entries.
* 2. Maintain number range and intervals in transaction code SNUM
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
* <a href="http://www.sap-img.com" TARGET="test_blank">http://www.sap-img.com</a>
*
call function 'NUMBER_RANGE_ENQUEUE'
exporting
object = 'ZOWNNO' "Create with SNUM
exceptions
foreign_lock = 1
object_not_found = 2
system_failure = 3
others = 4.
if sy-subrc ne 0.
* message e086 with 'Lock error' sy-subrc.
endif.
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = wnorange
object = 'ZOWNNO'
subobject = wsubobj
importing
number = wdocno "Number generated by SAP
exceptions
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
internal_overflow = 6
others = 7.
if sy-subrc ne 0.
* message e086 with 'Number Range' sy-subrc.
endif.
call function 'NUMBER_RANGE_DEQUEUE'
exporting
object = 'ZOWNNO'.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.‎2006 Nov 02 7:05 AM
Hi ,
Check this.
REPORT Y_SERAIL_NO .
data: w_range type INRI-NRRANGENR value '01',
w_obj type INRI-OBJECT value 'ZERROR_KEY',
w_serial_no type NRIV-NRLEVEL.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = w_range
OBJECT = w_obj
QUANTITY = '1'
* SUBOBJECT = ' '
* TOYEAR = '0000'
* IGNORE_BUFFER = ' '
IMPORTING
NUMBER = w_serial_no
* QUANTITY =
* RETURNCODE =
* 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.
ENDIF.
write:/ w_serial_no.
Regards,
Raghav
‎2006 Nov 02 7:10 AM
check the documentation :
NUmber range: Assigns next free number
Preliminary comment
This function module has been released.
The documentation is being revised so that it conforms to the requirements for released function modules.
The function module assigns the next free numbers of a number range. A number is assigned as a default if no larger number is demanded in the parameter QUANTITY. If more than one number is demanded and not enough numbers are available up to the interval limit, the numbers are only assigned up to the interval limit. If the last number was assigned, the first interval number is provided again during the next call.
The length of the number depends on the definition of the number range object. However, the length is not determined from the definition when allocating, but is calculated from the length of th from-number of the number range.
All exceptions are created with MESSAGE ... RAISING ... .
Example:
1. Object HUGO, not year-dependent, next free number searched for
DATA: RC LIKE INRI-RETURNCODE,
NUMBER(10) TYPE C.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING OBJECT = 'HUGO'
NR_RANGE_NR = '01'
IMPORTING RETURNCODE = RC
NUMBER = NUMBER.
CASE RC.
WHEN ' '.
everything o.k.
WHEN '1'.
the assigned number lies in the critical area.
WHEN '2'.
this was the last number, next time the first number
will be assigned
ENDCASE.
2. Object EGON, year-dependent, next 5 free numbers for 1992 in company code 0001 searched for.
DATA: RC LIKE INRI-RETURNCODE,
NUMBER(10) TYPE C,
YEAR LIKE INRI-TOYEAR,
QUAN LIKE INRI-QUANTITY.
YEAR = '1992'.
QUAN = 5.
T001-BUKRS = '0001'.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING OBJECT = 'EGON'
NR_RANGE_NR = '01'
SUBOBJECT = T001-BUKRS
TOYEAR = YEAR
IMPORTING RETURNCODE = RC
QUANTITY = QUAN
NUMBER = NUMBER.
the last assigned number is in NUMBER
the number of the assigned numbers is in QUANTITY
the first free number is calculated from:
NUMBER - QUANTITY + 1.
CASE RC.
WHEN ' '.
everything o.k.
WHEN '1'.
the assigned number lies in the critical area.
WHEN '2'.
this was the last number, next time the first number will be assigned
*
WHEN '3'.
more numbers are demanded than are available,
the number of the assigned numbers is in QUAN.
ENDCASE.
regards,
Sandeep Josyula
*Mark helpful answers
‎2006 Nov 02 9:52 AM
hi
good
NUMBER_GET_NEXT Get the next unique number in a number range. Use tcode SNRO for maintaining number ranges.
call function 'NUMBER_RANGE_ENQUEUE'
exporting
object = 'ZOWNNO' "Create with SNUM
exceptions
foreign_lock = 1
object_not_found = 2
system_failure = 3
others = 4.
if sy-subrc ne 0.
message e086 with 'Lock error' sy-subrc.
endif.
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = wnorange
object = 'ZOWNNO'
subobject = wsubobj
importing
number = wdocno "Number generated by SAP
exceptions
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
internal_overflow = 6
others = 7.
if sy-subrc ne 0.
message e086 with 'Number Range' sy-subrc.
endif.
call function 'NUMBER_RANGE_DEQUEUE'
exporting
object = 'ZOWNNO'.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
thanks
mrutyun^
‎2009 Jul 27 11:31 AM
Just to clarify for anyone who might be misled by the above (as I was) - you do not need to (nor should you) lock the number range itself with NUMBER_RANGE_ENQUEUE before calling NUMBER_GET_NEXT.
‎2009 Aug 25 8:03 PM
I have a question. How do you know which range you have to pass? For example I need the range for BSIS table. HOw should I know its range?
Thank you in advance for your help.
Regards,
Mohamed.
‎2010 Apr 30 7:41 PM
what makes you say this?
does the function module number of next lock and lock itself already?
‎2011 Feb 02 3:05 PM
Yes. The lock is only required if you are editing the number range itself, rather than retrieving the next number.