Exercise 3: Why Calling BALCHECK With Different Names and a Different Field Still Works — Possible Solution ==================================================================== WHAT CHAPTER 9 ALREADY ESTABLISHED ABOUT HOW CALL MATCHES PARAMETERS Chapter 9's own finding-box states the real rule plainly: caller and subprogram parameters are matched by real position and count, not by name. The first item in a CALL ... USING list binds to the first item in the subprogram's own PROCEDURE DIVISION USING, and the second binds to the second - regardless of what either side happens to call its own field. WHY TXN-AMOUNT WORKS IN PLACE OF WS-BALANCE BALCHECK's own LINKAGE SECTION, unchanged since Chapter 9, declares its first parameter as LS-BALANCE, PIC S9(7)V99. This chapter's own TXN-AMOUNT field is declared with that exact same real PICTURE clause, PIC S9(7)V99. Because CALL "BALCHECK" USING TXN-AMOUNT WS-VALID-FLAG places TXN-AMOUNT first, it binds to LS-BALANCE by real position - and because the two fields share the same real size and shape, that binding works correctly, exactly as it did with WS-BALANCE in Chapter 9's own original example. BALCHECK never knows or cares that the real field is now called TXN-AMOUNT rather than WS-BALANCE - it only ever refers to its own local name, LS-BALANCE. WHY WS-VALID-FLAG STILL WORKS AS THE SECOND PARAMETER The second parameter in this chapter's own CALL statement is WS-VALID-FLAG, PIC X(1) - the exact same field, and the exact same real declaration, used as the second parameter back in Chapter 9's own original example. Nothing about how this field is used has changed at all between the two chapters, so it continues to bind correctly to BALCHECK's own second LINKAGE SECTION item, LS-VALID-FLAG. WHY THIS DEMONSTRATES BALCHECK'S OWN REAL REUSABILITY This is precisely the practical benefit Chapter 9's own material was building toward: a subprogram written once can be genuinely reused by any calling program, as long as the calling program supplies real parameters in the correct order and of the correct real size and shape - it never needs matching field names. TXNBATCH reuses BALCHECK completely unmodified, calling it with a different field (TXN-AMOUNT instead of WS-BALANCE) that simply happens to share the same real PICTURE clause as what BALCHECK's own LINKAGE SECTION expects. ANSWER: CALL "BALCHECK" USING TXN-AMOUNT WS-VALID-FLAG works correctly because Chapter 9's own real rule is that parameters are matched by position, not by name - TXN-AMOUNT, listed first, binds to BALCHECK's first LINKAGE SECTION item, LS-BALANCE, and this succeeds specifically because TXN-AMOUNT shares the exact same real PICTURE clause, S9(7)V99, that LS-BALANCE was declared with. WS-VALID-FLAG, listed second, is the identical field used the same way back in Chapter 9, binding correctly to LS-VALID-FLAG. BALCHECK's own code never references either caller-side name directly - it only ever uses its own local LINKAGE SECTION names - which is exactly what makes it genuinely reusable across different calling programs like this one. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly applies Chapter 9's own positional-matching rule to a new, real calling context, explains specifically why the size/type match (not just the position) is what makes the reuse succeed, and identifies subprogram reusability as the real practical point being demonstrated.