For vary large output variables (max 16 Mb) you may use subprocedure
.
In this subprocedure, instead of passing the name or the value
of the substituting variable, you will pass a pointer to it and its length.
4. Write html sections and send the output buffer
This must be done using subprocedure
wrtsection.
One can write one or multiple sections in a single call.
Important.
Once all sections have been written,
do not forget to
send the output buffer to the client.
This must be done by writing a pseudo section named
*fini.
Example:
* Write a single section
C callp wrtsection('start')
* Write two sections
C callp wrtsection('part1 part2')
* Send the output html to the remote browser
C callp wrtsection('*fini') |
Note 4. Section names are not case sensitive.
A section name is a 50 char max alfanumeric string. Only english letters are supported.
Note 5. Subprocedure wrtSection supports two optional parameters:
- NoNewLine indicator.
Set it to *on to tell wrtsection
NOT to insert a newline character x'15' at the end of each HTML output line.
This may be useful when binary data are being sent to the browser.
- NoDataString value.
What to do when a substitution variable is encountered and no
value has been set up with UpdHtmlVar.
If not specified, output variables left without substitutions display
the default "**Missing Data**".
Examples:
D NoDataString c '<b>*** no substitution! ***</b>'
* Write a section without newline characters
C callp wrtsection('mysection':*on)
* Write a section with non-default warning for
* missing substitution variables
C callp wrtsection('mysection':*off:
C NoDataString) |
Note 6. WARNING - wrtSection(*fini) will not perform and return an error
message in file CGIDEBUG if the outbut buffer size exceeds 16 Mb.
5. Special output procedures
Subprocedure
wrtNoSection
writes data for the browser without using substitution variables
or sections.
This subprocedure can be used when a large block of data is to
written. This is more likely to happen when writing non-textual
data such as images.
The following example shows how to read an external IFS file
(an HTML page, an image, or what you need) and how to insert
it into the CGI output buffer:
D IfsInpBuff s 10000a varying
D InpBuffLen s 10i 0
D IfsObj s 255a
D FileHandle s 10i 0
D ReturnInt s 10i 0
D BytesIn s 10i 0
* ... ... ...
* Read an IFS object into "IfsInpBuff"
C eval IfsObj = '/mypath/mysubpath/myobj.xxx'
* 1-Open the IFS file
C eval FileHandle = open(%trim(IfsObj)
C : O_RDONLY + O_TEXTDATA)
* 2-Read the IFS file
C eval BytesIn = read(FileHandle
C : %addr(IfsInpBuff)
C : %size(IfsInpBuff))
* 3-Close the IFS file
C eval ReturnInt = close(FileHandle)
C eval IfsInpBuff = %trim(IfsInpBuff)
* Insert the string read into the CGI output buffer
C ' ' checkr IfsInpBuff InpBuffLen
C callp WrtNoSection(%addr(IfsInpBuff):
C InpBuffLen) |
WARNING - Be careful not to exceed the 16 Mb limit of the output buffer. If that limit is exceeded,
wrtSection(*fini) will fail.
Subprocedure
clrHtmlBuffer
clears any HTML output that has been buffered
but has neither been sent to the browser
nor written into a stream file.
This is useful when program logic dictates you need to output
something other than what has already been buffered.
Subprocedure
getHtmlBytesBuffered
Returns the number of bytes in the output HTML buffer.
This number is incremented each time output is written with
WrtSection or WrtNoSection.
It is reset to 0 when either WrtSection('*fini') or
WrtHtmlToStmf is run.
If this number is allowed to grow to more than 16 MB, the CGI
program will fail.
Could be useful to stop creating an output page when its size
exceeds a reasonable limit.
D buffsize s 10i 0
C eval buffsize = getHtmlBytesBuffered |
Subprocedure
getHtmlBufferP
Returns the pointer to the output HTML buffer and the number of bytes used in the output HTML buffer.
This is expecially useful for debugging.
D OutBuffer s 32767 based(OutbufferP)
D OutBufferInfo ds
D OutBufferP *
D OutBufferLen 10u 0
C eval OutBufferInfo=callp(GetHtmlBufferP) |
Subprocedure
crtTagOpt
Returns an HTML tag <option value="...">...</option>
for use within a <select ...> list.
Of course, this is not the only way to create selection lists.
/$strselect
<table>
<tr><td>Please select desired date:</td></tr>
<tr><td><select name="date">
/$option
/%optionvalue%/
/$endselect
</select>
</td></tr>
</table>
|
D dates s 15 dim(3)
D i s 10i 0
D optionValue s 200 varying
/free
wrtsection('strselect');
for i=1 to 3;
optionValue=CrtTagOpt(%char(i):dates(i));
updhtmlvar('optionvalue':optionValue);
wrtsection('option');
endfor;
wrtsection('endselect');
|
We have a program that demonstrates the use of subprocedure CrtTagOpt: