## Table handling logic

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

### Table handling logic

Hi guys,

I am working on a new program that will format 8192 record length of data in to 90 byte lines. This line can occurs up to 150 line max. Below is the logic that i have came upon.

I have defined two tables: -
*
01 TABLE.
05 WS-TABLE-DATA OCCURS 150 TIMES.
10 WS-LINE OCCURS 90 TIMES.
15 WS-DATA PIC X.
*
01 WS-TOT-DATA.
05 WS-TOT-DATA-REC OCCURS 8192 TIMES.
10 WS-DATA-TOT PIC X.
*****************************************************************

PERFORM VARYING WS-LINE-CNT FROM 1 BY 1 UNTIL
WS-LINE-CNT > WS-LINES
PERFORM VARYING WS-CHAR-CNT FROM 1 BY 1 UNTIL
WS-CHAR-CNT > 90
MOVE WS-DATA-TOT(S)
TO WS-DATA(WS-LINE-CNT WS-CHAR-CNT)
IF S = L
MOVE 90 TO WS-CHAR-CNT
END-IF
END-PERFORM
END-PERFORM.

before this logic i am calculating the actual length(L) of the record 8192(Which is variable in nature). And then calculating the numbers of line needed by dividing actual length with 90.

Today i was again asked that this logic should print line based on words i.e if the above perform loop executes and it detect that the last byte(90th) position is not empty then it will assume that there is a continuation of a word and it should start with the next line. Example below

-----------------7----+----8----+----9
......this is a test line is an continuation.

the above logic will print - ......this is a line is an continua
New line - tion

it should print - .........this is a test line is an
New line - continuation.

I would like to know how we can handle this situation. please let me know your views.

Thank you for your time ...

Regards
Anand
anand4u237

Posts: 15
Joined: Mon May 17, 2010 12:05 pm
Location: India
Has thanked: 4 times
Been thanked: 0 time

### Re: Table handling logic

There are a couple of options:
- if the 90th character is not blank, count back until you find a space and move those bytes to a hold area, change the WS-DATA values to space, and output. Then if the hold area is not blank, move it to start the line and clear it back to blanks.
- use the REVERSE intrinsic function to copy the WS-LINE to another field and check it to see if the first byte is non-blank. If so, you can use INSPECT to find the first blank and proceed to fix up the line.

The two approaches are functionally equivalent so either one will work, assuming they are coded correctly.

These users thanked the author Robert Sample for the post:
anand4u237 (Sat Apr 23, 2016 2:55 pm)
Robert Sample
Global moderator

Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

### Re: Table handling logic

Thanks Robert,

I was thinking of the first suggestion that you have provided.

could it be like rather than holding the data while checking for first space from backward and moving it to the subsequent line can't we make the logic to write the
next line where it found the last space ? will it work. Please let me know your views.

thanks
Anand
anand4u237

Posts: 15
Joined: Mon May 17, 2010 12:05 pm
Location: India
Has thanked: 4 times
Been thanked: 0 time