Exercise 1: Why WS-SALES-AMT(1) Is January, Not WS-SALES-AMT(0) — Possible Solution ==================================================================== WHAT THIS CHAPTER'S OWN EXAMPLE ESTABLISHES The chapter's own WS-MONTHLY-SALES table is declared with OCCURS 12 TIMES, reserving twelve real copies of WS-SALES-AMT in storage. COBOL tables are genuinely 1-based - the very first element that exists is referenced with subscript 1, not 0. So WS-SALES-AMT(1) is the real first element in the table, which this chapter treats as January. WHY WS-SALES-AMT(0) IS NOT A VALID "ELEMENT BEFORE THE FIRST ONE" In a 0-based language, index 0 genuinely is the first real element - it's just labeled differently. In COBOL, there is no element 0 at all. Subscript 0 doesn't quietly point at some earlier, unintended piece of memory the way an off-by-one bug might in some other languages - it's simply outside the real, valid range of subscripts for a table with OCCURS 12 TIMES (1 through 12), and a real COBOL implementation is expected to treat it as an invalid reference rather than a legitimate element. WHY THE PERFORM VARYING EXAMPLE ALREADY DEPENDS ON THIS The chapter's own loop, PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 12, starts WS-I at 1 specifically because 1 is the real first valid subscript, and stops once WS-I exceeds 12 because 12 is the real total count of elements - not 11, the way a 0-based table's last valid index would be one less than its element count. No "minus one" adjustment appears anywhere in this loop, because COBOL's own numbering already lines up subscript values directly with how many real elements exist. WHY THIS GENUINELY MATTERS COMING FROM A 0-BASED LANGUAGE Someone used to writing FOR i = 0; i < 12; i++ in a 0-based language, then translating that habit directly into COBOL by starting WS-I at 0 and looping WHILE WS-I < 12, would genuinely skip the real twelfth element (December) entirely, since the loop would only ever touch subscripts 0 through 11 - and subscript 0 itself would be an invalid reference to begin with, not simply "an unused slot." The real fix isn't a clever workaround - it's recognizing that COBOL's own subscript numbering and its own element count are already the same scale, with no adjustment needed in either direction. ANSWER: WS-SALES-AMT(1) is the correct reference for January because COBOL tables are genuinely 1-based - the first real element that exists is subscript 1, and there is no element 0 at all, unlike a 0-based language where index 0 legitimately is the first element. This matters directly for someone coming from a 0-based language because carrying over a 0-based loop habit into COBOL (starting a subscript at 0, looping while it's less than the element count) would use an invalid subscript at one end and skip the real last element at the other - the fix is recognizing that COBOL's own subscript range (1 through the element count) already matches the element count exactly, with no minus-one adjustment needed anywhere. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies COBOL's real 1-based indexing from this chapter's own material, explains specifically why subscript 0 is invalid rather than merely "unused," and connects the point directly to a concrete, practical consequence (a skipped last element and an invalid first reference) rather than stating the 1-based rule as an isolated fact.