Function SET014A: Word Wrap a list

LANSA

Function SET014A: Word Wrap a list
********** COMMENT(=======================================================);
********** COMMENT(Process ........: SET_014);
********** COMMENT(Function .......: SET014A);
********** COMMENT(Created on .....: 03/03/00 at 13:00:02);
********** COMMENT(Description ....: Word Wrap a list);
********** COMMENT(Full Description: The purpose of this function is to);
********** COMMENT(word wrap a list.);
********** COMMENT();
********** COMMENT(Restriction:);
********** COMMENT(Note that the automatic jump to the next);
********** COMMENT(field (RLTB input attribute) will only);
********** COMMENT(work in SAA/CUA partitions);
**********;
********** COMMENT(Disclaimer: The following material is supplied as an);
********** COMMENT(example only. No warranty is expressed or implied.);
********** COMMENT();
********** COMMENT(=======================================================);
********** COMMENT(Function control options);
FUNCTION OPTIONS(*DIRECT);
********** COMMENT();
********** COMMENT(Group and field definitions);
********** COMMENT();
**********;
DEF_ARRAY NAME(#LNG) INDEXES(#II) OVERLAYING(#S_LONGTXT) TYPE(*CHAR) TOT_ENTRY(256) ENTRY_LEN(1);
DEF_LIST NAME(#S_LSTRAW) FIELDS(#S_RAWTXT) COUNTER(#S_RAWCNT);
DEF_LIST NAME(#S_LSTWRAP) FIELDS(#STD_TEXTL);
**********;
**********;
DEFINE FIELD(#S_LONGTXT) TYPE(*CHAR) LENGTH(256) DESC('Long Text field');
DEFINE FIELD(#S_RAWCNT) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Raw Entries Count');
DEFINE FIELD(#S_RAWTXT) TYPE(*CHAR) LENGTH(30) DESC('Raw Text') COLHDG('Unwrapped Text') INPUT_ATR(LC RLTB);
DEFINE FIELD(#S_RAWLEN) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Raw text line length');
DEFINE FIELD(#S_ENDFLG) TYPE(*CHAR) LENGTH(1) DESC('End of Raw List Flag');
DEFINE FIELD(#S_LONGPOS) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Start position in LONGFLD');
DEFINE FIELD(#S_WRAPLEN) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Length to wrap to');
DEFINE FIELD(#S_ADDLEN) REFFLD(#S_WRAPLEN) DESC('Length to wrap to');
DEFINE FIELD(#S_WRAPPOS) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Actual Line wrap length');
DEFINE FIELD(#ENT) TYPE(*DEC) LENGTH(5) DECIMALS(0) DESC('List Entry Number');
DEFINE FIELD(#S_STRENT) REFFLD(#ENT) DESC('Current line starts at raw entry number ');
DEFINE FIELD(#S_WKENTRY) REFFLD(#ENT) DESC('Work field Raw Entry Number');
DEFINE FIELD(#S_BGNENT) REFFLD(#ENT);
DEFINE FIELD(#S_ENDENT) REFFLD(#ENT);
DEFINE FIELD(#CHR) TYPE(*DEC) LENGTH(3) DECIMALS(0) DESC('Position in text field');
DEFINE FIELD(#S_STRPOS) REFFLD(#CHR) DESC('Current Line starts at raw line positn ');
DEFINE FIELD(#S_WKPOS) REFFLD(#CHR) DESC('Work Field Raw Line Position');
DEFINE FIELD(#S_BGNPOS) REFFLD(#CHR);
DEFINE FIELD(#S_ENDPOS) REFFLD(#CHR);
OVERRIDE FIELD(#STD_TEXTL) COLHDG('Wrapped Text');
********** COMMENT(=======================================================);
********** COMMENT(Program Mainline );
********** COMMENT(=======================================================);
********** COMMENT();
FUNCTION OPTIONS(*DIRECT);
********** COMMENT();
**********;
********** COMMENT(process the text input by the user);
**********;
INZ_LIST NAMED(#S_LSTRAW) NUM_ENTRYS(6) WITH_MODE(*CHANGE);
CHANGE FIELD(#S_WRAPLEN) TO(55);
**********;
BEGIN_LOOP;
REQUEST FIELDS(#S_WRAPLEN) IDENTIFY(*DESC) BROWSELIST(#S_LSTRAW);
BEGINCHECK;
RANGECHECK FIELD(#S_WRAPLEN) RANGE((20 75)) MSGTXT('Must be between 20 and 75');
ENDCHECK;
********** COMMENT(raw text line length #S_RAWLEN (input text length));
********** COMMENT(wrapped line length #S_WRAPLEN (output text length));
********** COMMENT(these lengths can be any reasonable values);
CHANGE FIELD(#S_RAWLEN) TO(30);
CHANGE FIELD(#S_STRENT) TO(1);
CHANGE FIELD(#S_STRPOS) TO(1);
CHANGE FIELD(#S_ENDFLG) TO(N);
CLR_LIST NAMED(#S_LSTWRAP);
********** COMMENT(process until no more entries are available from );
********** COMMENT(the input raw text list);
DOUNTIL COND('#S_ENDFLG *eq Y');
********** COMMENT(read enough from the input raw list to produce a );
********** COMMENT(wrapped line);
EXECUTE SUBROUTINE(GETFROMLST) WITH_PARMS(#S_STRENT #S_STRPOS #S_WRAPLEN #S_LONGTXT #S_ENDFLG #S_RAWLEN);
********** COMMENT(determine how much to reduce the line for word wrap);
CHANGE FIELD(#S_WRAPPOS) TO(#S_WRAPLEN);
CHANGE FIELD(#II) TO(#S_WRAPPOS);
DOWHILE COND('#LNG#II *NE *BLANK');
CHANGE FIELD(#II) TO('#II - 1');
ENDWHILE;
CHANGE FIELD(#S_WRAPPOS) TO(#II);
********** COMMENT(move the wrapped line into the output list);
SUBSTRING FIELD(#S_LONGTXT 1 #S_WRAPPOS) INTO_FIELD(#STD_TEXTL);
ADD_ENTRY TO_LIST(#S_LSTWRAP);
********** COMMENT(move to the new start point and get ready to process );
********** COMMENT(the next wrapped line);
EXECUTE SUBROUTINE(MOVEPOINT) WITH_PARMS(#S_STRENT #S_STRPOS #S_WRAPPOS #S_ENDFLG #S_RAWLEN);
CHANGE FIELD(#S_LONGTXT) TO(*BLANKS);
ENDUNTIL;
DISPLAY FIELDS(#S_WRAPLEN) BROWSELIST(#S_LSTWRAP);
END_LOOP;
**********;
********** COMMENT(Subroutine to move along the raw text list by a number );
********** COMMENT(of characters);
**********;
SUBROUTINE NAME(MOVEPOINT) PARMS((#S_WKENTRY *BOTH) (#S_WKPOS *BOTH) (#S_ADDLEN *RECEIVED) (#S_ENDFLG *RETURNED) (#S_RAWLEN *RECEIVED));
CHANGE FIELD(#S_WKPOS) TO('#S_WKPOS + #S_ADDLEN');
DOWHILE COND('#S_WKPOS > #S_RAWLEN');
CHANGE FIELD(#S_WKENTRY) TO('#S_WKENTRY + 1');
CHANGE FIELD(#S_WKPOS) TO('#S_WKPOS - #S_RAWLEN');
ENDWHILE;
IF COND('#S_WKENTRY *GT #S_RAWCNT');
CHANGE FIELD(#S_WKENTRY) TO(#S_RAWCNT);
CHANGE FIELD(#S_WKPOS) TO(#S_RAWLEN);
CHANGE FIELD(#S_ENDFLG) TO(Y);
ENDIF;
ENDROUTINE;
**********;
********** COMMENT(Subroutine to read enough from the source list to );
********** COMMENT(produce another wrapped line);
**********;
SUBROUTINE NAME(GETFROMLST) PARMS((#S_WKENTRY *RECEIVED) (#S_WKPOS *RECEIVED) (#S_WRAPLEN *RECEIVED) (#S_LONGTXT *RETURNED) (#S_ENDFLG *RETURNED) (#S_RAWLEN *RECEIVED));
********** COMMENT(store the start position);
CHANGE FIELD(#S_BGNENT) TO(#S_WKENTRY);
CHANGE FIELD(#S_BGNPOS) TO(#S_WKPOS);
********** COMMENT(calculate the end position);
CHANGE FIELD(#S_ADDLEN) TO('#S_WRAPLEN - 1');
EXECUTE SUBROUTINE(MOVEPOINT) WITH_PARMS(#S_WKENTRY #S_WKPOS #S_ADDLEN #S_ENDFLG #S_RAWLEN);
CHANGE FIELD(#S_ENDENT) TO(#S_WKENTRY);
CHANGE FIELD(#S_ENDPOS) TO(#S_WKPOS);
********** COMMENT(read the raw text entries required for this wrapped );
********** COMMENT(line and put them in field #S_LONGTXT);
BEGIN_LOOP USING(#S_WKENTRY) FROM(#S_BGNENT) TO(#S_ENDENT);
GET_ENTRY NUMBER(#S_WKENTRY) FROM_LIST(#S_LSTRAW);
CASE OF_FIELD(#S_WKENTRY);
WHEN VALUE_IS(' = #S_BGNENT');
********** COMMENT(first raw text entry (or only raw text entry));
SUBSTRING FIELD(#S_RAWTXT #S_BGNPOS) INTO_FIELD(#S_LONGTXT);
CHANGE FIELD(#S_LONGPOS) TO('(#S_RAWLEN - #S_BGNPOS) + 2');
WHEN VALUE_IS(' = #S_ENDENT');
********** COMMENT(last raw text entry);
SUBSTRING FIELD(#S_RAWTXT 1 #S_ENDPOS) INTO_FIELD(#S_LONGTXT #S_LONGPOS);
OTHERWISE;
********** COMMENT(middle raw text entry);
SUBSTRING FIELD(#S_RAWTXT) INTO_FIELD(#S_LONGTXT #S_LONGPOS);
CHANGE FIELD(#S_LONGPOS) TO('#S_LONGPOS + #S_RAWLEN');
ENDCASE;
END_LOOP;
ENDROUTINE;