ABAP Guide: Your First ABAP Program

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-13 against open-abap 2.14.30 (the abaplint transpiler and runtime), abaplint 2.120.103 and Node.js 24.21.

What you build

You write a small ABAP program in two pieces: a class named zcl_first_program with a method run that prints three lines about one expense claim, and a report named zfirst_program that creates the class and calls run. You transpile the sources to JavaScript, run them on Node.js and read the output. Then you make a deliberate spelling mistake, read the first error message that the tools print, and fix it.

The playground is open-abap, a community open-source project, not SAP software. It runs only the part of the ABAP language that it implements, so a program that works here needs a check on a real SAP system before you rely on it there. Output is written with WRITE, the classic list statement; the keyword documentation no longer recommends it for new code, and it is what the playground offers.

Terminal with the command npm run run:first followed by the three program lines Claim 1001, Status: New and Amount: 45 EUR

Before you start

  • No account is needed: Node.js, the abaplint tools and open-abap install from the public npm registry without signing in. The licences you accept by installing (MIT for the abaplint packages) are listed in the README of the ABAP lab.

  • Set up the lab first, with the guide Set Up a Local ABAP Playground: the folder abap-lab with npm install done, and an editor such as Visual Studio Code open on it. This guide adds files to its src folder.

  • The lab already holds the finished files of this guide in modules/ROOT/examples/abap-lab/src/. Type them yourself rather than copying them, so that you meet the errors in this guide on your own screen.

  • Read Programming Concepts for Newcomers for the words variable, statement and method, and Program Types and Structure for what a report is.

  • The figures are drawings of the editor and the terminal, not screenshots. A highlighted box with a number marks the file or line of the step with the same number.

Steps

An ABAP object in the lab is stored as two files with the same name, the layout of the abapGit project: a .abap file with the source and a .xml file with the object’s attributes (its name, its description and the like). The tools find objects by these file names, so the names matter. A class is <name>.clas.abap and <name>.clas.xml, and a report is <name>.prog.abap and <name>.prog.xml.

Write the class

  1. In the src folder, create the file src/zcl_first_program.clas.abap with this source. The DEFINITION part announces what the class offers (one method, run), and the IMPLEMENTATION part holds the code of the method. Inside run, three DATA statements declare variables with a type and a start value, and three WRITE statements print one line each. The |...| text with { } is a string template: the value of the variable replaces the braces.

    CLASS zcl_first_program DEFINITION PUBLIC FINAL CREATE PUBLIC.
      PUBLIC SECTION.
        METHODS run.
    ENDCLASS.
    
    CLASS zcl_first_program IMPLEMENTATION.
      METHOD run.
        DATA claim_id TYPE i VALUE 1001.
        DATA status   TYPE string VALUE `New`.
        DATA amount   TYPE i VALUE 45.
    
        WRITE / |Claim { claim_id }|.
        WRITE / |Status: { status }|.
        WRITE / |Amount: { amount } EUR|.
      ENDMETHOD.
    ENDCLASS.
  2. Create the second file of the class, src/zcl_first_program.clas.xml, next to it:

    <?xml version="1.0" encoding="utf-8"?>
    <abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
     <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
       <VSEOCLASS>
        <CLSNAME>ZCL_FIRST_PROGRAM</CLSNAME>
        <LANGU>E</LANGU>
        <DESCRIPT>First program</DESCRIPT>
        <STATE>1</STATE>
        <FIXPT>X</FIXPT>
        <UNICODE>X</UNICODE>
       </VSEOCLASS>
      </asx:values>
     </asx:abap>
    </abapGit>
    Visual Studio Code with the abap-lab project: the file src/zcl_first_program.clas.abap is open and shows the class zcl_first_program with its run method that writes three lines; callout 1 marks the class file and callout 2 marks the companion XML file in the explorer

Write the report that starts it

A class cannot start by itself. A report is a program that can be started, so you write a short one that creates an object of your class and calls its method.

  1. Create src/zfirst_program.prog.abap and its attribute file src/zfirst_program.prog.xml. The REPORT statement names the program, START-OF-SELECTION is the block that runs when the program starts, and NEW zcl_first_program( )->run( ) creates the object and calls run on it.

    REPORT zfirst_program.
    
    START-OF-SELECTION.
      NEW zcl_first_program( )->run( ).
    <?xml version="1.0" encoding="utf-8"?>
    <abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
     <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
       <PROGDIR>
        <NAME>ZFIRST_PROGRAM</NAME>
        <SUBC>1</SUBC>
        <RLOAD>E</RLOAD>
        <UCCHECK>X</UCCHECK>
       </PROGDIR>
      </asx:values>
     </asx:abap>
    </abapGit>
    Visual Studio Code with the file src/zfirst_program.prog.abap open: a report named zfirst_program whose START-OF-SELECTION block creates the class with NEW and calls run; callout 3 marks the report file in the explorer

Transpile and run

ABAP does not run on Node.js directly. The transpiler turns every ABAP file of src into a JavaScript file in the output folder, and Node.js runs the JavaScript file of the report.

  1. In the terminal, in the abap-lab folder, run the script that does both:

    npm run run:first
  2. Read the output. The transpiler first prints how many files it found in src and in the open-abap library (which it fetches once) and how many output files it wrote; the figure shows one example run, and your counts will differ because the lab grows with every guide. The last three lines come from your program:

    Claim 1001
    Status: New
    Amount: 45 EUR

    The figure leaves out the lines that tell which library version the transpiler cloned.

    Terminal after npm run run:first: the transpiler counts its source and library files and reports the output files written (one example run), and the program prints Claim 1001, Status: New and Amount: 45 EUR; callout 4 marks the command and callout 5 marks the three output lines

Read your first error

Every programmer meets error messages daily. You make one on purpose, in a place where you know the fix.

  1. Open src/zcl_first_program.clas.abap and change the variable in the third WRITE statement (line 14) from amount to amont. Save the file. The name amont was never declared, so the program no longer makes sense.

  2. Run npm run run:first again. The transpiler checks the syntax before it translates anything, stops at the first problem and prints one line, and Node.js does not run. The line has four parts: check_syntax is the check that failed, "amont" not found is what is wrong, findTop is an internal detail you can ignore, and zcl_first_program.clas.abap:14 is the file and the line.

    Terminal after npm run run:first with a misspelled variable: the transpiler stops with the line Error: check_syntax, amont not found, findTop, zcl_first_program.clas.abap:14 and the program does not run; callout 7 marks the error line
  3. Run npm run lint to ask abaplint, the static checker of the lab, about the same file. It reports the same problem with the column as well. The finding reads file[line, column] - message (rule) [severity]: line 14, column 24 is where the unknown name starts, check_syntax is the rule that found it, and [E] means error.

    npm run lint
    Terminal after npm run lint: abaplint prints one finding, src/zcl_first_program.clas.abap at line 14 column 24, the message amont not found, findTop, the rule name check_syntax and the severity E, then 1 issue found in 10 files; callout 8 marks the finding
  4. Change amont back to amount, save and run npm run run:first. The three output lines return, and npm run lint reports 0 issue(s) found.

Check the result

npm run run:first ends without an error and prints the three lines Claim 1001, Status: New and Amount: 45 EUR. npm run lint prints abaplint: 0 issue(s) found, 10 file(s) analyzed, and npm test still passes with the test of the lab’s greeter class.

Variations

  • Change the start values (1001, New, 45) and run again to see your values in the output.

  • Add a fourth DATA variable and a fourth WRITE line, for example for a currency code.

  • Delete the final period of one statement and read how the error message changes.

What can go wrong

Symptom Cause Fix

Error: check_syntax, "x" not found, findTop and no program output

A name is misspelled or was never declared.

Open the file and line named at the end of the message and correct the name.

The old output appears although you changed the code

You ran node output/project/zfirst_program.prog.mjs yourself after a failed transpile. Node.js ran the files of the last successful build.

Run npm run run:first: it runs the program only when the transpile succeeded.

Error: Cannot find module with the path of the report

The output folder does not exist yet, or the report file has a different name.

Run npm run run:first, which transpiles first, and check that the report is named zfirst_program.prog.abap.

npm run lint reports nothing for a file you added

The file is not under src, or its name does not end in .abap.

Move it to src and keep the name layout <name>.<type>.abap.

Where to go next