ZCO0041 — An ABAP Report That Unfolds CO Distribution Cycles (KSV1/KSV3) into One Grid

ZCO0041 is a custom ABAP report that unfolds the definition of CO actual distribution cycles (KSV1/KSV2/KSV3) into a single ALV grid. In KSV3 you have to open a cycle and walk through five tabs per segment (Segment Header, Senders/Receivers, Sender Values, Receiver Tracing Factor, Receiver Weighting Factors); this report flattens all of that into rows you can scan at once — one row = segment × sender cost center × sender cost element × receiver.

Selection screen

The cycle F4 help is filtered by the controlling area entered on the screen (read at F4 time with DYNP_VALUES_READ, since PAI hasn't run yet). The "only cycles with execution history" checkbox is normally hidden — typing =A in the command field toggles it. Inputs starting with / are intercepted by the kernel as system commands, which is why = is used.

Two output modes — summary and expansion

A single checkbox ("expand sender/receiver groups and ranges") switches between two modes. Summary compresses each segment into one row (multiple values show as *). Expansion resolves groups (via the standard FM G_SET_GET_ALL_VALUES) and ranges (via the CSKB / CSKS masters) into individual values and shows every combination. The group a value came from stays visible in its own column, so you can always trace the origin.

Column layout

The grid is split into a sender block (yellow) and a receiver block (orange). Wherever a code appears, the name is placed right next to it (cost center names, cost element names, group names, order names). Columns that are empty across the whole result are hidden automatically (they can be re-enabled in the layout).

Data sources — the T811 family

A cycle definition is spread across five T811 tables. Knowing which KSV3 tab maps to which table is the backbone of the report:

Table Contents Notes
T811CCycle header (key TAB / CYCLE / SDATE)Distribution = ALART 'V', assessment = 'U'. Classic CO-OM uses TAB='CCSS'
T811SSegments (SEQNR / NAME / SRULE / RRULE / SPERCENT / RCDATA / NEGTEST)Sender rule, receiver rule, variable portion type, negative tracing factor handling
T811LCycle / segment textsSEQNR '0000' = cycle text, anything else = segment text
T811KSelection criteria per segmentOne table holds everything from cycle-level criteria to the allocation base — SETKIND tells them apart (below)
T811FReceiver tracing factors / weighting factorsSRFLAG 'R' = portion/percent (ELEMENT1 = receiver, VALUE = value), 'W' = weighting factor

T811K's SETKIND is the decoder ring:

SETKIND Role
0Cycle-level criteria (e.g. controlling area — T811C itself has no KOKRS field)
1Sender control (version, ...)
2Sender (cost centers, cost elements)
3Receiver (cost centers, orders)
4Receiver control = allocation base (e.g. activity type, statistical key figure)

Groups are stored as a SETID (class 4 + subclass 4 + group name); single values and ranges sit in VALMIN~VALMAX.

Codes → names

Every code column gets its name from the matching master. Internal keys padded with leading zeros (0000004010, 000000100160) are looked up first and stripped only for display:

Code Name source
Cost center (KOSTL)CSKT
Cost element (KSTAR)SKAT
Activity type (LSTAR)CSLT
Statistical key figure (STAGR)TKT03
Order (AUFNR)AUFK-KTEXT
Group (SETID)SETHEADERT
Domain codes (SRULE / RRULE / ...)DD07T (fixed-value texts), T811M (variable portion types)

Program structure

The flow is read_cycles → read_keys_and_texts → build_rows → display_alv:

FORM Role
read_cyclesT811C ⨝ T811S for ALART='V'; optional execution-history filter (LASTEXEC)
read_keys_and_textsBulk-load T811K / T811F / T811L with FOR ALL ENTRIES
build_rowsPer segment: classify T811K by SETKIND, expand groups/ranges, cross-join sender × receiver axes
expand_key / expand_rangeGroup → G_SET_GET_ALL_VALUES; range → CSKB (cost elements) / CSKS (cost centers)
collect_factors / sum_*T811F portions & weighting factors; summary-mode aggregation (1 value → value, more → *)
fill_texts / *_textAttach names from the masters above, then strip leading zeros for display
display_alv / user_commandClassic ALV (REUSE_ALV_GRID_DISPLAY), auto-hide empty columns, double-click → KSV3

Things learned while building it

  1. FOR ALL ENTRIES silently deduplicates. If the SELECT list doesn't include unique key columns, identical rows from different documents collapse into one.
  2. T811S-NEGTEST stores different codes than the KSV1 screen shows (DB 1=Absolute, 2=ToZero, 3=Standard, 4=None, 6·7=Smallest). The standard converts them (CHANGE_NORM_INTO_INTERN) before display — reading the DB value straight into DD07T gives you the wrong text.
  3. The same group name can exist multiple times with different class/subclass. SETHEADERT lookups must use the full SETID (class + subclass + name), not just the name.
  4. The allocation base (T811K SETKIND 4) only applies when the receiver rule is variable portions (RRULE '1'). Fixed-percentage segments can still carry leftover criteria rows — showing them as an allocation base would mislead, so they are cleared.
  5. The default weighting factor 100 is never stored in T811F. Rows exist only where someone changed the value; if everything is default, the column hides itself.
  6. Report globals reset when you return to the selection screen. The =A hidden-option state is kept across restarts in ABAP session memory (EXPORT/IMPORT ... MEMORY ID).

The Korean original (with screenshots and the full source file attached) is here: ABAP ZCO0041 — CO 분배 사이클(KSV1) 정의를 한 그리드로 펼치는 조회 리포트. Related reference posts on this blog: the T-code, table, and ABAP syntax references all mention ZCO0041.

Where these documents come from
Everything on this blog comes from one small dumpling factory built end-to-end in an S/4HANA sandbox — one plant, one product, one month, every document number real. The whole build is written up in two books.
· Free 16-page sample — the opening chapters, no email required
· How Sarah Joined a K-Dumpling Company and Became an SAP Genius — the business novel, 53 pages, $25
· The Dumpling Factory: Building a Complete SAP S/4HANA Company from Scratch — the build manual, 85 pages, $50

Comments

Popular posts from this blog

Modern ABAP Syntax Notes — Patterns and Pitfalls from Real Development

SAP S/4HANA Table Reference — Tables I Actually Query, by Topic

A 36% margin became 6% at month-end, and every posting was correct