Skip to Content

How to generate a unique number for a field every time

Hi every one,

I have a requirement where I have to generate a unique number every time, i.e. for an output only field (that is an account number field) I have given a number initially. So wnen ever an account is created this number is saved to the database table. Now again when I try to open a new account, autometically the account number has to be displayed by incrementing 1 to the previous number.

Please help me in doing this.

Thanks,

Sri...

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 29, 2009 at 06:12 AM

    hi,

    go to t-code SNRO and create a number range from 0 to 99999999.

    call the below fm in the report by passing the created number range name to fm to generate the new number every time..

    see

    NUMBER_GET_NEXT Get next free number in a range

    CALL FUNCTION 'NUMBER_GET_NEXT'

    EXPORTING

    NR_RANGE_NR = '01'

    OBJECT = 'YPOLLID' "number range name created in SNRO.

    IMPORTING

    NUMBER = LS_NUMBER. "new number with one increment..

    or

    you can try..

    you can use following code.

    select max( num ) from z_table into v_max_num.

    v_max_num = v_max_num+1.

    Regards,

    prabhudas

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 29, 2009 at 06:31 AM

    HI,

    Check FM NUMBER_GET_NEXT. For more help read the FM Documentation.

    Add comment
    10|10000 characters needed characters exceeded