I/O Operations in ABAP
How ABAP handles input and output - the WRITE list buffer, string-template formatting, parsing input records with SPLIT and CONCATENATE, tabular output from internal tables, selection-screen input, and application-server file I/O
Input and output in ABAP look very different from the print/read/fopen trio you find in most languages, because ABAP was never a console or shell language - it is a server-side, business-application language that runs inside an SAP application server. There is no terminal to read a line from and no working directory to open a file in. Instead, ABAP’s I/O grew out of two needs: producing formatted business reports and moving data between programs, screens, and the database.
That heritage shapes everything in this tutorial. Output goes to the list buffer through WRITE (introduced in Hello World) and, in modern code, through string templates for precise formatting. “Input” in the classic sense comes from a selection screen - the PARAMETERS and SELECT-OPTIONS fields a user fills in before the report runs - not from standard input. Genuine file I/O happens against the application server’s file system with OPEN DATASET, while database access (the most common ABAP “I/O” of all) uses Open SQL.
In this tutorial you’ll build one runnable program that exercises the parts open-abap supports on Node.js: detailed console output, string-template formatting with fixed decimals, parsing a delimited input record with SPLIT, reassembling it with CONCATENATE, and producing a formatted table from an internal table. After the runnable example, two Real-World ABAP sections show how selection-screen input and application-server file I/O work in an actual SAP system - syntax you’ll read constantly in real code but that needs a live SAP server to execute.
Output: WRITE and string templates
ABAP gives you two layers of output. WRITE sends a field to the list buffer and is ideal for fixed text and simple lines; a leading / starts a new line. For anything that mixes literals with variables - the common case - string templates (|...| with { } placeholders) are clearer and give you formatting options such as DECIMALS, WIDTH, and ALIGN. Because templates render numbers with a fixed . decimal separator regardless of user settings, their output is predictable, which is exactly what you want when formatting money or quantities.
“Input”: parsing records
Since open-abap has no selection screen, the runnable example demonstrates the other half of input handling that is portable: taking a raw record and breaking it into fields. SPLIT ... AT ... INTO is ABAP’s tokenizer, and CONCATENATE ... SEPARATED BY reassembles fields into a single string. This record-in, fields-out, line-out pattern is the heart of most ABAP I/O, whether the record originally came from a screen, a file, or a database row.
The runnable example
The program below produces a small order confirmation: a header, a formatted line of values, a parsed employee record, and a totaled item table. Every value is computed so the output is fully deterministic.
Create a file named io_operations.abap:
| |
Running with Docker
Run the program with the same open-abap transpiler pattern from the Hello World tutorial - this time pointing at io_operations.abap (program name zio).
| |
Expected Output
Order Confirmation
==================
Customer : ACME Corp
Unit price: 29.95 EUR
Quantity : 3
Amount : 89.85 EUR
------------------
Name : Alice
Dept : Engineering
Years: 7
Summary: Alice | Engineering | 7
------------------
Keyboard: 3 x 29.95 = 89.85
Monitor: 1 x 149.00 = 149.00
Cable: 5 x 4.50 = 22.50
Grand total: 261.35 EUR
Notes on Behavior
- The first
WRITEhas no leading/, so “Order Confirmation” lands on the first list line; every laterWRITE /starts a new line - the list-buffer behavior from Hello World. - Backticks (
`) create astring; single quotes (') create a fixed-lengthcliteral. Using backticks forlv_customerandlv_recordkeeps them as true strings, whichSPLITandCONCATENATEwork with cleanly. { lv_amount DECIMALS = 2 }formats a packed number with exactly two fraction digits and a.separator.29.95 * 3is89.85, and5 * 4.50is22.50- packed arithmetic stays exact, which is why ABAP uses typepfor money.SPLIT lv_record AT ',' INTO DATA(...) DATA(...) DATA(...)declares its three targets inline and fills them with the comma-separated fields.CONCATENATE ... SEPARATED BY \| `glues the fields back together with a" | “delimiter, producingAlice | Engineering | 7`.- The
LOOP AT ... INTOreads each table row into a work area; the runninglv_grandaccumulates each line total to261.35.
Real-World ABAP: Selection-Screen Input
On an actual SAP system, a report does not read stdin - it presents a selection screen. You declare input fields with PARAMETERS (single values) and SELECT-OPTIONS (ranges), and the runtime renders an input mask before START-OF-SELECTION runs. The user’s entries are simply available as variables:
| |
The obsolete ACCEPT/PARAMETER console statements exist only for legacy character-mode use; modern code always uses selection screens, classic dialog (PAI/PBO) screens, or Fiori/RAP services for input. The transpiler used here has no screen layer, so this snippet illustrates real-SAP syntax rather than something runnable on Node.js.
Real-World ABAP: File I/O on the Application Server
ABAP reads and writes files on the application server with the dataset statements - the closest analog to open/read/write/close. After each statement you check sy-subrc for success, the ABAP convention for I/O error handling:
| |
Note that OPEN DATASET targets the SAP server’s file system, not the user’s PC - a deliberate security boundary. For client-side files you use function modules such as GUI_UPLOAD / GUI_DOWNLOAD, and for the most common I/O of all - persistent business data - you use Open SQL (SELECT / INSERT / UPDATE) against database tables. These statements need a live SAP application server, so they are shown here for reference rather than run under open-abap.
Key Concepts
WRITEtargets the list buffer, not a console; a leading/starts a new line, a heritage of ABAP’s report-generation origins.- String templates (
|...|) are the modern way to format output, embedding expressions with{ }and offering options likeDECIMALS,WIDTH, andALIGN. - Type
p(packed) withDECIMALSgives exact decimal arithmetic for money;DECIMALS = 2in a template pins the displayed fraction digits. SPLIT ... AT ... INTOtokenizes a record into fields;CONCATENATE ... SEPARATED BYreassembles fields into a line - the core of record-oriented I/O.- Input comes from selection screens (
PARAMETERS,SELECT-OPTIONS), classic dialog screens, or Fiori/RAP services - ABAP is a server language with no stdin. - File I/O uses
OPEN DATASET/TRANSFER/READ DATASET/CLOSE DATASETagainst the application server, withsy-subrcchecked after each operation for error handling. - Database access is the most common ABAP I/O, handled by Open SQL rather than file statements.
- open-abap runs console output, templates, and string parsing on Node.js, while screens, datasets, and Open SQL need a real SAP system.
Comments
Loading comments...
Leave a Comment