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: 

How to move a file from one folder to another using data sets

Former Member
0 Kudos

Hi ABAP Gurus,

we have a scenario where in which after a file is read from a folder Eg: /home/prd/in on <b>application server</b>, it has to be <b>deleted from current folder</b> and has to be <b>moved to processed folder</b> Eg : /home/prd/processed.

We are using datasets for read / write . Can anybody help in this regard?

Thanx in advance ,

Regards,

Sriram.

1 ACCEPTED SOLUTION

andreas_mann3
Active Contributor
0 Kudos

Hi,

try this:

DATA: COMMAND(200).

DATA: BEGIN OF TABL OCCURS 0,

LINE(255),

END OF TABL.

command = 'mv /home/prd/file.in /home/prd/processed/file.out'.

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'TAB' FIELD TABM-SYS.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Could you please elaborate what problem are you facing in carrying out the task you mentioned? If you could post the portion of code where the error occurs, that would help as well.

Regards

andreas_mann3
Active Contributor
0 Kudos

Hi,

try this:

DATA: COMMAND(200).

DATA: BEGIN OF TABL OCCURS 0,

LINE(255),

END OF TABL.

command = 'mv /home/prd/file.in /home/prd/processed/file.out'.

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'TAB' FIELD TABM-SYS.

0 Kudos

Hi Andreas Mann ,

Thanx for the reply . From your reply , it is clear that you are trying to execute a unix command which will move a file from one folder to another .

But I am not clear about

CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND ID 'TAB' FIELD TABM-SYS.

can u please give some more details / codes ? Is there any function module which executes a unix command?

Thanx in advance,

Regards,

Sriram.

0 Kudos

Hi Sriram,

Check FM SXPG_COMMAND_EXECUTE.

For more information check SXPT function group.

Thanks

Lakshman

Message was edited by: Lakshman Tandra

Former Member
0 Kudos

Hi Sriram,

Another option would be as follows

open a new dataset(the processed file) for writing

write the contents that has be read using the "Transfer"abap statement

Delete the original file using the "delete dataset" abap statement to delete the original file...

Thanks,

Renjith.

0 Kudos

Here is some sample coding that I had in my bag of tricks.



report zrich_0001.

Parameters: d1 type localfile default '/usr/sap/TST/SYS/fld1/Data1.txt',
            d2 type localfile default '/usr/sap/TST/SYS/fld2/Data1.txt'.

data: begin of itab occurs 0,
      rec(20) type c,
      end of itab.
data: wa(20) type c.


start-of-selection.

  open dataset d1 for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset d1 into wa.
      if sy-subrc <> 0.
        exit.
      endif.
      itab-rec = wa.
      append itab.
    enddo.
  endif.
  close dataset d1.

  open dataset d2 for output in text mode.
  loop at itab.
    transfer itab to d2.
  endloop.
  close dataset d2.

  delete dataset d1.

Regards,

Rich Heilman

0 Kudos

This report works fine for file .txt, but not for files .jpg.

0 Kudos

Read the help for Open Dataset: Binary mode instead of text mode.

MattG