MMCC's PL/B notes
Mid Michigan Computer Consultants, Inc.
Bay City, MI 48708
From its humble beginnings as a hobby machine, the PC has become a mainstay business computer. Mainframe and mid-range systems continue to process data in large companies but even in those applications the PC has become the most common desktop machine for end users.
In the early years, PC programmers had a limited number of languages and tools at their disposal. That situation didn't last long. Today all of the major languages, and many obscure ones, are implemented for the PC platform. Modern tools and the personal nature of the PC have made it the most versital development platform programmers have ever had.
Although the "C" language has become generally associated with the PC, several other languages are heavily used. BASIC, once the lowest common denominator, is now VISUAL BASIC and is nearly as popular as "C". Database systems such as dBASE and FoxPro and their derivitives and now ACCESS are heavily used. Some people are surprized at how many well know application systems are actually written in the business mainstay COBOL!
Of the less well known languages, one that stands out as uniquely suited to PC's is ANSI standard PL/B. Designed for Datapoint Corporation's line of multi-user mini computers in the early 70's, PL/B (then called DATABUS) was ported to the MS/DOS world around 1983.
Fully 10 years before the PC, Datapoint's line of small computers were mining the small office market. Those machines and their disk operating systems were remarkably similar to today's PC and MS/DOS. Datapoint offered full multi-user support in it's DATASHARE environment and their "Attached Resource Computer" (ARCNET) is considered by many to be the first Local Area Network.
For years an international base of loyal Datapoint customers were fanatics about DATABUS. As the world migrated to the PC's these users created a market for a PC version of their favorite language. Today some dozen companies sell MS/DOS, Windows, Mackintosh and UNIX versions of DATABUS.
In the early 90's the ANSI X3-J15 committee was formed to standardize DATABUS. Today DATABUS, renamed PL/B, is the second ANSI standard "business" computer language. (MMCC participated as a member of the J15 committee).
MMCC, Inc. was founded as a mainframe and mid-range software and consulting firm but had a following of small computer clients as well. Most of those clients used Datapoint computers. Over time MMCC evolved into a PC software company. PL/B came along and today provides the basis for most of our software.
Of the many PL/B vendors, MMCC has chosen to work with Sunbelt Computer Systems of Tyler, Texas. Sunbelt was the first to write for the PC, one of the first to implement a WINDOWS version, was a major force in the ANSI standards committee, and continues to have close ties to Datapoint. Today, most would agree that they are the leading PL/B resource company.
A Programmer's Introduction
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-color 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 implicitely by use. Implicite 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. Implicite variables may be ambiguious 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 crashproof nature of the language.
PL/B is very easy to read. Instructions formats are intuitive and logical. Variable names mabe up to 32 characters in lenge thus 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 excpetion 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.)
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 are generally defined as strings or numbers. All variables must be explicitely defined by the programmer. Implicite 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 stringStrings (which may be up to 65K in length) are defined by the programmer with a maximum phisical length. In actual use, strings have three attributes which may, if needed, be manupulated 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.
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)
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
Logic operations are typically done with an IF statement such as:
IF (AGE>MAXAGE) ..... routine ELSE ..... routine ENDIFStructured 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
Object oriented programming methodologies are supported by both included code segments and by external calls to pre-compiled modules.
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 ..."
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 ROUTINESPL/B provides for internal subroutines as well as separately compiled, external subroutings.
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 attirubte (
*COLOR nnn) where
nnnmay 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 flavors of Windows including the Pocket PC.
The GUI implementation is conceptually similiar 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 texb based components can be combined in the same program and same screen, which can be very useful.)
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.
Sunbelt also offers a "File Managr" 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 optomizing file operations.
For more information be sure to visit Sunbelt's site at www.sunbelt-plb.com.