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 increment option

Former Member
0 Likes
1,235

Is there any option for auto increment the values in the tables. for example if we are inserting 100 data's for first data i should specify 1 and for second data it should specify 2 and goes on.

1 ACCEPTED SOLUTION
Read only

former_member188829
Active Contributor
0 Likes
1,081

Hi,

Use Sy-tabix in between loop and endloop.

or sy-index = sy-index + 1.

Check this Example.

TABLES:MARA.

*********************************************************************

  • Selection Screen

*********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

RANGES:S_MATNR FOR MARA-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.

S_MATNR-LOW = '000000000000000001'.

S_MATNR-HIGH = '0000000000001000'.

S_MATNR-SIGN = 'E'.

S_MATNR-OPTION = 'BT'.

APPEND S_MATNR.

CLEAR S_MATNR.

*********************************************************************

  • Internal Table

********************************************************************

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-ERNAM,

NTGEW LIKE MARA-NTGEW,

END OF ITAB.

**********************************************************************

  • Start of Selection

**********************************************************************

START-OF-SELECTION.

SELECT MATNR

ERSDA

ERNAM

NTGEW FROM MARA INTO TABLE ITAB WHERE MATNR IN S_MATNR.

LOOP AT ITAB.

WRITE:/ SY-TABIX,ITAB-MATNR.

ENDLOOP.

Is there any option for auto increment the values in the tables. for example if we are inserting 100 data's for first data i should specify 1 and for second data it should specify 2 and goes on.

5 REPLIES 5
Read only

former_member188829
Active Contributor
0 Likes
1,082

Hi,

Use Sy-tabix in between loop and endloop.

or sy-index = sy-index + 1.

Check this Example.

TABLES:MARA.

*********************************************************************

  • Selection Screen

*********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

RANGES:S_MATNR FOR MARA-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.

S_MATNR-LOW = '000000000000000001'.

S_MATNR-HIGH = '0000000000001000'.

S_MATNR-SIGN = 'E'.

S_MATNR-OPTION = 'BT'.

APPEND S_MATNR.

CLEAR S_MATNR.

*********************************************************************

  • Internal Table

********************************************************************

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-ERNAM,

NTGEW LIKE MARA-NTGEW,

END OF ITAB.

**********************************************************************

  • Start of Selection

**********************************************************************

START-OF-SELECTION.

SELECT MATNR

ERSDA

ERNAM

NTGEW FROM MARA INTO TABLE ITAB WHERE MATNR IN S_MATNR.

LOOP AT ITAB.

WRITE:/ SY-TABIX,ITAB-MATNR.

ENDLOOP.

Read only

0 Likes
1,081

Hi ,

Thanks. Is there any functional settings for auto increment inside the table screen.

Read only

former_member188829
Active Contributor
0 Likes
1,081

Hi,

Do like this also...

LOOP AT ITAB.

SY-INDEX = SY-INDEX + 1.

WRITE:/ SY-INDEX,ITAB-MATNR.

ENDLOOP.

Read only

Former Member
0 Likes
1,081

no

Read only

0 Likes
1,081

you can maintain "number ranges" that will provide numbers in sequence according to rules customized in transaction SNUM

in your program, you have to call FM NUMBER_GET_NEXT that will return the next number of the range