AL11 is a standard SAP transaction used to display and manage application server directories.
Think of it as the SAP file explorer for backend files.
It lists logical file paths configured in transaction FILE.
It shows the physical directories on the SAP application server (not your local PC).
You can view, upload, download, or delete files (depending on your authorizations).
CLASS zcl_al11_demo DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS:
write_to_al11,
read_from_al11.
ENDCLASS.
CLASS zcl_al11_demo IMPLEMENTATION.
METHOD write_to_al11.
“—————————————————
” Step 1: Define target file path (AL11 directory)
“—————————————————
DATA(lv_filename) = ‘/usr/sap/interfaces/hr/employee_data.txt’.
“—————————————————
” Step 2: Create sample employee data
“—————————————————
DATA(lt_employee) = VALUE stringtab(
( ‘E001|Alice|IT|65000’ )
( ‘E002|Bob|HR|55000’ )
( ‘E003|Carol|Finance|72000’ )
).
“—————————————————
” Step 3: Open dataset for output (text mode)
“—————————————————
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
WRITE: / ‘Error opening file for write:’, lv_filename.
RETURN.
ENDIF.
LOOP AT lt_employee INTO DATA(lv_line).
TRANSFER lv_line TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.
WRITE: / ‘File written successfully to:’, lv_filename.
ENDMETHOD.
METHOD read_from_al11.
“—————————————————
” Step 1: Define file path to read
“—————————————————
DATA(lv_filename) = ‘/usr/sap/interfaces/hr/employee_data.txt’.
“—————————————————
” Step 2: Open file for input
“—————————————————
OPEN DATASET lv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
WRITE: / ‘Error opening file for read:’, lv_filename.
RETURN.
ENDIF.
“—————————————————
” Step 3: Read and display file contents
“—————————————————
DATA(lv_line) = ”.
WHILE sy-subrc = 0.
READ DATASET lv_filename INTO lv_line.
IF sy-subrc = 0.
SPLIT lv_line AT ‘|’ INTO DATA(lv_id) DATA(lv_name) DATA(lv_dept) DATA(lv_salary).
WRITE: / lv_id, lv_name, lv_dept, lv_salary.
ENDIF.
ENDWHILE.
CLOSE DATASET lv_filename.
ENDMETHOD.
ENDCLASS.