pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Data Layout Considerations
Example 188 Scanning Adjacent Fields Within a Structure
STRUCT s FIELDALIGN(SHARED2);
BEGIN
STRING buffer[0:99];
STRING stopper;
END;
BADDR end_addr;
...
s.stopper := 0;
SCAN s.buffer UNTIL char -> end_addr;
IF end_addr = @s.stopper THEN ! Target character was not found
BEGIN
...
END;
Data Passed to Procedures in Reference Parameters
The rules in of the preceding subsection about data layouts apply if the buffer scanned in a SCAN
statement is a reference parameter.
P-Relative Arrays
The address type of pointers in a SCAN statement that scans a P-relative array must be CBADDR
or CWADDR.
When the SCAN statement in Example 189 (page 231) completes, t_start points to the first
character in the third message, and t_end points immediately after the last character in the third
message. The object data type of t_start and t_end is STRING; therefore, their address type
is BADDR.
Example 189 Scanning Data in a P-Relative Array
STRING s = 'P' := ! STRING P-relative array s
[ 1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
STRING .t_start, ! Start address of msg
.t_end; ! End address of msg
INT c := 3, ! Value to scan for in s
z := "."; ! Value to stop the scan
SCAN s UNTIL c -> @t_start; ! Scan s for c and store c's
! address in t_start
@t_start := @t_start '+' 1; ! Skip c
SCAN s[@t_start '-' @s]
UNTIL z -> @t_end; ! Find end of message
In Example 190 (page 231), the data type of t_start and of t_end is CBADDR. The object data
type of s is STRING. Its address type is CBADDR, not BADDR; therefore, you can subtract @s from
t_start because the data types of both are CBADDR.
Example 190 Scanning Data in a P-Relative Array
STRING s = 'P' := [ ! STRING P-relative array s
1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
CBADDR t_start, ! Start address of msg
t_end; ! End address of msg
SCAN and RSCAN 231