login as:
~/abapcraft.dev — code, crafted in SAP
florin@abapcraft:~/abap/posts/exercism-abap $ cat README.md

Exercism ABAP Track

11 katas solved in modern ABAP — internal tables, string operations, algorithms, and idiomatic use of VALUE #, COND #, and REDUCE.

What is Exercism?

Exercism is a free, open-source platform offering coding exercises across 70+ languages. The ABAP track presents progressively harder katas, each with a suite of unit tests you must make pass. It’s a low-friction way to practise idiomatic ABAP without needing a full SAP system setup.

Each solution lives in a zcl_<exercise>.clas.abap file alongside a .testclasses.abap counterpart — the same structure you’d use in a real system.

Exercises Solved

ExerciseTopic
ITAB BasicsInternal table fill, append, sort, search
ITAB AggregationREDUCE, COLLECT, group totals
ITAB CombinationJoining and merging internal tables
ITAB NestingDeeply nested structures and table-of-tables
LeapModulo arithmetic, COND #
Two FerString formatting, optional parameters
Reverse StringCharacter-level string manipulation
High ScoresSorting, VALUE #, functional style
Resistor ColorTable lookups, index arithmetic
Scrabble ScoreCA operator, character scoring loop
Atbash CipherString transformation, cipher logic

Highlights

ITAB Basics — VALUE # and line_index

The ITAB exercises are the meatiest on the track. fill_itab uses VALUE # constructor expressions to populate a structured internal table inline — no APPEND loops:

METHOD fill_itab.
  initial_data = VALUE #(
    ( group = 'A' number = 10 description = 'Group A-2' )
    ( group = 'B' number = 5  description = 'Group B'   )
    ( group = 'A' number = 6  description = 'Group A-1' )
    ( group = 'C' number = 22 description = 'Group C-1' )
    ( group = 'A' number = 13 description = 'Group A-3' )
    ( group = 'C' number = 500 description = 'Group C-2' )
  ).
ENDMETHOD.

Searching uses line_index — a functional alternative to READ TABLE ... TRANSPORTING NO FIELDS that returns the index directly:

METHOD search_itab.
  TRY.
    result_index = line_index( initial_data[ number = 6 ] ).
  CATCH cx_sy_itab_line_not_found.
  ENDTRY.
ENDMETHOD.

Leap — One-liner with COND #

The leap year rules (divisible by 4, except centuries unless also divisible by 400) collapse neatly into a single COND # expression:

METHOD leap.
  result = COND #(
    WHEN year MOD 4 = 0 AND ( year MOD 100 <> 0 OR year MOD 400 = 0 )
    THEN abap_true
    ELSE abap_false
  ).
ENDMETHOD.

No IF, no helper variable — just a direct mapping from condition to result.

Scrabble Score — CA for set membership

Rather than a CASE on individual characters or a lookup table, the score method uses the CA (contains any) operator to test set membership in one expression:

METHOD score.
  DO strlen( input ) TIMES.
    DATA(offset) = sy-index - 1.
    DATA(letter) = input+offset(1).
    DATA(letter_score) = COND #(
      WHEN letter CA 'AEIOULNRSTaeioulnrst' THEN 1
      WHEN letter CA 'DGdg'                 THEN 2
      WHEN letter CA 'BCMPbcmp'             THEN 3
      WHEN letter CA 'FHVWYfhvwy'           THEN 4
      WHEN letter CA 'Kk'                   THEN 5
      WHEN letter CA 'JXjx'                 THEN 8
      WHEN letter CA 'QZqz'                 THEN 10
      ELSE 0
    ).
    result = result + letter_score.
  ENDDO.
ENDMETHOD.

CA returns true if any character in the left operand appears in the right-hand set — making it a compact, readable dispatch table without branching on each letter individually.

Clone into Your System

1. abapGit → New Online Repository
2. URL: https://github.com/CiozZ/exercism
3. Package: $EXERCISM (or any local package)
4. Pull → Activate all
5. Run ABAP Unit on any zcl_* class