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: 

logic for next number

Former Member
0 Kudos

I am maintaining a number sequence in the ztable ie 4 digitis ie from

0001 to 9999 along with time and date.

And i am using the select single max query to get the next number and after getting then updating that number in the end of the program.

we wont maintain the numbers in sequence, user will maintain by table maintainance, it depends on user. where ever there is a blank that number we need to use.

For example

0001

0002

0003

0005

0020

9999

in the above case after reaching 9999 it need to go to 0004 and after that goto 0006 etc.

please tell how to do

8 REPLIES 8

former_member1245113
Active Contributor
0 Kudos

Hi,

Ask the user to maintain another field type Char1 which means status (Available/or NOT).

select Min of available value from that table maintained. This is the simplest way.
Programatically is very difficult and may not be consistent." for that one should know the entire table structure Etc
" to give you some insight.
And once the Next number is used update the Available Flag field with X( or any thing suitable to you )
Hope this serves your purpose.

Cheerz

Ram

Former Member
0 Kudos

HI,

1. Check if number is 9999.

2. If yes then update new internal table having only one field COUNT(4) with number from 0001 to 9999.

loop

incriment the count

append tab_new.

endloop.

3. Tab_new has 9999 entries.

4. Sort your table ( let say tab1) ascending by counter.

5. loop at tab_new.

6 Read table tab1 with key counter = tab_new-counter.

7. If sy-subrc fails then tab_new-counter has the nuber you need.

Little odd logic but I believe it will work

Former Member
0 Kudos

data: lf_index(04) type n.

lf_index = 1.

do.

select single * from ztable

where sequence = lf_index.

if sy-subrc ne 0.

exit.

endif.

add 1 to lf_index.

if lf_index = 9999.

exit.

endif.

enddo.

  • Atthe end of the DO-ENDDO ,field lf_index will contain the number to use

  • (or 9999 if all numbers are already taken).

Bye.

kesavadas_thekkillath
Active Contributor
0 Kudos

Why dont you generate the next number in table maintenance without allowing the user to enter it.

Is it the requirement that user should maintain the numbers ?

Former Member
0 Kudos

Hi,

Try function module 'NUMBER_GET_NEXT'.

-Maharshi

0 Kudos
CALL FUNCTION 'NUMBER_GET_NEXT' 
    EXPORTING
      nr_range_nr             = '01' "Number range of your number circle
      object                  = 'NAME' "of your created number circle
    IMPORTING
      number                  = name "of your datafield in which the next number should be inserted
    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.

Hope this helps

Former Member
0 Kudos

This is the code


tables : zsequense.
data : maxnum(4) type n.
data : prevnum(4) type n, diff type i, reqnum(4) type n.
data : i_zsequense like zsequense occurs 0 with header line.
select max( znum ) from zsequense into maxnum..
if maxnum = '9999'.
  select * from zsequense into table i_zsequense.
  sort i_zsequense.
  loop at i_zsequense.
    if sy-tabix = 1.
      prevnum = i_zsequense-znum.
    endif.
    if sy-tabix ne 1.
      diff = i_zsequense-znum - prevnum.
      if diff > 1.
        reqnum = prevnum + 1.
        exit.
      endif.
    endif.
     prevnum = i_zsequense-znum.

  endloop.
endif.
write / reqnum.

Former Member
0 Kudos

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

nr_range_nr = '01'

object = OBJECT NAME

  • subobject = '000001'

toyear = '9999'

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.