Application Development and Automation 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: 
Read only

how to do auto increment ?

Former Member
0 Likes
3,808

HI ,

         how to do auto increment for primary key field . When i am entered Remaining field data then it auto increment how to do . i am working in module pool screens . its possible for function modules like (NUMBER_GET_NEXT , QF05_RANDOM_INTEGER ) but i want logically how to do ....

please help me .....

for example..

  DATA : V_NUM  TYPE i.

  SORT ITAB BY NUMBER.

  V_NUM =  1 .

  V_NUM = V_NUM + 1.

        * it is increments to next number 2 but what about next ...

i want like v_num = max (from database ) ...how ...

thaks @ regards ,

prasad .

HI ,

         how to do auto increment for primary key field . When i am entered Remaining field data then it auto increment how to do . i am working in module pool screens . its possible for function modules like (NUMBER_GET_NEXT , QF05_RANDOM_INTEGER ) but i want logically how to do ....

please help me .....

for example..

  DATA : V_NUM  TYPE i.

  SORT ITAB BY NUMBER.

  V_NUM =  1 .

  V_NUM = V_NUM + 1.

        * it is increments to next number 2 but what about next ...

i want like v_num = max (from database ) ...how ...

thaks @ regards ,

prasad .

6 REPLIES 6
Read only

Former Member
0 Likes
1,849

There are two approaches -

1) If the program is running and runtime you need to get auto increment you need to use the varaible as static.

2) If you are updating these fields in a Db table then after each comming you need to read the max value from the table and increment it by one.

let me know some more details and I will be able to provide more concrete solution.

best regrads,

swanand

Read only

Clemenss
Active Contributor
0 Likes
1,849

Hi prasad,

yes, we have the SELECT MAX( NUM ) INTO LV_maxbum FROM <database table>.

Regards,

Clemens

Read only

Former Member
0 Likes
1,849

Thanq Clemens li its working ....

Read only

former_member156446
Active Contributor
0 Likes
1,849

You have some options:

1. If its database table update, use "table maint. generator events" and have code to build a number.

2. Can use a number range and use next_number_get / GET_NEXT_NUMBERS functions

3. You can save the max number into TVARVC / TVARV table and get that number each time and update that number after the processing is complete.

4. or as suggested above select max ...

Option 2 sounds good to me.

Read only

Former Member
0 Likes
1,849

Hi

for more than two values write the code within the loop it will work. so based on varable you can increment values under loops based on fatabase table.

Read only

prakashjasti
Contributor
0 Likes
1,849

Hi ,

For this when you find that there are no entries in your db table please send 1 in the key field.

and when there are entries in your database then select the maximum available number in your key field and increment it by 1 and store the new entry.

Regards,

Prakash.

Prakash J