What is PL/B
The Programming Language for Business or PL/B is an interactive, data entry programming language designed primarily for business programming. Originally called DATABUS, which is an acronym for Datapoint Business Language, it was developed by Datapoint Corporation for operation on Datapoint's proprietary disk operation system. Since its creation, PL/B has evolved into a powerful business programming language running under many operating systems, on many types of computers.
The PL/B language is easy to learn, and powerful enough to create complex programs. The PL/B language provides support for string manipulation, fixed-point arithmetic, interactive I/O, printer I/O, ISAM (Index Sequential Access Method) file access, and AIM (Associative Index Method) file access.
A Programmer's Introduction
This programmer's introduction is courtesy of Stephen G. Kent at Mid Michigan Computer Consultants, Inc. All their information on PL/B can be seen at: http://www.mmcctech.com/pl-b/
PL/B is a remarkably simple language to be as powerful as it is. It is extremely robust in all environments, provides support for all major file access methods, runs in every user interface format from text based to GUI and is fully network aware. As a mark of it's power, Sunbelt's PL/B compiler is itself written in PL/B.
PL/B programs lines are composed as:
[LABEL] OPERATION OPERAND,...,[operand] [comments]
The line is essentially free form. The LABEL is optional but when used must start in the first position of the line. The operation is required and must start somewhere past the first position. Label, operation and the first operand are separated by spaces. Operands are separated by commas or qualifiers like "TO", "IN" and "FROM".
Operations have a variable number of operands. When the proper number of operands have been found on a line then anything else is treated as a comment. A period or semi-colon anywhere on the line indicates the start of a comment. Any line may be continued after the first operand by following the last byte of the operand with a colon.
The language is strongly typed with the basic data types being string (called DIM) or numeric (called FORM). Numeric data is defined using a decimal format such as "9.2" indicating the magnitude of the field. Numeric data may also be defined in traditional binary integer, floating point, hex or octal formats.
Unlike some languages, variables may NOT be created implicitly by use. Implicit variables are defined simply by appearing in the code. For example, in BASIC one could code A = 123. "A" becomes a variable but required no previous definition. Implicit variables may be ambiguous when a programmer is working on a small section of unfamiliar code. PL/B requires that variables be specifically defined in advance prior to being used. This insures that there is no ambiguity concerning the variable... with one exception:
PL/B does allow a variable to be reformatted on-the-fly. The SMAKE instruction allows the size of a string variable to be defined at run time. The benefit is that a string variable can be defined in the source code as requiring one byte. At runtime the string can be reformatted on the fly to allow any number of bytes. The effect is that the load module requires less disk space to store. Furthermore, the programmer can write a loop at runtime to expand the variable's size to use all available memory.
As a high level language, PL/B does not require the programmer to be concerned with the actual machine implementation. There are no stack or register or address considerations. This contributes to the highly robust and almost crash-proof nature of the language.
PL/B is very easy to read. Instructions formats are intuitive and logical. Variable names have a maximum length of 32 characters, allowing for very descriptive naming. The language structure falls somewhere between the nearly English format of COBOL and the highly technical format of "C". Programmers from either of those backgrounds adapt quickly to PL/B and generally like it a great deal. (The only exception to the readability comment is where PL/B extends into the realm of Windows API calls. Those are, by definition, difficult for even experienced programmers to interpret.)
Example Code
A typical code segment might look like this:
...................
. Work areas:
.
NAME DIM 30 Working name variable
SAVENAME DIM 30(50) 50-element array of saved names
NAMEIDX FORM " 0" Two byte numeric variable
.
...................
. Loop to fill table of names
.
LOOP
ADD ONE,NAMEIDX Increment index to next array entry
IF (NAMEIDX=50) Is the table full?
BREAK Yes it is, break the loop
ENDIF
KEYIN "Please enter your name:",NAME
MOVE NAME to SAVENAME(NAMEIDX)
DISPLAY "Thank you ",NAME:
". You are number ",NAMEIDX
REPEAT
STOP
Variables
Variables are generally defined as strings or numbers. All variables must be explicitly defined by the programmer. Implicit variables, defined by being used in a statement, are not allowed.
Variables may appear anywhere in the program provided the definition appears in the code before the variables are used in an operation.
Three specifications define variables:
label FORM n[.n] Defines a numeric variable
label FORM " 10.33" Defines and initializes a numeric variable
label DIM n Defines a STRING
label INIT "xxxx" Defines and initializes a string
Strings (which may be up to 65K in length) are defined by the programmer with a maximum physical length. In actual use, strings have three attributes which may, if needed, be manipulated by the programmer. These attributes are the physical length, the logical length of the field's current contends and a "form pointer" designating the first byte within the string that is to be acted on.
For example, a 50 byte (physical length) string might contain only 25 bytes of data (logical length) and the pointer might be set to the 5th byte. Strings may be manipulated in whole or, by changing the pointers, as sub-strings. For the most part a programmer simply deals with the entire string.
Arrays
Multi-dimension arrays are specified by declaring variables with an array size defined in parenthesis. (Sunbelt's PL/B supports up to 14 dimensions)
TABLE1 DIM 15(25,25)
General Operations
Operations include the typical ADD, SUBtract, MULTiply, DIVide, MOVE, CALL, BRANCH and GOTO. Calculations may also be done with the CALC statement. For example:
CALC EXTENDED_PRICE = (QUANTITY * PRICE) + DEPOSIT
Logical Operations
Logic operations are typically done with an IF statement such as:
IF (AGE>MAXAGE)
..... routine
ELSE
..... routine
ENDIF
Structured programming techniques are handled by typical LOOP and CALL / RETURN structures. For example:
LOOP
CALL GET_USER_NAME_AND_ADDRESS
UNTIL NO_MORE_USERS = TRUE
FOR COUNTER FROM "1" TO "8" USING "2"
DISPLAY COUNTER
REPEAT
STOP
GET_USER_NAME_AND_ADDRESS
KEYIN "Enter your name:",NAME:
*N,"Enter your address:",ADDRESS
..... etc.....
RETURN
OOP
Object oriented programming methodologies are supported by both included code segments and by external calls to pre-compiled modules.
FILE HANDLING
Files are declared as sequential (ASCII) or indexed. Indexed files are simple ASCII files with a separate, self balancing index file. All files may be read randomly or sequentially, forward or backward. Files may have any number of indexes.
PL/B also supports standard Btreive files and a unique content addressed "associative" access method. PL/B can also participate with ODBC defined databases and similar structures.
Most PL/B language vendors provide SQL interfaces and Sunbelt also offers full ODBC support with it's PL/B implementation.
An inline FILE sort is provided by the operation:
[label] SORT "infile, outfile; key,key,key ..."
COMMAND SHELL
In the DOS environment automatic, in-line SHELL's to DOS are provided by an EXECUTE instruction. This same technique works in Windows to call the COMMAND.COM processor.
[label] EXECUTE "command line"
EXTERNAL ROUTINES
PL/B provides for internal subroutines as well as separately compiled, external subroutines.
Text Based Screen I/O
PL/B' most powerful feature, by far, is the text mode screen and keyboard handling. Two instructions do it all. DISPLAY is for output only, KEYIN does both output and input. Popup windows, borders and full color control are all built in. Consider this "popup" routine:
REPLY DIM 1 One byte work area
[label] KEYIN *SETSWALL 5:15:10:50: Define window
*SAVESW: Save screen area
*HON,*BLUE,*HOFF: Blue background
*YELLOW,*DION: Yellow foreground
*ES: Erase screen window
*BORDER: Double line around window
*P3:2: Column 3, Line 2
"Hi there! ": Literal text
*N: Next line
"Tap any key. ": Literal text
*+: Automatic ENTER
REPLY: Get one byte field
*-: Turn off automatic ENTER
*RESTSW; Restore window (popdown)
"Popup windows" may be stacked to almost any level. All screen coordinates may be hardcoded (*P10:25) or use variables (*Pcolumn:row). Colors may optionally be controlled by names (*BLUE) or by specifying a numeric attribute (*COLOR nnn) where nnn may be a variable.
GUI Implementations - VISUAL PL/B
The GUI implementation from Sunbelt, called Visual PL/B is fully compatible with the text based interface. Programs can be coded with a traditional text editor but a visual Integrated Development Environment (IDE) is also provided. The IDE incorporates project management, forms design, language specialized editor, debugging tools, and related tools. The forms designer allows screens to be be created and manipulated with standard visual tools. Properties as well as code segments are attached to each screen object then the objects are packaged into a shell program which provides the overall structure for the application.
Unlike the DOS implementation, which compiles to an "EXE" executable file, the GUI compiler writes to an intermediate, interpreted representation. This machine independent "p-code" can be transported to any platform which supports a PL/B interpreter. Currently supported platforms included various UNIX and LINUX systems and all flavours of Windows including the Pocket PC.
The GUI implementation is conceptually similar to other object oriented languages. Objects are defined and given properties. The application program activates various objects then waits for an event. The event is evaluated and invokes a processing routine to work with the object's results.
A truly unique element of the Sunbelt GUI implementation is the ability to compile and directly run traditional TEXT BASED PL/B programs under WINDOWS with no changes to the code! The text based code is evaluated and the interpreter faithfully replicates keyboard and screen handling within what is essentially a windows text box. (Interestingly, both GUI objects and text based components can be combined in the same program and same screen, which can be very useful.)
CLIENT/SERVER
Sunbelt provides a client/server implementation of the language. The Server program can run on a Windows, Unix or Linux platform. "Thin" client's can run on any remote workstation. The application program is executed on the server. The client program on the remote workstation handles the user interface.
The client program can be downloaded or run from the server via a standard internet browser. A web page would provide a link to the client program on the server. When clicked, the client is downloaded to the remote machine and begins to communicate with the server.
FILE MANAGER
Sunbelt also offers a "File Manager" program which runs on a Windows, Unix or Linux server. Standard PL/B programs running under windows, as well as thin client PL/B programs can communicate with the File Manager using standard TCP/IP connections. All file processing is centralized at the File Manager machine thus optimizing file operations.
For more information visit Sunbelt's site at www.sunbelt-plb.com.