Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding the function module Number_Get_Next

Former Member
0 Kudos

Hi All,

We have created one custom transaction. We need to generate one number when we save. The number will be generated using the function module NUMBER_GET_NEXT. How can i capture the number which will be generated.

When we create Sales Order, the sales order number gets generated and that number will go to the DB Table right.

Similarly i need to save the number in one custom table which gets generated for my transaction.

Thanks,

Ibrahim

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

The code should be like this:

IF RANGE_OPEN IS INITIAL.
      CALL FUNCTION 'NUMBER_GET_INFO'
           EXPORTING
                NR_RANGE_NR        = <Nr range>
                OBJECT             = <Object range>
           EXCEPTIONS
                INTERVAL_NOT_FOUND = 1
                OBJECT_NOT_FOUND   = 2
                OTHERS             = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      RANGE_OPEN = 'X'.
    ENDIF.

    CHECK RANGE_OPEN = 'X'..

    CALL FUNCTION 'NUMBER_GET_NEXT'
         EXPORTING
              NR_RANGE_NR             = <Nr range>
              OBJECT                  = <Object range>
         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.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

But I don't understand if you need an your own number or the number used for the sales order.

Max

9 REPLIES 9

Former Member
0 Kudos

Hi

The code should be like this:

IF RANGE_OPEN IS INITIAL.
      CALL FUNCTION 'NUMBER_GET_INFO'
           EXPORTING
                NR_RANGE_NR        = <Nr range>
                OBJECT             = <Object range>
           EXCEPTIONS
                INTERVAL_NOT_FOUND = 1
                OBJECT_NOT_FOUND   = 2
                OTHERS             = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      RANGE_OPEN = 'X'.
    ENDIF.

    CHECK RANGE_OPEN = 'X'..

    CALL FUNCTION 'NUMBER_GET_NEXT'
         EXPORTING
              NR_RANGE_NR             = <Nr range>
              OBJECT                  = <Object range>
         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.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

But I don't understand if you need an your own number or the number used for the sales order.

Max

0 Kudos

Hey Max,

i just gave the example of Sales Order. I need my own number.

I guess, the importing parameter of this function module will give me the generated number. Am i right?

0 Kudos

When assigning numbers internally, call the function module NUMBER_GET_NEXT in order to determine the next number(s) available.

If you have asked for more than one number using the import parameter QUANTITY, the last number assigned will be inserted into the export parameter NUMBER after the function module call. (The numbers available thus lie within the interval: (NUMBER - QUANTITY + 1) to NUMBER.)

Whenever the last number of the interval has been assigned, number assignment begins again with the interval's initial number!

The return code allows you to see if the number can be assigned without any problems, or if it lies within a critical area.

Former Member
0 Kudos

Hi,

Before using function you need to create Number Range Object

using tcode OYSN

Regards,

Vishal

Former Member
0 Kudos

Hi Ibrahim,

When ever any user want to create a record throught your custom transactions into your custom table, frist lock the table custom table, then get the max of the incrementing filed ,

then pass that value to the FM you will get the next record number , then insert the data, commit it.

then you unlock your custom table.

comment on it

regards

Kumar M

Former Member
0 Kudos

Hi,

Maintain number range and intervals in transaction code SNUM

Use this in code..


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.

Former Member
0 Kudos

Hi,

You need to create number range object using transaction 'SNRO' where you would provid number range.

In FM 'NUMBER_GET_NEXT', you have to provide the number range object as export parameter. You can capture the next generated number in IMPORT parameter of this FM.

Hope this information helps you.

Thanks,

Phani Diwakar.

Former Member
0 Kudos

What should we pass to the exporting paramater NR_RANGE_NR of the fn. module NUMBER_GET_NEXT?

Thanks,

Ibrahim

0 Kudos

Go to tcode SNUM.

1. Give the Object name (ZOWNNO)...

2. Press the button "NUMBER RANGES'

3. Press 'STATUS'

4. u see the value under 'NO' in the table ...

that is the 'nr_range_nr' eg. '01'....