Al 11
Al 11
Al 11
A to Z of AL11 Operations
By Swapnaja Bhandare - May 20, 2019
Shares
With A to Z of OLE Excel in ABAP 7.4 we explored a lot about excel file in SAP.
GUI_DOWNLOAD/UPLOAD is also very straight forward. But whenever I get requirement to
read multiple files from application server, do processing and store multiple files on another
server… well it stressed me hard in the beginning.
The other day one junior asked me, when we have GUI_DOWNLOAD and UPLOAD, then why
do we need to save file in AL11. I had to say one line, so that you can shut down your
laptop and go to sleep and when you come in the morning the files would be ready for you
to review in AL11. He did not understand my abstract sentence and I am sure, many of you
might also be wondering what I wrote.
Answer: Jobs can be scheduled in background mode not only at the current time, but it can
also be scheduled for future time. If you schedule a background job which does
GUI_DOWNLOAD/UPLOAD, your program would dump or cancel out. The reason being, SAP
did not want to take chance. GUI_DOWNLOAD/UPLOAD needs your laptop/computer to be
switched on for it to save the data in the presentation server path. Say you scheduled a job
which has GUI_DOWNLOAD/UPLOD and switched off your laptop and went to bed. When the
job actually triggers, where will it save the file since your laptop is switched off? Do
you get the catch 22 situation?
Therefore SAP came with Application File Concept (although not just for background job).
Now, let us do the same exercise. You have OPEN DATASET (for AL11) syntax in your
program. You schedule a job. Switch off your laptop and go to sleep. In the middle of the
night,
Shares the job triggers and it saves the file in Application Server (AL11). It is not dependent on
your local laptop or desktop. It is at the Server level and Servers normally never sleep (except
at planned outage or downtime).
Although the File Directory (AL11) concepts are well known to all of us, we always Google for
the syntax/tcode/FMs and use them without worrying much about the details and concepts
behind the scene (especially lazy programmers like me).
So I thought of doing a favor to myself. Next time I need anything related to T-Code AL11 i.e.
SAP Directories, I will not Google. Instead, I will come to this SAPYard page directly where I
have listed almost everything we do in AL11. This should be a one stop page for not only all
ABAP developers, but also the Basis Team and the Functional/Business team should also find it
enriching.
In this article we will try to cover everything about AL11. What AL11 is all about? How to
create folder in AL11? Ways to download files from AL11 and upload multiple files into
AL11? How to delete files etc. As the title suggests, this is A to Z of all AL11 Operations.
1 Wh t i AL11
https://sapyard.com/a-to-z-of-al11-operations/ d h t i it’ ? 2/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Shares
Name of Directory Parameter: Contains the directory names. It can contain multiple folders
and files.
Just for sake of a complete document, I coaxed one of my Basis friends in this crime. See I
have secret contacts in the SAP Administration and Security Team. My Basis friend was kind
enough to provide the below steps. Now, I am wondering what would be the return price I
need to pay for this favor. Just kidding. Tell me what you want. Open offer for you.
https://sapyard.com/a-to-z-of-al11-operations/ 3/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Basis folks and some privileged ones who have the authorization, log into the SAP Server
System and create Folders and File. Just like how we create Folders and Files in our
Windows/MAC Laptop and PC. As simple as that.
Below is a screenshot of one such SAP Server System. It looks like normal Windows Folder.
Right? But look closely. It is not part of the Windows operating system. It is another Server. If
they create a folder in this Server, we can see that same folder in AL11 t-code in SAP.
Shares
https://sapyard.com/a-to-z-of-al11-operations/ 4/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Shares
https://sapyard.com/a-to-z-of-al11-operations/ 5/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Shares
If you double click on this, you will see one file in it as I already created it.
That’s all. These directories are nothing but folders and as easy as right click and create new
https://sapyard.com/a-to-z-of-al11-operations/ 6/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
This is also not part of ABAP work. Only Basis teams have authorization to create it. And this is
nothing but creating new subfolder under our main folder in application server. Whereas main
folder works like directory and subfolder works like folders/subdirectories in AL11.
Whatever locations on server system, where we are creating folders are called as Physical
Paths of directories.
If main
Shares folder/directory is already configured then there is no need to configure the sub
directory again after addition of subfolders. Those would be displayed in AL11 directory path
automatically.
After hitting this T-Code CG3Z, you will get below screen.
https://sapyard.com/a-to-z-of-al11-operations/ 7/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Source file on front end: Select your file from your laptop or desktop system and put it in
this parameter.
Target file on application server: Provide path of file location in the AL11 directory.
Overwrite file: If it is checked, whatever file name you provided in target file parameter, if it
exists in AL11, it will be overwriting with provided file else it will create new file there.
I have provided below details:
Shares
Let’s check in AL11 folder now. We can see our file test.xls is created here.
Note: We can ONLY read Doc or Txt files directly by double clicking on the file in AL11 but we
can’t read XLS or XLSX files directly. XLS File will give below error.
This error comes because .XLS is a proprietary format of Microsoft. So, unless you have
dd ll d S
https://sapyard.com/a-to-z-of-al11-operations/ S ’ d Sfl f l S 8/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
some addons installed on SAP Server, you can’t read XLS files from Application Server.
Do not worry. That is not the end of the world. If you really want to read the XLS file, you can
download the file to your local machine (laptop/desktop) and then you can open and read it.
This brings us to question. How to download AL11 files? Please be patient. It will be covered in
the later sections in this article.
Here we are still covering how to create Folders/Files in AL11. Let’s look the second way.
As an ABAP Programmer, usually we do not play with t-codes. We want everything should be
done by our code. That gives us more sense of Power.
Sometimes
Shares we get requirement to upload multiple files on application server in a single go
with some conditions. Let us look into one practical example:
Suppose I have a requirement to collect data from EKKO and EKPO tables and prepare
multiple files for each new PO (EBELN) and store them on AL11 path. Each file should have PO
number as file_name.
First, we will select data from EKKO and EKPO tables and stores them in one internal table.
<code>*** Popoluate tables
SELECT ebeln,
bukrs,
bstyp,
bsart
INTO TABLE @DATA(gt_ekko)
FROM ekko
UP TO 15 ROWS
WHERE ebeln LIKE '45%'.
IF gt_ekko[] IS NOT INITIAL.
SELECT ebeln,
ebelp,
matnr,
https://sapyard.com/a-to-z-of-al11-operations/ 9/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
bukrs
INTO TABLE @DATA(gt_ekpo)
FROM ekpo
FOR ALL ENTRIES IN @gt_ekko
WHERE ebeln = @gt_ekko-ebeln
ORDER BY PRIMARY KEY.
ENDIF.</code>
All folders of an application server are stored in the database table FILEPATH. We can pass
our directory/folder name there and can confirm whether the folder exists or not.
<code>CONSTANTS: lc_filename TYPE filepath-pathintern
VALUE 'ZMM_BATCH_DATA_FOR_ASPECT'.
SELECT SINGLE pathintern
FROM filepath
INTO @DATA(lv_logical_path)
Shares
WHERE pathintern = @lc_filename.</code>
<code>CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
logical_path = lv_logical_path
file_name = lv_file_post
IMPORTING
file_name_with_path = lv_filepath
EXCEPTIONS
path_not_found = 1
missing_parameter = 2
operating_system_not_found = 3
file_system_not_found = 4
OTHERS = 5.</code>
Now using OPEN DATASET, we can open the file to write fetched data from EKPO into it.
<code>"Open the file to write.
OPEN DATASET lv_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. </code>
Mode ‘Output’ is used for writing data in application server file (all dataset concepts are
explained in the 5th point below).
https://sapyard.com/a-to-z-of-al11-operations/ 10/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Now using TRANSFER and CLOSE DATASET concept, we can pass all relevant data to
corresponding files, save them and take exit from the files.
<code>REPORT zal11_working.
By using COMMAND-BREAK statements (AT END OF), I have achieved to create new file for
new PO. The output is like below:
Shares
As shown above, these are different files with different POs. If you open any file, you can get
header text line as well as values of cells.
Shares
Source file on application server: Provide the path of file location from AL11 directory
which you need to download.
Target file on front end: Provide the file name from your system (can be new file) and
put it in this parameter.
Overwrite file: If it is checked, whatever file name you provided in target file parameter, if
it exists in system, it will be overwriting with provided file else it will create new file there.
Transfer format for data: Usually ASC format works. Do check your requirement. You
might need BIN as well.
https://sapyard.com/a-to-z-of-al11-operations/ 14/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
As I wanted to save/download test excel file from application server to my desktop, I have
provided below details:
Shares
It will create test file on the desktop and if it is already present then will overwrite it.
If the file is not so long, you can directly download the content from AL11. Navigate to the file.
Then Open the file. On System Menu, go to List->Save/Send/Local file:
Answer: In some case, the exported file is truncated. For List export in AL11, the limit is 512
characters. Apply SAP Note 952766 to increase the limit in AL11.
Now if we have complex requirement like reading/downloading multiple files and do some
calculation and massaging of data from the AL11 file then we need to create an ABAP
program.
For downloading the file from application server, we must know the below concepts:
Shares
a) OPEN DATASET:
<code>OPEN DATASET dset FOR access IN mode [position]
[os_additions]
[error_handling]. </code>
Input: It opens the file for reading. If the file does not exist, the sy-subrc is set to 8.
Output: Opens the file for writing. If the file exists, the content will be deleted
and replaced. If the file does not exist, the file will be created.
Appending: It opens the file for appending. The new content will be added to the end of
existing file or the file will be created if it does not exist. SY-SUBRC = 4 will be triggered
if appending is not successful.
Mode: You can specify which mode you want to read the file like binary or text.
https://sapyard.com/a-to-z-of-al11-operations/ 16/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
ii) TRANSFER DATASET: This statement passes the content of data object dobj to the file
specified in dset.
Syntax:
<code>TRANSFER dobj TO dset [LENGTH len]
[NO END OF LINE]. </code>
The file must be open for writes, appends, or changes. If a closed or invalid file is accessed, a
handleable exception is raised.
iii) CLOSE DATASET: This statement closes the file specified in dset.
Syntax:
Shares
<code>CLOSE DATASET dset.</code>
If the file is already closed or does not exist, the statement is ignored and the return code sy-
subrc is set to 0.
An opened file that was not explicitly closed using CLOSE DATASET is automatically closed
when the program is exited.
Did I bore you to death with too much of theories?? ufff.. Even I am tired, so I can understand
your plight.
Let’s bring some charm to our learning with the below examples:
In the point 4 above, we created multiple files on our application server now. Let’s read them
all. Here I have passed only one file for demonstration. You can make it dynamic as well by
passing all file names:
<code>DATA:v_file LIKE v_excel_string VALUE 'E:\Interfaces\ZMM_BATCH_DATA_FOR_ASPECT\4500000
*--- read the file from the application server
OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.</code>
Open the file in READ mode. We can read each line from the file in a loop and split the data
https://sapyard.com/a-to-z-of-al11-operations/ 17/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
<code>DO.
READ DATASET v_file INTO wa_tab.
IF sy-subrc IS INITIAL.
CLEAR it_string[].
SPLIT wa_tab AT delimiter INTO TABLE it_string.
LOOP AT it_string ASSIGNING FIELD-SYMBOL(<fs>).
ASSIGN COMPONENT sy-tabix OF STRUCTURE wa_tab2 TO FIELD-SYMBOL(<fs_f>).
IF sy-subrc = 0.
<fs_f> = <fs>.
ENDIF.
AT LAST.
APPEND wa_tab2 TO it_tab2.
ENDAT.
ENDLOOP.
ELSE.
EXIT.
ENDIF.
Shares
ENDDO. </code>
After receiving the data in an internal table, we can CLOSE the file using CLOSE DATSET
syntax:
<code>CLOSE DATASET v_file.</code>
Here I have used ALV factory method to display the results in ALV format. Below is the whole
executable program:
<code>REPORT zal11_working.
*--- Type structure declaration.
TYPES: BEGIN OF ty_tab1,
ebeln TYPE string,
ebelp TYPE string,
matnr TYPE string,
bukrs TYPE string,
END OF ty_tab1.
*--- work area and internal table declaration.
DATA : it_tab TYPE STANDARD TABLE OF alsmex_tabline,
wa_tab TYPE alsmex_tabline,
it_tab2 TYPE STANDARD TABLE OF ty_tab1,
wa_tab2 TYPE ty_tab1,
it_string TYPE TABLE OF string.
https://sapyard.com/a-to-z-of-al11-operations/ 18/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
*--- variable declaration
DATA: v_excel_string(2000) TYPE c,
v_file LIKE v_excel_string VALUE 'E:\Interfaces\ZMM_BATCH_DATA_FOR_ASPEC
delimiter TYPE c VALUE ',',
t_field(1000) TYPE c OCCURS 0.
*--- Factory method objects
DATA: lr_table TYPE REF TO cl_salv_table,
lr_columns type ref to cl_salv_columns_table,
lr_column type ref to cl_salv_column_table.
*--- read the file from the application server
OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
WRITE:/ 'error opening file'.
ELSE.
DO.
READ DATASET v_file INTO wa_tab.
IF sy-subrc IS INITIAL.
CLEAR it_string[].
SPLIT wa_tab AT delimiter INTO TABLE it_string.
LOOP AT it_string ASSIGNING FIELD-SYMBOL(<fs>).
Shares
ASSIGN COMPONENT sy-tabix OF STRUCTURE wa_tab2 TO FIELD-SYMBOL(<fs_f>).
IF sy-subrc = 0.
<fs_f> = <fs>.
ENDIF.
AT LAST.
APPEND wa_tab2 TO it_tab2.
ENDAT.
ENDLOOP.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET v_file.
*------display the data from the internal table
IF it_tab2[] IS NOT INITIAL.
DELETE it_tab2 INDEX 1. "Delete header line.
ENDIF.
cl_salv_table=>factory(
IMPORTING r_salv_table = lr_table
CHANGING t_table = it_tab2 ).
lr_columns = lr_table->get_columns( ).
try.
lr_column ?= lr_columns->get_column( 'EBELN' ).
https://sapyard.com/a-to-z-of-al11-operations/ 19/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
lr_column->set_short_text( 'EBELN' ).
lr_column ?= lr_columns->get_column( 'EBELP' ).
lr_column->set_short_text( 'EBELP' ).
lr_column ?= lr_columns->get_column( 'MATNR' ).
lr_column->set_short_text( 'MATNR' ).
lr_column ?= lr_columns->get_column( 'BUKRS' ).
lr_column->set_short_text( 'BUKRS' ).
catch cx_salv_not_found. "#EC NO_HANDLER
endtry.
lr_table->display( ).</code>
Shares
https://sapyard.com/a-to-z-of-al11-operations/ 20/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Shares
Enter the File name in the FILE_NAME and the directory path (Excluding the file name) in the
DIR_NAME and execute.
After execution, the file will disappear permanently from the AL11 location. As Spiderman’s
uncle said, “With more Power comes more Responsibility“. So please use it judiciously.
https://sapyard.com/a-to-z-of-al11-operations/ 21/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
This FM we can use at program level as well if required to delete files in mass.
We can use DELETE DATASET statement too at program level to delete files from application
server.
Syntax:
<code>DELETE DATASET dset.</code>
Shares
When you execute this report, you will get below selection screen.
https://sapyard.com/a-to-z-of-al11-operations/ 22/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
EPS_GET_DIRECTORY_LISTING or EPS2_GET_DIRECTORY_LISTING
https://sapyard.com/a-to-z-of-al11-operations/ 23/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
Shares
Here, we have to provide directory/folder path to get list of files present in it.
https://sapyard.com/a-to-z-of-al11-operations/ 24/31
11/6/2019 A to Z of AL11 - All SAP File Directory Operations |
As you see in above snapshot, we got 62 files of our directory. If you check the DIR_LIST
table, you will get below details:
Shares
This functionality you can use in the program whenever you want to do mass processing like
read file/download file/delete file etc from single directory. It indeed saves time and good for
performance.
Well, what else you want to do with AL11? I am blank now. Hell tired. Honestly, I don’t think
you will need to search any other thread in future for any queries related to AL11. This page
should be mother of all pages for AL11 and one source of truth for all AL11
requirements.
https://sapyard.com/a-to-z-of-al11-operations/ 25/31