PARAG: Dividing Text Into Smaller Lines

How to:

Available Languages: reporting, Maintain

The PARAG function divides a line of text into smaller lines by marking them with a delimiter. It scans a specific number of characters from the beginning of the line and replaces the last space in the group scanned with the delimiter. It then scans the next group of characters in the line, starting from the delimiter, and replaces the last space in this group with a second delimiter. It repeats this process until reaching the end of the line.

Each group of characters marked off by the delimiter becomes a sub-line. The GETTOK function can then place the sub-lines into different fields. If the function 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 no word of text is longer than the number of characters scanned (the maximum sub-line length).

If the input lines of text are roughly equal in length, you can keep the sub-lines equal by specifying a sub-line length that evenly divides into the length of the text lines. For example, if the text lines are 120 characters long, divide each of them into two sub-lines of 60 characters or three sub-lines of 40 characters. This technique enables you to print lines of text in paragraph form.

However, 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.


Top of page

x
Syntax: How to Divide Text Into Smaller Lines
PARAG(length, string, 'delim', subsize, outfield)

where:

length

Integer

Is the length in characters of string and outfield, or a field that contains the length.

string

Alphanumeric

Is the text enclosed in single quotation marks, or a field or variable that contains the text.

delim

Alphanumeric

Is the delimiter enclosed in single quotation marks. Choose a character that does not appear in the text.

subsize

Integer

Is the maximum length of each sub-line.

outfield

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Dividing Text Into Smaller Lines

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.

WebFOCUS