Top Banner
® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts around using EGL to assign variables and set their values, as well as doing concatenation and mathematical operations.
23

® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

Dec 24, 2015

Download

Documents

Eleanor Stevens
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

®

IBM Software Group

© 2006 IBM Corporation

EGL Programming – Assignment Statements and Math Operations

These slides walk you through the terms and concepts around using EGL to assign variables and set their values, as well as doing concatenation and mathematical operations.

Page 2: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

2

EGL Assignment Statements There are three types of EGL assignment statements:

1. Right-to-left assignment:

ReceivingVar = SendingValue; // value moved from right to left

PhoneNbrOut = PhoneNbrInput;empRecout.LastName = empRecIn.LastName;

2. Left-to-right (Move): Move SendingValue to ReceivingVar; //value moved from left to right, on a byte by byte basis

move PhoneNbrInput to PhoneNbrOut; move empRecIn.LastName to empRecOut.LastName;

3. Initial/Empty “set” statements:

You can blank out a record or field, re-initialize a record or field using set

set PhoneRecord initial; set empRecIn empty;

While it is may seem easier to code right-to-left assignment statements, there are several useful and time-saving variations on move provided in EGL available as statement templates.

Page 3: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

3

EGL Assignment – Move byName, Move byPosition Structure-based moves – Structure-based moves – movemove statement extensions for handling records statement extensions for handling records

move byName When you specify: Move A to B byName, data is written from each field in the source to a same-named field in the target.

move byPosition The purpose of: Move A to B byPosition is to copy data from each field in one structure to the field at the equivalent position in another – irrespective of field names.

** Array-specific move statement extensions.Array-specific move statement extensions. You can move all or some of the rows of “like-typed” arrays using: move for all, or move for count

Move for all - The purpose of for all is to assign values to all elements in a target fixed-element array.

Move for count - The purpose of for count is to assign values to a sequential subset of elements in a target fixed-element array.

Recommendation – always use Content Assist to help you code Move statements!

** NOTE **** NOTE ** for allfor all and for countfor count work only with arrays that are declared with an initial value > 0: > 0:

arrayRec type[n]; //where n is a number > 0

Page 4: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

4

EGL Mathematical Operators EGL supports a complete lexicon of math – allowing you to express business calculations and rules of any scale and computational complexity.

Besides the math operators shown above, EGL also includes a comprehensive set of math library functions and operations that will be discussed in a later unit of this course.

Page 5: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

5

EGL Mathematical Operators EGL supports a complete lexicon of math – allowing you to express business calculations and rules of any scale and computational complexity.

Besides the math operators shown above, EGL also includes a comprehensive set of math library functions and operations that will be discussed in a later unit of this course.

Page 6: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

6

EGL Logical Operators

EGL supports a large number of simple and advanced Logical Operators – allowing you to express business rules of any depth and sophistication.

Page 7: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

7

Redefining (casting) Data – Using ASYou concatenate strings (and char fields) in EGL using the + (plus) sign

fldOut1 = strfld1 + strfld2; //concatenate fields

You can use this same technique to redefine or “cast” numbers and dates, times, etc. to strings by simply adding a ""+ to the beginning of the expressionfldOut1 = ""+numField + strField; //concatenate 1st a numeric field

Alternatively, you can use the AS operator, to redefine a field to another fielddynamically within a function (see Content Assist options)

//Concatenate a numeric field as if it were a string

strFldOut = numField as string ++ strField;

//Perform math on a string field, as if it is a numeric

numFldOut = strField as int + numField;

Page 8: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

8

Sub-stringing EGL VariablesYou can substring a string or char text field with the following expression:

<variable> [startByte:endByte];

...where startByte is an integer >= 1, that specifies what position in the string to begin the substring operation, and endByte (an integer <= the length of the field) specifies at what position to end the substring operation. Note that the substring can be the left or right part of an assignment or conditional statement (see examples):

strField[7:9]; //Reference bytes 7, 8 and 9 of the variable strField

Examples – note, you can use either a literal integer or an integer variable as start/endBytes. Make fldOut4 = to the 4th through 7th character positions of fld1.

sub1 = 4;sub1 = 4;

sub2 = 7;sub2 = 7;

fldOut4 = fld1[sub1:sub2];fldOut4 = fld1[sub1:sub2];

Right-justifyRight-justify a string variable(strField) value, in a char (fixed-length) field of 21 bytes

charField [21 - strlib.characterLen(strField):20] = strField;charField [21 - strlib.characterLen(strField):20] = strField;

Standard Y2K date-windowing check – using date field stored as a string in format “yymmdd”

if ( dateAsStringField [1:2] > “50” ) //1900’s date processingelse //2000’s date processing

*** See Notes:*** See Notes: - For several - For severaladditional useful sub-string additional useful sub-string code examples!code examples!

*** See Notes:*** See Notes: - For several - For severaladditional useful sub-string additional useful sub-string code examples!code examples!

Page 9: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

9

Enhanced Concatenation and Mathematical (Shortcut) Operators

You can add numeric – or concatenate string variables using the following syntax:

myVariable += someOtherVariable;myVariable += someOtherVariable;

…this is equivalent to the traditional:

myVariable = myVariable + someOtherVariable;myVariable = myVariable + someOtherVariable;

The “+=+=” operator will work with strings (concatenation) numerical values (mathematical addition).

The following operations are only supported with numerical values:

-= (subtract) a -= 4;a -= 4; // a = a - 4;

*= (multiply) a *= 4; a *= 4; // a = a * 4;

/= (divide) a /= 4; a /= 4; // a = a / 4;

Page 10: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

10

EGL Constants – 1 of 2 Like many contemporary programming languages, EGL allows you to declare variables as constants – variables with values that are

initialized once, and cannot be changed. Using constants will allow you to make your programs more read-able, and can make them easier to maintain over time.

To declare a variable as a constant, type the following:

// Reserved Variable Primitive Constant// word name type value const <varName> <vartype> = value;

Examples:

constconst MAXSAL MAXSAL decimaldecimal (7,2) = 100000.00; (7,2) = 100000.00;

constconst MINSAL MINSAL decimaldecimal (7,2) = 20000.00; (7,2) = 20000.00;

constconst MINAGE MINAGE intint = 18; = 18;

constconst MAXAGE MAXAGE intint = 99; = 99;

Page 11: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

11

EGL Constants – 2 of 2

Another use for EGL constants might be to translate COBOL 88-level variables into EGL.

Here’s a COBOL structure and program Here’s a COBOL structure and program snippet:snippet:

WORKING STORAGE.WORKING STORAGE.

01 COLOR PIC X(1) VALUE 'Y'.01 COLOR PIC X(1) VALUE 'Y'.

88 YELLOW VALUE 'Y'.88 YELLOW VALUE 'Y'.

88 BLUE VALUE 'B'.88 BLUE VALUE 'B'.

88 RED VALUE 'R'.88 RED VALUE 'R'.

PROCEDURE DIVISION.PROCEDURE DIVISION.

PARA-1.PARA-1.

SET RED TO TRUE.SET RED TO TRUE.

IF YELLOW DISPLAY 'COLOR IS YELLOW'IF YELLOW DISPLAY 'COLOR IS YELLOW'

IF BLUE DISPLAY 'COLOR IS BLUE'IF BLUE DISPLAY 'COLOR IS BLUE'

IF RED DISPLAY 'COLOR IS RED'IF RED DISPLAY 'COLOR IS RED'

EXIT PROGRAM. EXIT PROGRAM.

And here’s an equivalent EGL re-engineered And here’s an equivalent EGL re-engineered snippet:snippet:

color char(1);color char(1);

const YELLOW char(1) = "Y";const YELLOW char(1) = "Y";

const BLUE char(1) = "B" ;const BLUE char(1) = "B" ;

const RED char(1) = "R"; const RED char(1) = "R";

function main()function main()

color = RED; color = RED;

case (color)case (color)

when(YELLOW) when(YELLOW)

writeStdOut(“Color is writeStdOut(“Color is Yellow");Yellow");

when(RED) when(RED)

writeStdOut("Color is Red");writeStdOut("Color is Red");

when(BLUE) when(BLUE)

writeStdOut("Color is Blue"); writeStdOut("Color is Blue");

end //end-caseend //end-case

end //end-mainend //end-main

Page 12: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

12

Resolving Syntax Errors – Best Practice EGL syntax errors are usually

very easy to resolve – because:

• The Problems view allows you to click on the error to position your cursor on the problem line – or even problem language element.

You can mouse-over the Red-circle’d X and see each error,

Best Practice: From either the EGL Generation Results or the Problems view – find and fix all IWN.SYN errors before IWN.VAL errors.

Page 13: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

13

Content

Using the math operators and assignment statements you have just learned, create the following web page calculator – named calculator.jsp. Use the A_gray.htpl Sample Template.

Note that if you started this workshop earlier (i.e. calc.jsp) you can use what you’ve already completed, and fill out the remaining functions.

Workshop – Assignment Statements and Math Operators – 1 of 2

Page 14: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

14

Create the calculator.JSP Page – and modify the page header as shown on the previous slide. From the JSFHandler (i.e. from calculator.EGL) – add code following these steps: Create a basicRecord out of the three Page Data variables

Decimal data type for all Name them Top, Bottom, Result Use the sign and zeroFormat properties on the Result variable

Add a function (below Function onPageLoad )– which adds Top to Bottom, giving Result Result = Top + Bottom;

Ctrl/S – save and syntax check your function

Copy and paste the function 4 times in your JSFHandler – and modify the remaining calculations for subtraction, multiplication and division Ctrl/S – save when finished with your EGL statements

From Page Designer/Page Data view (editing calculator.JSP) Drag the three variables onto the Content Area – creating controls that update an existing record

Top and Bottom should be Input fields with message tags, Result should be an Output field

Drag each of the functions onto the Content Area From the Properties/Format view – re-Label the Submit Buttons

Run on server – test and verify your work

Workshop Steps – 2 of 2

Page 15: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

15

Create a batch program and debug it! Steps:

1. Create a new EGL main program in the \programs\\programs\ directory• Name the program: payrollProgrampayrollProgram

2. From the Notes section of these slides – select all of the Program Source, and copy it to your paste buffer.

3. Select and delete (replace) the boiler-plate source for payrollProgram.egl – with the source from the notes section of this slide

4. Save the file (Ctrl/S)

5. Review the payrollProgram source. Read the comments and browse through the EGL functions, statements and records. This program will be one we use – and enhance – for a number of workshops over the next few days, so be sure you’re comfortable what it’s doing.

Workshop – Batch Program Debugging – 1 of 7

Page 16: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

16

The EGL Debugger is very powerful, and we’ll see over the course of the next few workshops how to use more of its features. Let’s go over a few quick setup concepts, before we start our first session:

1. Set preferences for the Debugger to Stop at first line. While you will probably always remember to set break points before you launch a Debugging session if you don’t remember, this preference will.1. From Windows, Preferences, expand EGL and expand Debug2. Check these options (see ***Notes for details)

2. Variable List – allows you to see and set (and re-set) variables dynamically during your debug session1. To reset variable values: 1. Single-click the variable value. 2. Change the value. 3. Click anywhere else1. Single-click the variable value. 2. Change the value. 3. Click anywhere else

Workshop – RBD/EGL Debugger – “101”

Page 17: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

17

Debug payrollProgram.egl – 2 of 7Return to your EGL program source:1. Create “break-points” in your code to tell the Debugger where to stop

Add Breakpoints Double-click in the gray border area of the EGL Editor, next to the line you want to stop at

2. After you have set all of your break-points, from Project Explorer, • Right-click over payrollProgram.egl• Select: DebugDebug EGL Program

You will be prompted to

Confirm Perspective Switch

Do so

The next slide shows the Debug

Perspective. Note the various

Sections and Views.

SettingBreak Points

Page 18: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

18

Workshop – Batch Program Debugging – 3 of 7

3. Your EGL Program Source3. Your EGL Program Source

1. Action Bar 1. Action Bar 2. Variable Values

2. Variable Values

4. OutlineView

4. OutlineView

The source code debugger allows you to see your EGL statements execute – in real-time, and view variable values. There are a number of sub-views

1. Action Bar – allows you to click an icon and step (execute) the current (highlighted) statement

2. Variables view –allows you to see (or double-click and modify) program variable values

3. Your source in the Content Area, shows which line is the “next sequential statement” (highlighted)

4. The Outline view shows your functions, records, fields etc. and allows you to navigate to a source element quickly

Page 19: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

19

Workshop – Batch Program Debugging – 4 of 7 From the Action Bar – click the Step Into icon - to execute the current

instruction From the Variables view, expand some of the folders to see: record, group and field

level contents change You can also Click the run icon - to execute all of the statements between

breakpoints

Page 20: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

20

Workshop – Batch Program Debugging – Context Menu – 5 of 7 From within the Content Area, try the following: Right-click in the gray side-border of the code. Try out the following options:

Show Line NumbersShow Line Numbers Toggle this on/offToggle this on/off

Add Breakpoint (on the fly)Add Breakpoint (on the fly) Run to LineRun to Line

From the current instruction, execute all instructions to the line your mouse-cursor is on

Jump to Line:Jump to Line: From the current instruction, branch immediately to the instruction on the line your

mouse-cursor is on This can be used to Restart your debugging session, although it does NOT re-

initialize variable values

Add Task or BookmarkAdd Task or Bookmark Allows you to create a list of tasks and bookmarks that you can:

– See in the EGL editor

– See in an organized list by opening the Tasks View or Bookmarks View

Note that there’s a Context Menu

for Variables too!

Page 21: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

21

Step through this program - seeing how the various move statements work – seeing the variable values – change Try modifying a variable value:

From the Variables view Right-click over a field Select Change Value…

(modify it)

Note that earlier we described a different way for you to change variable values dynamically – by clicking on the actual value, overtyping it, and clicking anywhere else in the Workbench (to save your change)

Workshop – Batch Program Debugging – 6 of 7

Page 22: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

22

When you have finished debugging – (whether or not you’ve debugged all the way to end-of-program)

1. Terminate your session Click the red box

2. Right-click over the Debug statements Select: Remove all terminated

3. Return to the Web Perspective Right-click over the Debug icon

(top right hand corner of the workbench) Select Close

Workshop – Batch Program Debugging – 7 of 7

Page 23: ® IBM Software Group © 2006 IBM Corporation EGL Programming – Assignment Statements and Math Operations These slides walk you through the terms and concepts.

23

Now that you have completed this topic, you should be able to:

List the three different types of EGL assignment operations Describe three of the EGL Move statement extensions Define the majority of the math operators, and use them in business

logic coding Code essential business math (add, subtract, multiply and divide) Debug batch programs, and watch

Executing EGL statements Changing EGL variables

Topic Summary