110 likes | 261 Views
EGL Programming – Data Parts and Assignment Statements - 1. These slides walk you through the terms and concepts around declaring EGL variables of different primitive data types, and using EGL to initialize the variables and assign values. Programming in EGL. UNIT. Topics:.
E N D
EGL Programming – Data Parts and Assignment Statements - 1 These slides walk you through the terms and concepts around declaring EGL variables of different primitive data types, and using EGL to initialize the variables and assign values.
Programming in EGL UNIT Topics: • 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
EGL Data Parts There are four different kinds of EGL Data Parts: 1. Primitive Data Types • Standard programming language variable types for storing data values: string, decimal, date, etc. 2. DataItem Data Parts • Enhanced type definitions, that can include properties for specifying field formatting, validation, etc. 3. Record Data Parts • Data structures (an organized hierarchy of variables) 4. DataTable Data Parts • Tables with operational behavior aimed at simplifying common processing routines (look-up, etc.) • You can declare variables with the above types(***Notes), and each has their own particular value and use in making you productive developing EGL business logic.
1. Primitive Data Types EGL supports all of the industry-standard data types you need for your applications (legacy and leading-edge). The categories of EGL primitive types include: • Character (char, String, MBchar, DBChar, Unicode) – For storing alpha-numeric data • Numeric – For storing numeric-only data • Date/Time/Timestamp – For storing legitimate date, time and timestamp values • Large object – For storing binary objects (BLOBs) and large character objects (CLOBs) • Logical – BOOLEAN (true/false) value • ANY – A type you can use to REDEFINE fields being passed between languages (like Java and EGL) • We assume you understand and have used most of the above in your programming career – and that you understand the concept of primitive data types. However the RBD Help documentation covers the EGL types extensively. Please take a few minutes, and from the RBD Help menu, select Help Contents and search on: EGL Primitive data types Read the information covered on Primitive Data Types before continuing:
Declaring EGL Variables of Primitive Types in a Logic Part • You can declare data variables of a primitive data type, for storing information processed by your business logic essentially as you would in COBOL, RPG or Basic. There are four parts to every declaration: <VariableName> <Primitive Data Type> ? ; 1. <Variable Name> – must adhere to EGL allowable identifiers 2. <Primitive DataType> – must be one of the 20+ EGL Primitive types 3. ? – allows nulls in this variable (Note: if no ? the variable does NOT allow nulls) 4. ; - end the declaration with a semi-colon Examples: //VariableName VariableType lastName String; //Variable length string paidDate Date?; //Calendar Date value – can be Null amountPaid Money(9,2); //Packed decimal number U.I.-formatted as money i, j Int; //Two Integer number variables postalCode Char(5); //Fixed-length string pi Float; //Floating point pKey Timestamp; //Timestamp data amountPaidRpt Num(9,2); //Zoned (display/output) decimal number indicatorVal Boolean; //True/False value 1. 2. 3. 4.
Declaring And Initializing EGL Variables • You can initialize the variables in the same statement that you declare them, and specify additional information (semantics) about them <VariableName> <PrimitiveType> = <valueOfSameOrEquivalentType>; StreetAddress string = “14 Belmont Road”; Examples: // VariableName VariableType Initial values lastName String = "Mr. Evans"; paidDate Date = "20070606" {DateFormat=isoDateFormat}; amountPaid Money(9,2) = 123567.89; i, j Int = 0; postalCode Char(5) = "90210"; pi Float = 3.14159265358979; pKey Timestamp; //Note will be current timestamp amountPaidRpt Num(9,2) = 123567.89; indicatorVal Boolean = false; //Note true/false • Note that the initialization value must be: • A valid value, of the same data type • Within the allowable max and min ranges for the data type • See Notes on dateFormat
Variables and Scope – Global, Local Variables, and Parameters You declare variables: • Before your functions – where they become “Global Variables” available to any function in the entire EGL Logic Part • Inside of a function – where they become Local Variables, available ONLY to EGL statements in that particular function • As parameters to the functions or programs – where they behave as Local Variables to the called function The EGL parser will catch invalid variable references and flag them when you press Ctrl/S (save) Global Variables Parameter Variables Local Variables You can also set your workspace preferences to catch syntax errors as you type. ***See Notes for details
Private …vs… Public Variables/Functions/Constants • You can add the modifier private to any EGL declaration. Private limits the scope of whatever is being declared. There is no "public" EGL keyword. EGL assumes that anything you do not specifically declare to be private is public. • The private keyword limits the scope of a function, variable, or constant to the part in which it is defined. No outside function can call a function or access the value of a variable or constant marked private, even by using a fully qualified path. Example – (OPTIONAL Lab) – add the following to hello1.egl (a private variable and function as shown) Open hello1.jsp field3 and clr()not available from Page Data View Note: field3 variable and clr() function declared as private.
Primitive Variables Workshop – 1 of 2 In this workshop you will type in some primitive variable declarations and ensure that they are syntactically correct (that is all – your work is successful simply when your code passes the Syntax Validation check (Ctrl/S) Using RBD tooling and EGL create a new JSP page and JSF Handler with custom EGL primitive variables Steps: • Create a new JSP page named: newaccount.jsp in the \WebContent\ directory that uses the theme/A_Gray Sample template • Customize the page header text (see figure below) • Access the JSFHandler for this page • Right-Click • Edit Page Code
Primitive Variables Workshop – 2 of 2 4. Select and delete all of the existing JSF Handler code, then copy and paste the following code in the file; package jsfhandlers; handler newaccount type JSFHandler {onConstructionFunction = onConstruction, view = "newaccount.jsp"} //*** Global variables section - available to your page and all functions Name _________; //variable length text data State char(2); //two bytes, fixed-length character data Zip _________; //five bytes, fixed-length character data Age _________; //integer numbers only DateOfBirth _________; //Date datatype AnnualSalary money(9,2); //Decimal numbers (…actually…Money values) Height _________; //Decimal datatype (inches: 68.5 inches, etc.) overDrawnInd _________; //True/False datatype EmpPhoto _________; //Used to hold an image (.jpg) file private PrivateVar string; //A private variable, used to hold text data //*** Function Declarations section (end of EGL Global variables section function onConstruction() LocalVar string; //used to hold variable length text data end //end onConstruction() End //end JSFHandler 5. Replace the under_scores above, with the appropriate EGL Primitive Data Type. 6. Press Ctrl/S to Save – and fix all syntax errors
Topic Summary • Now that you have completed this topic, you should be able to: • Define the essential business EGL primitive data types • Reference all of the EGL data types in the Help system • Code EGL variables of different data types • Describe the operational differences between: • Local variables • Global variables • Parameters • Private variable modifier