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: 

How to generate a number sequence for a column of a Z*table?

Former Member
0 Kudos

Hi ,

How to generate a number sequence for a column of a Z*table?

plz guide me.

thanks

Albert

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

you can use following code.

<b>select max( num ) from z_table into v_max_num.</b>

v_max_num = v_max_num+1.

regards,

sumit.

try to run this it'll work now.

Message was edited by: sumit kumar

10 REPLIES 10

Former Member
0 Kudos

Hi,

you can use following code.

<b>select max( num ) from z_table into v_max_num.</b>

v_max_num = v_max_num+1.

regards,

sumit.

try to run this it'll work now.

Message was edited by: sumit kumar

0 Kudos

Thanks sumit

Yes I tried the same,but i am getting an error info as

" max(num)cannot be determined until runtime"

Former Member
0 Kudos

You will need to create a Number range object using transaction SNRO. Enter the domain type of the object that you need the numbers to be generated for. In the 'Number Ranges' screen, create a new range defining the low and high values for the range (for eg, 1 to 9999).

Now use the NUMBER_GET_NEXT function module to call this number range object (the name given in SNRO) and the number range (the name/number given in the Number ranges screen).

Use the returned value from this FM as the generated number in your table.

Hope this helps.

Sudha

Former Member
0 Kudos

If you don't want to track the serial no. like Sumit has show, you create a Serial Number Range object in SNRO transaction, and whenever you are inserting values into the ztable, get the next number using the function NUMBER_GET_NEXT FUNCTION.

regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos

Use the function module 'NUMBER_GET_NEXT'. It will give you sequential numbers.

Regards,

Subhasish

former_member181962
Active Contributor
0 Kudos

In the transaction which updates the z table(Can be a table maintennce), you can increment the count by 1 every time you add a record.

in pai section of that screen where you save the data,

module user_command.

case sy-ucomm.

when 'SAVE'.

SELECT MAX( COLUMN ) FROM ZTAB INTO V_COL.

V_COL = V_COL + 1.

UPDATE ZTAB SET COL = V_COL

WHERE <COND>.

endcase.

endmodule.

Regards,

Ravi

Former Member
0 Kudos

1) Use SNRO for defining a number range.

2) Use FM NUMBER_GET_NEXT for getting the next number with object, sub object etc..

See one example below.

      CALL FUNCTION 'NUMBER_GET_NEXT'
        EXPORTING
          nr_range_nr                   = c_01
          object                        = c_z_prd_code
*           QUANTITY                      = '1'
         subobject                     = p_vkorg
*           TOYEAR                        = '0000'
*           IGNORE_BUFFER                 = ' '
       IMPORTING
         number                        = in_prd_code
*           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
                     .

3) You may write these code in main program of the table maintinence

rgds,

TM.

0 Kudos

put space bet ( and num

MAX( num )

regards,

sumit.

It'll work.

Former Member
0 Kudos

Hi albert,

The code which Sumit sent u will surely work just put a space like this ( num ) Hope u got it!!!

Thanks.

Seema.

0 Kudos

Guys,

thx for all the inputs..

Albert