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: 

Generating a unique filename

Former Member
0 Kudos

Hello,

I am generating a new filename using 'MYFILE' and sy-datum Sy-uzeit, under circumstances , because I am using the same mechanism in another area, which gets fired very quickly, it is not unique, and causes problems.

What is the easiest way to generate a new flle name guranteed to be unique?

Thanks

9 REPLIES 9

Former Member
0 Kudos

Hi

U could use the name of the report:

SY-REPID + SY-DATUM + SY-UZEIT

Max

0 Kudos

it may be the same repid which calls it , so this does not gurantee uniqueness

0 Kudos

Hi

So it would mean the same report can work twice at the same time? or I don't understand your issue

Max

0 Kudos

Hello,

I cannot strore the previous filename , as it is a function call which get called , not the same program,

so comparing to previous value does not help.

What I have currently is

CONCATENATE import_directory 'testfile_'

sy-datum '_' sy-uzeit '.xml' INTO file.

OPEN DATASET file FOR OUTPUT IN BINARY MODE.

0 Kudos

you can write it to the DB and read it back all the time, however it makes the program slower...

0 Kudos

"CREATE number range OBJECT using transaction snro
"then use this follwoing fm to generate unique number
"use this number in file name.

DATA : f_number TYPE char6.

CALL FUNCTION 'NUMBER_GET_NEXT'
  EXPORTING
    nr_range_nr             = '01'
    object                  = 'ZTEST'
  IMPORTING
    number                  = l_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.

0 Kudos

Hi,

the number range is one way of doing it, the way I did it was just getting the timesatmp in long format, and this gurantees to be unique.

JozsefSzikszai
Active Contributor
0 Kudos

hi Sims,

one solution would be to set up a numer range for this and create the file name accordingly. Another one probably to keep the last filename into a variable (I guess it is the same run of the program) and always compare with the newly created file name. If they are the same, you have to modify the new one (like CONCATENATE filename '_1' INTO filename).

hope this helps some

ec

Former Member
0 Kudos

You could use a random number, or use FM STREE_GET_UNIQUE_ID.

CALL FUNCTION 'QF05_RANDOM_INTEGER'
        EXPORTING
          ran_int_max = 1000000000
          ran_int_min = 1
        IMPORTING
          ran_int     = l_v_random_num.