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

UNIX scripting in ABAP

Former Member
0 Likes
1,556

Hi Champs,

I need integerate UNIX application in my ABAP program. Below are the list of requirements for which UNIX will be required:

1) Need to move a file from one directory to another in Application server.UNIX command can be

MV Source Target

2) Need to search for a file in certain Directory.UNIX command can be

LS <file> Directiories where in files to be search.

Please can you help me out how to integerate UNIX code with ABAP report.

Regards,

Nishant Khimesra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,379

Nishant,

To move a file from one directory to another in Application server.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'mv /tmp/file1.txt /usr/tmp/file1.txt'.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

To search for a file in certain Directory.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'ls /tmp/file1.txt '.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

Regards

Sabu

9 REPLIES 9
Read only

Former Member
0 Likes
1,379

hi,

you can do all the things by using the below commands..


FTP_CONNECT                    "Connect to FTP server
FTP_COMMAND                    "Execute FTP Command--here by passing you cammand you can do
FTP_DISCONNECT                " Disconnect from FTP server

Prabhu

Read only

0 Likes
1,379

Thanks Prabhu.

Can you explain me with an example.

Thanks in advance

Read only

Former Member
0 Likes
1,380

Nishant,

To move a file from one directory to another in Application server.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'mv /tmp/file1.txt /usr/tmp/file1.txt'.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

To search for a file in certain Directory.

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'ls /tmp/file1.txt '.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

Regards

Sabu

Read only

0 Likes
1,379

Hi Sabu,

First of all thanks o ton for your help.....:)

"mv" command is working fine......

but "ls" command is not working upto my requirement.

My requirement is search a file named "abc.txt" in all the directories starting with "/usr/feeder/ " and to list all the directories in a table .

Can you help me out with this.

Thanks

Nishant

Read only

0 Likes
1,379

Nishant

Try the below code for searching a file:

DATA: command LIKE rs37a-line.
DATA: BEGIN OF tabl OCCURS 0,
          line(2000),
      END OF tabl.
 
command = 'find /usr/feeder/ -name abc.txt -print'.
 
CALL 'SYSTEM' ID 'COMMAND' FIELD command
              ID 'TAB'     FIELD tabl-*sys*.

This will search for a file named abc.txt in the directory /usr/feeder and all its sub-directories.

Let me know if you need more info.

Regards

Sabu.

Read only

0 Likes
1,379

Thanks a lot Sabu, it really worked......and fully marks rewarded to you for help

but one more thing, if I don't want to print the directories in my output screen.

I tried to remove the -print from the code but still the directory name are being output on the output screen.

Below is the code I am using with -print removed.

CONCATENATE 'find /usr/feeders -name' file1 INTO command SEPARATED BY SPACE.

CALL 'SYSTEM' ID 'COMMAND' FIELD command

ID 'TAB' FIELD tabl-sys.

If you can further help me with this problem, that will be great.

Thanks a lot..

Regards,

Nishant

Read only

Former Member
0 Likes
1,379

Alternative ways of doing the same is:

Moving Files:


    CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'
      EXPORTING
        sourcepath        =  dir1 
        targetpath         =  dir 2
      EXCEPTIONS
       error_file            = 1
       OTHERS           = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF

Searching Files:


  CALL FUNCTION 'SUBST_GET_FILE_LIST'
    EXPORTING
      dirname      = p_p_fname
      filenm         = p_c_fname
      pattern       = p_c_pattern
    TABLES
      file_list    = p_i_files
    EXCEPTIONS
      access_error = 1
      OTHERS       = 2.
  IF p_i_files[] IS INITIAL.
   ' Error Message
  ENDIF

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,379

write ur unix code

then execute it from ABAP using FM SXPG_COMMAND_EXECUTE

Read only

Former Member
0 Likes
1,379

You can use the transaction SM69 to create your own unix commands and can use them in programs.

You can use the transactions to CG3Z and CG3Y to move the files to/from application server to presentation server.

Thanks,

Srinivas