FORMAT: PROC(STRING,WIDTH,FILE_NAME); /* PROCEDURE BREAKS A CHARACTER STRING INTO SEGMENTS AND WRITES THEM WITH A RULER TO FILE_NAME. AUTHOR: AL JAWORSKI DATE: 26 MAY 1982 */ %INCLUDE TRIM; DCL STRING CHAR(*) VARYING; DCL FILE_NAME FILE VARIABLE; DCL (I,WIDTH,SEGMENTS,REMAINDER) FIXED BINARY(31); IF WIDTH<10 | WIDTH>120 THEN DO; PUT FILE(FILE_NAME) EDIT('Invalid line width -- ',TRIM(CHAR(WIDTH)), ' -- Line cannot be formatted')(SKIP,3 A); RETURN; END; DCL RULER1 CHAR(120) INIT(' 1 2 3 4 5 6 7 8 9 10 11 12'); DCL RULER2 CHAR(120) INIT('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); DCL RULER3 CHAR(120) INIT('+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*+++++++++*'); REMAINDER=MOD(LENGTH(STRING),WIDTH); SEGMENTS=DIVIDE(LENGTH(STRING)-REMAINDER,WIDTH,31); IF LINENO(FILE_NAME)+SEGMENTS+6 > 60 THEN PUT FILE(FILE_NAME) PAGE; PUT FILE(FILE_NAME) EDIT(SUBSTR(RULER1,1,WIDTH),SUBSTR(RULER2,1,WIDTH), SUBSTR(RULER3,1,WIDTH))(SKIP,X(10),A); DO I=1 TO SEGMENTS; PUT FILE(FILE_NAME) EDIT((I-1)*WIDTH+1,SUBSTR(STRING,((I-1)*WIDTH)+1,WIDTH)) (SKIP,P'ZZZZZ9',X(4),A); END; PUT FILE(FILE_NAME) EDIT(SEGMENTS*WIDTH+1,SUBSTR(STRING,(SEGMENTS*WIDTH)+1)) (SKIP,P'ZZZZZ9',X(4),A); PUT FILE(FILE_NAME) EDIT(SUBSTR(RULER3,1,WIDTH))(SKIP,X(10),A); END FORMAT;