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

Serial number generation

Former Member
0 Likes
2,694

Hi,

I have a Z table, it has a component serial no.

My requirement is to auto generate a serial no. when a record is inserted.

Please help me solve the problem.

Thanks.

Sai.

Hi,

I have a Z table, it has a component serial no.

My requirement is to auto generate a serial no. when a record is inserted.

Please help me solve the problem.

Thanks.

Sai.

8 REPLIES 8
Read only

Former Member
0 Likes
1,730

YOu have to create a number range for your Z table:

http://help.sap.com/saphelp_nw04/helpdata/en/b4/185f28179c4f3cb8d00988cd139500/frameset.htm

YOu have to use the function module:

NUMBER_GET_NEXT to get the next free number in your number range.

Regards,

ravi

Read only

Former Member
0 Likes
1,730

Hi...

Before using the insert statement,

read the last record , u ll get the current value of the field and add 1 to it.

I hope this ll be simple 2 line code.

Thanks & Regards

vinsee

Read only

Former Member
0 Likes
1,730

from where ll u insert the record, se11 or u ll code some thiing

if u code then it is very simple.send me the further information.

Read only

alpesh_saparia3
Active Contributor
0 Likes
1,730

Hi,

Define a number range object using tcode "SNUM" for data element serial no. and generate next number using function module "NUMBER_GET_NEXT" passing object no.

Read only

sachin_mathapati
Contributor
0 Likes
1,730

Hi Sai,

Chk this link..

[https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/table%2bmaintenance%2bin%2babap]

Reward If helpful.

Regards,

Sachin M M

Read only

Former Member
0 Likes
1,730

Hi,

Thanks for your help, I am inserting records into Z table from an alv grid. I this is done when the user performs save.

Which is the best way to handle this sutation.

Thanks.

Sai.

Read only

Former Member
0 Likes
1,730

Hi Mohan Das,

The function module you have to use is Number_get_next.

Check out the sample implementation of that Function module..


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.

Before doing the above process check in SNUM transaction whether the number range has buffering or not.

so, if you do not want to have any gaps on your range, on transaction SNUM , from the menu choose "Edit -> Set-up buffering":

1 - no buffering (with this you will have gaps on your range)

2 - main memory (no gaps on your range)

On both you have to consider your "update methods".

Hope this would help you.

Regards

Narin Nandivada.

Edited by: Narin Nandivada on Jun 30, 2008 4:44 PM

Read only

Former Member
0 Likes
1,730

Hi,

Create a Number range using the Transaction SNRO.

By doing this you can create a number range object

NUMBER_GET_INFO

Number range: Provides information for a number range number

Regards,

VIjay