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 Serial Number in Module pool Primary Key

Former Member
0 Likes
1,966

Hi ,  in module programming  I want want to SR. no is generated automatic in z table with all recodes  when we press SAVE button in module pool screen .

  , I need sample code ,please help me

4 REPLIES 4
Read only

0 Likes
1,068

Hi,

You can add SR. no before inserting the internal table to DB table.

Here Sample code:

Count = 1.

Loop itab into wa.

wa-slno = count.

modify itab from wa index sy-tabix transporting slno.

clear wa.

count = count +1.

endloop.

insert DB from table itab.


regards,

Jyoti

Read only

Former Member
0 Likes
1,068

hello,

Please check this -

Hi,

1. Go to transaction SNRO (Simple way to remember is SapNumberRangeObject).

2. Enter the number range object name and press CREATE.  (Example ZDEMO)

3. Enter the description, Long text and Number Length domain and Warning %.

Warning% à Assume that an interval is defined from 1 to 1000. If you want to issue a warning at the number 900, enter 10 (%) here.

4. Press SAVE. You would get a prompt. Press YES and assign the object to a local class.

5. Now click on Number Ranges button on the application toolbar.

6. Click on Change Intervals.

7. Click on Insert Intervalue.

8. Enter the values as shown below: Click Insert and then SAVE. The number range object is generated. 

Testing the Number Range Object: 

We can use the function module, NUMBER_GET_NEXT, to get the next number of any number range object. 

Following is a test program to get the next available number of the object created above: 

REPORT zsnro_test.

DATA:

NUMBER TYPE I.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

   nr_range_nr = '01'

   object = 'ZDEMO'

IMPORTING 

  NUMBER = NUMBER

EXCEPTIONS

  INTERVAL_NOT_FOUND = 1

  NUMBER_RANGE_NOT_INTERN = 2

  OBJECT_NOT_FOUND = 3

  QUANTITY_IS_0 = 4

  QUANTITY_IS_NOT_1 = 5

  INTERVAL_OVERFLOW = 6

  BUFFER_OVERFLOW = 7

  OTHERS = 8

.

IF sy-subrc <> 0.

  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Write 😕 'Next available number is: ', Number.

best regards,

swanand

Read only

satyabrata_sahoo3
Contributor
0 Likes
1,068

Use Number Range object and FM ;NUMBER_GET_NEXT' to achieve this.

Refer:  http://saptechnical.com/Tutorials/ABAP/SNRO/SNRO.htm

-Satya

Read only

arindam_m
Active Contributor
0 Likes
1,068

This message was moderated.