Professional Documents
Culture Documents
This article explains how to create a external OS command in SAP through transaction SM69 and execute it using
ABAP.
Here, as an example we will create a OS command for renaming application server files in SAP. Steps below:
Go to transaction SM69, hit on the create button and proceed as shown in the below screen shot:
Now, you can execute the command by hitting the "Execute" button. And below is a code snippet to execute this OS
command from ABAP:
report z_exe_oscmd.
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.
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.
*&---------------------------------------------------------------------*
*& Report ZYA_MOVE_FILE
*&
*&---------------------------------------------------------------------*
report zya_move_file.
In move a file in SAP directories(AL11) from source path to target path post i have tried to explain,
how a file could be transported from one SAP server path to another SAP server path. Lately one of
my friend asked me how to transport from a local path to SAP server path. I directly suggested
CG3Y and CG3Z transactions. But as it was a BW system these transactions were not existing in
their SAP component.
Afterwards we
found ARCHIVFILE_SERVER_TO_CLIENT and ARCHIVFILE_CLIENT_TO_SERVER. These are
exactly doing what CG3Y and CG3Z transactions do. They have source and target paths as inputs
and populating these two fields they are directly doing the move operation.
Various ways for File Moving from one folder to
other on application server
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:
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.
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.
Else.
Endif.
Disadvantages
Data is handled while moving file
Advantages :
o No file data handling
o Time taken is less as we using system command to move file
Disadvantages:
o We need create Operating system command in T code SM49
Advantages:
o Standard Function Module is used for file archival
Disadvantages
o File names passed to Function Module should be logical paths to file
o 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-eb5bce1f9228?QuickLink=index&overridelayout=true&47519518718715
Creation of External Commands with the help of
UNIX Coding in SAP
Table of contents
Introduction
Create the command in SM49
Create the ABAP program which calls SXPG_COMMAND_EXECUTE
Result
Other links
Introduction
This gives an overview on how to create the External Commands using SM49, assigning UNIX (or
other operating system) file or using a UNIX Command and implementing them. Below given is the
step by step approach to the same.
v_dir_input = './sap/tmp'.
Result
T_RESULT will contain the list of files in the specified directory after execution of the function
module.
Example of result:
LENGTH MESSAGE
LENGTH MESSAGE
10 adm_script
7 backups
3 bin
4 boot
4 data
3 dev
7 distrib
3 etc
Other links
SAP Library - Programming Techniques (about SXPG_* function modules)
Move a file from source to target directories