INFORMIX-4GL TRAINING
© Kanbay Incorporated - All Rights Reserved
Versions of Informix-4GL »Informix-4GL Rapid Development System (RDS) »Informix-4GL C Compiler Version Compiling: Rapid Development System: Source file .4glPseudo code C Compiler System: Source .4gl->Intermediate fles->Executable file .4ge
| © Kanbay Incorporated. All Rights Reserved
Differences b/w the two versions: RDS
C Compiler
» Compile Time
Less
More
» Run Time
More
Less
| © Kanbay Incorporated. All Rights Reserved
Basic Components of Informix 4GL »PROGRAM »MODULE »FUNCTION »FORM
| © Kanbay Incorporated. All Rights Reserved
Program Blocks »MAIN »FUNCTION »REPORT
| © Kanbay Incorporated. All Rights Reserved
Compiling .4gl in RDS System »Creating a program from a single module fglpc filename.4gl »Creating a program from multiple modules Compile each program to p-code fglpc file1.4gl file2.4gl Concatenate p-code files together Cat file1.4go file2.4go >myprog.4gi »Executing the program fglgo filename.4go OR fglgo myprog.4gi | © Kanbay Incorporated. All Rights Reserved
Compiling .4gl in C Compiler version » Creating a program from a single module C4gl filename.4gl –o myprog.4ge » Creating a program from multiple modules To compile a singe module to object code C4gl filename.4gl –o filename.o To create an executable from multiple modules C4gl file1.4gl file2.o file3.0 –o myprog.4ge » Executing the program myprog.4ge
| © Kanbay Incorporated. All Rights Reserved
Sample makefile 4GL = filename.4gl filename2.4gl FORM = formname.per PROG_NAME = application.4ge COBJS = $(4GL: .4gl=.o) POBJS = $(4GL:.4gl=.4go) FORM = $(FORM:.per=.frm) CCODE: $(OBJS) c4gl –o $(PROG_NAME) $(COBJS) @-echo “Finished Compiling ccode…”
| © Kanbay Incorporated. All Rights Reserved
File Extensions Extension
Description
.4gl
Informix 4GL source module
.4ge
C Compiled version executable
.o
C Compiled version object
.4go
RDS Version object
.4gi
RDS Version executable
.per
Form File Source
.frm
Form File Compiled
| © Kanbay Incorporated. All Rights Reserved
DEFINING VARIABLES SYNTAX: DEFINE variablename data-type Example: DEFINE fname CHAR(10) DEFINE start_date DATE DEFINE x,y,z INTEGER (OR) DEFINE fname CHAR(10), start_date DATE, x,y,z
INTEGER
| © Kanbay Incorporated. All Rights Reserved
Initialization of Variables LET: Assigns value to a variable. Example: LET fname = “John” Let x = 5 Initialize: INITIALIZE variables to NULL Example: INITIALIZE lname TO NULL
| © Kanbay Incorporated. All Rights Reserved
Scope of Variables »Global »Module »Local EXAMPLE:
glob.4gl GLOBALS DEFINE var1 CHAR(1) END GLOBALS
emp_main.4gl GLOBALS “Glob.4gl” DEFINE var2 SMALLINT MAIN DEFINE var3 INTEGER CALL funct1() END MAIN FUCTION funct1() DEFINE var4 CHAR(1) END FUNCTION
| © Kanbay Incorporated. All Rights Reserved
Variable Scope var1
Global
var2
Module
Var3
Local
var4
Local
COMMENTS in 4GL »A pair of hyphens or minus signs -- this is a comment »The pound (or sharp) symbol # this is a comment »Left and right braces { this comment is multi-line} »Conditional comments --@ --# | © Kanbay Incorporated. All Rights Reserved
Decision and Looping Statements » IF » CASE » WHILE » FOR
| © Kanbay Incorporated. All Rights Reserved
Decisions: IF Statement SYNTAX: IF ……THEN ………….. ELSE ……. END IF
Example : IF var_name MATCHES “[Yy]” THEN ERROR “Customer will be deleted.” ELSE ERROR “Delete cancelled.” END IF.
| © Kanbay Incorporated. All Rights Reserved
IF Within Other Statements Syntax:
IF ….THEN IF…..THEN …………… END IF END IF
EXAMPLE: IF state=“IL” THEN IF zipcode MATCHES “601*” THEN ERROR “City is Schaumburg” END IF END IF
| © Kanbay Incorporated. All Rights Reserved
Decisions: CASE statement Syntax: CASE WHEN {expr/Boolean-expr} statement….. [EXIT CASE] ……… [OTHERWISE] statement…. [EXIT CASE] END CASE
Example: CASE WHEN answervar=“Y” MESSAGE “Answered Yes.” WHEN answervar=“N” MESSAGE “Answered NO.” OTHERWISE MESSAGE “Bad Answer.” END CASE.
| © Kanbay Incorporated. All Rights Reserved
Logical Loop: WHILE Loop Syntax: WHILE Boolean expression statement(s)…. [EXIT WHILE]…… [CONTINUE WHILE]….. END WHILE
EXAMPLE: WHILE boss_in_office = TRUE CALL act_busy() RETURNING boss_in_office END WHILE
| © Kanbay Incorporated. All Rights Reserved
FOR Loop Syntax: FOR integer variable = integer expression to integer expression [STEP integer expression] statement…… [CONTINUE FOR]……. [EXIT FOR]………. END FOR
Example: DEFINE i SMALLINT FOR i=1 TO 10 DISPLAY “i = “, i AT i,1 END FOR
| © Kanbay Incorporated. All Rights Reserved
SCREEN: »The screen is the area of the terminal where you can display the information. »Default size of the screen is 24*80 »Informix -4GL allows you to break the screen area into smaller sections called windows.
| © Kanbay Incorporated. All Rights Reserved
WINDOW OPEN WINDOW windowname AT screenparameters WITH no of rows ,no of columns [ATTRIBUTE(attribute-list)] Example: OPEN WINDOW w_yesno AT 10,10 WITH 4 ROWS,20 COLUMNS ATTRIBUTE (BORDER)
| © Kanbay Incorporated. All Rights Reserved
Screen Interaction Statements »ERROR »DISPLAY »MESSAGE »PROMPT
| © Kanbay Incorporated. All Rights Reserved
MESSAGE: Syntax: MESSAGE display-list [ATTRIBUTE(attribute-list)] Example: MESSAGE “Press the first letter of an option.” ATTRIBUTE (REVERSE) ATTRIBUTES: UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM | © Kanbay Incorporated. All Rights Reserved
ERROR Syntax: ERROR display-list [ATTRIBUTE(attribute-list)] EXAMPLE: ERROR “No Rows Found.” ATTRIBUTES: UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM | © Kanbay Incorporated. All Rights Reserved
DISPLAY Syntax: DISPLAY “message” [AT row, column] [ATTRIBUTE (attribute-list)] EXAMPLE: DISPLAY “Row Added.” AT 22,3 ATTRIBUTE (reverse) ATTRIBUTES: UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM | © Kanbay Incorporated. All Rights Reserved
PROMPT SYNTAX: PROMPT “message” [ATTRIBUTE (attribute-list)] FOR [CHAR] variable [ATTRIBUTE (attribute-list)] END PROMPT EXAMPLE: PROMPT “Are You Sure? Y/N” FOR CHAR answer ATTRIBUTES: UNDERLINE
REVERSE INVISIBLE
BOLD
BLINK
DIM | © Kanbay Incorporated. All Rights Reserved
NORMAL
OPTIONS EXAMPLE: OPTIONS MESSAGE LINE FIRST + 2, ERROR LINE 23, PROMPT LINE LAST -3
| © Kanbay Incorporated. All Rights Reserved
Syntax for creation and compiling of a Form »To create a default form use form4gl –d »To compile a form named filename.per use form4gl filename The .per extension is eliminated
| © Kanbay Incorporated. All Rights Reserved
FORM »MANDATORY sections Database section Screen section Attribute section »OPTIONAL Sections Table section Instruction section
| © Kanbay Incorporated. All Rights Reserved
Database Section The DATABASE section identifies the database (if any) on which the form is based. This can be any database that the engine can access, including remote databases. The DATABASE section is required , even if the form does not reference any database tables/columns. Syntax: » DATABASE FORMONLY You can specify only one database. Example : » DATABASE xyz » DATABASE xyz@server To create a form that is not related to any database , use FORMONLY and omit the TABLES section. Also , the table name has to be formonly in the ATTRIBUTES section for each of the field in the screen.
| © Kanbay Incorporated. All Rights Reserved
ATTRIBUTE SECTION »It links display fields to database columns by using field tags
| © Kanbay Incorporated. All Rights Reserved
FORM ATTRIBUTES: »AUTONEXT »COLOR »COMMENTS »UPSHIFT »DOWNSHIFT »DEFAULT »REQUIRED »INVISIBLE »REVERSE »WORDWRAP »NOENTRY »VERIFY »INCLUDE
| © Kanbay Incorporated. All Rights Reserved
TABLE SECTION »The TABLES section lists the database tables that are referenced in the specification file. »You must list in this section any table, view or synonym whose column is referenced in the form. »The table CANNOT be a temporary table.
| © Kanbay Incorporated. All Rights Reserved
Instruction Section »Used to define screen records and screen arrays »Change the default delimiters for display fields.
| © Kanbay Incorporated. All Rights Reserved
OPEN FORM Syntax: OPEN FORM form-name FROM form-file Example: OPEN FORM cust FROM “cust_form” Cust_form :Name that you gave the form when it was created Cust
:How you will refer to the form throughout the program.
OPEN FORM only loads the form onto the memory and does not display it. | © Kanbay Incorporated. All Rights Reserved
FORM DISPLAY FORM: DISPLAY FORM cust Opens the form from the memory. CLEAR SCREEN: Clears the form from the screen but the form still exists in the memory. CLOSE FORM: CLOSE FORM cust Removes the form from the memory.
| © Kanbay Incorporated. All Rights Reserved