Learn Abap - 10 Code Examples & CST Typing Practice Test
ABAP (Advanced Business Application Programming) is a high-level, strongly typed, event-driven programming language created by SAP for developing business applications on the SAP platform. It is primarily used for enterprise resource planning (ERP), reporting, and workflow automation.
Learn ABAP with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
ABAP Counter and Theme Toggle
DATA: count TYPE i VALUE 0.
DATA: isDark TYPE abap_bool VALUE abap_false.
FORM update_ui.
WRITE: / 'Counter:', count.
WRITE: / 'Theme:', (IF isDark = abap_true THEN 'Dark' ELSE 'Light').
ENDFORM.
FORM increment.
count = count + 1.
PERFORM update_ui.
ENDFORM.
FORM decrement.
count = count - 1.
PERFORM update_ui.
ENDFORM.
FORM reset.
count = 0.
PERFORM update_ui.
ENDFORM.
FORM toggle_theme.
isDark = abap_not isDark.
PERFORM update_ui.
ENDFORM.
" Simulate actions
PERFORM update_ui.
PERFORM increment.
PERFORM increment.
PERFORM toggle_theme.
PERFORM decrement.
PERFORM reset.
Demonstrates a simple counter with theme toggling using ABAP variables and WRITE statements.
ABAP Fibonacci Sequence
DATA: a TYPE i VALUE 0.
DATA: b TYPE i VALUE 1.
DATA: c TYPE i.
WRITE: / a, b.
DO 8 TIMES.
c = a + b.
WRITE: / c.
a = b.
b = c.
ENDDO.
Generates the first 10 Fibonacci numbers.
ABAP Factorial Calculator
DATA: n TYPE i VALUE 5.
DATA: factorial TYPE i VALUE 1.
DO n TIMES.
factorial = factorial * sy-index.
ENDDO.
WRITE: / 'Factorial:', factorial.
Calculates the factorial of a given number.
ABAP Even/Odd Checker
DATA: num TYPE i VALUE 7.
IF num MOD 2 = 0.
WRITE: / 'Even'.
ELSE.
WRITE: / 'Odd'.
ENDIF.
Checks if a number is even or odd.
ABAP Sum of Array
DATA: it_numbers TYPE TABLE OF i WITH DEFAULT KEY.
DATA: sum TYPE i VALUE 0.
APPEND 1 TO it_numbers.
APPEND 2 TO it_numbers.
APPEND 3 TO it_numbers.
APPEND 4 TO it_numbers.
APPEND 5 TO it_numbers.
LOOP AT it_numbers INTO DATA(num).
sum = sum + num.
ENDLOOP.
WRITE: / 'Sum:', sum.
Calculates the sum of an internal table.
ABAP Reverse String
DATA: text TYPE string VALUE 'Hello'.
DATA: reversed TYPE string.
DO STRLEN( text ) TIMES.
reversed = text+sy-index(1) && reversed.
ENDDO.
WRITE: / 'Reversed:', reversed.
Reverses a given string.
ABAP Prime Checker
DATA: num TYPE i VALUE 13.
DATA: isPrime TYPE abap_bool VALUE abap_true.
DO num - 2 TIMES.
IF num MOD ( sy-index + 1 ) = 0.
isPrime = abap_false.
EXIT.
ENDIF.
ENDDO.
IF isPrime = abap_true.
WRITE: / 'Prime'.
ELSE.
WRITE: / 'Not Prime'.
ENDIF.
Checks if a number is prime.
ABAP Multiplication Table
DATA: num TYPE i VALUE 5.
DO 10 TIMES.
WRITE: / num, 'x', sy-index, '=', num * sy-index.
ENDDO.
Displays multiplication table of a number.
ABAP Temperature Converter
DATA: celsius TYPE f VALUE 25.
DATA: fahrenheit TYPE f.
fahrenheit = ( celsius * 9 / 5 ) + 32.
WRITE: / celsius, 'C =', fahrenheit, 'F'.
Converts Celsius to Fahrenheit.
ABAP Simple Alarm Simulation
DATA: temperature TYPE i VALUE 80.
DATA: threshold TYPE i VALUE 75.
IF temperature > threshold.
WRITE: / 'Alarm: Temperature Too High!'.
ELSE.
WRITE: / 'Temperature Normal'.
ENDIF.
Simulates an alarm when a threshold is reached.
Frequently Asked Questions about Abap
What is Abap?
ABAP (Advanced Business Application Programming) is a high-level, strongly typed, event-driven programming language created by SAP for developing business applications on the SAP platform. It is primarily used for enterprise resource planning (ERP), reporting, and workflow automation.
What are the primary use cases for Abap?
Custom SAP reports and ALV grids. Enhancements to standard SAP functionality. Batch jobs and background processing. SAP interfaces (IDocs, BAPIs, RFCs). Workflow and business rule automation. Forms (SmartForms, Adobe Forms) development
What are the strengths of Abap?
Deep SAP ecosystem integration. Powerful for ERP customization. Supports complex business logic. Mature tools and debugging features. Extensive standard library of SAP function modules
What are the limitations of Abap?
Limited portability outside SAP. Less suitable for modern web or mobile apps. Verbose syntax for complex logic. Primarily tied to SAP database and environment. Steep learning curve for non-SAP developers
How can I practice Abap typing speed?
CodeSpeedTest offers 10+ real Abap code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.