Writing the INCLUDE statement
Suppose it is the end of the year and you want to sort, by title, only the books that you need to reorder for the coming year. If the number of copies sold this year for a particular book is greater than the number in stock, you can assume you need to order more copies.
An INCLUDE statement that selects only the books you need to order looks like this:
Here are the steps for writing this INCLUDE statement:
Step | Action |
---|---|
1 | Leave at least one blank and type INCLUDE |
2 | Leave at least one blank and type COND= |
3 | Type, in parentheses, and separated
by commas:
|
You can select from the following comparison operators:
You can place the SORT statement either before or after the INCLUDE statement. Control statements do not have to be in any specific order. However, it is good documentation practice to code them in the order in which they are processed. For a flowchart showing the order in which all the control statements are processed, see Processing order of control statements.
INCLUDE COND=(166,4,BI,GT,162,4,BI)
SORT FIELDS=(1,75,CH,A)
This sorts the selected subset of the input records by title in ascending order. Table 2 shows the sorted data set.
Book Title | Number In Stock | Number Sold |
---|---|---|
1 75
|
162 165
|
166 169
|
ADVANCED TOPICS IN PSYCHOANALYSIS
COMPUTER LANGUAGES COMPUTERS: AN INTRODUCTION CRISES OF THE MIDDLE AGES EDITING SOFTWARE MANUALS INKLINGS: AN ANTHOLOGY OF YOUNG POETS INTRODUCTION TO BIOLOGY MODERN ANTHOLOGY OF WOMEN POETS NUMBERING SYSTEMS STRATEGIC MARKETING SUPPLYING THE DEMAND SYSTEM PROGRAMMING THE COMPLETE PROOFREADER |
1
5 20 14 13 2 6 1 6 3 0 4 7 |
12
29 26 17 32 32 11 26 27 35 32 23 19 |
- The number sold is greater than the number in stock.
- The book is published by COR.
To add the second condition, expand the INCLUDE statement
by adding
a logical AND, and compare the contents of the publisher field to
the character string COR
(see Writing constants for
details how to specify constants). Because the publisher field is
4 bytes long, COR
will be padded on the right with one blank.
INCLUDE COND=(166,4,BI,GT,162,4,BI,AND,106,4,CH,EQ,C'COR')
SORT FIELDS=(1,75,CH,A)
Table 3 shows the result.
Book Title | Publisher | Number In Stock | Number Sold |
---|---|---|---|
1 75
|
106 109
|
162 165
|
166 169
|
CRISES OF THE MIDDLE AGES
INKLINGS: AN ANTHOLOGY OF YOUNG POETS MODERN ANTHOLOGY OF WOMEN POETS SUPPLYING THE DEMAND |
COR
COR COR COR |
14
2 1 0 |
17
32 26 32 |
As another example, you might sort only the books for courses 00032 and 10347 by writing the INCLUDE and SORT statements as follows:
INCLUDE COND=(115,5,CH,EQ,C'00032',OR,115,5,CH,EQ,C'10347')
SORT FIELDS=(115,5,CH,A)
- Padding
- adds fillers in data, usually zeros or blanks
- Truncation
- deletes or omits a leading or trailing portion of a string
- In a field-to-field comparison, the shorter field is padded as appropriate (with blanks or zeros).
- In a field-to-constant comparison, the constant is padded or truncated to the length of the field. Decimal constants are padded or truncated on the left. Character and hexadecimal constants are padded or truncated on the right.