UNIX scripting in ABAP

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

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

Similar Messages

  • Execute unix script from abap.

    Hi friends,
    I have a abap report which generate  a text file in<b> /usr/tmp/</b>  directory . Now i have a unix script   which encript the text file.  I want to this from abap report. How I can do this . and in which path  I should keep this unix script   Please help.
    Regards

    Hi,
    try the below code
    parameters : p_sfile(60) lower case
    "File to be moved
    "Eg : /home/in/SFILE1.txt
    p_dfile(60) lower case.
    "File's Destination
    "Eg: /home/archive/SFILE1.txt
    data : t_btcxpm
    like btcxpm occurs 0,
    p_addparam
    like sxpgcolist-parameters.
    concatenate
    '/home/ABAP/scripts/Archive_file.sh'
    p_sfile
    p_dfile
    into p_addparam separated by space.
    refresh t_btcxpm. clear t_btcxpm.
    call function 'SXPG_CALL_SYSTEM'
    exporting
    commandname = 'ZSHELL'
    additional_parameters = p_addparam
    tables
    exec_protocol = t_btcxpm
    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
    others = 12.
    if sy-subrc = 0.
    write : /
    'File',p_sfile,'moved to',p_dfile.
    else.
    write : / 'Error Occured'.
    endif.
    Reward points if found helpful……
    Cheers,
    Chandra Sekhar.

  • Call a unix script from ABAP program

    Can anybody help me on how to call a unix script from an ABAP program
    Regards
    Anjali

    Hi try the below code
    parameters : p_sfile(60) lower case
              "File to be moved
              "Eg : /home/in/SFILE1.txt
                p_dfile(60) lower case.
              "File's Destination
              "Eg: /home/archive/SFILE1.txt
    data : t_btcxpm
           like btcxpm occurs 0,
           p_addparam
           like sxpgcolist-parameters.
      concatenate
      '/home/ABAP/scripts/Archive_file.sh'
      p_sfile
      p_dfile
      into p_addparam separated by space.
      refresh t_btcxpm. clear t_btcxpm.
      call function 'SXPG_CALL_SYSTEM'
        exporting
          commandname = 'ZSHELL'
          additional_parameters = p_addparam
        tables
          exec_protocol = t_btcxpm
        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
          others                     = 12.
      if sy-subrc = 0.
        write : /
        'File',p_sfile,'moved to',p_dfile.
      else.
        write : / 'Error Occured'.
      endif.

  • Run Unix script from abap

    Hi
    Friends  i am runing a abap report which genrate a ( eft.txt ) text file in /usr/tmp/
    Now  i want  to run a unix script   which encript this file.
    I  have created this command in SM69
    type = customer
    command name = ZENC
    Operation system = unix
    externl program     = sh
    parameter for external program = /usr/tmp/ enc.sh eft.txt eftdc eftdo
    enc is unix script and eft.txt is imput text file eftdo eftdc are encripted  files.
    I am us the function module SXPG_CALL_SYSTEM'
    it is ending with  following messege
    1      5     hello
    2     19     eft.txt eftdo eftdc
    3     40     The jar file is not found: Encryptor.jar
    4     44     External program terminated with exit code 1
    and  do not give any output.
    please  help.
    Thanks & regards
    SS

    report zsrchsap.
    *-This is a demo report for Search Sap
    *-Author : Sandeep Kulkarni
    *-Date : 09/20/2001
    parameters : p_sfile(60) lower case
              "File to be moved
              "Eg : /home/in/SFILE1.txt
                p_dfile(60) lower case.
              "File's Destination
              "Eg: /home/archive/SFILE1.txt
    data : t_btcxpm
           like btcxpm occurs 0,
           p_addparam
           like sxpgcolist-parameters.
      concatenate
      '/home/ABAP/scripts/Archive_file.sh'
      p_sfile
      p_dfile
      into p_addparam separated by space.
      refresh t_btcxpm. clear t_btcxpm.
      call function 'SXPG_CALL_SYSTEM'
        exporting
          commandname = 'ZSHELL'
          additional_parameters = p_addparam
        tables
          exec_protocol = t_btcxpm
        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
          others                     = 12.
      if sy-subrc = 0.
        write : /
        'File',p_sfile,'moved to',p_dfile.
      else.
        write : / 'Error Occured'.
      endif.

  • Advantage's using Unix Script

    I'm creating ACH file using program RFPNFC00 which goes and stores in the application server. I need to ping this file from application server to FTP for which i wanna know which one is the best way to do is that with FM  CALL FUNCTION 'FTP_CONNECT' or shall i ask the Unix guy to write a small script to ping the file from app server to FTP.
    Basically can anyone lemme know the advantages and disadvantages of Unix script and ABAP code to ping the file to FTP.
    Regards
    VENk@

    Venkat,
    it depends on the security-configuration in your company.
    If you're authorized use SAP-FTP -> look sample program RSFTP004
    hope that helps
    Andreas

  • Call ABAP program from Unix script passing dynamic filename

    Hi,
    Does anyone know if it is possible to call an ABAP program from a Unix script passing a dynamic filename to the ABAP program?
    We are receiving a file from an external company and on receipt of the file want to call an ABAP program passing the filename.  The filename is made up of File ID, Date and Time which we need to read in the ABAP program.  We usually use Events to trigger a program which is fine when the filename if static however since this filename will be dynamic we cannot do this.  In addition we cannot just rename the file to a static name in the Unix script as we need to know the value of the date and time from the file ID in the ABAP program.  I can change the ABAP program to check our /in directory for a Filename that starts with the fixed File ID however I thought there must be a better way of doing this.  We want the external company to put this information in a file header record but they don't want to change the file contents.  Any ideas would be appreciated.
    Thanks,
    Sinead.

    You could follow the following method
    1.Let the external file reside in the SAP application layer in a defined path e.g. /usr/sap/tmp/interface/working/
    2.Write an ABAP program which will include the following steps:-
       i) read all files in the file path using function module EPS_GET_DIRECTORY_LISTING
      ii) Read the data from files existing in the directory using OPEN_DATASET statement
    iii) After the files have been read move the files to another directory e.g. /usr/sap/tmp/interface/backup/ or you can delete the file.
    3.Schedule this program to be executed depending on the frequency of the external file being generated.

  • Trigger ABAP program using UNIX script

    Hi All,
    I want to trigger an Abap program whenever a unix file comes to SAP.
    Can any1 please tellme how to write a unix script to trigger the ABAP program.
    Thanks in advance.

    you will need to create a batch job in SM37 for the ABAP program, and use an event for the start criteria.
    The event can be created in SM62
    Then in unix, you will need to call an executable SAPEVT.
    This will be in the directory /usr/sap/<SAPSID>/SYS/exe/run
    you will need to use the appropriate profile for the SAP system to run the sapevt utility.
    example :-
    sapevt abap_event -t pf=/usr/sap/<SID>/SYS/profile/<SID>_DVEBMGS00_<SYSNAME> nr=00

  • How to load abap ztable using unix script

    Hi Experts,
    I want to upload the data from excel sheet into abap ztable using unix script. If possible give me a sample coding for this..
    Regards,
    vijay

    hi vijay see the  code below
    REPORT YFTP1 .
    FTP by abap.
    This program passses host, user, source/target
    directory and file parameters to a UNIX script which
    in turn gets the required file from the host by ftp.
    The unix script should look like this:
    #! /bin/sh
    ftp -n $1 << !!
    user $2 $3
    cd ..                      <-- only for mainframe ftp
    get $4 $5
    quit
    placed in the adm path, preferably under
    /sapmnt//exe. In order to make this program
    work please create sapcpic/manager cpic user and
    apply note no. 41770.
    PARAMETERS: HOST(10) OBLIGATORY LOWER CASE,
    USER(8) OBLIGATORY LOWER CASE,
    PASSWORD(8) OBLIGATORY LOWER CASE,
    SRC_FILE(45) OBLIGATORY LOWER CASE,
    TRG_FILE(45) DEFAULT '/usr/sap/trans/data/??????' OBLIGATORY LOWER CASE,
    BIN AS CHECKBOX.
    DATA: JC(8), FLG(1), B(128), PRNAME(128), LOGFILE(30), AAA(40).
    DATA: BEGIN OF A,
    1(12), 2(10), 3(10), 4(47), 5(47),
    END OF A.
    IF HOST = 'zxaq'.
      IF BIN = 'X'.
        PRNAME = 'ftp_bin_vms'.
      ELSE.
        PRNAME = 'ftp_asc_vms'.
      ENDIF.
    ELSE.
      IF BIN = 'X'.
        PRNAME = '/usr/sap/trans/bin/ftp_bin_unix'.
      ELSE.
        PRNAME = '/usr/sap/trans/bin/ftp_asc_unix'.
      ENDIF.
    ENDIF.
    A-1 = HOST.
    A-2 = USER.
    A-3 = PASSWORD.
    A-4 = SRC_FILE.
    A-5 = TRG_FILE.
    CONDENSE A.
    B = A.
    CALL FUNCTION 'JOB_OPEN'
         EXPORTING
              JOBNAME  = 'FTP'
         IMPORTING
              JOBCOUNT = JC.
    CALL FUNCTION 'JOB_SUBMIT'
         EXPORTING
              AUTHCKNAM     = SY-UNAME
              EXTPGM_NAME   = PRNAME
              EXTPGM_PARAM  = B
              EXTPGM_SYSTEM = 'jupiter'
              JOBCOUNT      = JC
              JOBNAME       = 'FTP'.
    CALL FUNCTION 'JOB_CLOSE'
         EXPORTING
              JOBCOUNT         = JC
              JOBNAME          = 'FTP'
              STRTIMMED        = 'X'
              TARGETSYSTEM     = 'jupiter'
         IMPORTING
              JOB_WAS_RELEASED = FLG.
    LOGFILE = '/tmp/ftp.log'.
    DO.
      OPEN DATASET LOGFILE FOR INPUT IN TEXT MODE.
      IF SY-SUBRC = 0. EXIT. ENDIF.
    ENDDO.
    DO.
      READ DATASET LOGFILE INTO AAA.
      IF SY-SUBRC = 0. WRITE / AAA. ENDIF.
      IF AAA = 'FTP completed'. EXIT. ENDIF.
    ENDDO.
    CLOSE DATASET LOGFILE.
    delete dataset logfile.
    now the file is in the application server which you can upload in your internal table and update the database table....
    thnkx
    bhanu

  • Logic to run Unix script file through ABAP program

    Hi Friends,
    I need to run the Unix script file from abap program, for that user provided file directory of application server.
    Is there any logic/FM  to run through abap programing.
    pls can any one provide logic.
    Thanks,
    Ravi

    report zsrchsap.
    *-This is a demo report for Search Sap
    *-Author : Sandeep Kulkarni
    *-Date : 09/20/2001
    parameters : p_sfile(60) lower case
              "File to be moved
              "Eg : /home/in/SFILE1.txt
                p_dfile(60) lower case.
              "File's Destination
              "Eg: /home/archive/SFILE1.txt
    data : t_btcxpm
           like btcxpm occurs 0,
           p_addparam
           like sxpgcolist-parameters.
      concatenate
      '/home/ABAP/scripts/Archive_file.sh'
      p_sfile
      p_dfile
      into p_addparam separated by space.
      refresh t_btcxpm. clear t_btcxpm.
      call function 'SXPG_CALL_SYSTEM'
        exporting
          commandname = 'ZSHELL'
          additional_parameters = p_addparam
        tables
          exec_protocol = t_btcxpm
        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
          others                     = 12.
      if sy-subrc = 0.
        write : /
        'File',p_sfile,'moved to',p_dfile.
      else.
        write : / 'Error Occured'.
      endif.

  • Unix commands in ABAP

    Hi,
       I need to call the following unix command in ABAP to encrypt a file on the app server .
    crypt password <org filename> new_filename
    1 But when i run it using call 'SYSTEM' .. i get message security risk , command not executed ..
    2 I also created the command in SM69 and tries to run it but same error.
    3 I also created a shell script , but i get another message when i try to run sh ...
      Please help to find out a way to make it work ..
    Kunal

    Hi kunal,
    1. probably ur basis team might be able to help u.
    2. even if we have authorisations thru sap
       to run external os command,
       the actual OS user on application server
       must have the right for it
       and access/write/read/modify
       for the files (provided thru the command)
       in question.
    3. Due to this , the systems gives the message
       of SECURITY RISK.
    regards,
    amit m.

  • How to store UNIX script in SM69/SM49

    Hi,all
    Its urgent requirement..
    I wrote a UNIX script for moving files from source dir to target dir ,how to call this script in ABAP.
    I know SXPG_command_execute...in that we can give a external command .But i need to call a script?
    so how can i do this and where to store this script?
    Thanx in advance

    Hi,
    Check the below document in sap help.
    http://help.sap.com/saphelp_47x200/helpdata/en/bb/9f038d4b9b11d189750000e8322d00/frameset.htm
    Thanks,
    Ramakrishna

  • Unix script

    Hi Friends,
    I have a unix script to run regularly every month. I have uploded the script and created a command fior that. Can u plz tell me how to schedule it background to run everymonth.

    hi,
    1. create external command (sm49)
    2. create simple z-program in abap (se38) which call function
    SXPG_COMMAND_EXECUTE
    3. schedule a job (sm36) with this z-program and period = monthly
    regards, darek

  • I want to execute UNIX COMMAND in ABAP

    Hi All,
    I want to execute a UNIX XOMMAND sh <scriptname> <filename> to replace divsion codes.in ABAP.
    But, I came to know that we can't (2) or try the following program but unfortunately the command CALL SYSTEM is not supported by SAP. If you are on R/3 2.1 - 2.2x you can get some idea's from the program SAPMSOS0.
    REPORT ZUNIXCOM .
    DATA: U_COMMAND(200).
    Table for system messages
    DATA: BEGIN OF RT OCCURS 100 ,
    LINE(100) ,
    END OF RT .
    START-OF-SELECTION .
    MOVE 'unix command' to U_COMMAND .
    REFRESH RT.
    CALL 'SYSTEM' ID 'COMMAND' FIELD U_COMMAND
    ID 'TAB' FIELD RT-SYS .
    LOOP AT RT.
    WRITE : / RT-LINE .
    ENDLOOP. 
    So please can u help me how to call a unix command from ABAP. it is very urgent. I want complete details and all possible solutions
    <removed_by_moderator>
    Thanks,
    gyanaraj
    Edited by: Julius Bussche on Aug 26, 2008 11:29 AM

    Selvaraj Gyanaraj wrote:>
    > So please can u help me how to call a unix command from ABAP.
    I was about to help you.
    >it is very urgent.
    I changed my mind.
    >I want complete details and all possible solutions
    I'm glad I changed my mind.
    >Points are surely rewarded.
    Too late.

  • UNIX command in ABAP code

    Hi All,
    I need to use unix command (MOVE) in ABAP code for transfering a file from one directory to another directory.
    Can any one help with how to used unix commands in ABAP?
    Thanks in advance.
    Regards,
    Hemendra

    The recommended approach always used to be to use transaction SM69 to define a "soft" command name to the operating system command so that it could be configured to work across Windows, Unix etc.  For example:
    Command name       OS         Type             OS command                                 Parameters for operating system command 
    Z_FILE_MOVE        SunOS      Customer    mv                                                 ? ?   
    You can then call function module SXPG_COMMAND_EXECUTE (quite well documented) to actually perform the command passing in the appropriate number of parameters.
    Jonathan

  • Executing Unix scripts from a stored procedure

    From the sql*plus windows, I am able to execute the host command and '!sh' commands; but I need to ececute Unix scripts from a stored procedure. Hoe can I do this? Where can I get good documentation on this? Any help would be greatly appreciated!
    Thanks..

    Hi,
    U can use external procedure ( newly added feature in 8.0.3 onwards) and call any shared library. From shared library u can execute it.
    One sql command is there HOST(' '). U can run a OS command. But u can not use it in PL/SQL.
    U can call pls sql from shell !!!!!..
    Thanks...
    Boby Jose

Maybe you are looking for

  • Difference b/w ACC and BCC while data modifying

    HI Guys, What is the main diffeence b/w ACC and BCC  with respect to data modification what will happen it i modify data through acc and bcc

  • Trre like structure in JComboBox. (VERY VERY URGENT , PLZ. HELP)

    hi, Question is I want to get a tree like structure in my comboBox. I have built a custom component just like FileDialog. In my comboBox I have a directory showing that inturn contains directories inside. When I pop up my component my parent director

  • Required assistance in ALV filter

    Hi Experts, I am not very good in ALV's I have an issue with REUSE_ALV_GRID_DISPLAY function module.The issue is on the initial output if I select the 1st field BOM Header and click on filter it is working fine.I am getting a selection screen and if

  • Native Muxer - Performance Pack

    Is there any way to use the performance pack/native muxer in a client weblogic RMI program. We have a client callback into the WLAS server so we were hoping that there was a way to use the performance pack for the clients socket io??? I know about in

  • Windows Explorer - How to select the first item once we open the explorer?

    Hi, In Windows Explorer - How to select the first item once we open the explorer using keyboard shortcut. I typically use downward arrow, it goes to the 2nd item in the list, then I again have to use upward arrow to go up. Is there a shortcut to sele