Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Business Requirement

Move file on application server (T coade AL11) from one folder to another folder

Implementation Logic in BW

This can be achieved in BW in three different ways:

  1. Using Trasnfer dataset statement
  2. Using external operating system commands
  3. Using function module ‘ARCHIVFILE_SERVER_TO_SERVER’

Logic

Case 1: Using Transfer Dataset statement

ABAP Code

PARAMETERS: PS_dir(50)  TYPE C ,
                            pa_dir(50)  TYPE c

                          PF_name(50) TYPE C OBLIGATORY LOWER CASE.

DATA: L_OLDFILE type localfile,
            L_NEWFILE type localfile,

                L_NEWLINE(240) type c,

Concatenate  ps_dir pf_ name  into l_oldfile.

Concatenate pa_dir pf_name into l_newfile.

OPEN DATASET  l_oldfile FOR INPUT IN BINARY MODE.

    If sy-subrc = 0.

                OPEN DATASET l_newfile FOR OUTPUT IN BINARY MODE.

                If sy-subrc = 0.

              DO.
                                READ DATASET l_oldfile INTO l_newline.
                                IF sy-subrc EQ 0.
                                              TRANSFER l_newline  TO l_newfile.
                                ELSE.
                                              if l_newline is not initial.
                                                      TRANSFER l_newline TO l_newfile.
                                              endif.
                                              EXIT.
                                ENDIF.
                ENDDO.

                Endif.

                CLOSE DATASET l_newfile.

          Else.

                Message ‘Can not open source file’ type ‘E’.

          Endif.

CLOSE DATASET l_oldfile.

DELETE DATASET  l_oldfile.

Advantages of this approach:

                Simple Process which transfers data in set of 240 characters

Disadvantages

                Data is handled while moving file

                For large files program will take more time

Case 2: Using External Operating System Command

ABAP Code

PARAMETERS: p_src TYPE sapb-sappfad,
                          p_tgt TYPE sapb-sappfad.

DATA: l_para TYPE btcxpgpar,
            l_stat(1)  TYPE c.
CONCATENATE p_src p_tgt INTO l_para SEPARATED BY space.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
 
EXPORTING
    commandname                        =
'ZMV'
    additional_parameters              = l_para

IMPORTING
  status                              = l_stat
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
  wrong_asynchronous_parameters      =
12
  cant_enq_tbtco_entry                =
13
  jobcount_generation_error          =
14
 
OTHERS                              = 15
          .IF sy-subrc <> 0.
 
MESSAGE 'Error' TYPE 'E' DISPLAY LIKE 'I'.
ELSE.
 
if l_stat = 'O'.
   
message ‘File Archived successfully’ type 'I'.
  endif.
ENDIF.


Advantages :

No file data handling

Time taken is less as we using system command to move file

Disadvantages:

We need create Operating system command in T code SM49

Case 3: Using Function module ‘ARCHIVFILE_SERVER_TO_SERVER’

ABAP Code:

PARAMETERS: p_src TYPE sapb-sappfad,
            p_tgt TYPE sapb-sappfad.

CALL FUNCTION 'ARCHIVFILE_SERVER_TO_SERVER'
 
EXPORTING
    sourcepath            = p_src
  targetpath            = p_tgt* IMPORTING*  LENGTH                =
EXCEPTIONS
  error_file            =
1
  no_authorization      =
2
 
OTHERS                = 3
          .IF sy-subrc <> 0.
 
WRITE : 'Error in archival', sy-subrc.
ELSE.
 
WRITE 'File archived successfully'.
ENDIF.

Advantages:

Standard Function Module is used for file archival

Disadvantages

File names passed to Function Module should be logical paths to file

How to create logical path for file is given in below link

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60e86545-9940-2d10-9f89-eb5bce1f9...

4 Comments
Labels in this area