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: 

Special field in table

Former Member
0 Kudos
303

Hello All,

I need to create a new table and one of its field has a special property. This field have to inform automatically when new record is created and its value have to be secuencialy for each table key. For instance, The table key is the invoice number. When the first new record for the invoice number 00000001 is created, the field record number should be 001, the next should be 002,...

For the invoice number 00000002, when the first new record is created, the field record number should be 001, then 002,...

Can somebody help me?

Thank you in advance

Manuel

8 REPLIES 8

Former Member
0 Kudos
108

Use a number range for that

transaction SNRO / SNUM

Then you have fm

FUNCTION NUMBER_GET_NEXT.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"       IMPORTING
*"             VALUE(NR_RANGE_NR) LIKE  INRI-NRRANGENR
*"             VALUE(OBJECT) LIKE  INRI-OBJECT
*"             VALUE(QUANTITY) LIKE  INRI-QUANTITY DEFAULT '1'
*"             VALUE(SUBOBJECT) DEFAULT SPACE
*"             VALUE(TOYEAR) LIKE  INRI-TOYEAR DEFAULT '0000'
*"             VALUE(IGNORE_BUFFER) DEFAULT SPACE
*"       EXPORTING
*"             VALUE(NUMBER)
*"             VALUE(QUANTITY) LIKE  INRI-QUANTITY
*"             VALUE(RETURNCODE) LIKE  INRI-RETURNCODE
*"       EXCEPTIONS
*"              INTERVAL_NOT_FOUND
*"              NUMBER_RANGE_NOT_INTERN
*"              OBJECT_NOT_FOUND
*"              QUANTITY_IS_0
*"              QUANTITY_IS_NOT_1
*"              INTERVAL_OVERFLOW
*"              BUFFER_OVERFLOW
*"----------------------------------------------------------------------

Former Member
0 Kudos
108

hi manuel..

i have also done same problem..

algorithm is..

find the last record and last number from the database.

now when new invoice is creted generate a new number and saved in your tables ..

following code may be helpful to u..

select * into corresponding fields of table ITAB_znor from znor where

site = ZGKPF-plant.

if sy-subrc = 0.

read table ITAB_znor index sy-dbcnt.

docno = ITAB_znor-doc_no+6(7).

else.

docno = '0000001'.

endif.

x = ZGKPF-plant.

y = SY-DATUM+2(2).

if sy-subrc = 0.

docno = docno + 1.

concatenate x y docno into ge_no.

else.

concatenate x y docno into ge_no.

endif.

ITAB_ZNOR-DOC_NO = GE_NO.

itab_zgseg-docno = ge_no.

zgkpf-docno = ge_no.

itab_znor-site = zgkpf-plant.

ITAB_ZNOR-F_YEAR = SY-DATUM+0(4).

insert into znor values ITAB_znor.

regards..

Former Member
0 Kudos
108

Thaks for your answer but maybe I didn't explaing the problem. I can't write code. I have to maintain the table in SM30 and I need that when I create a new record in the table (in SM30) one field is a counter and gives consecutive numbers.

0 Kudos
108

Hi,

This especially validations or any updations

for entering values using se30 tcode.

You can automatically update the field in the table as follows.

After creating a table follow the below path:

UTILITIES->TABLE MAINTAINCE GENERATOR

then from that screen

ENVIRONMENT->MODIFICATION->EVENTS

u will go next screen.

In that screen press f4 on the column T of the table control and choosen event 01 i think this will be suitable for you requirement.

then just give a name for form and

write an abap code as alogrithm below.

1)take the previous value of the field

2) check for the change of the invoice number add 1 for this special field.

I think this will solve your problem.

Please let me if any clarifications required on this.

Regards

Anil Kumar K

0 Kudos
108

Hello Anil,

Thank you very much for your answer. I think that it will be the solution but I still have some questions.

1 - When I try to add an event the following alert message appear: 'Modification is forbiden (data belongs to SAP)'. Do you think that is good idea to modify the values? is it usual?

2 - If I implement the code I think it'll work but it's not funny because if the user write '004' in the special field then the code will modify this value. Do you know if it's possible change the fields attributes in order to avoid that the user write values for that field?

Thank you very much

Manuel

0 Kudos
108

Hi Manual

1- It's only a warning: you can use the event you need.

2- You can create a MAINTENANCE VIEW and generate the view for SM30 for it.

In this kind of view you can specify the screen attribute (for SM30) and in particular you can set a flag with these values:

H -> To hidden the field

R -> To read only the the field

Max

0 Kudos
108

Thanks for your answer Max.

Could you please, let me know, where I can set the flag with the values 'H' or 'R'. I read that in the SAP help but I did't find where it is. What I did was modify the screen and change the screen attribute but that is a thick.

Thank you very much.

former_member191468
Participant
0 Kudos
108

Hi ,

You can automatically update the field in the table as follows.

After creating a table follow the below path:

UTILITIES->TABLE MAINTAINCE GENERATOR

then from that screen

ENVIRONMENT->MODIFICATION->EVENTS

u will go next screen.

In that screen press f4 on the column T of the table control and choosen event 01 i think this will be suitable for you requirement.

then just give a name for form and

write an abap code as alogrithm below.

1)take the previous value of the field

2) check for the change of the invoice number add 1 for this special field.

I think this will solve your problem.

Please let me if any clarifications required on this.

Regards

Anil Kumar K