Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

@IF (format 2) - Compare strings, line numbers and numbers

&pagelevel(3)&pagelevel

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
| line1 rel line2
| [ I ] int1 rel int2 } :[text]

S

The keyword S is only obligatory if string1 and string2 contain line
numbers or line number variables without column specifications, in which
case it specifies that the content of the lines identified by the line numbers or
knowledge variables is to be compared and not the line numbers
themselves.

For example, the statement @IF #L1=#L2 compares the line numbers in
#L1 and #L2. However, if the contents of the lines indicated by #L1 and #L2
are to be compared then @IF S #L1=#L2 must be entered.

string1, string2The strings to be compared.

line1, line2

The line numbers to be compared. The contents of the lines are not
compared.

I

The keyword I only has to be entered if a number (a literal) has been
explicitly entered for int1 as otherwise EDT cannot tell whether the input is
a line number or an integer.

int1, int2

The integers to be compared.

A (positive or negative) integer or an integer variable can be entered for
each of these (#I0..#I20).

rel

Defines the relational operator:

Symbol

Meaning

>       or       GT

greater than

<       or       LT

less than

>=     or       GE

greater than or
equal to

<=     or       LE

less than or equal
to

=       or       EQ

equal to

<>     or       NE

not equal to

text

EDT statement or data line. If the condition is fulfilled, the string is treated
as if it had been entered at the prompt in L mode. In particular, the decision
to interpret the text as data input or as a statement is made in accordance
with the same rules (for more information, see section “L mode”).

The text operand starts immediately after the character ':', i.e. any
specified blanks form part of the operand and are taken over into the line in
the case of data input.

If text is not specified (although the colon is), then an empty line (line of
length 0) is inserted.

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 #S0 and #S1 as well as the integer variable #I9 are filled with content.

(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 (%+#I9) and 1 ($-2L, i.e. 3-2). Since the contents of these two lines are identical, processing branches to line 4 of work file 3.

(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 #S4 is to be output. This is to be followed by the current content of #S4 preceded by the letter M.

If the content of #S4 is smaller than MMMMMMMM then processing should start from the beginning again.


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 !. If the content of the line currently addressed via the counter ! is different from ABC then the line content should not be modified. Otherwise, the line content is to be replaced by
******************** .

(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 #S0 and #S1 are filled with content. The value 1 is assigned to the integer variable #I9.

(2)Work file 1 is opened.
(3)

If @DO 1 is subsequently issued then this line causes the line numbers %+#I9 and $–1L to be compared.

% addresses the first line number (i.e. 1).

$ addresses the last line number (i.e. 3).

$-1L addresses the penultimate line number (i.e. 2).

(4)

The procedure in work file 1 is executed. At this point, the relation indicated there %+#I9=$–1L is true since 1+1=3–1 is true.

(5)

At this point, the relation indicated in work file 1%+#I9=$-1L is false since 1+2=3–1 is false.


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 (<> means not equal to) then the procedure is aborted at this point.

(2)

Work file 2 is executed. Because *=$–1=2, the expression %+6–#L3<>$–* is equivalent to 1+6–5<>3–2 and is therefore true. The execution of the procedure is therefore aborted.

(3)

At this point, *=1 and consequently the relation in work file 2 %+6–#L3<>$–* is false because 1+6–5=3–1. Consequently, the remaining statements in work file 2 are executed.


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 #I3 (@STATUS =#I3) and increment these (#I3+1) until #I3 has a value greater than 5 for the first time.

(3)Work file 7 is executed.