Basic SOUL statements and commands: Difference between revisions
mNo edit summary |
|||
Line 1: | Line 1: | ||
<p> | |||
<p>This chapter discusses in more detail the basic statements that can be used within a request. This chapter also presents the system control commands that you commonly use during a terminal session. There are many more User Language statements and [[:Category:Commands|commands]] than are presented here.</p> | This chapter discusses in more detail the basic statements that can be used within a request. This chapter also presents the system control commands that you commonly use during a terminal session. There are many more User Language statements and [[:Category:Commands|commands]] than are presented here.</p> | ||
__TOC__ | |||
<p>Before learning about User Language statements, it is important to understand the role of <var class="product">Model 204</var> commands that are required for basic request processing.</p> | |||
==System control commands== | |||
<p>System control commands are used outside requests to perform system level operations such as opening files and saving requests. Although system control commands are not part of User Language, many commands you might find useful are illustrated in examples throughout this manual. </p> | <p> | ||
<p>Complete descriptions of these and other commands are included in [[:Category:Commands|commands]]. </p> | Before learning about User Language statements, it is important to understand the role of <var class="product">Model 204</var> commands that are required for basic request processing.</p> | ||
===Use of commands with requests=== | |||
<p>The following system control commands are essential to allow User Language requests to function: </p> | <p> | ||
System control commands are used outside requests to perform system level operations such as opening files and saving requests. Although system control commands are not part of User Language, many commands you might find useful are illustrated in examples throughout this manual. </p> | |||
<p> | |||
Complete descriptions of these and other commands are included in [[:Category:Commands|commands]]. </p> | |||
===Key commands=== | |||
<p> | |||
The following system control commands are essential to allow User Language requests to function: </p> | |||
<table> | <table> | ||
<tr class="head"> | <tr class="head"> | ||
Line 28: | Line 35: | ||
</tr> | </tr> | ||
</table> | </table> | ||
<p>The MORE command and END MORE statement are discussed in the section [[#Request continuation|Request continuation]] and in [[Large Request Considerations#Large Request Considerations|Large Request Considerations]].</p> | <p> | ||
The MORE command and END MORE statement are discussed in the section [[#Request continuation|Request continuation]] and in [[Large Request Considerations#Large Request Considerations|Large Request Considerations]].</p> | |||
<div id="findRecords"></div> | <div id="findRecords"></div> | ||
<p>You can retrieve sets of records, records with specified characteristics, and individual records. </p> | ==FIND statement== | ||
<p>The basic retrieval statement in User Language is the FIND statement. Several forms of the FIND statement are provided for basic and complex retrievals. Basic retrieval statements are discussed in this chapter. See [[Record Retrievals#Record Retrievals|Record Retrievals]] for a discussion of more complex retrieval statements. </p> | <p> | ||
You can retrieve sets of records, records with specified characteristics, and individual records. </p> | |||
<p> | |||
The basic retrieval statement in User Language is the FIND statement. Several forms of the FIND statement are provided for basic and complex retrievals. Basic retrieval statements are discussed in this chapter. See [[Record Retrievals#Record Retrievals|Record Retrievals]] for a discussion of more complex retrieval statements. </p> | |||
===FIND ALL RECORDS statement=== | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The syntax for retrieving records in a <var class="product">Model 204</var> file is:</p> | <p> | ||
<p class="syntax"><span class="term">label</span>: FIND ALL RECORDS | The syntax for retrieving records in a <var class="product">Model 204</var> file is:</p> | ||
<p class="syntax"><span class="term">label</span>: FIND ALL RECORDS | |||
[IN {FILE <span class="term">filename</span> | GROUP <span class="term">groupname</span>}] - | [IN {FILE <span class="term">filename</span> | GROUP <span class="term">groupname</span>}] - | ||
FIND [AND RESERVE] [ALL] RECORDS - | FIND [AND RESERVE] [ALL] RECORDS - | ||
[IN <span class="term">label</span> | ON [LIST] <span class="term">listname</span>] - | [IN <span class="term">label</span> | ON [LIST] <span class="term">listname</span>] - | ||
FOR WHICH | WITH] <span class="term">retrieval-conditions</span> | FOR WHICH | WITH] <span class="term">retrieval-conditions</span> | ||
. . . . . | . . . . . | ||
END FIND | END FIND | ||
Line 63: | Line 76: | ||
</p></li> | </p></li> | ||
</ul> | </ul> | ||
<p><i>fieldname</i> identifies the field from which to retrieve values.</p> | <p> | ||
<p>The <i>value_set</i> label represents an existing value set. Values of the value set in the EQ VALUE IN <i>value_set</i> clause are treated as boolean OR, for example:</p> | <i>fieldname</i> identifies the field from which to retrieve values.</p> | ||
<p> | |||
The <i>value_set</i> label represents an existing value set. Values of the value set in the EQ VALUE IN <i>value_set</i> clause are treated as boolean OR, for example:</p> | |||
<p class="syntax"><span class="term">field</span> = <span class="term">value1</span> OR <span class="term">field</span> = <span class="term">value2</span> OR.... | <p class="syntax"><span class="term">field</span> = <span class="term">value1</span> OR <span class="term">field</span> = <span class="term">value2</span> OR.... | ||
</p> | </p> | ||
<p>The NE VALUE IN <i>value_set</i> clause is likewise treated as boolean AND, for example:</p> | <p> | ||
The NE VALUE IN <i>value_set</i> clause is likewise treated as boolean AND, for example:</p> | |||
<p class="syntax"><span class="term">field</span> <> <span class="term">value1</span> AND <span class="term">field</span> <> <span class="term">value2</span> AND.... | <p class="syntax"><span class="term">field</span> <> <span class="term">value1</span> AND <span class="term">field</span> <> <span class="term">value2</span> AND.... | ||
</p> | </p> | ||
<b>Example</b> | <b>Example</b> | ||
<p>A basic FIND statement is coded as follows: </p> | <p> | ||
A basic FIND statement is coded as follows: </p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS | <p class="code">FIND.RECS: FIND ALL RECORDS | ||
END FIND | END FIND | ||
</p> | </p> | ||
===Ending a FIND statement=== | |||
<p>Except where noted in this manual, you must end a FIND statement with either an END FIND statement or a label. A FIND statement cannot be ended by an END BLOCK statement. </p> | <p> | ||
Except where noted in this manual, you must end a FIND statement with either an END FIND statement or a label. A FIND statement cannot be ended by an END BLOCK statement. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format of the END FIND statement is:</p> | <p> | ||
<p class="syntax">END FIND [<span class="term">label</span>] | The format of the END FIND statement is:</p> | ||
<p class="syntax">END FIND [<span class="term">label</span>] | |||
</p> | </p> | ||
<p>In addition, the retrieval conditions of a FIND statement must not be labeled, even if they begin new lines.</p> | <p> | ||
In addition, the retrieval conditions of a FIND statement must not be labeled, even if they begin new lines.</p> | |||
<p>The FIND statement supports Large Object data in the following format:</p> | ===Large Object data support=== | ||
<p> | |||
The FIND statement supports Large Object data in the following format:</p> | |||
<p class="syntax">FIND <span class="term">lob-fieldname</span> IS [NOT] PRESENT | <p class="syntax">FIND <span class="term">lob-fieldname</span> IS [NOT] PRESENT | ||
</p> | </p> | ||
==Understanding retrieval conditions== | |||
<p>You can incorporate a VALUE IN clause in the following User Language statements: </p> | ===Processing a VALUE IN clause=== | ||
<p> | |||
You can incorporate a VALUE IN clause in the following User Language statements: </p> | |||
<ul> | <ul> | ||
<li>FIND ALL RECORDS: see <i>retrieval-conditions</i> in [[#FIND ALL RECORDS statement|FIND ALL RECORDS statement]]</li> | <li>FIND ALL RECORDS: see <i>retrieval-conditions</i> in [[#FIND ALL RECORDS statement|FIND ALL RECORDS statement]]</li> | ||
Line 100: | Line 123: | ||
</li> | </li> | ||
</ul> | </ul> | ||
<p>The VALUE IN clause is valid for fields that include the ORDERED attribute. The interprocessing between fields works between fields of the same ORDERED type: ORDERED CHARACTER or ORDERED NUMERIC. If processing between fields of differing types, you will likely not find records. </p> | <p> | ||
The VALUE IN clause is valid for fields that include the ORDERED attribute. The interprocessing between fields works between fields of the same ORDERED type: ORDERED CHARACTER or ORDERED NUMERIC. If processing between fields of differing types, you will likely not find records. </p> | |||
<p>If your User Language applications now use nested loops to perform join processing, you could rewrite your applications to take advantage of the VALUE IN clause.</p> | |||
<p>You are likely to see performance improvements, which result in a reduction of overall wall clock time due to:</p> | ====Rewriting applications to take advantage of VALUE IN clause processing==== | ||
<p> | |||
If your User Language applications now use nested loops to perform join processing, you could rewrite your applications to take advantage of the VALUE IN clause.</p> | |||
<p> | |||
You are likely to see performance improvements, which result in a reduction of overall wall clock time due to:</p> | |||
<ul> | <ul> | ||
<li>A decrease in disk I/O</li> | <li>A decrease in disk I/O</li> | ||
Line 110: | Line 137: | ||
</li> | </li> | ||
</ul> | </ul> | ||
<p>The following code example illustrates the use of a VALUE IN clause:</p> | <p> | ||
The following code example illustrates the use of a VALUE IN clause:</p> | |||
<p class="code">OPEN CLAIMS90 | <p class="code">OPEN CLAIMS90 | ||
FILEMGR | FILEMGR | ||
Line 127: | Line 155: | ||
END | END | ||
</p> | </p> | ||
===FIND ALL RECORDS FOR WHICH/WITH statement=== | |||
<p>The basic statement for retrieving data based on specific retrieval conditions is: </p> | <p> | ||
The basic statement for retrieving data based on specific retrieval conditions is: </p> | |||
<p class="syntax"><span class="term">label</span>: FIND ALL RECORDS | <p class="syntax"><span class="term">label</span>: FIND ALL RECORDS | ||
{FOR WHICH | WITH} | {FOR WHICH | WITH} | ||
{<span class="term">fieldname</span>=<span class="term">value</span> | <span class="term">fieldname</span>=<span class="term">value1</span> OR <span class="term">value2</span> | {<span class="term">fieldname</span>=<span class="term">value</span> | <span class="term">fieldname</span>=<span class="term">value1</span> OR <span class="term">value2</span> | ||
| <span class="term">fieldname</span> NOT=<span class="term">value</span> | | <span class="term">fieldname</span> NOT=<span class="term">value</span> | ||
| <span class="term">fieldname</span>=<span class="term">value1</span> AND NOT=<span class="term">value2</span> | | <span class="term">fieldname</span>=<span class="term">value1</span> AND NOT=<span class="term">value2</span> | ||
| <span class="term">fieldname</span> NOT=<span class="term">value1</span> NOR <span class="term">value2</span> | | <span class="term">fieldname</span> NOT=<span class="term">value1</span> NOR <span class="term">value2</span> | ||
| <span class="term">fieldname</span> IS LIKE <span class="term">pattern</span>} | | <span class="term">fieldname</span> IS LIKE <span class="term">pattern</span>} | ||
| <span class="term">fieldname</span> {EQ | NE} VALUE IN <span class="term">value-set</span> | | <span class="term">fieldname</span> {EQ | NE} VALUE IN <span class="term">value-set</span> | ||
</p> | </p> | ||
<b>Example</b> | <b>Example</b> | ||
<p>This FIND ALL RECORDS FOR WHICH statement directs <var class="product">Model 204</var> to look for records of blue Fords:</p> | <p> | ||
This FIND ALL RECORDS FOR WHICH statement directs <var class="product">Model 204</var> to look for records of blue Fords:</p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
MAKE = FORD | MAKE = FORD | ||
COLOR = BLUE | COLOR = BLUE | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p>This statement contains an AND implied by the fact that COLOR = BLUE appears on a separate line. Only the records containing both fields, MAKE = FORD and COLOR = BLUE, are retrieved. </p> | <p> | ||
This statement contains an AND implied by the fact that COLOR = BLUE appears on a separate line. Only the records containing both fields, MAKE = FORD and COLOR = BLUE, are retrieved. </p> | |||
<p>You can use expressions for value retrieval in the following FIND statements:</p> | ==Using expressions for value retrieval== | ||
<p> | |||
You can use expressions for value retrieval in the following FIND statements:</p> | |||
<ul> | <ul> | ||
<li>FIND - POINT$ condition</li> | <li>FIND - POINT$ condition</li> | ||
Line 162: | Line 194: | ||
<li>FIND ALL VALUES</li> | <li>FIND ALL VALUES</li> | ||
</ul> | </ul> | ||
<p>For syntax examples, see [[Statement syntax#Retrieval condition syntax|"Retrieval condition syntax"]]. For more information on expression types that you can use to supply retrieval values, see [[Using Variables and Values in Computation#Using expressions for value retrieval|Using expressions for value retrieval]].</p> | <p> | ||
For syntax examples, see [[Statement syntax#Retrieval condition syntax|"Retrieval condition syntax"]]. For more information on expression types that you can use to supply retrieval values, see [[Using Variables and Values in Computation#Using expressions for value retrieval|Using expressions for value retrieval]].</p> | |||
<p>You can use the Boolean operators AND, OR, NOT, and NOR to create complex retrieval conditions. In the previous example, the AND could be stated implicitly. Thus this statement: </p> | |||
==Using Boolean operators with retrieval statements== | |||
<p> | |||
You can use the Boolean operators AND, OR, NOT, and NOR to create complex retrieval conditions. In the previous example, the AND could be stated implicitly. Thus this statement: </p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
MAKE = FORD AND COLOR = BLUE | MAKE = FORD AND COLOR = BLUE | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p>retrieves the same data as the example in the section above. </p> | <p> | ||
<p>However, the statement:</p> | retrieves the same data as the example in the section above. </p> | ||
<p> | |||
However, the statement:</p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
MAKE = FORD OR COLOR = BLUE | MAKE = FORD OR COLOR = BLUE | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p>finds records for which either the make is Ford, the color is blue, or both.</p> | <p> | ||
<p>The following statement:</p> | finds records for which either the make is Ford, the color is blue, or both.</p> | ||
<p> | |||
The following statement:</p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
MAKE = NOT FORD NOR COLOR = BLUE | MAKE = NOT FORD NOR COLOR = BLUE | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p>finds all records other than blue Fords. NOR is the same as AND NOT. </p> | <p> | ||
finds all records other than blue Fords. NOR is the same as AND NOT. </p> | |||
<p>Although a FIND statement with the NOT operator ultimately returns a foundset that excludes records, <var class="product">Model 204</var> FIND processing starts by creating a foundset based on the retrieval without the NOT operator. For the following code example, <var class="product">Model 204</var> locates all the records with MAKE=FORD, then returns to you the remainders or complimentary foundset: a foundset of records where MAKE=NOT FORD. </p> | ===Understanding NOT operator processing=== | ||
====Creating the complimentary foundset==== | |||
<p> | |||
Although a FIND statement with the NOT operator ultimately returns a foundset that excludes records, <var class="product">Model 204</var> FIND processing starts by creating a foundset based on the retrieval without the NOT operator. For the following code example, <var class="product">Model 204</var> locates all the records with MAKE=FORD, then returns to you the remainders or complimentary foundset: a foundset of records where MAKE=NOT FORD. </p> | |||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
MAKE = NOT FORD | MAKE = NOT FORD | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p class="note"><b>Note:</b> Records that do not have the MAKE field are not included in either foundset.</p> | <p class="note"><b>Note:</b> Records that do not have the MAKE field are not included in either foundset.</p> | ||
<p>In the following abstract examples, notice the placement of the NOT operator.</p> | ====Creating a foundset based on the position of the NOT operator==== | ||
<p> | |||
In the following abstract examples, notice the placement of the NOT operator.</p> | |||
<b>Example A</b> | <b>Example A</b> | ||
<p class="syntax"><span class="term">label1</span>: FIND ALL RECORDS FOR WHICH | <p class="syntax"><span class="term">label1</span>: FIND ALL RECORDS FOR WHICH | ||
NOT <span class="term">fieldname</span> IS LIKE* | NOT <span class="term">fieldname</span> IS LIKE* | ||
</p> | </p> | ||
<p>In Example A, <var class="product">Model 204</var> locates a found set of the records with <i>fieldname</i>=*: that is, any value. Then <var class="product">Model 204</var> applies the NOT operator to <i>fieldname</i> and returns a found set of records that does not include <i>fieldname</i>. This mimics the behavior of IS NOT PRESENT; see [[Record Retrievals#IS PRESENT condition|IS PRESENT condition]].</p> | <p> | ||
In Example A, <var class="product">Model 204</var> locates a found set of the records with <i>fieldname</i>=*: that is, any value. Then <var class="product">Model 204</var> applies the NOT operator to <i>fieldname</i> and returns a found set of records that does not include <i>fieldname</i>. This mimics the behavior of IS NOT PRESENT; see [[Record Retrievals#IS PRESENT condition|IS PRESENT condition]].</p> | |||
<b>Example B</b> | <b>Example B</b> | ||
<p class="syntax"><span class="term">label2</span>: FIND ALL RECORDS FOR WHICH | <p class="syntax"><span class="term">label2</span>: FIND ALL RECORDS FOR WHICH | ||
<span class="term">fieldname</span> IS NOT LIKE* | <span class="term">fieldname</span> IS NOT LIKE* | ||
</p> | </p> | ||
<p>In Example B, <var class="product">Model 204</var> locates a foundset of the records with <i>fieldname</i>=*: that is, any value. Then <var class="product">Model 204</var> applies the NOT operator to LIKE* and returns a foundset of no records, because all values for <i>fieldname</i> have been excluded from the foundset.</p> | <p> | ||
<p>Use the following example data set with three records of defined fields ABC and XYZ to illustrate the differing found sets from the placement of the NOT operator.</p> | In Example B, <var class="product">Model 204</var> locates a foundset of the records with <i>fieldname</i>=*: that is, any value. Then <var class="product">Model 204</var> applies the NOT operator to LIKE* and returns a foundset of no records, because all values for <i>fieldname</i> have been excluded from the foundset.</p> | ||
<p> | |||
Use the following example data set with three records of defined fields ABC and XYZ to illustrate the differing found sets from the placement of the NOT operator.</p> | |||
<table> | <table> | ||
<tr class="head"> | <tr class="head"> | ||
Line 229: | Line 277: | ||
NOT XYZ IS LIKE* | NOT XYZ IS LIKE* | ||
</p> | </p> | ||
<p>The count returned to you is 2: Records 2 and 3.</p> | <p> | ||
The count returned to you is 2: Records 2 and 3.</p> | |||
<b>Repeating Example B</b> | <b>Repeating Example B</b> | ||
<p class="code">LABEL1: FIND ALL RECORDS FOR WHICH | <p class="code">LABEL1: FIND ALL RECORDS FOR WHICH | ||
XYZ NOT IS LIKE* | XYZ NOT IS LIKE* | ||
</p> | </p> | ||
<p>The count returned to you is 0.</p> | <p> | ||
The count returned to you is 0.</p> | |||
<p>Once a set of records or values has been located, the found set can be referred to by using the FOR statement. </p> | ==Loop statements== | ||
<p>The FOR statement introduces a loop. The complete set of statements within the loop is performed once for each record or value located. If no record or values are found, the statements in the loop are skipped.</p> | <p> | ||
<p>When a FIND statement refers back to a previous found set and the found set is empty, then the loop for the FIND statement is skipped. Performance for the FIND processing is enhanced because no retrieval is performed. </p> | Once a set of records or values has been located, the found set can be referred to by using the FOR statement. </p> | ||
<p> | |||
<p>Use the FOR EACH RECORD statement to refer to each record within a set of records located by a FIND statement.</p> | The FOR statement introduces a loop. The complete set of statements within the loop is performed once for each record or value located. If no record or values are found, the statements in the loop are skipped.</p> | ||
<p> | |||
When a FIND statement refers back to a previous found set and the found set is empty, then the loop for the FIND statement is skipped. Performance for the FIND processing is enhanced because no retrieval is performed. </p> | |||
===FOR EACH RECORD statement=== | |||
<p> | |||
Use the FOR EACH RECORD statement to refer to each record within a set of records located by a FIND statement.</p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The form of the FOR EACH RECORD statement is: </p> | <p> | ||
<p class="syntax">FOR EACH RECORD IN <span class="term">label</span> | The form of the FOR EACH RECORD statement is: </p> | ||
<p class="syntax">FOR EACH RECORD IN <span class="term">label</span> | |||
</p> | </p> | ||
<p>where <i>label</i> is the label of a preceding FIND statement. </p> | <p> | ||
where <i>label</i> is the label of a preceding FIND statement. </p> | |||
<b>Example</b> | <b>Example</b> | ||
<p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | <p class="code">FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
Line 255: | Line 312: | ||
. | . | ||
. | . | ||
END FOR | END FOR | ||
</p> | </p> | ||
<p class="note"><b>Notes:</b> | <p class="note"><b>Notes:</b> | ||
<ul> | <ul> | ||
<li>The FOR EACH RECORD statement also can be used to combine retrieval and looping when a particular set of records is processed only once in a request.</li> | <li>The FOR EACH RECORD statement also can be used to combine retrieval and looping when a particular set of records is processed only once in a request.</li> | ||
<li><var class="product">Model 204</var> also supports a prefetch (look-ahead read) feature, which can provide performance improvements for applications containing FOR EACH RECORD statements. See [[Record Loops#Record Loops|Record Loops]] for more information on the FOR EACH RECORD statement and the prefetch feature. | <li><var class="product">Model 204</var> also supports a prefetch (look-ahead read) feature, which can provide performance improvements for applications containing FOR EACH RECORD statements. See [[Record Loops#Record Loops|Record Loops]] for more information on the FOR EACH RECORD statement and the prefetch feature. | ||
</li> | </li> | ||
</ul> | </ul> | ||
</p> | </p> | ||
===Ending a FOR statement=== | |||
<p>The FOR statement must be ended by using an END FOR or an END BLOCK statement. </p> | <p> | ||
The FOR statement must be ended by using an END FOR or an END BLOCK statement. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format of the END FOR statement is: </p> | <p> | ||
<p class="syntax">END FOR [<span class="term">label</span>] | The format of the END FOR statement is: </p> | ||
<p class="syntax">END FOR [<span class="term">label</span>] | |||
</p> | </p> | ||
<p>where <i>label</i> is the label of the line containing the FOR statement.</p> | <p> | ||
where <i>label</i> is the label of the line containing the FOR statement.</p> | |||
<p>Any loop in User Language can be nested: embedded in another loop or series of statements. The END FOR statement returns the nesting level to the same level as the FOR statement.</p> | ===Nested loops=== | ||
<p> | |||
<p>The IF statement tests a condition and then executes one or more statements if the condition is true. </p> | Any loop in User Language can be nested: embedded in another loop or series of statements. The END FOR statement returns the nesting level to the same level as the FOR statement.</p> | ||
<p>The IF statement is discussed in detail in [[Flow of Control in User Language#Flow of Control in User Language|Flow of Control in User Language]]. </p> | |||
==IF statement== | |||
<p> | |||
The IF statement tests a condition and then executes one or more statements if the condition is true. </p> | |||
<p> | |||
The IF statement is discussed in detail in [[Flow of Control in User Language#Flow of Control in User Language|Flow of Control in User Language]]. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format of the IF statement is:</p> | <p> | ||
<p class="syntax">IF <span class="term">condition</span> THEN <span class="term">statements</span> | The format of the IF statement is:</p> | ||
<p class="syntax">IF <span class="term">condition</span> THEN <span class="term">statements</span> | |||
</p> | </p> | ||
<p>where <i>condition</i> follows the syntax rules described in [[Statement syntax#Expression syntax|"Expression syntax"]].</p> | <p> | ||
where <i>condition</i> follows the syntax rules described in [[Statement syntax#Expression syntax|"Expression syntax"]].</p> | |||
<p>The IF statement must be ended by an END IF statement or an END BLOCK statement. </p> | |||
===Ending an IF statement=== | |||
<p> | |||
The IF statement must be ended by an END IF statement or an END BLOCK statement. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format of the END IF statement is:</p> | <p> | ||
The format of the END IF statement is:</p> | |||
<p class="syntax">END IF [<span class="term">label</span>] | <p class="syntax">END IF [<span class="term">label</span>] | ||
</p> | </p> | ||
Line 298: | Line 367: | ||
. | . | ||
. | . | ||
. | . | ||
</p> | </p> | ||
==Counting records== | |||
<p>In addition to retrieving specified records and printing fields from them, you might wish to know the number of records that satisfy a certain condition. Use either of these statements: </p> | <p> | ||
In addition to retrieving specified records and printing fields from them, you might wish to know the number of records that satisfy a certain condition. Use either of these statements: </p> | |||
<ul> | <ul> | ||
<li>COUNT RECORDS IN/ON (or CT)</li> | <li>COUNT RECORDS IN/ON (or CT)</li> | ||
<li>FIND AND PRINT COUNT (or FPC)</li> | <li>FIND AND PRINT COUNT (or FPC)</li> | ||
</ul> | </ul> | ||
<p>The COUNT RECORDS statement takes two forms:</p> | ===COUNT RECORDS IN/ON statement=== | ||
<p> | |||
The COUNT RECORDS statement takes two forms:</p> | |||
<ul> | <ul> | ||
<li>COUNT RECORDS IN is used for counting records in a set of records retrieved with the FIND ALL RECORDS statement.</li> | <li>COUNT RECORDS IN is used for counting records in a set of records retrieved with the FIND ALL RECORDS statement.</li> | ||
Line 315: | Line 387: | ||
</li> | </li> | ||
</ul> | </ul> | ||
<p>The COUNT RECORDS IN/ON statement is supported in scattered group context. See [[Files, Groups, and Reference Context#Files, Groups, and Reference Context|Files, Groups, and Reference Context]] for more information on the reference context.</p> | <p> | ||
The COUNT RECORDS IN/ON statement is supported in scattered group context. See [[Files, Groups, and Reference Context#Files, Groups, and Reference Context|Files, Groups, and Reference Context]] for more information on the reference context.</p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The format for the COUNT RECORDS IN statement is:</p> | <p> | ||
<p class="syntax"><span class="term">label.b</span>: COUNT RECORDS IN <span class="term">label.a</span> | The format for the COUNT RECORDS IN statement is:</p> | ||
<p class="syntax"><span class="term">label.b</span>: COUNT RECORDS IN <span class="term">label.a</span> | |||
</p> | </p> | ||
<p>where <i>label.a</i> is the label of a previous FIND statement. </p> | <p> | ||
<p>The format for the COUNT RECORDS ON statement is:</p> | where <i>label.a</i> is the label of a previous FIND statement. </p> | ||
<p class="syntax"><span class="term">label.b</span>: COUNT RECORDS ON <span class="term">list</span> | <p> | ||
The format for the COUNT RECORDS ON statement is:</p> | |||
<p class="syntax"><span class="term">label.b</span>: COUNT RECORDS ON <span class="term">list</span> | |||
</p> | </p> | ||
<p>where <i>list</i> is the name of a list on which you have previously placed found records.</p> | <p> | ||
<p>For both forms of the COUNT RECORDS statement, you can print the count using the statement:</p> | where <i>list</i> is the name of a list on which you have previously placed found records.</p> | ||
<p class="syntax">PRINT COUNT IN <span class="term">label.b</span> | <p> | ||
For both forms of the COUNT RECORDS statement, you can print the count using the statement:</p> | |||
<p class="syntax">PRINT COUNT IN <span class="term">label.b</span> | |||
</p> | </p> | ||
<b>Example</b> | <b>Example</b> | ||
<p>This COUNT RECORDS IN request:</p> | <p> | ||
This COUNT RECORDS IN request:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
DRIVER: FIND ALL RECORDS FOR WHICH | DRIVER: FIND ALL RECORDS FOR WHICH | ||
Line 337: | Line 416: | ||
CT: COUNT RECORDS IN DRIVER | CT: COUNT RECORDS IN DRIVER | ||
PRINT COUNT IN CT | PRINT COUNT IN CT | ||
END | END | ||
</p> | </p> | ||
<p>causes <var class="product">Model 204</var> to note that two records were found by the FIND statement. <var class="product">Model 204</var> then prints the number 2.</p> | <p> | ||
causes <var class="product">Model 204</var> to note that two records were found by the FIND statement. <var class="product">Model 204</var> then prints the number 2.</p> | |||
<p>The FIND AND PRINT COUNT statement is used to combine record retrieval with the COUNT and associated PRINT statements. </p> | ===FIND AND PRINT COUNT statement=== | ||
<p> | |||
The FIND AND PRINT COUNT statement is used to combine record retrieval with the COUNT and associated PRINT statements. </p> | |||
<b>Example 1</b> | <b>Example 1</b> | ||
<p>This statement: </p> | <p> | ||
This statement: </p> | |||
<p class="code">DRIVER: FIND AND PRINT COUNT | <p class="code">DRIVER: FIND AND PRINT COUNT | ||
RECTYPE = DRIVER | RECTYPE = DRIVER | ||
POLICY NO = 100340 | POLICY NO = 100340 | ||
END FIND | END FIND | ||
</p> | </p> | ||
<p>is similar to:</p> | <p> | ||
is similar to:</p> | |||
<p class="code">DRIVER: FIND ALL RECORDS FOR WHICH | <p class="code">DRIVER: FIND ALL RECORDS FOR WHICH | ||
RECTYPE = DRIVER | RECTYPE = DRIVER | ||
Line 356: | Line 439: | ||
END FIND | END FIND | ||
CT: COUNT RECORDS IN DRIVER | CT: COUNT RECORDS IN DRIVER | ||
PRINT COUNT IN CT | PRINT COUNT IN CT | ||
</p> | </p> | ||
<p>The label for the FIND AND PRINT COUNT statement can be referred to in the same way in which a label for a FIND ALL RECORDS FOR WHICH statement can be used. </p> | <p> | ||
The label for the FIND AND PRINT COUNT statement can be referred to in the same way in which a label for a FIND ALL RECORDS FOR WHICH statement can be used. </p> | |||
<b>Example 2</b> | <b>Example 2</b> | ||
<p>The count found by a FIND AND PRINT COUNT statement cannot be positioned to a specified column. The position defaults to column 1 or the next print location, if preceded by an ellipsis (...).</p> | <p> | ||
<p>For example, this request:</p> | The count found by a FIND AND PRINT COUNT statement cannot be positioned to a specified column. The position defaults to column 1 or the next print location, if preceded by an ellipsis (...).</p> | ||
<p> | |||
For example, this request:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
DRIVER: FIND AND PRINT COUNT | DRIVER: FIND AND PRINT COUNT | ||
Line 370: | Line 456: | ||
PRINT FULLNAME | PRINT FULLNAME | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
<p>results in this output:</p> | <p> | ||
results in this output:</p> | |||
<p class="code">2 | <p class="code">2 | ||
ABBOTT, FRANKLIN G | ABBOTT, FRANKLIN G | ||
ABBOTT, GAIL H | ABBOTT, GAIL H | ||
</p> | </p> | ||
<p>Print statements are often used in loops to display information from each record located by a FIND statement. </p> | ==Output statements== | ||
<p>The two statements described in this section, PRINT ALL INFORMATION and PRINT <i>fieldname</i>, are basic output statements. PRINT ALL INFORMATION and PRINT <i>fieldname</i> can be used only in a record loop.</p> | <p> | ||
<p>The PAI INTO statement, an extension of the PAI statement, allows you to store the field names and values associated with a record in an array. See [[Record Loops#PAI INTO statement|PAI INTO statement]] for more information.</p> | Print statements are often used in loops to display information from each record located by a FIND statement. </p> | ||
<p>More complex statements are used for variable format output. These are discussed in [[Report Generation#Report Generation|Report Generation]].</p> | <p> | ||
The two statements described in this section, PRINT ALL INFORMATION and PRINT <i>fieldname</i>, are basic output statements. PRINT ALL INFORMATION and PRINT <i>fieldname</i> can be used only in a record loop.</p> | |||
<p> | |||
The PAI INTO statement, an extension of the PAI statement, allows you to store the field names and values associated with a record in an array. See [[Record Loops#PAI INTO statement|PAI INTO statement]] for more information.</p> | |||
<p> | |||
More complex statements are used for variable format output. These are discussed in [[Report Generation#Report Generation|Report Generation]].</p> | |||
===PRINT ALL INFORMATION (or PAI) statement=== | |||
<b>Purpose</b> | <b>Purpose</b> | ||
<p>The PRINT ALL INFORMATION (or PAI) statement causes output of whole records. </p> | <p> | ||
The PRINT ALL INFORMATION (or PAI) statement causes output of whole records. </p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The form of the PAI statement is:</p> | <p> | ||
The form of the PAI statement is:</p> | |||
<p class="syntax">PRINT ALL INFORMATION <span class="term">option</span> | <p class="syntax">PRINT ALL INFORMATION <span class="term">option</span> | ||
</p> | </p> | ||
<p>where <i>option</i> can be one of the following and specifies how Large Object fields are handled.</p> | <p> | ||
where <i>option</i> can be one of the following and specifies how Large Object fields are handled.</p> | |||
<ul> | <ul> | ||
<li>LOB_FLOD, the default, which means output in a format that FLOD can read and reload Large Object fields. The output includes the descriptor in binary format, plus the full field value.</li> | <li>LOB_FLOD, the default, which means output in a format that FLOD can read and reload Large Object fields. The output includes the descriptor in binary format, plus the full field value.</li> | ||
Line 403: | Line 499: | ||
</ul> | </ul> | ||
<b>Example</b> | <b>Example</b> | ||
<p>This request:</p> | <p> | ||
This request:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
FIND.RECS: FIND ALL RECORDS FOR WHICH | FIND.RECS: FIND ALL RECORDS FOR WHICH | ||
Line 412: | Line 509: | ||
PRINT ALL INFORMATION | PRINT ALL INFORMATION | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
<p>results in output with the format:</p> | <p> | ||
results in output with the format:</p> | |||
<p class="code">FULLNAME = ABBOTT, GAIL H | <p class="code">FULLNAME = ABBOTT, GAIL H | ||
POLICY NO = 100340 | POLICY NO = 100340 | ||
Line 425: | Line 523: | ||
INCIDENT = T3 | INCIDENT = T3 | ||
INCIDENT DATE = 19900921 | INCIDENT DATE = 19900921 | ||
DATE OF BIRTH = 19390305 | DATE OF BIRTH = 19390305 | ||
</p> | </p> | ||
<p>In the example on the previous page, the fieldname = value pair, | ===INVISIBLE fields not printed=== | ||
<p> | |||
In the example on the previous page, the fieldname = value pair, | |||
RECTYPE = DRIVER, is not printed in the output because the RECTYPE field has the INVISIBLE attribute. </p> | RECTYPE = DRIVER, is not printed in the output because the RECTYPE field has the INVISIBLE attribute. </p> | ||
<p>For more information about the INVISIBLE attribute, refer to [[Field_Design_(File_Management)#Field_descriptions_and_attributes | Field descriptions and attributes]]. </p> | <p> | ||
For more information about the INVISIBLE attribute, refer to [[Field_Design_(File_Management)#Field_descriptions_and_attributes | Field descriptions and attributes]]. </p> | |||
===PRINT <i>fieldname</i> statement=== | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>To display the value of a certain field in a record, use this form of the PRINT statement: </p> | <p> | ||
To display the value of a certain field in a record, use this form of the PRINT statement: </p> | |||
<p class="syntax">PRINT <span class="term">fieldname</span> [AND <span class="term">fieldname2</span>] | <p class="syntax">PRINT <span class="term">fieldname</span> [AND <span class="term">fieldname2</span>] | ||
</p> | </p> | ||
<b>Example</b> | <b>Example</b> | ||
<p>Here is a sample PRINT <i>fieldname</i> statement:</p> | <p> | ||
Here is a sample PRINT <i>fieldname</i> statement:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
DRIVER: FIND ALL RECORDS FOR WHICH | DRIVER: FIND ALL RECORDS FOR WHICH | ||
Line 447: | Line 550: | ||
PRINT FULLNAME | PRINT FULLNAME | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
<p>In response to the above request, <var class="product">Model 204</var> prints:</p> | <p> | ||
In response to the above request, <var class="product">Model 204</var> prints:</p> | |||
<p class="code">ABBOTT, FRANKLIN G | <p class="code">ABBOTT, FRANKLIN G | ||
ABBOTT, GAIL H | ABBOTT, GAIL H | ||
</p> | </p> | ||
<p>Each value of the FULLNAME field is displayed on a new line. A record that has no FULLNAME field produces a blank line of output. </p> | <p> | ||
Each value of the FULLNAME field is displayed on a new line. A record that has no FULLNAME field produces a blank line of output. </p> | |||
<p>The values of more than one field can be printed on the same output line by using the keywords AND and WITH. AND causes a space to be printed between values, as in the following example:</p> | |||
===Printing several fields=== | |||
<p> | |||
The values of more than one field can be printed on the same output line by using the keywords AND and WITH. AND causes a space to be printed between values, as in the following example:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
DRIVER: FIND ALL RECORDS FOR WHICH | DRIVER: FIND ALL RECORDS FOR WHICH | ||
Line 464: | Line 571: | ||
PRINT SEX AND DATE OF BIRTH | PRINT SEX AND DATE OF BIRTH | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
<p>Running the request above results in this output:</p> | <p> | ||
Running the request above results in this output:</p> | |||
<p class="code">M 19480204 | <p class="code">M 19480204 | ||
F 19390305 | F 19390305 | ||
</p> | </p> | ||
<p>If a retrieved record has no SEX field, the value of DATE OF BIRTH is printed on a line beginning with a space, as specified by the keyword AND, for example:</p> | <p> | ||
If a retrieved record has no SEX field, the value of DATE OF BIRTH is printed on a line beginning with a space, as specified by the keyword AND, for example:</p> | |||
<p class="code">19480204 | <p class="code">19480204 | ||
</p> | </p> | ||
<p>If a record has neither field, it produces a blank line of output.</p> | <p> | ||
<p>The keyword WITH works like AND except that WITH does not cause a space to be printed between values. </p> | If a record has neither field, it produces a blank line of output.</p> | ||
<p> | |||
<p>The SKIP LINE(S) and NEW PAGE statements enable you to control spacing between lines.</p> | The keyword WITH works like AND except that WITH does not cause a space to be printed between values. </p> | ||
<p>The SKIP LINE(S) statement directs <var class="product">Model 204</var> to skip a specified number of lines before printing the next line of output. If the number of lines remaining on a page is fewer than the number of lines specified, <var class="product">Model 204</var> skips the remainder of the lines on the page, starts a new page, and then continues to skip lines until <i>n</i> is reached. </p> | ===Controlling spacing between output lines=== | ||
<p>The syntax of the SKIP LINE(S) statement is as follows:</p> | <p> | ||
The SKIP LINE(S) and NEW PAGE statements enable you to control spacing between lines.</p> | |||
====SKIP LINE(S)==== | |||
<p> | |||
The SKIP LINE(S) statement directs <var class="product">Model 204</var> to skip a specified number of lines before printing the next line of output. If the number of lines remaining on a page is fewer than the number of lines specified, <var class="product">Model 204</var> skips the remainder of the lines on the page, starts a new page, and then continues to skip lines until <i>n</i> is reached. </p> | |||
<p> | |||
The syntax of the SKIP LINE(S) statement is as follows:</p> | |||
<p class="syntax">SKIP {<span class="term">n</span> | %<span class="term">variable</span>} LINE[S] | <p class="syntax">SKIP {<span class="term">n</span> | %<span class="term">variable</span>} LINE[S] | ||
</p> | </p> | ||
Line 489: | Line 605: | ||
</li> | </li> | ||
</ul> | </ul> | ||
<p>SKIP %<i>variable</i> LINE(S) bypasses the processing and skips no lines if the value of the %<i>variable</i> is zero. However, if <i>n</i> is zero, SKIP <i>n</i> LINES is invalid. </p> | <p> | ||
<p>The SKIP %<i>variable</i> LINE(S) option does not apply to the full-screen SKIP LINE(S) statement, as described on [[Full-Screen Feature#SKIP statement for menus|SKIP statement for menus]].</p> | SKIP %<i>variable</i> LINE(S) bypasses the processing and skips no lines if the value of the %<i>variable</i> is zero. However, if <i>n</i> is zero, SKIP <i>n</i> LINES is invalid. </p> | ||
<p> | |||
<p>The NEW PAGE statement directs <var class="product">Model 204</var> to start a new page before printing further output. </p> | The SKIP %<i>variable</i> LINE(S) option does not apply to the full-screen SKIP LINE(S) statement, as described on [[Full-Screen Feature#SKIP statement for menus|SKIP statement for menus]].</p> | ||
<p>For example, in response to:</p> | |||
====NEW PAGE==== | |||
<p> | |||
The NEW PAGE statement directs <var class="product">Model 204</var> to start a new page before printing further output. </p> | |||
<p> | |||
For example, in response to:</p> | |||
<p class="code">FOR EACH RECORD IN DRIVER | <p class="code">FOR EACH RECORD IN DRIVER | ||
NEW PAGE | NEW PAGE | ||
PRINT ALL INFORMATION | PRINT ALL INFORMATION | ||
END FOR | END FOR | ||
</p> | </p> | ||
<p><var class="product">Model 204</var> starts a new page before printing each record.</p> | <p> | ||
<var class="product">Model 204</var> starts a new page before printing each record.</p> | |||
<p>A <var class="product">Model 204</var> file that contains Large Object data can be reorganized using the standard [[File_Loading_Techniques#Loading Large Object Data | PAI and FLOD procedure]], which employs the User Language PAI (PRINT ALL INFORMATION) statement to unload the data from a file, and a standard FLOD program to reload the data. This is identical to previous releases of <var class="product">Model 204</var>, and no change to your existing unload or load code is required.</p> | |||
===Loading Large Object data=== | |||
<p>Many User Language statements can be preceded by an IN clause. An IN indicates explicitly the file or group to which a statement applies when several files or groups are open.</p> | <p> | ||
<p>When you do not use the IN clause, <var class="product">Model 204</var> acts on the default file as established by the most recently executed OPEN or DEFAULT command.</p> | |||
<p>In addition to specifying an individual file or group name, the IN clause has more detailed information about the reference context of the statement it precedes. For example, when you are working with individual remote files, you can specify the location of the file; and when you are working in group context, you can restrict the context of certain statements to one member file in the group by using the IN GROUP MEMBER form of the IN clause.</p> | A <var class="product">Model 204</var> file that contains Large Object data can be reorganized using the standard [[File_Loading_Techniques#Loading Large Object Data | PAI and FLOD procedure]], which employs the User Language PAI (PRINT ALL INFORMATION) statement to unload the data from a file, and a standard FLOD program to reload the data. This is identical to previous releases of <var class="product">Model 204</var>, and no change to your existing unload or load code is required.</p> | ||
<p>Refer to [[Files, Groups, and Reference Context#Files, Groups, and Reference Context|Files, Groups, and Reference Context]] for more information on the reference context and ways to use the IN clause.</p> | |||
==IN clauses== | |||
<p> | |||
Many User Language statements can be preceded by an IN clause. An IN indicates explicitly the file or group to which a statement applies when several files or groups are open.</p> | |||
<p> | |||
When you do not use the IN clause, <var class="product">Model 204</var> acts on the default file as established by the most recently executed OPEN or DEFAULT command.</p> | |||
<p> | |||
In addition to specifying an individual file or group name, the IN clause has more detailed information about the reference context of the statement it precedes. For example, when you are working with individual remote files, you can specify the location of the file; and when you are working in group context, you can restrict the context of certain statements to one member file in the group by using the IN GROUP MEMBER form of the IN clause.</p> | |||
<p> | |||
Refer to [[Files, Groups, and Reference Context#Files, Groups, and Reference Context|Files, Groups, and Reference Context]] for more information on the reference context and ways to use the IN clause.</p> | |||
<b>Syntax</b> | <b>Syntax</b> | ||
<p>The simplest form of the IN clause is:</p> | <p> | ||
<p class="syntax">IN {<span class="term">filename</span> | <span class="term">groupname</span>} [AT <span class="term">location</span>] | The simplest form of the IN clause is:</p> | ||
<p class="syntax">IN {<span class="term">filename</span> | <span class="term">groupname</span>} [AT <span class="term">location</span>] | |||
</p> | </p> | ||
<b>Example</b> | <b>Example</b> | ||
<p>This request prints the policy number, body, and make of a policy in the VEHICLES file, and the full name, marital status, and sex of records for that policy number in the CLIENTS file:</p> | <p> | ||
This request prints the policy number, body, and make of a policy in the VEHICLES file, and the full name, marital status, and sex of records for that policy number in the CLIENTS file:</p> | |||
<p class="code">OPEN CLIENTS | <p class="code">OPEN CLIENTS | ||
OPEN VEHICLES | OPEN VEHICLES | ||
Line 531: | Line 663: | ||
PRINT FULLNAME AND MARITAL STATUS AND SEX | PRINT FULLNAME AND MARITAL STATUS AND SEX | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
<p>The output from this request would be:</p> | <p> | ||
The output from this request would be:</p> | |||
<p class="code">100340 4DR DATSUN | <p class="code">100340 4DR DATSUN | ||
ABBOTT, FRANKLIN G SINGLE M | ABBOTT, FRANKLIN G SINGLE M | ||
ABBOTT, GAIL H SINGLE F | ABBOTT, GAIL H SINGLE F | ||
</p> | </p> | ||
==Request continuation== | |||
<p>Lengthy requests can be handled by using the END MORE statement and the MORE command. See [[Large Request Considerations#Large Request Considerations|Large Request Considerations]] for more information on request continuation, including a discussion of the MORE command and the END MORE statement and its USE option. </p> | <p> | ||
Lengthy requests can be handled by using the END MORE statement and the MORE command. See [[Large Request Considerations#Large Request Considerations|Large Request Considerations]] for more information on request continuation, including a discussion of the MORE command and the END MORE statement and its USE option. </p> | |||
<b>Example</b> | <b>Example</b> | ||
<p>The sample request below tells you how many records exist in a given file for female drivers registered in Florida:</p> | <p> | ||
The sample request below tells you how many records exist in a given file for female drivers registered in Florida:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
GET.DRIVER: FIND AND PRINT COUNT | GET.DRIVER: FIND AND PRINT COUNT | ||
Line 549: | Line 684: | ||
SEX = F | SEX = F | ||
END FIND | END FIND | ||
END MORE | END MORE | ||
</p> | </p> | ||
<p>After printing its output, this request returns you to command level. Using the MORE command, you can continue the request, adding further statements as well as referring to the results of statements in the original request. If, for example, you wanted to perform further processing of the records found in the original request without repeating the FIND operation, you could enter the following lines, referencing the label GET.DRIVER:</p> | <p> | ||
After printing its output, this request returns you to command level. Using the MORE command, you can continue the request, adding further statements as well as referring to the results of statements in the original request. If, for example, you wanted to perform further processing of the records found in the original request without repeating the FIND operation, you could enter the following lines, referencing the label GET.DRIVER:</p> | |||
<p class="code">MORE | <p class="code">MORE | ||
FOR EACH RECORD IN GET.DRIVER | FOR EACH RECORD IN GET.DRIVER | ||
PRINT FULLNAME AND DATE OF BIRTH | PRINT FULLNAME AND DATE OF BIRTH | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
[[Category:SOUL]] | [[Category:SOUL]] |
Revision as of 21:03, 31 May 2013
This chapter discusses in more detail the basic statements that can be used within a request. This chapter also presents the system control commands that you commonly use during a terminal session. There are many more User Language statements and commands than are presented here.
System control commands
Before learning about User Language statements, it is important to understand the role of Model 204 commands that are required for basic request processing.
Use of commands with requests
System control commands are used outside requests to perform system level operations such as opening files and saving requests. Although system control commands are not part of User Language, many commands you might find useful are illustrated in examples throughout this manual.
Complete descriptions of these and other commands are included in commands.
Key commands
The following system control commands are essential to allow User Language requests to function:
Command | Action |
---|---|
BEGIN | Initiates a User Language request. |
OPEN | Opens a Model 204 file or group. See OPEN or OPENC statement for a detailed discussion of the OPEN statement. Refer to IN clauses for a discussion of using the IN clause when several files are open. |
CLOSE | Closes a Model 204 file or group that has been opened. |
The MORE command and END MORE statement are discussed in the section Request continuation and in Large Request Considerations.
FIND statement
You can retrieve sets of records, records with specified characteristics, and individual records.
The basic retrieval statement in User Language is the FIND statement. Several forms of the FIND statement are provided for basic and complex retrievals. Basic retrieval statements are discussed in this chapter. See Record Retrievals for a discussion of more complex retrieval statements.
FIND ALL RECORDS statement
Syntax
The syntax for retrieving records in a Model 204 file is:
label: FIND ALL RECORDS [IN {FILE filename | GROUP groupname}] - FIND [AND RESERVE] [ALL] RECORDS - [IN label | ON [LIST] listname] - FOR WHICH | WITH] retrieval-conditions . . . . . END FIND
Where
- filename specifies the file that has the records you want to retrieve.
- groupname specifies the group of files that has the records you want to retrieve.
- label specifies the label of a preceding FIND statement.
- listname specifies a list from a preceding FIND statement.
- The retrieval-conditions can be:
[fieldname {EQ | NE} VALUE IN value_set]
fieldname identifies the field from which to retrieve values.
The value_set label represents an existing value set. Values of the value set in the EQ VALUE IN value_set clause are treated as boolean OR, for example:
field = value1 OR field = value2 OR....
The NE VALUE IN value_set clause is likewise treated as boolean AND, for example:
field <> value1 AND field <> value2 AND....
Example
A basic FIND statement is coded as follows:
FIND.RECS: FIND ALL RECORDS END FIND
Ending a FIND statement
Except where noted in this manual, you must end a FIND statement with either an END FIND statement or a label. A FIND statement cannot be ended by an END BLOCK statement.
Syntax
The format of the END FIND statement is:
END FIND [label]
In addition, the retrieval conditions of a FIND statement must not be labeled, even if they begin new lines.
Large Object data support
The FIND statement supports Large Object data in the following format:
FIND lob-fieldname IS [NOT] PRESENT
Understanding retrieval conditions
Processing a VALUE IN clause
You can incorporate a VALUE IN clause in the following User Language statements:
- FIND ALL RECORDS: see retrieval-conditions in FIND ALL RECORDS statement
- FIND ALL VALUES: see FIND ALL VALUES statement
- FOR EACH RECORD WHERE: see Restricting FOR EACH RECORD processing
The VALUE IN clause is valid for fields that include the ORDERED attribute. The interprocessing between fields works between fields of the same ORDERED type: ORDERED CHARACTER or ORDERED NUMERIC. If processing between fields of differing types, you will likely not find records.
Rewriting applications to take advantage of VALUE IN clause processing
If your User Language applications now use nested loops to perform join processing, you could rewrite your applications to take advantage of the VALUE IN clause.
You are likely to see performance improvements, which result in a reduction of overall wall clock time due to:
- A decrease in disk I/O
- Decreases in the number of FINDs and BXFINDs, because the processing has moved. You will see an increase in BXNEXTs
The following code example illustrates the use of a VALUE IN clause:
OPEN CLAIMS90 FILEMGR REDEFINE FIELD POLICY NO (ORD CHAR) OPEN CLIENTS FILEMGR REDEFINE FIELD POLICY NO (ORD CHAR) BEGIN /? FIND ALL CLIENTS WHO MADE CLAIMS ?/ CLAIM.POLICYS: IN CLAIMS90 FDV POLICY NO CLIENT.FD: IN CLIENTS FD POLICY NO EQ VALUE IN CLAIM.POLICYS END FIND FR CLIENT.FD PRINT POLICY NO AND FULLNAME END FOR END
FIND ALL RECORDS FOR WHICH/WITH statement
The basic statement for retrieving data based on specific retrieval conditions is:
label: FIND ALL RECORDS {FOR WHICH | WITH} {fieldname=value | fieldname=value1 OR value2 | fieldname NOT=value | fieldname=value1 AND NOT=value2 | fieldname NOT=value1 NOR value2 | fieldname IS LIKE pattern} | fieldname {EQ | NE} VALUE IN value-set
Example
This FIND ALL RECORDS FOR WHICH statement directs Model 204 to look for records of blue Fords:
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = FORD COLOR = BLUE END FIND
This statement contains an AND implied by the fact that COLOR = BLUE appears on a separate line. Only the records containing both fields, MAKE = FORD and COLOR = BLUE, are retrieved.
Using expressions for value retrieval
You can use expressions for value retrieval in the following FIND statements:
- FIND - POINT$ condition
- FIND - SFL$ and SFGE$ conditions
- FIND ALL VALUES
For syntax examples, see "Retrieval condition syntax". For more information on expression types that you can use to supply retrieval values, see Using expressions for value retrieval.
Using Boolean operators with retrieval statements
You can use the Boolean operators AND, OR, NOT, and NOR to create complex retrieval conditions. In the previous example, the AND could be stated implicitly. Thus this statement:
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = FORD AND COLOR = BLUE END FIND
retrieves the same data as the example in the section above.
However, the statement:
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = FORD OR COLOR = BLUE END FIND
finds records for which either the make is Ford, the color is blue, or both.
The following statement:
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = NOT FORD NOR COLOR = BLUE END FIND
finds all records other than blue Fords. NOR is the same as AND NOT.
Understanding NOT operator processing
Creating the complimentary foundset
Although a FIND statement with the NOT operator ultimately returns a foundset that excludes records, Model 204 FIND processing starts by creating a foundset based on the retrieval without the NOT operator. For the following code example, Model 204 locates all the records with MAKE=FORD, then returns to you the remainders or complimentary foundset: a foundset of records where MAKE=NOT FORD.
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = NOT FORD END FIND
Note: Records that do not have the MAKE field are not included in either foundset.
Creating a foundset based on the position of the NOT operator
In the following abstract examples, notice the placement of the NOT operator.
Example A
label1: FIND ALL RECORDS FOR WHICH NOT fieldname IS LIKE*
In Example A, Model 204 locates a found set of the records with fieldname=*: that is, any value. Then Model 204 applies the NOT operator to fieldname and returns a found set of records that does not include fieldname. This mimics the behavior of IS NOT PRESENT; see IS PRESENT condition.
Example B
label2: FIND ALL RECORDS FOR WHICH fieldname IS NOT LIKE*
In Example B, Model 204 locates a foundset of the records with fieldname=*: that is, any value. Then Model 204 applies the NOT operator to LIKE* and returns a foundset of no records, because all values for fieldname have been excluded from the foundset.
Use the following example data set with three records of defined fields ABC and XYZ to illustrate the differing found sets from the placement of the NOT operator.
Record number | Field ABC | Field XYZ |
---|---|---|
1 | 14 | 11 |
2 | 25 | |
3 | 7 |
Repeating Example A
LABEL1: FIND ALL RECORDS FOR WHICH NOT XYZ IS LIKE*
The count returned to you is 2: Records 2 and 3.
Repeating Example B
LABEL1: FIND ALL RECORDS FOR WHICH XYZ NOT IS LIKE*
The count returned to you is 0.
Loop statements
Once a set of records or values has been located, the found set can be referred to by using the FOR statement.
The FOR statement introduces a loop. The complete set of statements within the loop is performed once for each record or value located. If no record or values are found, the statements in the loop are skipped.
When a FIND statement refers back to a previous found set and the found set is empty, then the loop for the FIND statement is skipped. Performance for the FIND processing is enhanced because no retrieval is performed.
FOR EACH RECORD statement
Use the FOR EACH RECORD statement to refer to each record within a set of records located by a FIND statement.
Syntax
The form of the FOR EACH RECORD statement is:
FOR EACH RECORD IN label
where label is the label of a preceding FIND statement.
Example
FIND.RECS: FIND ALL RECORDS FOR WHICH MAKE = FORD END FIND PRINT.MODEL: FOR EACH RECORD IN FIND.RECS . . . END FOR
Notes:
- The FOR EACH RECORD statement also can be used to combine retrieval and looping when a particular set of records is processed only once in a request.
- Model 204 also supports a prefetch (look-ahead read) feature, which can provide performance improvements for applications containing FOR EACH RECORD statements. See Record Loops for more information on the FOR EACH RECORD statement and the prefetch feature.
Ending a FOR statement
The FOR statement must be ended by using an END FOR or an END BLOCK statement.
Syntax
The format of the END FOR statement is:
END FOR [label]
where label is the label of the line containing the FOR statement.
Nested loops
Any loop in User Language can be nested: embedded in another loop or series of statements. The END FOR statement returns the nesting level to the same level as the FOR statement.
IF statement
The IF statement tests a condition and then executes one or more statements if the condition is true.
The IF statement is discussed in detail in Flow of Control in User Language.
Syntax
The format of the IF statement is:
IF condition THEN statements
where condition follows the syntax rules described in "Expression syntax".
Ending an IF statement
The IF statement must be ended by an END IF statement or an END BLOCK statement.
Syntax
The format of the END IF statement is:
END IF [label]
Example
FOR EACH RECORD IN FIND.RECS IF TOTAL PREMIUM = 300 THEN PRINT POLICY NO END IF END FOR . . .
Counting records
In addition to retrieving specified records and printing fields from them, you might wish to know the number of records that satisfy a certain condition. Use either of these statements:
- COUNT RECORDS IN/ON (or CT)
- FIND AND PRINT COUNT (or FPC)
COUNT RECORDS IN/ON statement
The COUNT RECORDS statement takes two forms:
- COUNT RECORDS IN is used for counting records in a set of records retrieved with the FIND ALL RECORDS statement.
- COUNT RECORDS ON is used for counting records on a list. See Lists for more about lists.
The COUNT RECORDS IN/ON statement is supported in scattered group context. See Files, Groups, and Reference Context for more information on the reference context.
Syntax
The format for the COUNT RECORDS IN statement is:
label.b: COUNT RECORDS IN label.a
where label.a is the label of a previous FIND statement.
The format for the COUNT RECORDS ON statement is:
label.b: COUNT RECORDS ON list
where list is the name of a list on which you have previously placed found records.
For both forms of the COUNT RECORDS statement, you can print the count using the statement:
PRINT COUNT IN label.b
Example
This COUNT RECORDS IN request:
BEGIN DRIVER: FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER POLICY NO = 100340 END FIND CT: COUNT RECORDS IN DRIVER PRINT COUNT IN CT END
causes Model 204 to note that two records were found by the FIND statement. Model 204 then prints the number 2.
FIND AND PRINT COUNT statement
The FIND AND PRINT COUNT statement is used to combine record retrieval with the COUNT and associated PRINT statements.
Example 1
This statement:
DRIVER: FIND AND PRINT COUNT RECTYPE = DRIVER POLICY NO = 100340 END FIND
is similar to:
DRIVER: FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER POLICY NO = 100340 END FIND CT: COUNT RECORDS IN DRIVER PRINT COUNT IN CT
The label for the FIND AND PRINT COUNT statement can be referred to in the same way in which a label for a FIND ALL RECORDS FOR WHICH statement can be used.
Example 2
The count found by a FIND AND PRINT COUNT statement cannot be positioned to a specified column. The position defaults to column 1 or the next print location, if preceded by an ellipsis (...).
For example, this request:
BEGIN DRIVER: FIND AND PRINT COUNT RECTYPE = DRIVER POLICY NO = 100340 END FIND FOR EACH RECORD IN DRIVER PRINT FULLNAME END FOR END
results in this output:
2 ABBOTT, FRANKLIN G ABBOTT, GAIL H
Output statements
Print statements are often used in loops to display information from each record located by a FIND statement.
The two statements described in this section, PRINT ALL INFORMATION and PRINT fieldname, are basic output statements. PRINT ALL INFORMATION and PRINT fieldname can be used only in a record loop.
The PAI INTO statement, an extension of the PAI statement, allows you to store the field names and values associated with a record in an array. See PAI INTO statement for more information.
More complex statements are used for variable format output. These are discussed in Report Generation.
PRINT ALL INFORMATION (or PAI) statement
Purpose
The PRINT ALL INFORMATION (or PAI) statement causes output of whole records.
Syntax
The form of the PAI statement is:
PRINT ALL INFORMATION option
where option can be one of the following and specifies how Large Object fields are handled.
- LOB_FLOD, the default, which means output in a format that FLOD can read and reload Large Object fields. The output includes the descriptor in binary format, plus the full field value.
- LOB_DATA specifies whether to display the field value. The PAI statement displays the Large Object descriptor in printable format.
- LOB_SHORT_DATA specifies to display the first 255 bytes of the field value. The PAI statement displays the Large Object descriptor in printable format.
- LOB_NO_DATA specifies not to display the value. However, the PAI statement displays the Large Object descriptor in printable format.
- LOB_NONE, which specifies not to display any Large Object fields.
Example
This request:
BEGIN FIND.RECS: FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER FULLNAME = ABBOTT, GAIL H END FIND FOR EACH RECORD IN FIND.RECS PRINT ALL INFORMATION END FOR END
results in output with the format:
FULLNAME = ABBOTT, GAIL H POLICY NO = 100340 DRIVER ID = 100817 MARITAL STATUS = SINGLE SEX = F STATE = CALIFORNIA INCIDENT = T1 INCIDENT DATE = 19890820 INCIDENT = T3 INCIDENT DATE = 19900921 DATE OF BIRTH = 19390305
INVISIBLE fields not printed
In the example on the previous page, the fieldname = value pair, RECTYPE = DRIVER, is not printed in the output because the RECTYPE field has the INVISIBLE attribute.
For more information about the INVISIBLE attribute, refer to Field descriptions and attributes.
PRINT fieldname statement
Syntax
To display the value of a certain field in a record, use this form of the PRINT statement:
PRINT fieldname [AND fieldname2]
Example
Here is a sample PRINT fieldname statement:
BEGIN DRIVER: FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER POLICY NO = 100340 END FIND FOR EACH RECORD IN DRIVER PRINT FULLNAME END FOR END
In response to the above request, Model 204 prints:
ABBOTT, FRANKLIN G ABBOTT, GAIL H
Each value of the FULLNAME field is displayed on a new line. A record that has no FULLNAME field produces a blank line of output.
Printing several fields
The values of more than one field can be printed on the same output line by using the keywords AND and WITH. AND causes a space to be printed between values, as in the following example:
BEGIN DRIVER: FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER POLICY NO = 100340 END FIND FOR EACH RECORD IN DRIVER PRINT SEX AND DATE OF BIRTH END FOR END
Running the request above results in this output:
M 19480204 F 19390305
If a retrieved record has no SEX field, the value of DATE OF BIRTH is printed on a line beginning with a space, as specified by the keyword AND, for example:
19480204
If a record has neither field, it produces a blank line of output.
The keyword WITH works like AND except that WITH does not cause a space to be printed between values.
Controlling spacing between output lines
The SKIP LINE(S) and NEW PAGE statements enable you to control spacing between lines.
SKIP LINE(S)
The SKIP LINE(S) statement directs Model 204 to skip a specified number of lines before printing the next line of output. If the number of lines remaining on a page is fewer than the number of lines specified, Model 204 skips the remainder of the lines on the page, starts a new page, and then continues to skip lines until n is reached.
The syntax of the SKIP LINE(S) statement is as follows:
SKIP {n | %variable} LINE[S]
Where
- n is a positive integer less than or equal to 100.
- %variable is a positive integer from 0 through 100 supplied by a %variable or a :% variable. Field names or %% variables are invalid.
SKIP %variable LINE(S) bypasses the processing and skips no lines if the value of the %variable is zero. However, if n is zero, SKIP n LINES is invalid.
The SKIP %variable LINE(S) option does not apply to the full-screen SKIP LINE(S) statement, as described on SKIP statement for menus.
NEW PAGE
The NEW PAGE statement directs Model 204 to start a new page before printing further output.
For example, in response to:
FOR EACH RECORD IN DRIVER NEW PAGE PRINT ALL INFORMATION END FOR
Model 204 starts a new page before printing each record.
Loading Large Object data
A Model 204 file that contains Large Object data can be reorganized using the standard PAI and FLOD procedure, which employs the User Language PAI (PRINT ALL INFORMATION) statement to unload the data from a file, and a standard FLOD program to reload the data. This is identical to previous releases of Model 204, and no change to your existing unload or load code is required.
IN clauses
Many User Language statements can be preceded by an IN clause. An IN indicates explicitly the file or group to which a statement applies when several files or groups are open.
When you do not use the IN clause, Model 204 acts on the default file as established by the most recently executed OPEN or DEFAULT command.
In addition to specifying an individual file or group name, the IN clause has more detailed information about the reference context of the statement it precedes. For example, when you are working with individual remote files, you can specify the location of the file; and when you are working in group context, you can restrict the context of certain statements to one member file in the group by using the IN GROUP MEMBER form of the IN clause.
Refer to Files, Groups, and Reference Context for more information on the reference context and ways to use the IN clause.
Syntax
The simplest form of the IN clause is:
IN {filename | groupname} [AT location]
Example
This request prints the policy number, body, and make of a policy in the VEHICLES file, and the full name, marital status, and sex of records for that policy number in the CLIENTS file:
OPEN CLIENTS OPEN VEHICLES BEGIN VEHICLE.RECS: IN VEHICLES AT BOSTON FIND ALL RECORDS FOR WHICH OWNER POLICY = 100340 VIN = DAT7100707 END FIND FOR EACH RECORD IN VEHICLE.RECS PRINT OWNER POLICY AND BODY AND MAKE END FOR DRIVER: IN CLIENTS FIND ALL RECORDS FOR WHICH RECTYPE = DRIVER POLICY NO = 100340 END FIND FOR EACH RECORD IN DRIVER PRINT FULLNAME AND MARITAL STATUS AND SEX END FOR END
The output from this request would be:
100340 4DR DATSUN ABBOTT, FRANKLIN G SINGLE M ABBOTT, GAIL H SINGLE F
Request continuation
Lengthy requests can be handled by using the END MORE statement and the MORE command. See Large Request Considerations for more information on request continuation, including a discussion of the MORE command and the END MORE statement and its USE option.
Example
The sample request below tells you how many records exist in a given file for female drivers registered in Florida:
BEGIN GET.DRIVER: FIND AND PRINT COUNT RECTYPE = DRIVER STATE = FLORIDA SEX = F END FIND END MORE
After printing its output, this request returns you to command level. Using the MORE command, you can continue the request, adding further statements as well as referring to the results of statements in the original request. If, for example, you wanted to perform further processing of the records found in the original request without repeating the FIND operation, you could enter the following lines, referencing the label GET.DRIVER:
MORE FOR EACH RECORD IN GET.DRIVER PRINT FULLNAME AND DATE OF BIRTH END FOR END