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: 

Rename a UNIX File from an ABAP program.

Former Member
0 Kudos

hello all,

I have to rename a UNIX file in a UNIX directory. How can I do that using an ABAP statement?

EX: local/data/sap/temp/filename.TXT ==> local/data/sap/temp/filename.XML

Thank's everyone.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

This reports obtains a total control of file/s with the original Unix commands( move, rename, delete, list, etc. ) : please, pay attention about a correct use of this fuction ! <b>It's very powerfull</b> !

REPORT YUNIX000 LINE-SIZE 250.
DATA:
      BEGIN OF TABL OCCURS 0,
        LINE(200),
      END OF TABL.
DATA:
      PARCOM(180).

PARAMETERS:
      COMMA(30) LOWER CASE,
      FILE1(75) LOWER CASE.

START-OF-SELECTION.

  PARCOM+00(30) = COMMA.
  PARCOM+30(75) = FILE1.

  CONDENSE PARCOM.

  PERFORM EXECUNIX.

END-OF-SELECTION.

  EDITOR-CALL FOR TABL DISPLAY-MODE.

*---------------------------------------------------------------------*
*       FORM EXECUNIX                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM EXECUNIX.
  REFRESH TABL. CLEAR TABL.
  CALL 'SYSTEM' ID 'RN' FIELD PARCOM
                ID 'TAB'    FIELD TABL-*SYS*.
ENDFORM.

Hope this helps you

Regards

Sudheer

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I would image that you can copy the file and delete the old one. Here is a sample program. Of course the file names and path may be different because you are using UNIX.



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: 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

Former Member
0 Kudos

Hi,

This reports obtains a total control of file/s with the original Unix commands( move, rename, delete, list, etc. ) : please, pay attention about a correct use of this fuction ! <b>It's very powerfull</b> !

REPORT YUNIX000 LINE-SIZE 250.
DATA:
      BEGIN OF TABL OCCURS 0,
        LINE(200),
      END OF TABL.
DATA:
      PARCOM(180).

PARAMETERS:
      COMMA(30) LOWER CASE,
      FILE1(75) LOWER CASE.

START-OF-SELECTION.

  PARCOM+00(30) = COMMA.
  PARCOM+30(75) = FILE1.

  CONDENSE PARCOM.

  PERFORM EXECUNIX.

END-OF-SELECTION.

  EDITOR-CALL FOR TABL DISPLAY-MODE.

*---------------------------------------------------------------------*
*       FORM EXECUNIX                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM EXECUNIX.
  REFRESH TABL. CLEAR TABL.
  CALL 'SYSTEM' ID 'RN' FIELD PARCOM
                ID 'TAB'    FIELD TABL-*SYS*.
ENDFORM.

Hope this helps you

Regards

Sudheer

former_member188685
Active Contributor
0 Kudos
REPORT ZUNIX line-size 400
                no standard page heading.

selection-screen begin of block ucmd with frame title text-001.
parameters: unixcom like   rlgrap-filename.   " ...SAP Interface file
selection-screen end of block ucmd.

data: begin of tabl occurs 500,
        line(400),
      end of tabl.

data: lines type i.


*----------------------------------------------------------------------

start-of-selection.
  refresh tabl.

  call 'SYSTEM' id 'COMMAND' field unixcom
                id 'TAB'     field tabl[].

  describe table tabl lines lines.
  loop at tabl.
    write:/01 tabl-line.
  endloop.
  skip 2.
  if lines = 0.
    write:/ 'NO Occurances were found'.
  else.
    write:/ 'Command was successfully executed' color col_total.
    write:/ 'Number of entries in Search' color col_total,
             lines color 6.
  endif.
*----------------------------------------------------------------------

end-of-selection.
*----------------------------------------------------------------------

after running , give the command

<b>

mv local/data/sap/temp/filename.TXT local/data/sap/temp/filename.XML

</b>

Former Member
0 Kudos

A better way would be defining external commands in transaction SM49 and then using function module SXPG_COMMAND_EXECUTE to use the command created in transaction SM49.

Regards,

Ankur Bhandari