Skip to Content
avatar image
Former Member

ABAP: Copy files from one R3 directory to another

Hi All,

I'm looking to copy files from one R3 directory to another. For example, I want to copy files from /com/out to /com/tmp, but I want to ensure that the files remain in /com/out.

I'm not an avid ABAP'er, but I just wanted to know if there's a way to do this.

Will reward with full points - Thanks,

John

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

7 Answers

  • Best Answer
    Oct 09, 2007 at 07:30 PM

    Hi,

    Please use FM ARCHIVFILE_SERVER_TO_SERVER or PFL_COPY_OS_FILE.

    Regards,

    Ferry Lianto

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 07:29 PM

    Hi

    check the Tcodes

    CG3Y and

    CG3Z

    for transferring files from application to presentation and viceversa

    also see the fiels in AL11 tcode

    we can take the files to an harddisk/external drive and can transfer into another system also.

    Regards

    Anji

    Message was edited by:

    Anji Reddy Vangala

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 07:29 PM

    Use SM69 or SXDB.

    Regards

    Aneesh.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 07:32 PM

    Give this a try:

    REPORT ztest .
    
    DATA: BEGIN OF itab OCCURS 0,
            field(256),
          END   OF itab.
    DATA: dsn_o(100) VALUE '/com/out',
          dsn_n(100) VALUE '/com/tmp'.
    
    OPEN DATASET dsn_o FOR INPUT IN BINARY MODE.
    
    DO.
      READ DATASET dsn_o INTO itab-field.
      IF sy-subrc = 0.
        APPEND itab.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
    
    OPEN DATASET dsn_n FOR OUTPUT IN BINARY MODE.
    
    LOOP AT itab.
      TRANSFER itab-field TO dsn_n.
    ENDLOOP.
    
    CLOSE DATASET dsn_n.

    Rob

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 12:55 PM

    As hinted at above, I'd set up a logical command using SM69 (as "copy" would be different in Windows vs Unix), e.g. Y_FILE_COPY, and then use something like the code below.

    Jonathan

     data:
        l_result(255)  type c,
        l_status       like extcmdexex-status,
        l_parm         like sxpgcolist-parameters,
        lt_prot        like btcxpm occurs 10 with header line.
    
      concatenate i_filename i_target_directory into l_parm
        separated by space.
    
      call function 'SXPG_COMMAND_EXECUTE'
           exporting
                commandname                = 'Y_FILE_COPY'
                additional_parameters      = l_parm
                trace                      = ' '
           importing
                status                     = l_status
           tables
                exec_protocol              = lt_prot
           exceptions
                command_not_found          = 01
                no_permission              = 02
                parameters_too_long        = 03
                parameter_expected         = 04
                program_start_error        = 05
                program_termination_error  = 06
                security_risk              = 07
                too_many_parameters        = 08
                wrong_check_call_interface = 09
                x_error                    = 10
                others                     = 11.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 22, 2007 at 12:20 PM

    this can be done easily by script at OS level rather than in ABAP, that would be the easier solution. Check with your BASIS guy

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 16, 2009 at 03:43 AM

    Hi All,

    I feel that i will get answer here, i tried past 30 days i never found correct answer

    I have a file with document no& revision in external server which is not in SAP.

    I have created command line in MS-dos(os command) to get the file to SAP server.

    Now the problem is how i can call this external command in SAP ABAP program because i want to get every time based on document no & revision of the document and trigger external command get the pdf from external server and print locally.

    here question how to call external command in SM69 i tried but it is not working....and another question is how to pass variable in command line (external command ) by ABAP program i am getting document no & revision in SAP based on this i want to get pdf from external server.

    Please help to do this in ABAP.. If you have any Sample program please provide me.

    Thanks,

    Harikiran

    Edited by: harikiran mitnala on Nov 16, 2009 11:43 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      One year lataer...

      Try the following if you are still interested and not running the program in batch mode:

      CALL METHOD cl_gui_frontend_services=>file_copy

      EXPORTING

      SOURCE =

      destination =

      • overwrite = SPACE

      • EXCEPTIONS

      • cntl_error = 1

      • error_no_gui = 2

      • wrong_parameter = 3

      • disk_full = 4

      • access_denied = 5

      • file_not_found = 6

      • destination_exists = 7

      • unknown_error = 8

      • path_not_found = 9

      • disk_write_protect = 10

      • drive_not_ready = 11

      • not_supported_by_gui = 12

      • others = 13

      .

      IF sy-subrc <> 0.

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

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

      ENDIF.