Modularization Part 2: FORM Routines — Legacy but Still Important
Preview · a free account unlocks the full lesson
Read and maintain FORM routines in existing programs: PERFORM and FORM, USING and CHANGING, pass by value vs reference, TABLES parameters, global data side effects — and how to refactor them safely.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 1 of this series introduced modularization units in general; FORM routines are the oldest of these processing units, and even though they're obsolete for new code, you'll still maintain thousands of them across reports, user exits, and print programs, so you need to be able to read, debug, and carefully change them.
The basic syntax is PERFORM calc_free_seats USING gs_flight CHANGING gv_free. to call a routine, matched against FORM calc_free_seats USING us_flight TYPE sflight CHANGING cv_free TYPE i. … ENDFORM. to define it; parameters are matched purely by position. Typed parameters (declared with TYPE …) get checked at syntax time, while untyped parameters, common in older code, accept anything at all, which is risky.
The passing mechanisms matter a great deal here. USING p is intended as input, but is actually passed by reference by default, so changing it inside the FORM also changes the caller's variable. USING VALUE(p) passes a copy instead, so changes stay local to the FORM. CHANGING p is passed by reference and intended for output.
CHANGING VALUE(p) is a copy that gets written back to the caller only when the FORM reaches a normal ENDFORM. TABLES itab is the obsolete way of passing internal tables, using a header line; USING or CHANGING with proper table types should be used instead in any code you touch.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Related SAP topics
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.