Available Languages: reporting, Maintain
The PARAG function divides a character string into substrings by marking them with a delimiter. It scans a specific number of characters from the beginning of the string and replaces the last space in the group scanned with the delimiter, thus creating a first substring, also known as a token. It then scans the next group of characters in the line, starting from the delimiter, and replaces its last space with a second delimiter, creating a second token. It repeats this process until it reaches the end of the line.
Once each token is marked off by the delimiter, you can use the function GETTOK to place the tokens into different fields (see GETTOK: Extracting a Substring (Token)). If PARAG does not find any spaces in the group it scans, it replaces the first character after the group with the delimiter. Therefore, make sure that any group of characters has at least one space. The number of characters scanned is provided as the maximum token size.
For example, if you have a field called 'subtitle' which contains a large amount of text consisting of words separated by spaces, you can cut the field into roughly equal substrings by specifying a maximum token size to divide the field. If the field is 350 characters long, divide it into three substrings by specifying a maximum token size of 120 characters. This technique enables you to print lines of text in paragraph form.
Tip: If you divide the lines evenly, you may create more sub-lines than you intend. For example, suppose you divide 120-character text lines into two lines of 60 characters maximum, but one line is divided so that the first sub-line is 50 characters and the second is 55. This leaves room for a third sub-line of 15 characters. To correct this, insert a space (using weak concatenation) at the beginning of the extra sub-line, then append this sub-line (using strong concatenation) to the end of the one before it. Note that the sub-line will be longer than 60 characters.
PARAG(length, source_string, 'delimiter', max_token_size, output)
Is the number of characters in source_string and output, or a field that contains the length.
Is a string to divide into tokens enclosed in single quotation marks, or a field or variable that contains the text.
Is the delimiter enclosed in single quotation marks. Choose a character that does not appear in the text.
Is the upper limit for the size of each token.
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
PARAG divides ADDRESS_LN2 into smaller lines of not more than ten characters using a comma as the delimiter. It then stores the result in PARA_ADDR:
TABLE FILE EMPLOYEE PRINT ADDRESS_LN2 AND COMPUTE PARA_ADDR/A20 = PARAG(20, ADDRESS_LN2, ',', 10, PARA_ADDR); BY LAST_NAME WHERE TYPE EQ 'HSM'; END
The output is:
LAST_NAME ADDRESS_LN2 PARA_ADDR --------- ----------- --------- BANNING APT 4C APT 4C , CROSS 147-15 NORTHERN BLD 147-15,NORTHERN,BLD GREENSPAN 13 LINDEN AVE. 13 LINDEN,AVE. IRVING 123 E 32 ST. 123 E 32,ST. , JONES 235 MURRAY HIL PKWY 235 MURRAY,HIL PKWY MCKNIGHT 117 HARRISON AVE. 117,HARRISON,AVE. ROMANS 271 PRESIDENT ST. 271,PRESIDENT,ST. SMITH 136 E 161 ST. 136 E 161,ST.