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: 

Moving read only flatfile to folder.

Former Member
0 Kudos

Hi all.

I have a problem i hope someone can help me with.

I am reading a flatfile from a server-library. After the file has been read and the information have been processed, it has to be moved to a backup folder. This is the code im using:


CONCATENATE p_dirnam '' file_list-name INTO l_fil1.
    CONCATENATE p_dirnam '' c_arkivdir
                               file_list-name INTO l_fil2.
    OPEN DATASET l_fil1 FOR INPUT IN TEXT MODE.
    IF sy-subrc = 0. "should always be OK
      OPEN DATASET l_fil2 FOR OUTPUT IN TEXT MODE.
      IF sy-subrc = 0.
        DO.
          READ DATASET l_fil1 INTO l_rec.
          IF sy-subrc NE 0.
            EXIT.
          ENDIF.
          TRANSFER l_rec TO l_fil2.
        ENDDO.
        CLOSE DATASET l_fil2.
        CLOSE DATASET l_fil1.
* Slet input-fil
        DELETE DATASET l_fil1.

Now the problem is that the file is and has to be read only, and this apparently interferes with the copying. What can i do, is there another way of copying a flatfile i can use??

Regards

Liselotte

9 REPLIES 9

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Liselotte,

if it's read-only, then deleting is prohibited. This is also end of 'MOVE', because move is build with copy and delete (from authority point of view).

Either you get more rights, or you just can copy.

Regards,

Christian

andreas_mann3
Active Contributor
0 Kudos

Hi ,

look at this link:

regards Andreas

Former Member
0 Kudos

Hi Liselotte,

you may want to try a "move" OS-command (like "mv" in Unix, or "ren" in VMS), instead of programming the write-and-delete by yourself in ABAP.

In order to do so, you may use


CALL 'SYSTEM'
  ID 'COMMAND' FIELD l_command
  ID 'TAB'     FIELD lt_outp-*sys*.

Best regards,

Alvaro

0 Kudos

Hi Alvaro.

The approach you have suggested, can i use that even if the file is read-only? If yes can you elaborate on how to use it

Regards

Liselotte

0 Kudos

Hi Liselotte,

I'm using Unix as OS for my application server. Here, the command for moving/renaming files is "mv".

If this is your case, you should use something like this:


DATA: l_path_name1(150) TYPE c.
DATA: l_path_name2(150) TYPE c.
DATA: l_command(1000) TYPE c.

DATA: BEGIN OF lt_outp OCCURS 0,
        line(255) TYPE c,
      END OF lt_outp.

CLEAR: lt_outp.
REFRESH: lt_outp.

*** here you should populate the complete paths of the
*** source and the target files

CONCATENATE 'mv' l_path_name1 l_path_name2
  INTO l_command SEPARATED BY space.

CALL 'SYSTEM'
  ID 'COMMAND' FIELD l_command
  ID 'TAB'     FIELD lt_outp-*sys*.

IF NOT lt_outp[] IS INITIAL.
*** then there's been an error in the command
  LOOP AT lt_outp.
*** error processing
  ENDLOOP.
ENDIF.

If you were using (for example) Windows NT as application server, you should replace "mv" by "ren" at your command definition.

I hope it helps. BR,

Alvaro

0 Kudos

Hi Alvaro.

I tried to use the code you suggested, but nothing happens, what am i doing wrong?

Here is my code:

CLEAR: lt_outp.
  REFRESH: lt_outp.

  CONCATENATE 'ren' g_file1 g_file2 INTO l_command SEPARATED BY
  space.

  CALL 'SYSTEM'
    ID 'COMMAND' FIELD l_command
    ID 'TAB'     FIELD lt_outp-*sys*.

  IF NOT lt_outp[] IS INITIAL.
    LOOP AT lt_outp.
      WRITE:/ lt_outp-line.
    ENDLOOP.
  ENDIF.

Many thanks

Liselotte

0 Kudos

Hi Liselotte,

what's the operating system of your application server? (watch it! NOT your presentation server)

Alvaro

0 Kudos

Hi Alvaro.

I am not sure, but i have tried using both 'mv' and 'ren'.

Thanks

Liselotte

0 Kudos

Hi Liselotte,

don't spend your time on several coding solutions - you are facing a authority problem (which you can only solve by coding, when you use operation system bugs).

When your file is read-only, then no matter if you try operation system or sap system commands - you can't delete or move it. That's the fact. If it's required to move this file after processing, then you need more rights to access this file - it's simply that.

Regards,

Christian