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

temp files

Former Member
0 Likes
541

Hi all,

I am using a dataset to tempororily store some data in my program. the thing is if my program is executed by multiple users at a same time, the same dataset './mytempfile' is used and everything goes wrong. so suggest me how to overcome this.


 OPEN DATASET './mytempfile' FOR OUTPUT IN BINARY MODE.
  IF sy-subrc EQ 0.
    LOOP AT t_myfile.
      TRANSFER t_myfile TO './mytempfile'.
    ENDLOOP.
    CLOSE DATASET './mytempfile'.
  ENDIF.


  OPEN DATASET './mytempfile' FOR INPUT IN BINARY MODE.
  IF sy-subrc EQ 0.
    DO.
      CLEAR t_mybin.
      READ DATASET './mytempfile' INTO t_mybin MAXIMUM LENGTH 255.
      IF sy-subrc NE 0.
        EXIT.
      ELSE.
        APPEND t_mybin.
      ENDIF.
    ENDDO.
    CLOSE DATASET './mytempfile'.
  ENDIF.


  DELETE DATASET './mytempfile'.
  IF sy-subrc NE 0.
    MESSAGE 'Error when deleting MY file'(008) TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.

3 REPLIES 3
Read only

former_member378318
Contributor
0 Likes
511

Well I don;t know why you are using a dataset to temp store data but if you must. You can use something to make each file name unique, maybe add the username to the end of the file and if that is not enough then perhaps a timestamp or long timestamp.

Read only

Former Member
0 Likes
511

Well, you can create dynamic file names.

The file names can be a concatenation of filename + date + time + username + random number.

  • please reward points for the useful answers

Regards

Vivek

Read only

Former Member
0 Likes
511

I would store the data in a internal table while you are processing. Then once processing has been completed you can move the contents of the internal table to a external file, the filename can be a parameter on the selection screen, or you can use the dynamic names mentioned earlier.

With this method each time a user executes the transaction/program ABAP will generate a separate working area on the disk for the internal table. Even if you have 10 people running at the same time they will be witting to 10 different internal tables. All that is left is to manage the name of the external file.