Skip to main content

About Your PxPlus Programs

Use the information in this section and the examples throughout this reference documentation as an aid when you create your web applications. See Appendix - HTML Examples.

Output from Your PxPlus Program

As output, you can return any data that is valid to the browser. This includes:

  • HTML pages generated by your program code.

  • Binary data which is to become a file on the end-user's system.

  • JAVA script (which becomes part of the page to be evaluated by the browser).

  • Raw data. (Set the flag %raw_text in your program. Then the Web Server wraps the required HTML around your data.)

Your PxPlus programs can send files to a browser if you set the %content_type="application/octet-stream" and %content_filename$="somefile.ext" and then dump the file into the %print_fn channel (maximum 4096 bytes per WRITE RECORD).

See PxPlus Web Server Variables.

No Direct Interaction with User

Your PxPlus web application can do virtually anything except interact directly with the user interface. This means you cannot use:

  • INPUT or OBTAIN directives

  • Built-in graphics control objects, such as BUTTONs and LIST_BOXes

  • Print mnemonics, such as 'FRAME', 'TEXT', 'CS', etc.

Interaction with the user must be done indirectly through HTML forms or pages that can request information and return resulting responses and data to your program. Your program can construct an HTML page on the fly from the data.

See entry points 9 to 13 in *web/util CALL EntryPoints and Merge Dynamic Data with HTML Templates (*web/merge).

Standard Output Channel

Think of coding for browsers as block mode transmission to a background task. The Web Server sets up a memory-resident logical file using %print _fn. This variable contains the logical file number or channel the Web Server is using for standard output. You dump your data into the memory file by using PRINT, WRITE and other output directives with "(%print_fn)" as the file channel, as in PRINT (%PRINT_FN)DATA. Then, the Web Server transmits the contents for you.

Limits on Output

There are a few limits on the amount and type of output you can generate:

  • Although the memory file has a block size of 6K, your individual WRITE, WRITE RECORD or PRINT output to the %print_fn channel should not exceed 4K, because the PxPlus Web Server needs part of the memory file for other purposes (e.g. to add end-of-line translations and characters which are needed by the browser but illegal in HTML code).

  • Although you can generate more than one style of output in a single program (see Example 2 - Basic HTML Output below with raw text in a single program), each mime style must be generated through a separate request. You cannot mix different styles in a single output to the memory file.

  • Remember that your application has a 90-second time-to-live. If the task handler does not complete your given PxPlus application before the timeout, the port monitor will terminate your job and start a new task handler in its place. See About Timeouts.

Example 1: Basic Raw Text Output

The URLs and PxPlus program below illustrate simple raw text requests. Three URL requests are set up in the browser's address field:

  • To run the program

  • To dump the variables

  • To list the program

http://127.0.0.1:4000/web_text
http://127.0.0.1:4000/web_text;dump
http://127.0.0.1:4000/web_text;list

The simplest method of generating a report is by using the %raw_text flag, as in the PxPlus program below.   Notice the WEB_TEXT entrypoint line labels which were requested in the URLs above.   The task handler starts executing each of the three requests at its respective executable line or label entrypoint (0010 , DUMP: and LIST:) below.

0010 ! WEB_TEXT (Report Style Output in Raw Text):
0020 LET %RAW_TEXT=1,%RAW_TITLE$="Example: Raw Text Output"
0030 LET C=HFN; OPEN (C,IOL=*)"CSTFILE"
0040 PRINT (%PRINT_FN)@(1),"CustID",@(20),"Customer Name",'LF'
0050 LOOP:
0060 READ (C,END=DONE)
0070 PRINT (%PRINT_FN)@(1),CST_ID$,@(20),CST_NAME$
0080 GOTO LOOP
0090 DONE:
0100 CLOSE (C)
0110 END
0120 ! 
0130 DUMP:
0140 LET %RAW_TEXT=1,%RAW_TITLE$="VARIABLE DUMP FOR WEB_TEXT"
0150 DUMP (%PRINT_FN)
0160 END
0170 !
0180 LIST:
0190 LET %RAW_TEXT=1,%RAW_TITLE$="LISTING OF WEB_TEXT PROGRAM"
0200 LIST (%PRINT_FN)
0210 END

Example 2: Basic HTML Output

In the next example, two URL requests are set up in the browser's address field:

http://127.0.0.1:4000/web_html
http://127.0.0.1:4000/web_html;list_and_dump

This is a simple example of a PxPlus application which contains code to generate HTML and raw text to illustrate that; since each entrypoint routine (i.e. line 0020 and LIST_AND_DUMP:) stands alone as a separate request, each can have its own styling.

0020 PRINT (%PRINT_FN)"<html><head>"
0030 PRINT (%PRINT_FN)"<title>"+"This is a simple HTML example"+"<title>"
0040 PRINT (%PRINT_FN)"</head><body>"
0050 PRINT (%PRINT_FN)"<h1>"+"This is a simple HTML example"+"<h1><hr><p>"
0060 PRINT (%PRINT_FN)"Welcome to PxPlus Web Server</p>"
0070 PRINT (%PRINT_FN)"<p>This is an HTML output example</p>"
0080 PRINT (%PRINT_FN)"<p>You can use any HTML code as output as long as it "
0090 PRINT (%PRINT_FN)"adheres to standard HTML specifications."
0100 PRINT (%PRINT_FN)"</p><body></html>"
0110 END
0120 !
0130 LIST_AND_DUMP:
0140 LET %RAW_TEXT=1,%RAW_TITLE$="Listing + Variable Dump in Raw Text"
0150 LIST (%PRINT_FN)
0160 PRINT (%PRINT_FN)'FF'
0170 DUMP (%PRINT_FN)
0180 END