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: 

SECUENTIAL FIELD IN ZTABLE

former_member182371
Active Contributor
0 Kudos

Hi,

i´m developing a ZTABLE. In this ztable there are two key fields. One of them (

ZNUMDE

) must be the result of concatenating

sy-uname(3) sy-datum+2(2) and a secuential
number of 2 digits

the moment the entry is created.
This key field must distinguish the number of entries in the table by user.
e.g. user PETER has 2 entries -> 1st ZNUMDE = PET0501
2nd ZNUMDE = PET0502
for user JOHN (1 entry) -> ZNUMDE = JOH0501.
In order to achieve this i´ve created a maintenance view of the table and within the event '01' BEFORE SAVING IN THE DATABASE i´ve created a routine within which i´ve added the following code:

DATA: v_max(2) TYPE i,

v_numde(7) TYPE c,

v_conta(2) TYPE c.

CLEAR: v_max, v_numde, v_conta.

  • Here i check the number of entries of a the user

SELECT COUNT( DISTINCT usuar ) INTO v_max

FROM ZTABLE WHERE usuar = sy-uname.

IF v_max GT 0.

v_max = v_max + 1.

v_conta = v_max.

ELSE.

v_max = 1.

v_conta = v_max.

ENDIF.

SHIFT v_conta RIGHT.

REPLACE '' WITH '0' INTO v_conta.

CONCATENATE sy-uname(3) sy-datum+2(2) v_conta

INTO z_v_devolucion-numde.

z_v_devolucion-usuar = sy-uname.

The question is that thus i´m not able to get ZDEVNUM as desired.

Any suggestion?

Best regards.

1 REPLY 1

christian_wohlfahrt
Active Contributor
0 Kudos

Hi!

It would be easier, if you had described your current (wrong) result.

But my guess is, your not counting existing entries correctly.

Your key znumde has three parts: user, year and counter. In your select, you define just user, but not year.

But when you have already second field usuar (why not user?) for user-id, why not split your key into three separate fields? This would make your selection easier:

select count( * ) into v_max
  from ztable
  where user = sy-uname
   and  year = sy-datum+2(2)
   and  (other key except counter).

.

By the way: you create a year 2100-problem!

Use v_max type i instead of v_max(2).

with v_conta(2) type n you might get correct format without additional conversion. Otherwise FM CONVERSION_EXIT_ALPHA_INPUT will do the job, too.

Or do you struggle with the event?

Regards,

Christian