Presentation is loading. Please wait.

Presentation is loading. Please wait.

® IBM Software Group © 2006 IBM Corporation EGL Programming Model These slides walk you through the concepts and vocabulary the make up the Enterprise.

Similar presentations


Presentation on theme: "® IBM Software Group © 2006 IBM Corporation EGL Programming Model These slides walk you through the concepts and vocabulary the make up the Enterprise."— Presentation transcript:

1 ® IBM Software Group © 2006 IBM Corporation EGL Programming Model These slides walk you through the concepts and vocabulary the make up the Enterprise Generation Language – including the programming model, project file organization, and logic “parts”.

2 2 Course  RBD and Course Setup   RBD Workbench  EGL/Web QuickStart Programming in EGL  Programming in EGL  Database and File Access  EGL and Services (SOA)  Calling External Languages From EGL  EGL and Batch Applications  Appendices Units: RBD/EGL Programming

3 3 UNIT The EGL Programming Model – Terms/Concepts  The EGL Programming Model – Terms/Concepts   EGL Data Parts and Assignment Statements  EGL Conditional Logic and Looping Statements  The EGL Built-in Functions and Date Math Topics: Programming in EGL

4 4 To master EGL programming you will need to learn the following EGL topics:  File Model  Parts Concept  Programming Model  Namespace Concept  Editor  Instruction set, specifically:  Data declarations –Primitives –Records –DataItems –Arrays  Logic constructs, specifically –Assignment statements –Conditionals –Looping statements –EGL System Libraries  EGL data access verbs –SQL database statements –Non-SQL files  Calling external programs, from EGL  Debugger  As a broad and deep platform for developing business applications that generate to both mainframe (traditional) and server (contemporary) run-times, EGL has introduced a few new programming constructs, in order to simplify your work. Additionally, the EGL programming language has been kept procedural (for legacy programmers) in nature, yet growing into a “modern” vocabulary – which allows you to leverage advances in computer language engineering, since the days of COBOL, RPG, i4GL, etc.

5 5 The EGL File Model and File Types Your EGL projects will contain a number of different file types:  Programs  Traditional business logic files with a single entry point. Calling (main) or called subroutines.  Libraries  Business logic files that contain multiple functions, each of which can be called separately by other Logic Parts.  Services  Business logic files that are like Libraries, except they can be published and made available as Web Services – and called by other Logic Parts.  JSFHandlers  Specialized business logic files that manage the functionality required by JSF web pages. JSFHandlers typically call programs, library and service functions.  BIRTHandlers  Specialized business logic files that manage the functionality required by reporting tools such as BIRT and Jasper  Build files  EGL files that provide specifications for language generation (to Java, or COBOL) Related file types are often organized within an EGL package, which is essentially a folder that acts as a unit of scope for file management.  - See the Help topic: Introduction to EGL files

6 6 The EGL File Model Hierarchy – Organization of Folders and Files ProjectWorkspace ProjectA … \EGLSource\ \package1\ File1.egl File2.egl File3.egl \package2\ File5.egl File6.egl EGLBuild file.eglbld … ProjectB \EGLSource\ \package3\ File7.egl File8.egl \package4\ File9.egl EGLBuild file.eglbld … Project Explorer manages your files and folders (called packages) in a hierarchical tree Notes:  Your project Workspace, all projects and all packages are physically maintained on your PC as file folders.  If a file that resides under \package1\ needs to reference EGL business logic in a file that resides under \package2\ (a folder at the same level, as shown on the right)  You will need an EGL “ import ” statement to allow the EGL parser to find the file. This is because packages act to maintain “scope” – a concept we will discuss in a minute.

7 7 The EGL Part Model  In order to allow us to group related EGL language keywords into a higher level of abstraction, EGL introduces the notion of “parts” as an organizational meta-concept. Specifically, EGL understands the notion of:  Data Parts:  Record  DataItem  EGL DataTable  Logic Parts:  Function  Program  Library  Service  Handlers: JSFHandler, ReportHandler, Forms  Generate-able Parts egl  Any EGL Part that is it’s own file (ending in. egl ) that gets generated to COBOL or to Java  Build Parts eglbld  An EGL file that ends with the extension. eglbld – Build parts control the generation process and run-time behavior  By using the term “parts” we can collectively refer to a number of language abstractions as one term. Also - the product documentation references parts ubiquitously  - See the Help topic: Introduction to EGL Parts

8 8 EGL Parts – Source Code Reuse and Productivity As soon as an EGL Logic or Data part is successfully saved and validated, it is entered into an EGL “Parts Dictionary”, maintained for your current workspace. EGL Data and Logic parts (Records, DataItems, Programs, Functions, etc.) in this dictionary are accessible using Content Assist (Ctrl/Spacebar) when you edit your code.  Ctrl+Spacebar

9 9 The EGL Program Model All EGL business logic files are organized in a consistent, structured model, consisting of five source code areas, or segments: 1. Package statement – what is my parent package/folder? 2. Import statements – what other folders do you want to reference EGL source from 3. Part Type statement – what kind of Generate-able Part am I – including any EGL Properties that refine my run-time behavior 4. Global data variable declarations – Declarations That can be referenced from any Function in the Namespace 5. Function declarations – operational EGL statements – business logic 1. 2. 3. 4. 5.

10 10 Namespace – AKA “scope” Like almost all contemporary languages, EGL adheres to the concept of a Namespace – which means essentially, “What can be referenced by an EGL statement in a file?” From our example shown here … note the following:  Any statement in any function in the updatecustomer2 JSFHandler part can reference:  (Global) variables customer and status  All three functions in this file  Additionally, any statement in any function can reference any defined Logic or Data part in any file under:  The jsfhandlers package  Any file in an imported package (there are four imports in this file)  If you attempt to reference an EGL Part that is outside of the Namespace (not in the current file, and not a defined part in the jsfhandlers package, or in any of the import packages) you will get a “cannot be resolved” syntax error, when you try to save your work. See Slide Notes – for additional info on Namespace

11 11 EGL Functions  A function is the fundamental business logic unit in an EGL Logic Part. Functions contain a series of EGL statements and can include the following elements: name  Function name – unique within the Namespace, followed by parentheses () parameters  A set of positional parameters, enclosed in the parentheses, each of which corresponds to an argument (and its data type) passed when the function is called by another function. return type  A return type, which describes the type of data that the function returns to the calling function. local variables  A set of local variables, each of which has meaning within the function only.  EGL statements – as per your business logic requirements  An end delimiter.  Functions are invoked by simply specifying their underlying part and function name, and passing parameters as defined Customerlib.DeleteCustomer(customer, status);

12 12 Other Language Concepts  Most EGL statements are terminated with a semi-colon. A few statements are terminated with the reserved word: end - including:  Part and Function declarations  Conditional and Looping statements  EGL is a case-insensitive language – except where it interfaces with Java – examples: Page Data Variables and Functions, etc.  You can comment on a single line with: //  You can comment across lines with /*… …*/  Variable, function and part identifiers:  Can be from 1 – 128 characters long  Must start with letter or underscore  Cannot be an EGL reserved word  Should not be the same as a defined Logic or Data Part  Statement order in an EGL file:  Package must be the first (non- comment) statement in your file. Followed by  Import statement(s)  Part Type declaration  Global Data variable declarations  EGL Function declarations

13 13 JSFHandler Part  A JSF Handler part is an EGL Logic Part that is customized to control a Web page at run time. JSF Handlers contain your business logic functions and specialized functions that run automatically at certain points in a Web page's life ( onConstruction() is one, please see the product help documentation for more info.)  Use EGL functions in a JSF Handler to validate or change the data that a user types into a Web page, to assign values to JSF fields, to respond to a user's actions on the page, or to forward to a different page.  Complex and lengthy business logic should be coded in EGL Libraries, Services and Programs and called from JSF Handlers.  EGL global data variables (coded after the JSFHandler statement and outside of a Function) can be bound to JSF page controls.

14 14 Program Part  A Program part is a generate-able logic part with a single point of entry and a required function called main(), which represents the logic that runs at program start up.  A program can include other functions an can access functions that are outside of the program. The function main() can invoke those other functions, and any function can call other programs, Libraries or Services – but not JSFHandlers.  Programs can be defined  Without parameters (Main programs)  With parameters (Called programs)  Main programs run when started by an operating system command or a transfer from another main program. They are used primarily for “batch”, IMS or CICS applications. call  Called programs are invoked from other programs via the call statement. Example of an EGL Called Program

15 15 Library Part  A Library part is another generate-able part, similar to an EGL Program Part, except that it supports sharing individual functions and variables through direct references.  When you imported the database schema awhile back, the import process created a number of EGL Libraries with functions you called in other workshops and labs.  EGL provides a number of system libraries containing commonly-required functions (date/time handling routines, string functions, math library functions, etc.). These will be covered in a section later on in the course.  You can also create your own libraries of frequently used functions. Example of an EGL Library

16 16 Service Part  A service is similar to a library, with the major exception that a service may be located remotely from its client.  The client – which can be a program, JSF handler, library, or other service - uses (invokes) the functions defined in the service.  Services have one or more public functions that contain business logic. Once you have written the business logic, you can deploy the service as one of the following:  an EGL Java™ service  a Web service  an EGL COBOL service  a CICS® Web Service  In general, you create a Service part when you want to make your business logic available to other programs, either locally or remotely, in an encapsulated way. Example of an EGL Service

17 17 The EGL File Model and File Types – Calling …vs… Called Routines and Functions Library1Function4 Library2.Function10 Library2.Function10Function5Service1.Function7Function6 Call Program2 Call Program2 Service1Function7Function8 Service2.Function9 Service2.Function9 JSFHandlerFunction16 Call program1… Call program1… Library1.function4… Library1.function4…Function17 Service2.Function9 Service2.Function9Function18 Program1Main()…Function19 Call program2… Call program2…Function20 Library2Function10 Service2.Function9 Service2.Function9Service2Function9Function14Function15 Program2Main() Library1.Function6 Library1.Function6Function1 Service2.Function15 Service2.Function15 JSFHandlers can call/invoke Programs – at the program level Libraries – through Function calls Services – through Function calls Programs, Libraries, and Services can invoke other: Programs – at the program level Libraries – through Function calls Services – through Function calls not … But can not invoke JSFHandlers

18 18 Structured Programming in EGL – Best Practices  Some simple concepts to keep in mind, when designing your business logic solutions:  Break-up (formulate) your logic into EGL functions  EGL functions should be between 10 and 30 lines of code (best practice)  Almost all substantial business logic belongs in functions within EGL Libraries and Services  All data access logic  All substantial business computations  JSFHandlers should contain only:  Page display (U.I.) logic  Navigation logic  Screen-specific edits (and consider moving these to Libraries as well)  Transaction logic (commit, rollback, etc.) Programs  EGL Programs are used for:  Batch processing (the “main” module, called from the Operating System)  COBOL Generation – for traditional online processing  DataItems should be used for:  Formatting  As much validation and editing as possible

19 19 EGL and “Inheritance”  Inheritance is an O-O principle that promotes code reuse  EGL supports “object-based” not object-oriented inheritance through:  DataItem properties  Parts Dictionary – Logic parts/Data parts Variable references to DataItems in records and fields. Can: Inherit properties Over-ride properties Workspace Reuse existing Parts. Library, Service and Program functions DataItems, Records, DataTables BusinessLogic DataItems PartsDictionary BusinessLogic

20 20 Workshops for this Topic  Using RBD tooling and EGL, follow the steps which start on the next slide and create the following software architecture scaffolding and EGL Logic Parts:  Packages – under \EGLSource\ for back-end business logic – for organizing logic parts in your project  Libraries  Programs  Services  A JSFHandler that calls the back-end logic components You will test your work, running a simple Web Page that calls functions in all of the above logic parts. JSPPage EGLProgram EGLJSFHandler EGLLibraryFunction EGLServiceFunction

21 21  Create EGL Packages Create the following EGL packages, all under the \EGLSource\ folder:  programs  services  libraries  data  EGL DataTables  EGL DataTables (if time permits) Notes: lower-case  All package names must be lower-case  You will create five new packages, as shown here  (From Project Explorer) \EGLSource\  Right-click over \EGLSource\ New  EGL Package  Select New  EGL Package  Name the packages (one at a time):  data, datatables, libraries, programs, and services Example – creating the programs package

22 22  Create an EGL Library  Create the following EGL Library and function under the \EGLSource\libraries\ folder:  Right click over the \EGLSource\libraries\ folder and select: New > Library  Create a basic library. library1  The EGL source file name should be: library1  Using the EGL Editor, modify the text so that library1 contains the code shown below: Initialized msg string global variable  Function that takes a parameter in  And concatenates the parameter with the msg data  And returns – to the calling program  Press Ctrl/S when finished, to Save and Validate your EGL coding

23 23  Create an EGL Program  Create the following EGL Program and function under the \EGLSource\programs\ folder:  Right click over the \EGLSource\programs\ folder and select: New > Program  Create a called program program1  The EGL source file name should be: program1  Using the EGL Editor, use Content Assist, and typing . Modify the text so that program1 contains the code shown below: Program Logic Part with string parameter  Initialized msg string global variable  msg Concatenate the parameter with the msg data  Invoke the Library function you just created  Press Ctrl/S when finished, to Save and Validate your EGL coding

24 24  Create an EGL Service  Create the following EGL Service and function under the \EGLSource\services\ folder  Right click over the \EGLSource\services\ folder and select: New > Service service1  The EGL source file name should be: service1  Using the EGL Editor, modify the text so that service1 contains the code shown below: msg Initialized msg string global variable  Function that takes a parameter in  msg And concatenates the parameter with the msg data  And returns – to the calling program  Press Ctrl/S when finished, to Save and Validate your EGL coding

25 25  EGL Service Deployment Descriptors  EGL Services have their own special resource management file called a Deployment Descriptor, which allows you to optimally generate and deploy to different run-time environments. When you create a new EGL project, you have the option of asking the tooling to create a new service descriptor for you (we suggest you let the tooling do this – although it’s not “rocket-science” to create one manually.  After you’ve finished creating your 1 st EGL Service you need to register your services to the project’s deployment descriptor by following these steps: 1.From Project Explorer, open: EGLWeb.egldd (it’s towards the bottom of the \EGLSource\ folder) 2.From the EGL Deployment Descriptor Overview, Click the Service Client Bindings Tab (the second-from-left tab on the bottom of the window) Add 3.From Service Client Binding Configuration, click: Add 4.From Add a Service Client Binding, click:  EGL Binding then click Next > service1 5.From: Add an EGL Binding, click Browse and Select service1 Finish press Ctrl/S 6.Click Finish and press Ctrl/S to save your changes

26 26  Generate Your Project  In order to produce the executable code for your application (whether COBOL or Java) you need to generate your EGL resources. Conceptually this can be depicted as… Right-click over EGLWeb, and select Generate  Right-click over EGLWeb, and select Generate

27 27  Create a.JSP Page and JSFHandler – 1 of 3 Steps: Right click over the \WebContent\ folder and select: New > Web Page jsfhandler 1.jsp  The file name should be: jsfhandler 1.jsp.jsp  Don’t forget to add the.jsp extension  And DON’T name it: jsfhandler.jsp –Why not? … see ***Notes My Templates  Expand: My Templates theme/A_Gray.htpl  Select: theme/A_Gray.htpl  From Page Designer, modify the default header text.  Right-Click and select Edit Page Code

28 28  Create JSFHandler – 2 of 3  Add the following statements to the default JSFHandler (shown in the screen capture and notes below)  Use Content Assist to create the calls to the program and service (Ctrl/Spacebar) Press Ctrl/Shift/F to format, then Ctrl/S when finished, to Save and Generate your EGL code String global variables  Service variable declaration  Custom EGL Function  Assignment statement  Call to your program  Invoke service function 

29 29  Create the.JSP Page from the JSFHandler Variables – 3 of 3  From Page Designer, 1. Select the two fields in Page Data. Drag & Drop them on the page to create an input and an output control as shown below. 2. Expand the Actions folder, and drag the calledModules() function on top of the Submit Button

30 30  Run the Page  Right-click over the page in the Content Area and select:  Run on Server…  Enter an initial value for Fieldin and click Submit  Verify your results – note the message text returned from the called routines

31 31  Generate and Project Clean Clean Generate  From time-to-time you will need to Clean your work-space projects - delete all generated J2EE resources and rebuild them from their EGL sources) – and Generate your project: re-create all EGL (batch and J2EE) from their EGL source files. Clean  To Clean your projects:  Pull-down the Project menu  Select Clean…   (typically) Select clean all projects in your workspace Generate  To Generate your project:  From Project Explorer – Right-click over the Project Icon  Select Generate  To save time (if you only need to generate or re-generate a single EGL file), you can Generate individual resources (like EGL Packages, Programs, Services and Libraries) Ctrl/G  With your mouse-focus inside the file, press: Ctrl/G *** See Notes

32 32 The “Easy Button” – or Buttons The EGL editor provides many hot-key combinations that improve productivity: Ctrl/S Ctrl/S - Save and validate your EGL statements in your source file Ctrl/G Ctrl/G – Generate your EGL to either Java or COBOL Ctrl/Shift/F Ctrl/Shift/F – format the source code in the current file Ctrl/Shift/O Ctrl/Shift/O – Resolve any missing import statements in your source file  All of these are available after you’ve set your mouse cursor focus into the EGL source file (1. set cursor focus; 2. press one of the above hot-key combinations)     

33 33 The Rest of the “Easy Buttons” – (Ctrl/”whatever”) Ctrl/Shift/L The Eclipse editor provides a much larger list of hot key combinations, available from anywhere in your source by pressing: Ctrl/Shift/L   

34 34 The EGL Editor Keyboard Shortcuts  Many developers – when writing business logic tend to want to use their keyboard skills exclusively. If you fall into this category, here is a list of specific EGL editing keyboard shortcuts you can use for common code development tasks 

35 35  OPTIONAL Lab – Check Out the Parts/Navigator Menu  There is a Parts selection dialog available from the Navigate menu, which allows you to view all of the parts in your EGL Parts Dictionary, and search/open them in the Content Area.  From the RBD menu bar, pull-down Navigate  Or from anyplace in the product, press:  Ctrl/Shift/N  Type a letter – or you can mix letters with wildcards  Select and open the part

36 36  OPTIONAL Lab - Check Out “F3” – Open Selection  For every defined element of your EGL Logic and Data Parts (including all variable and function declarations) you can: 1. Highlight a reference, 2. Press F3 on your keyboard – to open that reference in the Content Area (this is called Open on Selection in the Context menu). updatecustomer2.egl  From Project Explorer, open: updatecustomer2.egl F3  Highlight any called Library function and press F3  F3

37 37  Are We On Track? From the source file here   Pick out (identify) the following:  Comment  EGL identifier  EGL statement delimiter  EGL function  Global variable declaration  Local (inside a function) declaration  Library (function) call  A literal  The statement that describes which folder the source is in  The statement that provides reference-ability to EGL source files in other folders  The statement that defines the type of file this is  An EGL conditional statement  And EGL assignment statement See – this stuff is not so hard and really, not all that much is new, is it?

38 38  Are We on Track?  Match the following definitions and terms – note that some terms may have more than one definition and vice versa 1. JSFHandler___ A folder that contains files or sub-folders within a Project – also a unit of Namespace scope 2. Package___ A file that contains generation options and settings 3. EGL Logic Part___ An EGL Logic Part that can contain multiple Functions, each of which, can be called separately 4. Service___ The first line in any EGL Logic Part. It sets the initial scope for what can be referenced throughout the file. 5. Library___ An EGL logic part that manages program/web page interaction 6. Program___ An EGL logic part that controls the compilation (build) process 7. EGL Data Part___ The parser’s concept of what can be referenced within an EGL Logic Part (what files and folders etc. are “in scope”) 8. Namespace___ EGL statements that provide reference-ability to files within other folders of your project 9. EGL Parts Dictionary___ An EGL Logic Part similar to a Library that can be deployed and called across run-time platforms. Also known as a Web ______. 10. Import statement___ The collective name by which EGL programs, libraries, services, etc. are referred to – especially in the doc 11. Function___ The collective name by which EGL Records, DataItems and DataTables are referred to 12. Build File___ All of the EGL parts that have been successfully coded and saved in your workspace, and now can be referenced using Content Assist

39 39 EGL Language General – (True/False) “Global Variables” 1.Variables declared inside of a function are known as “Global Variables” - and can be used to create JSF controls. They can also be accessed from any function inside the file 2.Every EGL logic part has the same structure (from top to bottom in the file):  Package statement – that identifies under which folder the file resides  Import statements – necessary if your source references a file from another parent folder  fileType (Library, Service, Program, Handler, etc.) – which uniquely identifies/names the file and sets specific file properties  Global (Page Data) variables  Business Functions { … } 3.File and variable properties are contained inside curly braces { … } 4.All EGL business logic is contained inside logic functions 5.All EGL statements end with a semi-colon 6.Almost all EGL statements end with a semi-colon. The ones that don’t end with a semi-colon include:  If  If statements hile  For and while loops functions  EGL logic functions parts  EGL parts (like JSFHandler, Program, Service, Record, etc.) 7.EGL Deployment Descriptor files are used to describe how EGL service applications are linked to the clients that call them, and vice versa 8.EGL programs contain functions that can be called individually from other logic parts variableType variableName; 9.EGL variable declarations are coded like Java declarations: variableType variableName; 10.EGL Build Files are used to specify code generation options.  Locate your projects EGL Build file. It’s named: EGLWeb.eglbld 12.All.EGL files must be contained under the \EGLSource\ folder in your project (most likely in a sub- folder within \EGLSource\) 13.Okay we lied, EGL Services and Libraries contain functions that can be called individually! Review Questions – Be able to answer and to demonstrate your understanding through Workbench use

40 40  Checkpoint – EGL Project and File Types (From Project Explorer) \libraries\ tempLib 1.Create a new EGL Library in the \libraries\ folder named: tempLib end 2.In this library add two new functions and a record, you will use to convert Fahrenheit to Celsius and vice versa. Note – add the record AFTER the final Library end statement (as shown here) {} Also note that you enclose variable extended properties (like ZeroFormat = yes) in curly braces { ……. } - not parenthesis Ctrl/SCtrl/G 3.Save (Ctrl/S) and Generate (Ctrl/G) the library

41 41 converter.jsp Optional Workshop – converter.jsp  Create the following new web page: converter.jsp  Name: converter.jsp  Layout  EGL Code Ctrl/Shift/O  Don’t forget to press Ctrl/Shift/O – to organize the imports  Notes (and optional exercises):  Use of EGL Basic Record for U.I. (tempRec)  Use of EGL Properties in the record:  ZeroFormat – displays zeros, not blanks  Sign – displays negatives with leading dash  You could turn the Library functions into calls to a local EGL service

42 42  Now that you have completed this topic, you should be able to:  Define what EGL Logic, Data, Build and Generate-able parts are  Define the purpose for the following types of Logic parts:  Program  Library  Service  JSFHandler  Define what is in a Build file and what is its purpose  Describe the following data parts:  DataItem  Record  Create packages Topic Summary


Download ppt "® IBM Software Group © 2006 IBM Corporation EGL Programming Model These slides walk you through the concepts and vocabulary the make up the Enterprise."

Similar presentations


Ads by Google