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

Similar Messages

  • Execute unix command in abap code

    Hi, I have a request to execute a script command in a remote unix server, should i use 'call function ...destination'?
    Thanks.
    Legend.

    Use like this :
    data: begin of t_tabl occurs 0,
    line(132),
    end of t_tabl,
    data: lc_command(100) type c.
    Get all the file name falling under specified directory...
    lc_command(3) = 'ls '.
    lc_command+3(45) = p_dir. " Directory of file path
    call 'SYSTEM' id 'COMMAND' field lc_command
    id 'TAB' field t_tabl-sys.
    Check any files exits in the directory.......................
    if t_tabl[] is initial.
    message e006 with 'No files exist in the specified directory ' p_dir.
    endif.
    Do not look for sy-subrc ,here sy-subrc will not work.
    Thanks
    Seshu

  • 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 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 Move file / call UNIX command using ABAP Program

    Hi, ABAP Guru.
    I need to Cut & Paste file (Move file from one location to another location) on Network Shared Drive using ABAP program.
    But I can't figured out how to do this and what ABAP Command / FM / Method (and maybe UNIX command) that being used.
    Please give me the advice.
    Best regard and Thank you all.
    Nattapash C.

    all methods for your requirements should be in class CL_GUI_FRONTEND_SERVICES

  • Using Unix command in ABAP

    Hi guy,
    I am using " Call 'SYSTEM' id 'COMMAND' field UnixCommand id 'TAB' field itFiles-SYS"  to read number of files in folder, it works fine if number of line are around 200 but if its more then that it doesn't any file.
      UnixCommand = 'ls -ld'.
      UnixCommand+7(45) = /abap/.
      call 'SYSTEM' id 'COMMAND' field UnixCommand
                    id 'TAB' field itFiles-SYS.
    Thanks
    Atul

    Hi,
    DATA: L_DIRNAME LIKE EPSF-EPSDIRNAM,
          L_FILEMASK LIKE EPSF-EPSFILNAM.
    CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
        EXPORTING
          dir_name                  = l_dirname
          file_mask                 = l_filemask
    * IMPORTING
    *   DIR_NAME                    =
    *   FILE_COUNTER                =
    *   ERROR_COUNTER               =
        TABLES
          dir_list                  = pi_filelist
    EXCEPTIONS
       invalid_eps_subdir           = 1
       sapgparam_failed             = 2
       build_directory_failed       = 3
       no_authorization             = 4
       read_directory_failed        = 5
       too_many_read_errors         = 6
       empty_directory_list         = 7
       OTHERS                       = 8.
    Try with this

  • SQL Command conversion in abap code

    Hi,
    I want to implement the UNION, INTERSECT and MINUS SQL commands in abap code. Please give me the appropriate solutions asap.
    For Example:
    select field1, field2, . field_n
    from tables
    <b>UNION</b>
    select field1, field2, . field_n
    from tables;
    select field1, field2, . field_n
    from tables
    <b>MINUS</b>
    select field1, field2, . field_n
    from tables;
    select field1, field2, . field_n
    from tables
    <b>INTERSECT</b>
    select field1, field2, . field_n
    from tables;
    Thanks,
    Ravi

    Hi Ravi
    Check out this procedure...
    DATA: FRANKFURT(4) TYPE X,
          FRISCO(4)    TYPE X,
          INTERSECT(4) TYPE X,
          UNION(4)     TYPE X,
          BIT          TYPE I.
    DATA: CARRID TYPE SPFLI-CARRID,
          CARRIER LIKE SORTED TABLE OF CARRID
                              WITH UNIQUE KEY TABLE LINE.
    DATA WA TYPE SPFLI.
    SELECT CARRID FROM SCARR INTO TABLE CARRIER.
    SELECT CARRID CITYFROM FROM SPFLI
                           INTO CORRESPONDING FIELDS OF WA.
      WRITE: / WA-CARRID, WA-CITYFROM.
      READ TABLE CARRIER FROM WA-CARRID TRANSPORTING NO FIELDS.
      CASE WA-CITYFROM.
        WHEN 'FRANKFURT'.
          SET BIT SY-TABIX OF FRANKFURT.
        WHEN 'SAN FRANCISCO'.
          SET BIT SY-TABIX OF FRISCO.
      ENDCASE.
    ENDSELECT.
    INTERSECT = FRANKFURT BIT-AND FRISCO.
    UNION     = FRANKFURT BIT-OR  FRISCO.
    SKIP.
    WRITE 'Airlines flying from Frankfurt and San Francisco:'.
    DO 32 TIMES.
      GET BIT SY-INDEX OF INTERSECT INTO BIT.
        IF BIT = 1.
          READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.
          WRITE CARRID.
        ENDIF.
    ENDDO.
    SKIP.
    WRITE 'Airlines flying from Frankfurt or San Francisco:'.
    DO 32 TIMES.
      GET BIT SY-INDEX OF UNION INTO BIT.
        IF BIT = 1.
          READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.
          WRITE CARRID.
        ENDIF.
    ENDDO.
    This produces the following output list:
    The program uses four hexadecimal fields with length 4 - FRANKFURT, FRISCO, INTERSECT, and UNION. Each of these fields can represent a set of up to 32 elements. The basic set is the set of all airlines from database table SCARR. Each bit of the corresponding bit sequences representes one airline. To provide an index, the external index table CARRIER is created and filled with the airline codes from table SCARR. It is then possible to identify an airline using the internal index of table CARRIER.
    In the SELECT loop for database table SPFLI, the corresponding bit for the airline is set either in the FRANKFURT field or the FRISCO field, depending on the departure city. The line number SY-TABIX is determined using a READ statement in which no fields are transported.
    The intersection and union of FRANKFURT and FRISCO are constructed using the bit operations BIT-AND and BIT-OR.
    The bits in INTERSECT and UNION are read one by one and evaluated in two DO loops. For each position in the fields with the value 1, a READ statement retrieves the airline code from the table CARRIER.
    Comparing Bit Sequences
    Use the following three operators to compare the bit sequence of the first operand with that of the second:
    <operator>
    Meaning
    O
    bits are one
    Z
    bits are zero
    M
    bits are mixed
    The second operand must have type X. The comparison takes place over the length of the second operand. The first operand is not converted to type X.
    The function of the operators is as follows:
    O (bits are one)
    The logical expression
    <f> O <hex>
    is true if the bit positions that are 1 in <hex>, are also 1 in <f>. In terms of set operations with bit sequences, this comparison is the same as finding out whether the set represented by <hex> is a subset of that represented by <f>.
    Z (bits are zero)
    The logical expression
    <f> Z <hex>
    is true if the bit positions that are 1 in <hex>, are 0 in <f>.
    M (bits are mixed)
    The logical expression
    <f> M <hex>
    is true if from the bit positions that are 1 in <hex>, at least one is 1 and one is 0 in <f>.
    Caution: The following programs are no longer supported in Unicode systems:
    REPORT demo_log_expr_bits .
    DATA: text(1) TYPE c VALUE 'C',
          hex(1) TYPE x,
          i TYPE i.
    hex = 0.
    DO 256 TIMES.
      i = hex.
      IF text O hex.
        WRITE: / hex, i.
      ENDIF.
      hex = hex + 1.
    ENDDO.
    The output is as follows:
    00          0
    01          1
    02          2
    03          3
    40         64
    41         65
    42         66
    43         67
    Here, the bit structure of the character 'C' is compared to all hexadecimal numbers HEX between '00' and 'FF' (255 in the decimal system), using the operator O. The decimal value of HEX is determined by using the automatic type conversion during the assignment of HEX to I. If the comparison is true, the hexadecimal number and its decimal value are displayed on the screen. The following table shows the bit sequences of the numbers:
    Thanks
    Ashok

  • Using Unix command lines in java code

    I was wondering if there was a way to run a unix command in java code. I know in C++ there is popen, but i don't know of a way in java. The command i need to run is the whois "domain name" command. Any help would be great!
    jarad

    try something like this:
      public static String whois(String domain) throws IOException {
        BufferedReader is = null;
        Process p = null;
        String result = "";
        p = Runtime.getRuntime().exec("whois " + domain);
        is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while((line = is.readLine()) != null)
          result += line;
        return result;
      }

  • Unix Command to search file

    Hi
    Can anyone tell me how to get filename from server using
    UNIX command in ABAP program.I have requirement to search file in server using date criteria.
    should i use 'FIND' command to search file??
    Plz do needful..

    You need to use SM69 to define command and use it in your report.
    Regards,
    Christophe

  • How to generate a empty file in AL11 using ABAP and unix command

    Hi Experts,
    when load infopackage triggers it will search file from AL11 if file is available it will get loaded successfully.  When there is no file in AL11 error while opening file (orgin A) and the load will fail.  At this level i have to write a abap code using unix command to generate a empty file.
    Is there any way to achieve the above requirement.
    Thanks
    Vara

    Hi,
    If i get your requirement properly then you want to create a blank file if there is no file on the application server so that your infopackage does not fail, am i correct.
    If this is your requirement then this can be easily done if you use process chain to load the file via infopackage. Follow the following steps:
    1. Add a ABAP program before the infopackage and check if the file is present on the server or not. Use a simple ABAP statement OPEN DATASET <FNAME>. Check the SY-SUBRC after this statement if it is not 0 then it means that the file does not exist on the application server.
    2. Once you have established that the file is not present create a flat file using a code similar to the below one
    OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                          MESSAGE D_MSG_TEXT.
    IF SY-SUBRC NE 0.
      WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
      EXIT.
    ENDIF.
    * Transferring Data
    LOOP AT INT_table.
      TRANSFER INT_table-field1 TO FILENAME.
    ENDLOOP.
    * Closing the File
    CLOSE DATASET FILENAME.
    3. Add your infopackage step after this ABAP program in your process chain.
    I hope this helps.
    Best Regards,
    Kush Kashyap

  • To execute from ABAP code an external Unix program

    HI,
    I would like to know how to execute from ABAP code an external Unix program and check for a return code?

    HI,
    There are different ways to this:
    (1) OPEN DATASET <file> FOR OUTPUT 'unix command'
    CLOSE DATASET <file>
    This command executes the unix command and writes the output into <file>
    Look into OSS Note 9391.
    (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. 
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • Command in ABAP Editor to improve the source code

    Which command in ABAP Editor to be used to improve the readability of the program code ?plzz tell
    Edited by: Alvaro Tejada Galindo on Feb 13, 2008 3:48 PM

    Use Pretty Printer or do a CTRL+F1.
    Also u can change the settings of the way u want preety printer to behave by
    going in the Settings->Abap Editor -> Pretty Printer

  • Working Code from Unix Command, needs fixing!

    /* Codes needs modification to run and display in GUI, will run and produce output in terminal, but will not display in GUI with setText and getText */
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class UnixCommand extends JFrame
    private JComboBox comboBox;
    private JTextArea displayArea;
    private JPanel mainPanel, displayPanel, comboPanel;
    private String names[] = { "Check Processes", "Check Network Connectivity",
                        "Check Remote Users", "Check Share Devices" };
    TitledBorder selectBorder, displayBorder;
    public UnixCommand()
         super( "Unix Command Tools in GUI" );
         Container container = getContentPane();
         mainPanel = new JPanel( new BorderLayout() );
         container.add( mainPanel );
         displayPanel = new JPanel();
         comboPanel = new JPanel();
              mainPanel.add( displayPanel, BorderLayout.CENTER );
              mainPanel.add( comboPanel, BorderLayout.NORTH );
                   comboBox = new JComboBox( names );
                   comboBox.setMaximumRowCount( 3 );
                   comboPanel.add( comboBox );
                        selectBorder = BorderFactory.createTitledBorder( "Select the Task to Perform" );
                        selectBorder.setTitlePosition( TitledBorder.TOP );
                        comboPanel.setBorder( selectBorder );     
                   displayArea = new JTextArea( 22, 40 );
                   displayPanel.add( displayArea );
                        displayBorder = BorderFactory.createTitledBorder( "The Command Output Selected" );
                        displayBorder.setTitlePosition( TitledBorder.BOTTOM );
                        displayPanel.setBorder( displayBorder );
    String s = null;
         displayArea.setText("\tHere is the standard output of the command:\n");
    try
                             // run the Unix "ps -ef" command
    Process p = Runtime.getRuntime().exec("ps -ef");
    BufferedReader stdInput = new BufferedReader(new
    InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new
    InputStreamReader(p.getErrorStream()));
                        // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null)
    System.out.println(s);
                        // read any errors from the attempted command
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null)
    System.out.println(s);
    System.exit(0);
    catch (IOException e)
         System.out.println("exception happened - here's what I know: ");
         e.printStackTrace();
         System.exit(-1);
    setSize( 500, 500 );
    setVisible( true );
    public static void main( String args[] )
         UnixCommand application = new UnixCommand();
         application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }

    All files are regenerated if changed.
    That goes for the .java and the .class files that are created. The jsp server checks to see if the current version is the latest. If it is, nothing gets changed or recompiled. If things are different, programs are recompiled.
    Youll notice that if you have a new jsp it always takes longer the first time. Or even when you change a jsp, the first time takes the longest for the page to come up in a browser. This is because of recompiling.
    Does this make any sense?
    Adam

  • *"Wrong process return code"* Unix Command

    Hi,
    I have created Package with Procedure having Unix command.Unix command is only to cp data file from one folder to another archive folder.
    we are defining variable FilePath and FileName.
    cp #FILE_PATH/#FILE_NAME.tag #FILE_PATH/archive/;
    But while running this we are getting following erorr.
    *"Wrong process return code"*
    Plz suggest.
    Thanks
    Ashwini

    Hi Aswini-
    You should not use # symbol for your variable pointers, it will take as a comment line. Please use the below syntax:
    FILE_PATH=c:\temp
    FILE_NAME=test.txt
    cp $FILE_PATH/$FILE_NAME.tag $FILE_PATH/archive/
    And also you can check the exact error by executing the script file in your unix command prompt like this:
    /home/test/test.sh
    Hope this will work for you.
    Thanks,
    Saravanan Rajavel

  • Calling an Unix command on Remote sun Server in a Java Code

    Hello All
    I have an Java Application which is run on windows server (I)
    I have another Sun Server (II)
    I want to call an unix command on server(II) from java application which is on server(I)
    I am using Samba Server in order to share files between Windows Server and Unix Server
    Can I use samba in order to call command
    or is there any way to open an telnet session within java application
    I will be grateful if you give me some suggestion on this issue
    Regards
    BEKIR BALCIK
    Argela Technologies ...

    Can I use samba in order to call commandYes, smaba supports "magic" files that cause a program to be executed when they are accessed. Note, this does not provide for arguments but you can put these in a file which you command reads.
    or is there any way to open an telnet session within java applicationYes. just use a Socket connection.

Maybe you are looking for

  • Java Programming Problem

    Hi all, I was looking for this java programming problem which had to do with a large building and there was some gallons of water involved in it too somehow and we had to figure out the height of the buiding using java. This problem is also in one of

  • Maximum installable ram for ibook g4 800mhz?

    i get conflicting answers...can i install 1g of ram into this thing?

  • Oracle 9i ignores INDEX hint

    Hello, I try to convince Oracle to do a index scan rather then a full table scan in a query. To do this I created a view on top of the table which simply adds this hint: CREATE OR REPLACE VIEW V_FHDDSC3_FACT_DATA_4WEEK AS SELECT /*+ INDEX(T P_FHDDSC3

  • 802.1X Inaccessible Authentication Bypass

    On a 4506-E switch with supervisor engine 6L-E running IOS version 12.2(54)SG1, the command to enable Inaccessible Authentication Bypass is not available.  The interface configuration mode command is supposed to be "dot1x critical".  Has it changed t

  • Can't find old profile, was it deleted by updating?

    win 7 pro, old computer was hit by lightning, hd was ok. replaced computer & had all files transfered to new computer, still can't get old profile, address book & emails w/ folders. where to look? tried search on start no luck just current profile