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

moving file in apps

Former Member
0 Likes
843

Hi,

how to move the file from original folder

in application server to backup folder.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
815

You must copy this file and delete the old one. Here is an example program.



report zrich_0001.

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

data: itab type table of string.
data: wa type string.


start-of-selection.

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


* Copy to new file
  open dataset d2 for output in text mode.
  loop at itab into wa.
    transfer wa to d2.
  endloop.
  close dataset d2.

* Delete the first
  delete dataset d1.

Regards,

Rich Heilman

Hi,

how to move the file from original folder

in application server to backup folder.

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
816

You must copy this file and delete the old one. Here is an example program.



report zrich_0001.

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

data: itab type table of string.
data: wa type string.


start-of-selection.

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


* Copy to new file
  open dataset d2 for output in text mode.
  loop at itab into wa.
    transfer wa to d2.
  endloop.
  close dataset d2.

* Delete the first
  delete dataset d1.

Regards,

Rich Heilman

Read only

0 Likes
815

Hi Guys,

in the following way i am writing a file for my customer. now i want to take back up. for that i am thinking of file to another directory.

is it possible. if so can you suggest somechangs inth efollowing code.

appreciate your timely help.

form writefile.

data: msg(100).

data: todir like rsmrgstr-path value '/apps/MQBridge/idocproc/'.

data: tofile like edi_path-pthnam.

clear msg.

concatenate todir 'amkor4b2' sy-datum sy-uzeit w_seqno '.xml'

into tofile.

open dataset tofile for output in text mode encoding default

message msg.

if sy-subrc ne 0.

message e168(j4) with tofile.

else.

write:/ 'File transferred:', tofile.

endif.

loop at wlines.

transfer wlines to tofile.

endloop.

close dataset tofile.

endform. "WriteFile

Read only

0 Likes
815

If you look at my example above, you can see that all you need to do is just change the path of D2, this will put the file in another folder.

Regards,

Rich Heilman

Read only

0 Likes
815

Hi rich,

is it possible to copy the file without deleting the source file?

Read only

0 Likes
815

Sure, just comment out the last line of code from my example above.

REgards,

Rich Heilman

Read only

Former Member
0 Likes
815

Hi Nihi,

If you have the authority to execute Unix command then this is what you should write in your ABAP prg.

DATA: COMMAND(200).

DATA: BEGIN OF TABL OCCURS 0,

LINE(255),

END OF TABL.

command ='cat > /hodarchlogs/outbound/testfile.txt'.

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

if sy-subrc = 0.

write : 'Success'.

endif.

and if you do have this authority then there is a workaround method...

You have to create a command "zmv" throught t-code SM69... this command should be tested using t-code SM49 ...

and then in you ABAP code you should call the following FM :-

  • Internal table to store the move to directory.

DATA : T_MOVETODIR LIKE BTCXPM OCCURS 0 WITH HEADER LINE.

DATA : ARCH_DIR TYPE SXPGCOLIST-PARAMETERS.

CONSTANTS : C_CMD_TEST LIKE SXPGCOLIST-NAME VALUE 'ZMV'.

(This ZMV is the command defined in SM69).

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'

EXPORTING

COMMANDNAME = C_CMD_TEST

ADDITIONAL_PARAMETERS = ARCH_DIR

OPERATINGSYSTEM = SY-OPSYS

  • TARGETSYSTEM = SY-HOST

  • DESTINATION =

  • STDOUT = 'X'

  • STDERR = 'X'

  • TERMINATIONWAIT = 'X'

  • TRACE =

  • IMPORTING

  • STATUS =

  • EXITCODE =

TABLES

EXEC_PROTOCOL = T_MOVETODIR

EXCEPTIONS

NO_PERMISSION = 1

COMMAND_NOT_FOUND = 2

PARAMETERS_TOO_LONG = 3

SECURITY_RISK = 4

WRONG_CHECK_CALL_INTERFACE = 5

PROGRAM_START_ERROR = 6

PROGRAM_TERMINATION_ERROR = 7

X_ERROR = 8

PARAMETER_EXPECTED = 9

TOO_MANY_PARAMETERS = 10

ILLEGAL_COMMAND = 11

WRONG_ASYNCHRONOUS_PARAMETERS = 12

CANT_ENQ_TBTCO_ENTRY = 13

JOBCOUNT_GENERATION_ERROR = 14

OTHERS = 15

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

hope this helps you.