© serviceprofessionalgmbh

The purpose of the program is to store a string into records in such a way that a pre-defined record length is not exceeded and no word gets truncated at the end of the record. Input parameter is a character string. The first word resembles the record length in bytes. Data are accepted from the second word onward. The line breaks of the records within the defined record length are performed without truncation of the words (word wrap).


/* REXX
*/
PARSE ARG MAXLEN TEXT
IF MAXLEN < 50 ! MAXLEN > 132 then MAXLEN = 70
DSN = "'"userid()".RXDEMO.DATA'"
"FREE DD(DEMO)"
"DEL" DSN
"ALLOC DD(DEMO) DA("DSN") NEW CATALOG SPACE(1 1) TRACKS" ,
   "LRECL("MAXLEN") BLKSIZE(0) RECFM(F B) DSORG(PS)"
I = 1
R = 0
DO FOREVER
   IF LENGTH(TEXT) < MAXLEN THEN DO
      R = R + 1;INFO.R = TEXT
      LEAVE
   END
   IF LENGTH(SUBWORD(TEXT,1,I+1)) > MAXLEN THEN DO
      R = R + 1;INFO.R = SUBWORD(TEXT,1,I)
      TEXT = DELWORD(TEXT,1,I)
      I    = 1
   END
   ELSE DO
      I = I + 1
   END
END
"EXECIO * DISKW DEMO (STEM INFO. FINIS"
"FREE DD(DEMO)"
EXIT

back to Help in Daily Life