Vous êtes sur la page 1sur 11

27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner

About
About

Home / Community / Blogs + Actions

File operations in SAP Application server


(AL11) using UNIX Command
March 9, 2014 | 1,626 Views |

Vishnudas N.M
more by this author

BW (SAP Business Warehouse)

share
0 share
0 tweet share
0 0
like

Follow

File operations in SAP Application server


(AL11) using UNIX Command
Applies to:

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 1/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

SAP BW 3.5, BI 7.0

Summary

This paper demonstrates how to implement basic file operations like


move, merge and delete files in SAP Application server (AL11) by calling
UNIX script file through OS commands and to automate the OS
command through process chain.

Introduction

UNIX shell

A Unix shell is a command language interpreter, the primary purpose of which is

to translate command lines typed at a terminal into system actions. The shell

itself is a program through which other programs are invoked. The shell has

some built-in functions, which it performs directly, but most commands that you

enter cause the shell to execute programs that are external to the shell. This

sets the shell apart from other command interpreters, because it is just another

user program at the same time that it functions almost exclusively as a

mechanism for invoking other programs. With Shell we can use standard UNIX

commands as building blocks to create new commands.

External Commands

An external command is a pre-defined operating system command that can


be executed within the SAP system. Both the maintenance and execution of
external commands is protected with SAP authorizations. You can maintain
and execute external commands in dialog (from the CCMS menu) or in
ABAP programs, using special function modules. External commands can
also be executed as a step in a background job.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 2/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

As the CCMS administrator, you can modify commands and activate


additional security mechanisms without having to change the program. You
can add your own commands and parameters to the variety of (pre-defined)
commands delivered by SAP

Business Scenario

There can be scenarios to perform basic file operations (like move, merge,

Zip, delete etc.) on files generated in AL11 via Open hub destinations or APDs.

These operations can be achieved in SAP BW by direct use of UNIX

commands in OS command or calling UNIX script file through OS command.

Consider that an open hub destination is generating .csv file in AL11. Every time
when you run the DTP for that Open hub it will overwrite the existing file which
was already generated. So if we need to retain the previously generated file,
then every time when a file is generated we can move it to a new file with time
stamp in the file name. There can be a requirement to merge files generated in
AL11 to a single file before sending out of SAP BW. Similarly as a part of data
retention & clean up activity it may be required to delete older files.

Procedure to implement the above scenarios

In this approach we will create a UNIX script file (UNIX commands for the
file handling operations are written in this file) and access this UNIX script
file through OS command.

Following steps will demonstrate how to achieve the above mentioned


scenarios.

Step 1:

Create UNIX script file containing UNIX commands for performing the required
file handling operations.

Write the UNIX script in notepad and save it as .sh file format.

Below provided sample code will merge two files (FILE1 and FILE 2) into a
single file with a new name (MERGERFILE) and timestamp. It will also delete
files with name starting MERGEFILE in AL11 older than 30 days.

Sample code:

timestamp=$( date +%Y%m%d%H%M%S ) */ Assign server


time stamp to variable timestamp.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 3/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

cat /var/opt/sapbi/FILE1.txt /var/opt/sapbi/FILE2.txt > /var/opt/sapbi/


MERGEFILE$timestamp.txt

*/ Combine the data in FILE1 & FILE2 present the path /var/opt/sapbi/
into a new file and the new file will have name MERGEFILE preceded
by the timestamp at which it was generated.

find /var/opt/sapbi/ -type f -name MERGEFILE*.txt.gz -mtime +29 -


exec rm {} \;

*/ Files having name starting with MERGEFILE and older than 30 days
present in the path /var/opt/sapbi/ in AL11 will be deleted

Upload the unix script file into Application server (AL11).

Function module: ARCHIVFILE_CLIENT_TO_SERVER can be used to


upload.

UNIX command syntax used and its meaning:

cat [path of file1] [path of file2] > [path of merged file] : This command
will merge the mentioned files present in the given path and make a new
merged file in the mentioned path with the given name.

gzip [path of file] : this command will zip the file.

Step 2:

Go to Tcode SM69 and click on create button to create OS command as


shown below:

Enter the details:

Command name: Give a name for the command.

Operating system command: sh

Parameters for operating system command: enter the UNIX script file
path.

Command sh will trigger/execute the script file mentioned in the


parameter box.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 4/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Below are the screenshots of application server:

UNIX script file Script.sh is uploaded in AL11

FILE1 & FILE2 present in AL11. This may be generated by open hub
destinations or APDs or flat file loads.

Data in FILE1:

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 5/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Data in FILE2:

Click on Execute button after opening the OS command in SM69 to execute it.

Merge file generated in AL11 after execution of the OS command.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 6/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Data in Merge File:

If gzip command is used, then generated file will be zipped and will have
extension as.gz

If this file handling has to be done after the execution of Open hub DTPs or
APD execution or flat file load via process chain, then this can be added in to
the process chain flow.

OS command process type in Process chain can be used for this.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 7/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Inside the process variant enter the OS command Name & details which was
already created.

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 8/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

So when the process chain executes this step, it will trigger the OS command &
which in turn will trigger the UNIX script script.sh and the file handling
operations will be carried out.

Alert Moderator

10 Comments

Suman Chakravarthy K

March 9, 2014 at 6:41 am

Nicely explained with screen shots. Thanks for sharing this scenario. It may come
handy whenever I come across this similar scenario.

Matthew Jones

March 24, 2014 at 4:19 pm

Hi Vishnu,
Good Work, Its a nice that you have shared a document which is realy helpful for us.
Thanks!

Sharmila Selvaraj

March 25, 2014 at 5:42 am

Very Helpful document!!

Shruti Suresh

March 26, 2014 at 6:22 am

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 9/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

Good Work Vishnu!

Ameya Bobhate

March 26, 2014 at 6:32 am

Thank you!

Sriram Suresh Kumar

April 3, 2014 at 2:31 pm

Thats very helpful

Ninu Sankar

February 3, 2015 at 9:39 am

Thank you for the good explanation. Very helpful.


Regards,
Ninu

Mohan Babu K J

September 22, 2015 at 11:18 pm

Hi Vishnu,
Thanks for sharing. Do you have any similar wiki for decrypting gpg file? Im not able
to execute from SM69. Do I need to have Script file for that as well?
Regards,
MB

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 10/11
27/7/2017 File operations in SAP Application server (AL11) using UNIX Command | SAP Blogs

KD Jain

September 23, 2015 at 1:00 am

Hi Vishnu,
Very nice document and Thanks for sharing, Definitely it gonna use someday.
Thanks,
KD Jain

Prakash K

October 16, 2015 at 7:52 am

Hi Vishnu,
Great work.
BR,
Prakash

Add Comment

Share & Follow


Privacy Terms of Use Legal Disclosure Copyright Trademark Sitemap Newsletter

https://blogs.sap.com/2014/03/09/file-operations-in-sap-application-server-al11-using-unix-command/# 11/11

Vous aimerez peut-être aussi