OPEN DATASET — files on the application server¶
Level: 201 · working knowledge
Status: stub — the shape is here; the worked program is not yet.
One line: OPEN DATASET reads and writes files on the application server, not on the user's PC, and the addition that decides whether the file is readable elsewhere is the encoding — IN TEXT MODE ENCODING UTF-8 versus DEFAULT, where "default" means the system's own code page and therefore something different on the next system.
What it does¶
OPEN DATASET lv_path FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc = 0.
TRANSFER lv_line TO lv_path.
CLOSE DATASET lv_path.
ENDIF.
FOR INPUT, FOR OUTPUT, FOR APPENDING; IN TEXT MODE with an ENCODING, or IN BINARY MODE for bytes. Reading is READ DATASET … INTO … MAXIMUM LENGTH …, and every statement reports through sy-subrc: a missing file is not an exception.
The user's own machine is a different mechanism entirely — cl_gui_frontend_services or GUI_DOWNLOAD, which only work where there is a SAP GUI, and therefore not in a background job.
Why it earns a page¶
- Encoding.
ENCODING DEFAULTis the system code page, so the same program writes a different file on two systems. NameUTF-8and say so in the interface agreement. - Byte order mark.
WITH BYTE-ORDER MARKis needed by some Windows consumers and breaks others. This is a decision, not a default. - Authorization. File access is checked by
S_DATASET, and the physical path is usually mapped through logical file names (FILE,SF01) so that a path is not hard-coded per system. - ABAP Cloud.
OPEN DATASETis not released in ABAP Cloud. Code moving to the cloud model needs a different answer entirely. See ABAP Cloud.
What this page still needs¶
- [ ] a
snippets/program writing and reading back a UTF-8 file with error handling - [ ] a recorded run showing what
ENCODING DEFAULTproduced on a named system - [ ] logical file names:
FILE_GET_NAMEand why the hard-coded path always survives to production - [ ] the same job done with
cl_abap_conv_codepagefor in-memory conversion
See also¶
- File handling — the topic page, including the frontend side
- How long is a string? — bytes against characters, with a program
- Authorizations —
S_DATASET - Background jobs — why the frontend alternative is not available there
- Unicode and code pages — characters, bytes, and naming the code page
- Security — injection in dynamic SQL, code and file paths