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

auto counter field

rodrigo_paisante3
Active Contributor
0 Likes
1,853

Hi all,

I have to create a ztable with a field id that will be a auto counter when execute maintenance transaction for the ztable. Can anyone help me?

Regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,201

If you want the number to always be unique, create a number range object and use function number_get_next to get the next number.

If using standard table maintenance, put code for this in a maintenance event (probably 01) and mod the screen field to make it display only.

Andrew

Hi all,

I have to create a ztable with a field id that will be a auto counter when execute maintenance transaction for the ztable. Can anyone help me?

Regards.

6 REPLIES 6
Read only

George_Lioumis
Active Participant
0 Likes
1,201

Hi.

In fact, you cannot create an "auto-counter" field as in mySQL for example. You will have to handle that field writing code. I suggest you create a new dialog program to handle this, so that you can also handle the delete and the insert functions etc.

Regards,

George

Read only

Former Member
0 Likes
1,202

If you want the number to always be unique, create a number range object and use function number_get_next to get the next number.

If using standard table maintenance, put code for this in a maintenance event (probably 01) and mod the screen field to make it display only.

Andrew

Read only

rodrigo_paisante3
Active Contributor
0 Likes
1,201

Hi, thanks for replies.

But i found one solution, can anyone sugest better?

I edited the function group generated by the se11 (maintenance). At the pai in the first screen i use a select max( filed ) o a variable.

At the pai in the second screen i copy and change a standard module, adding a statement MOVE var to ztable-field.

It works

Read only

0 Likes
1,201

Disadvantage of changing the generated maintenance is that if anyone adds fields to the table or makes other changes in future and re-generates the maintenance dialog, then your changes will be wiped.

Events in the generated mantenance do not get over-written when you re-generate and are thus a bit safer. (Menu path Environment->Modification->Events when in table maintenance generator screen - documentation in help is quite good).

The select max( field ) statement may return the same number to different users using the transacion at the same time unless the table is enqueued and locked first. Inside the generated maintenance this is not an issue as it locks the table and will not allow two users to update. However, if you also use this logic in your own program code you need to make sure no one else is updating at the same time.

Andrew

Read only

Former Member
0 Likes
1,201

Hi Rodrigo,

Try it.

go to Function Group at SE80 and add a Include PBO-Module.

then

in PROCESS BEFORE OUTPUT. ( at all Screen's )

add a module at last line of Output. ( Can be the same for all Screen's )

ex:

module ZFGTESTEO.

create this module at Include created above (double click in) and put this code.

IF SY-UCOMM = 'NEWL' OR ( sy-ucomm = 'NEXT' AND NOT <TABLE1> <> 0 ).

DATA: temp LIKE ZTABLE.

temp = total+3(10) + 1.

<TABLE1>+3(10) = temp.

ENDIF.

Regards,

Allan Cristian

Read only

rodrigo_paisante3
Active Contributor