This format of the @IF statement can be used in EDT procedures to compare strings, line numbers or integer numbers with one another. The operands may be specified either explicitly (as literals) or via a reference (line number or EDT variable).
If the condition for the comparison is fulfilled then the specified string is processed as input. If the condition is not fulfilled, the statement has no effect.
Operation | Operands | L mode |
@IF | { [ S ] string1 rel string2 |
S | The keyword For example, the statement @IF #L1=#L2 compares the line numbers in | ||||||||||||||
string1, string2 | The strings to be compared. | ||||||||||||||
line1, line2 | The line numbers to be compared. The contents of the lines are not | ||||||||||||||
I | The keyword | ||||||||||||||
int1, int2 | The integers to be compared. A (positive or negative) integer or an integer variable can be entered for | ||||||||||||||
rel | Defines the relational operator:
| ||||||||||||||
text | EDT statement or data line. If the condition is fulfilled, the string is treated The If |
The previous specification of GOTO
or RETURN
without a colon in procedures continues to be supported for reasons of compatibility.
Comparisons of two strings depend, on the one hand, on the character set in which the strings are encoded and, on the other, on the length of the strings (strings of zero length are permitted).
In all cases, it is possible to assign the operands string1
and string2
a character set which corresponds to their source. If the two character sets determined in this way are identical then a binary comparison is performed in this shared character set.
If the two character sets are different but are both EBCDIC 7/8-byte character sets then a binary comparison is performed as in the past.
Otherwise, the two character sets are converted internally into UTF16
and the comparison is performed in UTF16
.
Following any necessary conversion, the corresponding characters in the two strings are compared. Processing thus either reaches a non-identical character pair or the end of one or other of the two character strings. If the characters differ at any point then the two strings
are considered to be non-identical. EDT interprets the two non-identical characters as binary numbers on the basis of their character sets. The string with the character with the larger binary number is considered to be the greater of the two. If no non-identical pair of characters is identified then the longer of the two strings is considered to be the greater. If the two strings are of the same length and no non-identical character pair is detected then the strings are identical. If the two strings are of different lengths they can therefore never be identical.
Note
When line numbers are compared, both%+3L
and %+3
designate valid line numbers. This can lead to difficulties of interpretation if followed by the relational operator LE
. It is therefore usually advisable to use the mathematical symbols for the relational operators.
The use of column specifications with the string2
operand can also result in difficulties of interpretation when the text
operand is introduced. Special care must be taken to ensure that the notation can be interpreted unambiguously in such cases. In particular, it is obligatory to conclude the column specification with a colon (otherwise optional).
For reasons of compatibility, the sort weighting defined by XHCS when comparing characters is ignored. This also applies to Unicode character sets. A sort operation, for example using the SORT
program, may therefore return a sequence different from the result supplied by an @IF query in EDT.
Using @IF with @RETURN as a statement outside of procedures may cause EDT to terminate (see the @RETURN statement).
Example 1
4. @PRINT 1.0000 PLEASE DO NOT LAUGH 2.0000 AT THIS EXAMPLE 3.0000 PLEASE DO NOT LAUGH 4. @SET #S0 = 'FIRST LINE = LAST LINE' 4. @SET #S1 = 'FIRST LINE NOT EQUAL TO LAST LINE' --------------- (1) 4. @SET #I9 = 2 4. @PROC 3 1. @ @IF S %+#I9 = $-2L : @GOTO 4 ------------------------------- (2) 2. @ @PRINT #S1 N 3. @ @RETURN 4. @ @PRINT #S0 N 5. @END 4. @DO 3 -------------------------------------------------------- (3) FIRST LINE = LAST LINE 4. @ON 1 DELETE 'NOT' 4. @DO 3 -------------------------------------------------------- (4) FIRST LINE NOT EQUAL TO LAST LINE 4.
(1) | The string variables |
(2) | When work file 3 is executed, line contents are compared here instead of line numbers. |
(3) | The execution of the statements stored in work file 3 results in the comparison of lines ( |
(4) | Since the content of line 1 has now changed, processing does not branch to line 4 of work file 3. |
Example 2
1. @SET #S4 = 'M' ------------------------------------------------ (1) 1. @PROC 4 1. @ @PRINT #S4 N ------------------------------------------------ (2) 2. @ @CREATE #S4: 'M',#S4 3. @ @IF #S4 < 'M'*8 : @GOTO 1 4. @END 1. @DO 4 M MM MMM MMMM MMMMM MMMMMM MMMMMMM 1.
(1) | The string variable #S4 contains the character M . |
(2) | The following procedure is entered in work file 4: the content of If the content of |
Example 3
9. @PRINT 1.0000 ABC 2.0000 WHO 3.0000 ABC 4.0000 WANTS 5.0000 ABC 6.0000 TO TRY 7.0000 ABC 8.0000 HIS LUCK? 9. @PROC 6 1. @ @IF ! <> 'ABC' : @GOTO 3 ------------------------------------ (1) 2. @ @CREATE !: '*' * 20 3. @ @CONTINUE 4. @END 9. @DO 6,!=%,$ --------------------------------------------------- (2) 9. @PRINT 1.0000 ******************** 2.0000 WHO 3.0000 ******************** 4.0000 WANTS 5.0000 ******************** 6.0000 TO TRY 7.0000 ******************** 8.0000 HIS LUCK? 9.
(1) | In work file 6, the line numbers are addressed via the loop counter |
(2) | Work file 6 is executed. During processing, all the lines in the current work file are to be addressed in sequence by the loop counter |
Example 4
4. @PRINT 1.0000 PLEASE DO NOT LAUGH 2.0000 AT THIS EXAMPLE 3.0000 IT IS TOO SIMPLE 4. @SET #S0 = 'RESULT POSITIVE' 4. @SET #S1 = 'RESULT NEGATIVE' ---------------------------------- (1) 4. @SET #I9 = 1 4. @PROC 1 ------------------------------------------------------- (2) 1. @ @IF %+#I9 = $-1L : @GOTO 4 ---------------------------------- (3) 2. @ @PRINT #S1 N 3. @ @RETURN 4. @ @PRINT #S0 N 5. @END 4. @DO 1 --------------------------------------------------------- (4) RESULT POSITIVE 4. @SET #I9 = 2 4. @DO 1 --------------------------------------------------------- (5) RESULT NEGATIVE 4.
(1) | The string variables |
(2) | Work file 1 is opened. |
(3) | If @DO 1 is subsequently issued then this line causes the line numbers
|
(4) | The procedure in work file 1 is executed. At this point, the relation indicated there |
(5) | At this point, the relation indicated in work file 1 |
Example 5
4. @PRINT 1.0000 PLEASE DO NOT LAUGH 2.0000 AT THIS EXAMPLE 3.0000 IT IS TOO SIMPLE 4. @SET #L3 = 5 4. @PROC 2 1. @ @IF %+6-#L3 <> $-* : @RETURN -------------------------------- (1) 2. @ @CREATE $+1: 'OR PERHAPS NOT' 3. @ @PRINT 4. @END 4. @$-1 2. @DO 2 --------------------------------------------------------- (2) 2. @1 1. @DO 2 --------------------------------------------------------- (3) 1.0000 PLEASE DO NOT LAUGH 2.0000 AT THIS EXAMPLE 3.0000 IT IS TOO SIMPLE 4.0000 OR PERHAPS NOT 1.
(1) | If when work file 2 is executed, the relation indicated here is not fulfilled ( |
(2) | Work file 2 is executed. Because |
(3) | At this point, |
Example 6
1. @SET #I3 = 1 -------------------------------------------------- (1) 1. @PROC 7 1. @ @IF #I3 > 5 : @RETURN 2. @ @STATUS = #I3 ----------------------------------------------- (2) 3. @ @SET #I3 = #I3+1 4. @ @GOTO 1 5. @END 1. @DO 7 --------------------------------------------------------- (3) #I03= 0000000001 #I03= 0000000002 #I03= 0000000003 #I03= 0000000004 #I03= 0000000005 1.
(1) | The value 1 is assigned to the integer variable #I3 . |
(2) | The procedure in work file 7 should output the values for the integer variable |
(3) | Work file 7 is executed. |