Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 21, 2008

Generating a number range automatically in sap

If you need a unique key in a table or a sequential number for any other purpose, you can use a range object .

Ranges are maintained in transaction SNRO

After maintaining the first screen you have to maintain the intervals by clicking the button "number ranges"

These informations are stored in tables :

- TNRO Definition of number range objects

- NRIV Number range intervals. Note: Field NRLEVEL Contains the last assigned number.

In you program you read the next number by using the function NUMBER_GET_NEXT

DATA l_number TYPE i.
CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
        nr_range_nr = '01'
        object = 'ZTEST'
        quantity = '1'
    IMPORTING
        number = l_number
*       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
        OTHERS = 7.

display l_number.

each time you call NUMBER_GET_RANGE the number is automatically increased.

You can also create the number range in your program instead of using SNRO with the functions:

NUMBER_RANGE_INTERVAL_LIST : verify if a number range already exist

NUMBER_RANGE_ENQUEUE : lock the specifier number range

NUMBER_RANGE_INTERVAL_UPDATE : create the number range

NUMBER_RANGE_UPDATE_CLOSE : commit changes NUMBER_RANGE_DEQUEUE : unlock

If you need a unique key in a table or a sequential number for any other purpose, you can use a range object .

Ranges are maintained in transaction SNRO

After maintaining the first screen you have to maintain the intervals by clicking the button "number ranges"

These informations are stored in tables :

- TNRO Definition of number range objects

- NRIV Number range intervals. Note: Field NRLEVEL Contains the last assigned number.

In you program you read the next number by using the function NUMBER_GET_NEXT

DATA l_number TYPE i.
CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
        nr_range_nr = '01'
        object = 'ZTEST'
        quantity = '1'
    IMPORTING
        number = l_number
*       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
        OTHERS = 7.

display l_number.

each time you call NUMBER_GET_RANGE the number is automatically increased.

You can also create the number range in your program instead of using SNRO with the functions:

NUMBER_RANGE_INTERVAL_LIST : verify if a number range already exist

NUMBER_RANGE_ENQUEUE : lock the specifier number range

NUMBER_RANGE_INTERVAL_UPDATE : create the number range

NUMBER_RANGE_UPDATE_CLOSE : commit changes NUMBER_RANGE_DEQUEUE : unlock

No comments:

Post a Comment

Content

Recent Topics