Basic ABAP Syntax

ABAP (Advanced Business Application Programming) is a programming language used in SAP for developing applications. Below is a summary of some basic syntax elements in ABAP.

Comments

  • Single-line comment:
    * This is a single-line comment.
    
  • Multi-line comment:
    " This is a
    " multi-line comment.
    

Data Types

  • Defining a variable:
    DATA: variable_name TYPE data_type.
    
  • Example:
    DATA: lv_name TYPE string.
    

Control Structures

  • IF Statement:
    IF condition.
        " code to execute
    ELSEIF another_condition.
        " code to execute
    ELSE.
        " code to execute
    ENDIF.
    
  • CASE Statement:
    CASE variable.
        WHEN value1.
            " code to execute
        WHEN value2.
            " code to execute
        WHEN OTHERS.
            " code to execute
    ENDCASE.
    

Looping

  • DO Loop:
    DO n TIMES.
        " code to execute
    ENDDO.
    
  • WHILE Loop:
    WHILE condition.
        " code to execute
    ENDWHILE.
    

Subroutines

  • FORM:
    FORM subroutine_name.
        " code to execute
    ENDFORM.
    

Function Modules

  • Calling a function module:
    CALL FUNCTION 'FUNCTION_NAME'
      EXPORTING
        parameter1 = value1
        parameter2 = value2
      IMPORTING
        return_value = variable
      EXCEPTIONS
        exception1 = 1
        exception2 = 2
        OTHERS = 3.
    

Example Program

REPORT z_example.

DATA: lv_text TYPE string.

lv_text = 'Hello, ABAP!'.

WRITE: / lv_text.

Conclusion

This cheat sheet covers the basics of ABAP syntax. For more detailed and advanced topics, refer to official SAP documentation or specific tutorials.