ABAP Core
ABAP Developmentintermediate

Control Flow and String Templates

IF/CASE, LOOP AT variants, and modern string templates.

Explanation

Prefer CASE over IF chains for enumerations. LOOP AT โ€ฆ ASSIGNING <fs> is the fastest read pattern for internal tables. String templates |{ }| replace CONCATENATE for readability and support formatting options such as ALPHA=IN, DATE=USER, NUMBER=USER.

Code example

ABAP Code
DATA(msg) = |Order { ebeln ALPHA = OUT } created on { sy-datum DATE = USER }|.LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<i>).  <i>-total = <i>-price * <i>-qty.ENDLOOP.

Real project scenario

Replaced 40 CONCATENATE lines in a shipping notification with a single string template โ€” reduced defects and simplified translation.

Common mistakes

Modifying a LOOP work area copy instead of an ASSIGNING field symbol; forgetting to MODIFY when using INTO wa.

Best practices

Use ASSIGNING for read-modify loops; keep CASE branches exhaustive with a WHEN OTHERS fallback.

Interview angle

Difference between INTO wa, REFERENCE INTO and ASSIGNING <fs> and their performance.