# 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:

Table 1. Steps to Create the INCLUDE Statement for Books You Need to Order
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:
1. The location, length, and data format of the number sold field
2. The comparison operator GT (comparison operators are shown in Figure 1) for greater than
3. The location, length, and data format of the number in stock field.

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.

Table 2. Books for which Number Sold is greater than Number in Stock
Book Title Number In Stock Number Sold
1            75
162  165
166  169
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
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
Suppose you want to reduce the subset of input records even further, to sort only the books you need to order from COR publishers. In this case, two conditions must be true:
• The number sold is greater than the number in stock.

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.

Table 3. COR Books for which Number Sold is greater than Number in Stock
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)``````
Note: In the previous example, you cannot substitute C'32' for C'00032', because character constants are padded on the right with blanks. DFSORT uses the following rules for padding and truncation: