Rapid Application Development with WSED
Part 1: EGL Development and Test

INTRODUCTION

This lab exercise will take you through the steps of building a server program using the Enterprise Generation Language (EGL). The EGL server program will be part of a web banking application. The web client part of the application, which is built in Part2, lets the user enter their account number, enter an amount to withdraw from that account, and then press a button to initiate the withdrawal. The EGL server program is called to perform the withdrawal and return the account's new balance. The web client then displays the confirmation page with the new account balance.

Enterprise Generation Language (EGL) is a development technology (IDE tooling and programming language) that lets you quickly write full-function  applications that can be deployed in WebSphere Application Server, CICS, IMS, and z/OS batch. EGL enables developers, regardless of their experience with underlying run-time technologies, to quickly deliver enterprise data to browsers (in the future, support for other user interface types is likely to be added).

EGL, which is built on the technology of VisualAge Generator, offers several benefits:

To find out more about EGL, visit the online help in WSED.
 
Note: This lab exercise requires that the following products are installed: 
  • WebSphere Studio Enterprise Developer Early Availability Version 5.0
  • DB2 UDB 7 (tested with V7.2 fixpak 6, other levels may work)
  • The account table in the AIS Database must exist with data (use T3.ddl)

Section 1 - Build an EGL Server Program

___ 1. Create a Project for the EGL Source
  1. From the menu bar of the Workbench window, select File, New, Project…
  2. On the New Project - Select page, select Simple from the left-hand list and double click on Project in the right-hand list (to double click on an item is the same as selecting the item and clicking on the default button)
  3. On the New Project - Project page,
___ 2. Open an EGL perspective
  1. From the menu bar select Window, Open Perspectives, Other..., or click on the Open a Perspective button in the Perspectives tool bar,  select the menu item, Other...
     
  2. In the Select Perspective window, select EGL and click OK
___ 3. Set EGL SQL preferences to enable DB2 catalog access
 
Later you will use the RETRIEVE SQL feature, which will create data item definitions based on the column definitions stored in relational database catalog. To identify which database and how to connect to that database,  set the SQL database access information in the Preferences view.
  1. From the Workbench menu bar, select Window -> Preferences
  2. In the Preferences window,


___ 4. Create an EGL Definitions file

 
EGL definitions are stored in one of 3 file types: program file (extension .eglpgm), definitions file (extension .egldef), or build file (extension .eglbld).
  • Program files contain a single top-level program part, which may embed functions and data parts for the program to reference. The name of the program file must match the name of the program part.
    • A program file can import any number of definitions files, which also contain functions and data parts.
    • A program file is written in EGL source format.
    • A program file is what you test or generate.
  • Definitions files contain any number of functions and data parts.
    • A definitions file can be imported by program files or by other definition files.
    • A definitions file is written in EGL source format.
  • Build files contain any number of build parts, which determine how a program is generated and prepared.
    • A build file can import other build files. 

You will create an EGL definitions file called, AIS, to contain a DB2 record definition (account) to use when accessing the account table and a record definition (acctws) to use when communicating with the EGL server program.  By having these records in a separate file, then one definition can be easily maintained and still shared by multiple programs - e.g. by a detail program and or by a list program. By storing all of the record definitions for the AIS database in a separate file, the database administrator could be given the responsibility to create and maintain this file for developers to use.

  1. In the Navigator View select ATMServer and type Ctrl+N
  2. In the New wizard, select EGL from the list on the left and double click on EGL Definitions File in the list on the right.
  3. On the Create EGL Definitions File - Select Container page,
  4. On the Create EGL Definitions File - Add Import Statements page, click Next
  5. On Add EGL Part - Select Type of Part to Add page,
  6. On Add a Record Part - Enter Record Name... page,
  7. On Add a Record Part - Select Record Organization page,
  8. On Add a Record Part - Enter SQL Properties page,
  9. AIS.egldef is opened in the editor area.
  10. In addition, AIS.egldef appears in the Navigator view, and the parts it contains are displayed in the Outline view.  The "SQL" next to account in the Outline view indicates that it will access a relational database.

  11. Close the editor for AIS.egldef.
___ 5. Complete the account record part
 
EGL provides 2 editors for defining and maintaining parts defined in a program file or a definitions file: 
  • The EGL Parts Editor provides a graphical interface for defining/editing EGL programs, functions, data parts, and build parts. For the new user, this editor is easier because it offers a fill-in-the-blank approach.  We will also use it for a time-saving  feature, RETRIEVE SQL, which will create, on the click-of-a-button,  data item definitions for the account record based on the column definitions stored in relational database catalog.  In the future, RETRIEVE SQL will be available in the EGL Source editor as well.
  • The EGL Source Editor provides a language sensitive text editor, where you specify logic and data parts in a similar way to writing code in any procedural language. In this case, your work is in EGL source format. You will use this editor later when defining the record, acctws.
  1. In the Navigator view, right click on AIS.egldef and select

  2.      Open with..., EGL Part Editor
  3. In editor for account record, right click in the table (see picture below) and from the context menu select Retrieve SQL

  4. Click on  (Show SQL Item Properties)
  5. For ACCT_NUMBER set Key to YES (hint: click once to select the row, click a second time to select the column value, click a third time to open the drop down list)

  6. Save your changes (Ctrl+S) and close the AIS.egldef file.
___ 6. Define Acctws record
 
acctws is a working storage record, a temporary data area defined in a program or function. Later you will declare acctws to be the parameter data area in our server program. The client that calls the server program will pass the account # and the withdrawal amount in acctws. On return, the server program will pass the new account balance in acctws. 

To take advantage of copy support (cut and paste) and to explore use of an alternative editor,  you will use the EGL Source Editor to define the acctws record.

  1. In the Navigator view, right click on AIS.egldef and select Open with -> EGL Source Editor
  2. To add a Record definition for acctws.
  3. Create the data items for acctws by copying those from account
  4. Type Ctrl+S to save your changes.  The source in the editor area should look like:

  5. Notice the information displayed in the Outline view. It is a summary of what is in AIS.egldef and enables us to quickly access specific definitions.
  6. Double click on acctws - Working Storage in the Outline view, and observe that the definition for acctws is now highlighted in the editor area.
  7. Double click on the data item, TXN_AMT Pack(10,2), under acctws in the Outline view, and observe that the definition for TXN_AMT is now highlighted in the editor area.
  8. Close the AIS.egldef file.
___ 7. Create an EGL Program file
 

By having the data areas defined first, code assist can help when inserting data references into a program's or function's logic. This is much faster and more accurate than doing so by hand.

Data areas must be both defined and declared in a program or function before any reference to them is valid. Since the records, account and acctws, are defined in another file, AIS.egldef, the IMPORT statement will link those definitions to our program.

These records can be declared as parameters or variables. Parameters are passed to a program or function from an external source, whereas variables are data areas internal to a program or function. In our EGL server program, the record, acctws, will be declared as a parameter and the record, account, will declared as a variable.

  1. In the Navigator View select ATMServer and type Ctrl+N
  2. In the New wizard, select EGL from the list on the left and double click on EGL Program File in the list on the right.
  3. On the Create EGL Program File - Select Container page,
  4. On the Create EGL Program File - Add Import Statements page,
  5. On the Add a Program Part - Enter External Name... page, click Next
  6. On the Add a Program Part - Enter Program Parameters... page,
  7. On the Add a Program Part - Enter Program Variables... page,
  8. account.eglpgm is opened in the editor area. It should look like:
___ 8. Using Code Assist to add program logic
 
When writing the logic, code assist (Ctrl+Space) can help you code faster and with greater accuracy.  For example, code assist shortens the time it takes to key EGL statements. By having the data areas defined first, code assist can help when inserting data references in the logic.
  1. When working in the EGL Source editor, the logic of a program or function is identified by tags,
  2. Script
    ScriptEnd
    Here are the steps using code assist:
  3. Add the script:
    account.ACCT_NUMBER = acctws.ACCT_NUMBER;
    Here are the steps using code assist:
  4. Add the script:
    update account on exception
            ezertn();
            end
    Here are the steps using code assist:
  5. Add the remaining script. EGL is not case sensitive, however case is kept as entered. (hint: use code assist for the IF and REPLACE statements)
    if (account not err)
            account.bALANCE = account.bALANCE - acctws.TXN_AMT;
     
        replace account on exception
              ezertn();
        end
        acctws.balance = account.bALANCE;
     end
  6. Type Ctrl+S to save your changes. Your workbench should look like (except that the Outline View was moved up to condense the image size): 
  7. Fix any errors that are displayed in the Task list for account.eglpgm.
  8. Save any changes and close account.eglpgm editor.

Section 2 - Test the EGL server program

 
The EGL server program can be tested independently of a web browser client and WebSphere application server. The EGL is generated into Java code and then debugged using the integrated EGL debugger of WSED. A build descriptor controls the generation of EGL into Java code. Build descriptors are stored in an EGL build file.

The build descriptor will have these options set:

  • debug=YES causes special files to be created for use with the debugger
  • genProject and packageName indicate where the generated code will be stored
  • J2EE=NO says to create code that does not require a J2EE container
  • sqlDB identifies the database
  • sqlJDBCDriverClass identifies the jdbc support classes to use
  • system=WIN causes Java code to be generated for the Windows
___ 1. Create an EGL Build file
  1. In the Navigator view, select the project ATMServer and type Ctrl+N
  2. In the New - Select page, select EGL from the list on the left and double click on EGL Build File in the right-hand list.
  3. On the Create EGL Build File - Select Container page,
___ 2. Create a "debug" build descriptor
  1. In the Outline view, right-click on accountBuild, and then select Add part…
  2. In Add EGL Build Part - Select Type... wizard, select Build Descriptor and click Next.
  3. On the Add a Build Descriptor Part - Enter Build Descriptor Name... page, set Name to debug, and then click Finish.
  4. debug is added to the Outline view, and the part opens ready for editing. In the editor,
  5. Close and save accountBuild.eglbld

___ 3. Generate Java code from account.eglpgm using the debug descriptor

  1. In the Navigator view, right-click on the account.eglpgm file, and then  from the context menu select Generate EGL with -> Java Debugging Build Descriptor.
  2. The Generate wizard appears. Make sure that account is selected in the list of parts to generate and click Next.
  3. On the Generate - Select one or more Java debugging build descriptors... page,
  4. In the Generation Results view, verify that "Generation completed for program account with no errors."
___ 4. Add DB2 path variable to EGLDebug project
  1. In Navigator view, right click on EGLDebug and select Properties from the context menu
  2. On the Properties window,
___ 5. Set a breakpoint in account.eglpgm
  1. In the Navigator view, double click on account.eglpgm
  2. In the editor, double click in the left-hand margin of the line: account.ACCT_NUMBER = acctws.ACCT_NUMBER;. A blue sphere appears indicating a breakpoint is set for this line.

  3. Close account.eglpgm
___ 6. Create debug launch definition for account.eglpgm
  1. Open a Debug perspective (from the menu bar: Window, Open Perspective, Other..., Debug)
  2. From menu bar select Run, Debug...
  3. Launch Configurations window opens. Right click on Debug an EGL Java program and select new
___ 7. Debug the EGL program
  1. When debugger has stopped on the first line of script in account.eglpgm, in the Variables view (upper right corner) expand the structure account and then expand acctws and account
  2. Under acctws, set acct_number=2 and txn_amt=2 in acctws. (hint: double click on the variable name, enter a new value, and hit Enter).

  3. Step through the program observing the changes to the account variable (hint: click Run, Step Over from the menu bar, or click Step Over in the tool bar, or hit F6)
  4. After the program has terminated, close the debug perspective
  5. Close account.eglpgm editor.

Section 3 - Creating Run-time Build Descriptors (Java Class and Java Wrapper)

 
Part of EGL’s power lies in its ability to generate code for many different runtime environments - Java for WebSphere and COBOL for CICS, IMS and z/OS batch. To enable you to control the generation of such code, EGL provides build descriptors. EGL’s Build descriptors are extremely flexible and can be used to define numerous aspects of how code generation should take place. 

You will create two build descriptors now that you will actually use in Part2. "win-java" will define how to create a set of Java class files to perform the EGL logic. "wrapper" will define how to create a Java wrapper file which will provide a connector to our EGL server program. 

___ 1. Create a Build Descriptor for Java code generation
  1. In the Navigator view, double click on accountBuild.eglbld
  2. In the Outline view, right-click on the accountBuild, and then select Add part…
  3. The Add EGL Build Part wizard appears. Select Build Descriptor, and click Next.
  4. On the Add EGL Build Part - Enter Build Descriptor Name page, in Name enter win-java, and then click Finish.
  5. The win-java part is added to the Outline view, and the part opens ready for editing.
  6. Type Ctrl+S to save your changes
  7. Check Show only specified options to reduce the list of options to those entered.  Compare to the list below:

___ 2. Create a Build Descriptor for Java wrapper generation
 
An EGL generated Java wrapper is a set of classes that acts as an interface between a servlet or Java program, on the one hand, and an EGL generated program, on the other.  A java wrapper makes calling our EGL server quick and easy for a Java programmer.  It provides methods to call the server and methods to get and set the parameter values. The java wrapper will marshall parameter data between java objects and record structures (for generated COBOL programs), convert data between ASCII and EBCDIC, and handle all communication.

When you request that a program part be generated as a Java wrapper, EGL produces a wrapper class for each of the following: 

  • The generated program 
  • Each record or structure that is declared as a parameter in that program 
The Java wrapper build descriptor will have these options set:
  • linkage points to a set of options that describe how to call the EGL server program
  • nextBuildDescriptor adds the option settings in another build descriptor to the options defined in this build descriptor such as genProject, genProperties, packageName.
  • system=JAVAWRAPPER causes the Java wrapper classes to be generated
  1. In the Outline view, right-click on the accountBuild, and then select Add part…
  2. The Add EGL Build Part wizard appears. Select Build Descriptor, and click Next.
  3. On the Add EGL Build Part - Enter Build Descriptor Name page, in Name enter wrapper, and then click Finish.
  4. The wrapper part is added to the Outline view, and the part opens ready for editing. In the editor,
  5. Type Ctrl+S to save your changes
  6. Check Show only specified options to reduce the list of options to those entered.  Compare to the list below:

___ 3. Create Linkage part
 
A linkage part defines how the generated java wrapper should invoke a called EGL program. A brief description of the options you will specify:
  • location is the address where the server program executes
  • package specifies the directory where the runtime Java classes can be found
  • remoteBind=Generation causes the linkage information to be generated into the Java Wrapper, otherwise a linkage properties file must be provided at runtime
  • remotePgmType indicates kind of program call conventions to use
  1. In the Outline view, right-click on accountBuild, and then select Add part…
  2. The Add EGL Build Part wizard appears. Select Linkage Options, and click Next.
  3. On the Add EGL Build Part - Enter Build Descriptor Name page, set Name to linkage, and then click Finish.
  4. The linkage part is added to the Outline view, and the part opens ready for editing. In the editor,
  5. Type Ctrl+S to save your changes. Your linkage should look like:

  6. Close the account.eglbld file.
___ 4. Set EGL Default Build Descriptors
 
By setting the default descriptors in the properties for a project, folder, or individual EGL program, then a build descriptor does not have to be specified for each generation request.
  1. In Navigator view, right click on ATMServer and select Properties from the context menu
  2. On the Properties window,
Congratulations, you completed building (section 1) and testing (section 2) an EGL server program.  In addition, you created (section 3) build descriptors for generating the runtime code for use in Part 2.