12.3Bloom · ANot started

Migrate FORM/PERFORM to classes

Reading depth

What you'll learn

Map each FORM to one public method on a ZCL_ class, turn PERFORM into method calls, replace globals with attributes/parameters, then ATC and delete the old FORMs.

  • 1. Identify each FORM's responsibilities and its inputs/outputs.
  • 2. Create a ZCL_ class with one public method per FORM, mirroring the signatures.
  • 3. Move each FORM body into its method and replace PERFORM calls with method calls.

FORM/PERFORM is a procedural smell that ABAP Cloud forbids outright: subroutines and the global program state they lean on do not exist in a class-based, restricted world. Migrating them is a mechanical refactor, but the discipline is to keep behaviour identical at each step so ATC and your tests stay the arbiter, not your memory of what the program did.

Start by reading each FORM as a unit of responsibility: what does it take in, what does it change, what does it return. You then create a ZCL_ class with one public method per FORM, initially mirroring the FORM's signature so the mapping is one-to-one. Move each FORM body into its method and replace every PERFORM with the corresponding method call.

The real work is killing global state. Classic programs share data through global variables; the class equivalent is instance attributes for genuinely shared state and explicit parameters for everything else. Once the bodies are in and globals are pulled in, run ATC to surface obsolete-API findings exposed by the move, fix them, and only then delete the FORM scaffolding — when nothing references it anymore.

Key points

  • 1. Identify each FORM's responsibilities and its inputs/outputs.
  • 2. Create a ZCL_ class with one public method per FORM, mirroring the signatures.
  • 3. Move each FORM body into its method and replace PERFORM calls with method calls.
  • 4. Pull global state into instance attributes or method parameters.
  • 5. Run ATC and fix the obsolete-API findings the move exposes.
  • 6. Delete the original FORM scaffolding once nothing references it.

Examples

BeforeA FORM and its PERFORM caller

Classic procedural style: a subroutine mutating a global, invoked with perform. Forbidden in ABAP Cloud and a Clean Core smell.

ABAPdata gv_total type p decimals 2.

perform add_line using ls_item-amount.

form add_line using iv_amount type p.
  gv_total = gv_total + iv_amount.
endform.
AfterOne method per FORM, no global

The FORM becomes a public method; the global becomes an instance attribute; perform becomes a method call.

ABAPclass zcl_order_totals definition public.
  public section.
    methods add_line importing iv_amount type p.
  private section.
    data mv_total type p decimals 2.
endclass.

class zcl_order_totals implementation.
  method add_line.
    mv_total = mv_total + iv_amount.
  endmethod.
endclass.

go_totals->add_line( ls_item-amount ).

Source notes: clean-core-curriculum §12.4

Ask Claude

Build a prompt from this lesson + your question and open a fresh Claude chat with it pre-filled — handy for adapting a before/after pattern to your own object.