Skip to content

More about Conditional Entries

You have already seen how a single COBOL condition may be used to decide whether to output a report field. Multiple-choice entries are used when you have several possible contents for a field. Just write a series of SOURCE or VALUE clauses, each followed by PRESENT WHEN condition. (The keyword PRESENT is often omitted in a multiple-choice entry.) The period does not come until the end. Report writer examines all the conditions in sequence until it finds the first that is true and then uses the VALUE or SOURCE associated with that true condition. WHEN OTHER can be used to indicate "when none of the given conditions is true". (Compare the use of ELSE in elementary COBOL.) Study the following example:

conditional entries

Note that the third person in our list, ANALYST, has no title because there is no WHEN OTHER ("catch-all") in the choice of titles.

You may produce many useful effects with the PRESENT WHEN clause by causing fields or lines, relative or absolute, to appear or disappear at certain times. If a relative entry (COLUMN + ... or LINE + ...) follows an entry that may or may not be PRESENT, its position is variable:

conditional entries

The ABSENT WHEN clause has the same effect as PRESENT WHEN except that you write the negative condition. Other conditional clauses are PRESENT AFTER (previously known as GROUP INDICATE) and ABSENT AFTER. Instead of checking a standard COBOL condition, these clauses test whether there has been a page advance or a control break since the group was last produced. You may write PRESENT AFTER NEW PAGE, PRESENT AFTER NEW control-id, or PRESENT AFTER NEW control-id OR PAGE:

conditional entries

Back to top