{"id":7934,"date":"2025-10-19T02:05:37","date_gmt":"2025-10-18T20:35:37","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=read-and-write-file-in-al11"},"modified":"2025-10-19T02:05:37","modified_gmt":"2025-10-18T20:35:37","slug":"read-and-write-file-in-al11","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=read-and-write-file-in-al11","title":{"rendered":"READ and WRITE file in AL11"},"content":{"rendered":"<p><strong>AL11<\/strong> is a standard SAP transaction used to <strong>display and manage application server directories<\/strong>.<\/p>\n<p>Think of it as the <strong>SAP file explorer<\/strong> for backend files.<\/p>\n<ul>\n<li>\n<p>It lists <strong>logical file paths<\/strong> configured in <strong>transaction FILE<\/strong>.<\/p>\n<\/li>\n<li>\n<p>It shows the <strong>physical directories<\/strong> on the SAP application server (not your local PC).<\/p>\n<\/li>\n<li>\n<p>You can <strong>view, upload, download, or delete files<\/strong> (depending on your authorizations).<\/p>\n<p><\/p>\n<\/li>\n<\/ul>\n<p>CLASS zcl_al11_demo DEFINITION<br \/>PUBLIC<br \/>FINAL<br \/>CREATE PUBLIC.<\/p>\n<p>PUBLIC SECTION.<br \/>METHODS:<br \/>write_to_al11,<br \/>read_from_al11.<br \/>ENDCLASS.<\/p>\n<p>CLASS zcl_al11_demo IMPLEMENTATION.<\/p>\n<p>METHOD write_to_al11.<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 1: Define target file path (AL11 directory)<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>DATA(lv_filename) = &#8216;\/usr\/sap\/interfaces\/hr\/employee_data.txt&#8217;.<\/p>\n<p>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 2: Create sample employee data<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>DATA(lt_employee) = VALUE stringtab(<br \/>( &#8216;E001|Alice|IT|65000&#8217; )<br \/>( &#8216;E002|Bob|HR|55000&#8217; )<br \/>( &#8216;E003|Carol|Finance|72000&#8217; )<br \/>).<\/p>\n<p>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 3: Open dataset for output (text mode)<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.<\/p>\n<p>IF sy-subrc &lt;&gt; 0.<br \/>WRITE: \/ &#8216;Error opening file for write:&#8217;, lv_filename.<br \/>RETURN.<br \/>ENDIF.<\/p>\n<p>LOOP AT lt_employee INTO DATA(lv_line).<br \/>TRANSFER lv_line TO lv_filename.<br \/>ENDLOOP.<\/p>\n<p>CLOSE DATASET lv_filename.<\/p>\n<p>WRITE: \/ &#8216;File written successfully to:&#8217;, lv_filename.<\/p>\n<p>ENDMETHOD.<\/p>\n<p>METHOD read_from_al11.<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 1: Define file path to read<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>DATA(lv_filename) = &#8216;\/usr\/sap\/interfaces\/hr\/employee_data.txt&#8217;.<\/p>\n<p>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 2: Open file for input<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>OPEN DATASET lv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.<\/p>\n<p>IF sy-subrc &lt;&gt; 0.<br \/>WRITE: \/ &#8216;Error opening file for read:&#8217;, lv_filename.<br \/>RETURN.<br \/>ENDIF.<\/p>\n<p>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>&#8221; Step 3: Read and display file contents<br \/>&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>DATA(lv_line) = &#8221;.<br \/>WHILE sy-subrc = 0.<br \/>READ DATASET lv_filename INTO lv_line.<br \/>IF sy-subrc = 0.<br \/>SPLIT lv_line AT &#8216;|&#8217; INTO DATA(lv_id) DATA(lv_name) DATA(lv_dept) DATA(lv_salary).<br \/>WRITE: \/ lv_id, lv_name, lv_dept, lv_salary.<br \/>ENDIF.<br \/>ENDWHILE.<\/p>\n<p>CLOSE DATASET lv_filename.<\/p>\n<p>ENDMETHOD.<\/p>\n<p>ENDCLASS.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,430,448,177],"class_list":["post-7934","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-al11","question_tags-file-handling","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7934"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7934"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7934"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}