How to understand the usage of DocOffset and PageOffset in PCE in DOC1 Generate


The use of DOCOFFSET and PAGEOFFSET in PCE requires some consideration due to the fact that only one set of offsets are retained in memory at any time. This means that the current offsets are only valid for the last written file. Also, it has to be remembered that the current PAGEOFFSET refers to the position of the file pointer after the last write operation. I.e. it points to the next page that is to be written ( or the current end of file ).

To further understand how the offsets work, you need to understand how a file is written in PCE.

1. A file is opened for writing ( all offsets are 0 )
2. A write operation is called for a single page. At this point any header information is written out at the start of the file. This then updates the DOCOFFSET vector. The first page is then written out and the PAGEOFFSET is updated.
3. Subsequent page writes output the data to file and then update the PAGEOFFSET to the “end of file” or where the next page will be written.

The following pseudo code illustrates this:

OPEN “in.afp” for input as file 1 wsafp/afpds;
OPEN “out.afp” for output as file 2 wsafp/afpds;

READ 1 page from file 1 into <page-data>;
WRITE 1 page into file 2 from <page-data>;

LET <start-of-doc> = DOCOFFSET; // This is the first page offset;
LET <page-offset> = PAGEOFFSET; // This is the pointer to the next page to be written;

// At this point you can write the DOCOFFSET out to a journal;

Initialise page counter;

If no more pages then exit loop;

READ page data ….

WRITE <page-offset> …. From the above assignment;

WRITE page data ….

LET <page-offset> = PAGEOFFSET; // This is the pointer to the next page to be written;

Decrement page
Environment Details
Product Feature: Installation / Upgrade
UPDATED:  November 8, 2017