BaanERP Tools. Programming features

Size: px
Start display at page:

Download "BaanERP Tools. Programming features"

Transcription

1 BaaERP Tools

2 A publicatio of: Baa Developmet B.V. P.O.Box AC Bareveld The Netherlads Prited i the Netherlads Baa Developmet B.V All rights reserved. The iformatio i this documet is subject to chage without otice. No part of this documet may be reproduced, stored or trasmitted i ay form or by ay meas, electroic or mechaical, for ay purpose, without the express writte permissio of Baa Developmet B.V. Baa Developmet B.V. assumes o liability for ay damages icurred, directly or idirectly, from ay errors, omissios or discrepacies betwee the software ad the iformatio cotaied i this documet. Documet Iformatio Code: U7168A US Group: User Documetatio Editio: A Date: December, 1998

3 Table of cotets 1 Itroductio 1-1 3GL scripts 1-1 4GL UI ad DAL scripts 1-1 Report scripts 1-2 Baa SQL 1-2 Dyamic-lik libraries 1-2 BaaERP debugger 1-2 Multitaskig 1-3 3GL/4GL fuctios GL programmig laguage features 2-1 Overview 2-1 Vocabulary 2-1 Character set 2-1 Cotiuatio symbol 2-1 Commet 2-1 Separators 2-2 Reserved words 2-2 Costats 2-3 Numeric costats 2-3 Strig costats 2-4 Symbolic costats 2-4 Eumerate ad set costats 2-4 Variables 2-5 Data types 2-6 Declaratios 2-6 Tables 2-7 Domais 2-8 Arrays 2-9 Fixed ad based variables 2-12 Multibyte strigs 2-13 Bidirectioal strigs 2-14 Commo variables 2-14 NULL characters i strigs 2-15 Expressios ad operators 2-16 Arithmetic operators 2-17 Relatioal operators 2-18 i

4 Table of cotets Logical operators 2-18 Operator precedece 2-19 Assigmet Operator 2-20 Trasfer of cotrol 2-21 The GOTO statemet 2-21 The IF... THEN... ELSE statemet 2-22 The ON CASE statemet 2-23 Iteratios 2-25 WHILE statemet 2-25 FOR statemet 2-26 REPEAT... UNTIL statemet 2-26 Usig BREAK ad CONTINUE (iteratios) 2-26 Fuctios 2-27 Fuctio type ad retur value 2-27 Local variables 2-28 Static variables 2-28 Global variables 2-30 Exteral variables 2-31 Fuctio argumets 2-32 Fuctio prototypes 2-35 Fuctio calls 2-36 Preprocessor 2-36 Iclude files 2-36 Macro defiitio 2-37 Toke pastig 2-39 Object idetificatios 2-39 Pragma codes 2-40 Coditioal compilig 2-41 Compiler GL programmig features 3-1 Overview 3-1 4GL script types 3-1 Evet-drive programmig 3-2 Evet sectios 3-2 Program sectios 3-3 Mai sectios 3-3 Form sectios 3-5 Mai sectios 3-5 Subsectios 3-6 Group sectios 3-7 Mai sectio 3-7 Subsectios 3-7 ii

5 Table of cotets Choice sectios 3-8 Mai sectio 3-8 Subsectios 3-8 Stadard commads 3-9 Field sectios 3-13 Mai sectios 3-13 Subsectios 3-13 Example 3-16 Zoom.from sectios 3-17 Mai sectios 3-17 Subsectios 3-17 Example 3-18 Mai table sectios 3-18 Mai sectio 3-18 Subsectios 3-18 Example 3-20 Flow of stadard program 3-21 Mai routie 3-21 Choice sectios 3-22 Form sectios 3-22 Field sectios 3-23 Ed of program 3-25 Zoom sectios 3-25 Update database 3-25 Mai table i/o sectio 3-27 Automatic import of variables 3-27 Case Case Case Case Case Case Report scripts 4-1 Overview 4-1 Evet sectios 4-1 Program sectios 4-1 Report sectios 4-2 Mai sectios 4-3 Subsectios 4-4 Text field sectios 4-4 Mai sectio 4-5 Subsectio 4-5 iii

6 Table of cotets Predefied variables 4-5 Report script fuctios 4-7 Expadig text variables 4-8 Sytax 4-8 Example Database hadlig 5-1 Overview 5-1 Database tables 5-2 Primary keys 5-2 Relatioships/refereces 5-2 Combied fields 5-3 Idexes 5-3 Structured Query Laguage (SQL) 5-3 Namig covetios 5-4 Usig tables i program scripts 5-4 Data types 5-4 Trasactio hadlig 5-5 Lockig 5-5 Record/page lockig 5-6 Table locks 5-7 Applicatio locks 5-7 Retry poits 5-8 Codig retry poits 5-8 Testig retry poits 5-9 Baa SQL 5-9 SQL sytax 5-10 SELECT <select list> 5-10 FROM <from list> 5-11 WHERE <where coditio> 5-11 GROUP BY <group coditio> 5-13 HAVING <havig coditio> 5-14 ORDER BY<order by coditio> 5-14 Set specificatio 5-15 Usig program variables 5-15 SELECT clause 5-16 FROM clause 5-16 Note 5-16 Refereces 5-17 Retrievig refereces to a record 5-17 Retrievig refereces usig REFERS TO 5-17 REFERS TO sytax 5-18 Usig aliases with REFERS TO 5-19 iv

7 Table of cotets Usig program variables or costats with REFERS TO 5-19 Example 5-21 Compay umbers 5-21 The <table._compr field 5-21 Usig <table>._compr i the WHERE clause 5-22 SQL ad combied fields 5-23 Specifyig a combied field 5-23 Compariso operators for combied fields 5-24 Idexes as combied fields 5-24 Meaigs of upper ad lower limits 5-25 SQL subqueries 5-26 Example Example SQL programmig 5-27 Embedded SQL 5-27 Dyamic SQL 5-29 SQL ad delayed locks 5-31 SQL trace optios 5-32 Cliet tracig 5-32 Server tracig 5-32 Query idetificatio 5-33 Trace optios 5-33 Error hadlig 5-39 Fatal ad o-fatal errors 5-39 The eflag 5-40 Example 5-41 Hits for usig SQL 5-41 Hits for usig db.retry.poit 5-43 Situatio 1: Oly update actios, commit per fetch 5-44 Situatio 2: Oly update actios, commits over fetches 5-44 Situatio 3: oly prit / collect actios (o commit) 5-45 Situatio 4: Update actios plus prit/collect with commit per fetch 5-45 Situatio 5: Update actios plus prit/collect with commit over fetches Data Access Layer (DAL) 6-1 Overview 6-1 Database itegrity checks 6-2 Busiess methods 6-2 DAL termiology 6-3 UI, DAL, ad STP iteractio 6-3 Overview 6-3 Example 6-4 v

8 Table of cotets UI fuctio calls 6-4 Fuctio flow 6-4 Oe-way iteractio 6-5 DAL hooks 6-5 Property hooks 6-6 fieldame.check() 6-6 Object hooks 6-7 Available object hooks 6-7 Retur values ad errors 6-8 before.ope.object.set() 6-9 before.get.object() 6-9 after.get.object() 6-10 before.destroy.object() 6-12 after.destroy.object() 6-12 before.save.object() 6-13 after.save.object() 6-14 after.commit.trasactio() 6-15 method.is.allowed() 6-15 Data Access Methods (DAM) 6-16 Property methods 6-17 Settig properties 6-17 Retrievig properties 6-17 Query extesios 6-17 Commuicatio with STP ad CDAS 6-18 Trasitio issues (BAAN IV to BaaERP) GL evet sectios GL fuctios 6-19 Sessio codes 6-20 Predefied variables 6-20 Questios 6-20 Messages 6-21 No-table fields 6-21 Iclude files Multitaskig ad the GUI 7-1 Overview 7-1 Bshell scheduler 7-2 Ruig queue 7-2 Blockig queue 7-2 Sleepig queue 7-3 Termiatig queue 7-3 Cotext switches 7-3 Forcig a cotext switch 7-3 vi

9 Table of cotets Allocatig bous ticks 7-3 Evets 7-5 Evet types 7-5 Evet flow 7-5 Evet masks 7-6 Evet fuctios 7-6 Evet arrays 7-6 Sample code 7-7 Requests, iquiries, ad replies 7-7 Processes, process groups, ad mai widows 7-8 Processes 7-8 Process groups 7-9 Mai widows 7-9 Process groups ad mai widows 7-9 Sychroizig processes with the wait() fuctio Dyamic-lik libraries 8-1 Overview 8-1 Fuctio declaratios 8-2 Scope of variables across DLLs 8-2 Global variables 8-2 Exteral variables 8-2 Database fields 8-2 Sharig DLL object code 8-3 Dyamic likig 8-3 Dyamic likig at compile time 8-3 Dyamic likig at rutime 8-4 Fuctio overloadig 8-4 Specifyig which DLLs belog to a object 8-5 Fuctio search algorithm 8-5 Fuctio overloadig example 8-6 Object iformatio tool 8-7 Sytax 8-7 Optios 8-7 Object ad fuctio descriptios 8-8 DLL compilatio ad rutime errors 8-9 Compilatio errors 8-9 Rutime errors The BAAN debugger 9-1 Overview 9-1 Commads 9-1 Debugger mouse actios 9-7 vii

10 Table of cotets 10 Errors 10-1 UNIX errors 10-1 Database errors Kow limits 11-1 Reports 11-1 Bshell 11-1 Bic 11-1 SQL 11-1 Tables 11-1 Idexes ASCII table (ISO ) Idex 13-1 viii

11 About this documet This documet describes the mai features of the Baa 3GL/4GL programmig laguage. Programmig fuctios are described i a separate documet: BaaERP Tools: Fuctios Referece (documet umber: U7167A US). Summary Chapter 1 provides a brief itroductio to Baa 3GL/4GL programmig features. Chapter 2 describes i detail the features of the Baa 3GL programmig laguage. Chapter 3 describes the 4GL laguage features for BaaERP Tools. I particular it describes the 4GL evet sectios used i Baa 4GL program scripts. It also describes the flow of the stadard program, ad it discusses the automatic import of variables Chapter 4 describes the fuctioality available for creatig report scripts. Chapter 5 provides iformatio about database hadlig ad describes Baa SQL i detail. Chapter 6 describes i detail the Data Access Layer (DAL) ad the fuctioality available for creatig DAL scripts. Chapter 7 describes how the bshell provides a multitaskig executio eviromet for BAAN applicatios. It provides iformatio about the Bshell scheduler, cotext switches, evets, requests, iquiries ad replies, process ad process groups, ad process sychroizatio. Chapter 8 discussio the use of Dyamic Lik Libraries (DLLs) i Baa applicatios. Chapter 9 provides iformatio o the Baa Debugger. Chapter 10 lists ad describes operatig system ad database errors. Chapter 11 lists the kow limits that apply to Baa applicatios. Chapter 12 presets a ASCII table (ISO ). ix

12 Table of cotets Typographical covetios The followig covetios are used i this maual: bold Bold type is used for the ames of fuctios, 4GL evet sectios, ad predefied variables, whe these are icluded i descriptive text. italics Italics are used for the ames of fuctio argumets, whe these are icluded i descriptive text. Italics are also used for other o-literals, for emphasis i the text, ad for the titles of publicatios. moospace Moospace type is used for the sytax of fuctios, declaratios, expressios, SQL statemets, ad so o, for program startup commads, ad for code examples. Acroyms CDAS Commo Data Access Server DAL Data Access Layer DAM Data Access Methods DLL Dyamic-lik library RDBMS Relatioal Database Maagemet System SQL Structured Query Laguage STP Stadard Program UI User Iterface Related documets BaaERP Tools: Fuctios Referece (documet umber: U7167A US) This documet describes i detail the fuctios available for developig BaaERP applicatios with the Baa 3GL/4GL programmig laguage. BaaERP Tools: Programmig Features olie This documet is available olie as a Microsoft Widows help file. The help file icludes the documet BaaERP Tools: Fuctios Referece. Both the help file ad the prited mauals are similarly orgaized. However, the help file icludes umerous hypertext liks to facilitate avigatio, ad a comprehesive idex ad full text search facility. You ca access the help file by choosig the Maual Pages optio o the Specific meu of the sessio Program Scripts (ttadv2530m000). The ame of the help file is tt_mp2.hlp. x

13 1 Itroductio The developmet tools supplied by the BaaERP Tools package eable developers to program additioal fuctioality for existig BaaERP applicatios or to build etirely ew applicatios. The features provided by the developmet tools iclude: The BaaERP 3GL programmig laguage. 4GL laguage features that eable you to add to or modify the default behaviour of sessios, reports, ad the Data Access Layer. Baa SQL, which eables you to retrieve database data. Support for Dyamic Lik Libraries (DLLs). A debugger that eables you to cotrol ad test the executio of your programs. 3GL scripts 3GL scripts are program scripts that are either liked to sessios without forms or ot liked to sessios at all. They do ot have ay relatioship with the 4GL Egie (previously kow as the Stadard Program or STP). Whe creatig such scripts, you must specify the etire program flow, icludig the mai fuctio. You caot use 4GL evet sectios or fuctios. Chapter 2, 3GL programmig laguage features, describes the 3GL programmig laguage i detail. 4GL UI ad DAL scripts I BaaERP applicatios, the 4GL egie provides much of the default fuctioality for a sessio. You ca add to or modify the default fuctioality of a sessio by creatig a 4GL script that is liked to the sessio. 4GL scripts are evet-orieted. They cosist of oe or more evet sectios i which you program actios to be performed at particular states of executio of the 4GL egie. I previous versios of the software, chages or additios to the default fuctioality of a sessio were programmed i a sigle script that was associated with the sessio. I BaaERP, user iterface actios ad database actios have bee separated. 1-1

14 Itroductio The Data Access Layer (DAL) ow hadles database iteractio. Programmers create a user iterface (UI) script to chage the default behavior of a sessio. They create a DAL script to program all the logical itegrity rules for a particular table. Chapter 3, 4GL programmig features, describes the 4GL evet sectios that you ca use i UI scripts. Chapter 6, Data Access Layer, describes the evet sectios ad DAL fuctios that you ca use i DAL scripts. The statemets programmed i evet sectios ca be a combiatio of 3GL/4GL fuctios ad 3GL laguage statemets. Report scripts Report scripts are 4GL scripts that are liked to a report i order to add to or modify its output. I a report script, you ca program actios that you wat to be performed at particular stages of the report executio. Chapter 4, Report scripts, describes the evet sectios ad report fuctios that you ca use i report scripts. Baa SQL You ca use Baa SQL (Structured Query Laguage) i 4GL scripts to retrieve data from database tables. There are two ways to use Baa SQL i a 4GL program. You ca embed it i the laguage (embedded SQL), or you ca use BaaERP 4GL fuctios (dyamic SQL). Chapter 5, Database hadlig, describes both optios i detail. Dyamic-lik libraries BaaERP Tools supports the use of dyamic-lik libraries (DLLs). A DLL cosists of a library of fuctios that is compiled ad stored separately from the processes that use the library. Each program that uses a DLL liks to it at rutime. Chapter 8, Dyamic-lik libraries, describes the use of DLLs i BaaERP applicatios. BaaERP debugger Whe you compile your programs, you ca use the BaaERP debugger to cotrol ad test their executio. Chapter 9 provides a overview of the debugger ad describes the umerous optios it supports. 1-2

15 Itroductio Multitaskig The bshell (also referred to as the Baa Virtual Machie) provides a multitaskig executio eviromet for BaaERP applicatios. Each bshell ca execute ad schedule multiple parallel processes. Chapter 7, Multitaskig ad the GUI, provides a overview of how processes ad user iterface iteractio are maaged by the bshell. 3GL/4GL fuctios BaaERP 3GL ad 4GL fuctios are described i a separate documet: BaaERP Tools: Fuctios Referece (documet umber U7167A US). 1-3

16 Itroductio 1-4

17 2 3GL programmig laguage features Overview This sectio describes the features of the Baa 3GL programmig laguage. You ca use the 3GL laguage i both 3GL scripts ad 4GL scripts. Vocabulary Character set You ca iclude the followig characters i a 3GL laguage statemet: The full alphabet a-z ad A-Z The digits 0-9 The characters # $ ^ & * ( ) - _ + = { } [ ] \ ; : ",. / < > This documet uses uppercase characters to idicate keywords. However, this is ot ecessary i your programs. Cotiuatio symbol If a statemet does ot fit o oe lie, you ca split it across two or more lies. There is o limit to the umber of lies that you ca use for oe statemet. Wherever you ca iclude a space, you ca also make a ew lie. There are two exceptios: a strig costat ad a macro defiitio. If these do ot fit o oe lie, you must place a caret symbol [^] at the begiig of the secod ad subsequet lies. You ca use the caret symbol i other statemets also, but this is ot ecessary. Commet The pipe symbol [ ] idicates that the text from the symbol to the ed of the lie must be hadled as a commet. The compiler igores this text. Good commets help the reader of a program source to uderstad the program better. 2-1

18 3GL programmig laguage features Separators You ca use tabs, ewlies, ad spaces as separators i your program. Reserved words The Baa 3GL programmig laguage icludes a umber of words with defied meaigs. These are reserved words that you caot use other tha i the cotext for which they were desiged. Not all these words are described i this documet; some are for iteral use or for compatibility with older releases. The followig is a list of these reserved words: AND END IN SELECTBIND AT ENDCASE INPUT SELECTDO BASE ENDFOR LE SELECTEMPTY BASED ENDIF LONG SELECTEOS BREAK ENDWHILE LT SELECTERROR BSET ENDSELECT MB STATIC CALL ENDDLLUSAGE MULTIBYTE STEP CASE EQ NE STOP COMMON EXTERN NOT STRING CONST FALSE ON TABLE CONTINUE FIXED OR THEN DEFAULT FOR PRINT TO DIM FUNCTION PROMPT TRUE DLLUSAGE GE REF UNTIL DOMAIN GLOBAL REFERENCE VOID DOUBLE GOTO REPEAT WHEREBIND ELSE GT RETURN WHEREUSED EMPTY IF SELECT WHILE 2-2

19 3GL programmig laguage features Costats A costat is a value of a special type that you ca assig to a variable. The Baa 3GL programmig laguage supports the followig types of costats: Numeric costats Strig costats Symbolic costats Eumerate / set costats Numeric costats The Baa 3GL programmig laguage supports log ad floatig poit costats. Both types ca be preceded by a + or a - sig. Log costats A log costat cosists of the digits 0-9 oly. For example: xFFF (hexadecimal) Floatig poit costats Floatig poit costats cosist of the digits 0-9 ad a decimal poit. You caot ed a costat with a decimal poit. A expoetial part ca be added to a costat by icludig the letter e followed by a log costat (maximum 307). You ca have up to six digits after the decimal poit i a costat. For example: e e10 2-3

20 3GL programmig laguage features Strig costats A strig costat is a umber of displayable sigle-byte or multibyte characters eclosed by double quotatio marks. A strig costat with legth zero (that is, a empty strig) is idicated by two adjacet quotatio marks. To iclude a double quotatio mark withi a strig costat, you must iclude two adjacet double quotes. For example: "This is a strig costat" "" "A quote "" withi a strig costat" "This is a very log strig costat whic ^h does ot fit o oe lie" Symbolic costats A symbolic costat is used i your program as a symbolic ame, but at rutime it has a fixed value. The defied costats are: FALSE The actual value is 0 TRUE The actual value is 1 PI The actual value is Note that if FALSE ad TRUE are used as boolea values (for example, as a result of expressios), they mea zero ad ot zero respectively. Eumerate ad set costats I the data dictioary you ca defie database table fields ad domais of type eumerate or set. A eumerate or set domai cosists of a umber of costats. I the program script (ad other places i the data dictioary), a symbolic ame is used. The symbolic ame is the domai ame, followed by a period [.] followed by the ame of the costat. Variables of type set ca also cosist of a combiatio of set values. Examples of eumerate costats DOMAIN colorbox_color color is a eumerate domai with two costats, gree ad red box_color = color.gree box_color = color.red 2-4

21 3GL programmig laguage features Examples of set costats DOMAIN feature cf feature is a domai of type set with the costats bold, reverse, uderlied cf = feature.bold cf = cf + feature.reverse add costat, cf cotais bold ad reverse cf = cf - feature.bold etol( cf ) subtract costat returs the combied umber of the curret value, here reverse. For workig with sets, see also the bit fuctios i U7167A US BaaERP Tools: Fuctios referece. A special costat of type eumerate or set is EMPTY. This idicates a empty set or a eumerate which is ot defied. Iterally, it has the value 0. Variables The ame of a variable is used to idicate the memory locatio where data (characters, umbers, ad so o) is stored. The ame of the variable refers to the associated data. The value of a variable ca chage durig executio of the program. A variable belogs to a data type ad must be declared before its use. This is usually doe at the start of the program. I some cases iitializatio of the declared variables is ecessary. The default iitial value is always zero for logs ad doubles, ad a empty strig for strigs. The ame of a variable ca cosist of ay umber of letters, digits, uderscores [_], ad periods [.]. It must begi with a alphabetic character. You should keep the followig i mid whe amig a variable: The ame of a variable must ot be the same as a reserved word or a previously declared variable. The ame of the variable must give a idicatio of its cotets. It is good practice to idicate the purpose of a variable beside its declaratio, i the form of commets. A variable must ot be used for a purpose other tha the oe for which it was origially iteded. 2-5

22 3GL programmig laguage features Data types There are five types of variables: log, double, strig, table, ad domai variables. Log variables ca cotai ay whole umber from to For umbers beyod this rage, use double variables istead. Physically, four bytes are reserved for each log variable. Double variables are used for ay umber cotaiig a decimal poit, with a maximum of 15 sigificat digits (8 bytes). A strig variable cotais a strig costat. The maximum legth of a strig is 1024 characters. A table variable is used for database tables i your program. The table must be defied i the data dictioary. A domai variable is a variable of a certai type that is defied i the data dictioary. Each of the followig types are possible: log, byte, iteger, date, eumerate, set, float, double, strig, text. Each domai defied i the data dictioary ca be used i a declaratio of your program. See also Domais later i this chapter. Declaratios You ca declare variables either withi a fuctio block or at the start of the program. Variables declared i a fuctio block ca be used withi that fuctio block oly. Variables declared at the start of the program ca be used i each fuctio described below the declaratio. Geeral sytax You declare variables with the followig sytax (parts betwee [ ] are optioal): [ special ] <type> <variable> [ optio ] [, <variable> [ optio ],...] 2-6

23 3GL programmig laguage features The followig are the possible values for the various parts of a variable declaratio: special EXTERN Not i fuctio blocks STATIC Oly i fuctio block; see "Fuctios" later i this chapter. type LONG DOUBLE STRING TABLE DOMAIN <domai ame> domai ame is a domai defied i the data dictioary variable The sytax for <variable> is: <ame>[(<expressio>,...)] optio BASED (oly for arrays) FIXED MB (multibyte) You ca declare several variables of the same type i the same statemet. To do so, simply iclude commas betwee the variable ames. If a variable is to be accessed by its symbolic ame from outside the program, it must be declared with the keyword EXTERN, so that the variable ame is stored i the symbol table of the object. You must declare a variable with the keyword EXTERN if that variable is used withi other programs, withi forms (field ames ad variables withi expressios), or withi the fuctio expr.compile(). If the fuctios get.var() ad put.var() are used withi the program, the variables i the other program must be declared as EXTERN. Tables If you use database tables ad records i your program, you must declare the tables as follows: TABLE <table ame> table ame must start with a t. This declaratio creates a poiter to the table. Declaratio of a table implies declaratio of all its fields ad its record buffer. It is ot ecessary to declare these separately. For a further details see Chapter 5, Database hadlig. 2-7

24 3GL programmig laguage features Domais Whe declarig temporary variables for storig values of database fields, you ca use ormal variables of type log, double, or strig. But this ca cause problems if the legth or type of the table field has bee chaged i the data dictioary. It is preferable to use domai declaratios for storig the value of a database table field. Whe you use a domai declaratio, the type ad legth for the declared variable are read from the data dictioary. Variables of type eumerate or set must always be declared with a domai declaratio. It is also possible to declare a array by usig a domai. I that case the umber of elemets must be set betwee the brackets, the legth of the elemets is embedded i the data dictioary. Examples The followig examples illustrate various domai declaratios, ad the declaratio of the same variables without domais. DOMAIN declaratios DOMAIN tst_str10 tmp_str, Strig of legth 10 tmp_str_arr(100) 100 strigs of legth 10 DOMAIN tst_log tmp_lg1, A log umber tmp_lg2, Aother log umber tmp_lg_matr(5,2) A matrix 5 x 2 DOMAIN tst_double tmp_dbl, A floatig poit tmp_dbl_arr(100) 100 floatig poits STRING declaratios #defie LENG 10 STRING tmp_str(leng), Strig of legth 10 tmp_str_arr(leng*10,10) 10 strigs of legth 100 LONG declaratios LONG tmp_lg1, A log umber tmp_lg2, Aother log umber tmp_lg_matr(5,2) A matrix 5 x 2 DOUBLE declaratios #defie MAXLEN=1000 DOUBLE tmp_dbl, A floatig poit tmp_dbl_array(maxlen/10) MAXLEN/10 floatig poits 2-8

25 3GL programmig laguage features Arrays You use arrays to store multiple variables of the same type withi oe data item. Each variable ca be referred to with the costructio array_ame(idex). For example, the first elemet i a oe-dimesioal array is array_ame(1). A array ca have up to four dimesios. The dimesio (ad, i case of a strig, also the legth) of a array must be stated i the declaratio. There are three types of arrays: log, double, ad strig. Log arrays You declare oe-dimesioal log arrays as follows: LONG lg_array(5) 1-dimesioal array for 5 logs The umber i paretheses after the array ame specifies the umber of logs that ca be stored i the array. You declare two-dimesioal log arrays as follows: LONG lg_array(2,4) The first umber after the array ame idicates the umber of dimesios i the array. The secod umber idicates the umber of logs that ca be stored i each dimesio. The followig diagram illustrates a two-dimesioal array as a matrix: lg_array(1,1) = 3 lg_array(2,1) = 100 lg_array(1,2) = 4 lg_array(2,2) = 98 lg_array(1,3) = 56 lg_array(2,3) = 55 lg_array(1,4) = 78 lg_array(2,4) = 77 Double arrays A double array differs from a log array oly i that it is prefixed by the keyword DOUBLE ad the array elemets must be filled with double values. You declare a double array as follows: DOUBLE dbl_array(5) 2-9

26 3GL programmig laguage features Strig arrays The declaratio of strig arrays differs from that for other array type i that the first dimesio cotais the legth of the strigs to be stored i the array. For example: STRING str_arr(10,5) 5 strigs of legth 10 STRING str_arr(10,5,5,5) A 5 x 5 x 5 matrix of strigs of legth 10 Whe referecig a strig array, the first dimesio idicates the start positio i the strig. The particular strig to be accessed is idicated by the other dimesios. It is possible to specify a legth for the strig to be retrieved by usig a semicolo [;] followed by the required legth. If you omit the legth, the total legth of the strig is take. Example 1 (two-dimesioal strig array) STRING str_arr(6,2) str_arr(1,1) = "abcdef" str_arr(2,1;1) = "b" str_arr(3,2) = "CDEF" Space reserved for 2 strigs of 6 characters each. For example, the first strig cotais "abcdef" ad the secod "ABCDEF". This refereces the first strig startig at positio 1. This refereces the first strig startig at positio 2 with legth 1. This refereces the secod strig begiig at positio 3. Example 2 (fillig strig variables) Cosider a strig declared as: STRING strg(26) The statemets listed below will have the idicated results: strg = "good morig" strg(1) = "good morig" The words "good morig" are stored from the first positio of strg: "good morig" The same result but filled with spaces: "good morig " 2-10

27 3GL programmig laguage features strg(9) = "good morig" The strig is stored from positio 9 owards ad filled with spaces: strg(2;3) = "Hello" " good morig " The letters "Hel" (3 characters) are stored from positio 2 owards: " Hel good morig " Example 3 (accessig strig variables) Suppose the strig declared i the previous example has the value "ABCDEFGHIJKLMNOPQRSTUVWXYZ". The results of the statemets below will be as idicated: prit strg prit strg(13) prit strg(2;3) "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "MNOPQRSTUVWXYZ" "BCD" I these examples, strg() refers to the etire array from positio owards ad strg(;x) refers to x positios startig at positio. Example 4 (two-dimesioal strig array) Cosider a 2-dimesioal strig array declared as: STRING twice(6,2) The statemets below will have the idicated results. twice(1,1) = "ABCDEF" The first strig is filled from positio 1 owards. twice(1,2) = "123456" The secod strig is filled from positio 1 owards. prit twice(3,1) prit twice(4,1;2) "CDEF" is prited. Two characters are prited startig at positio 4 i strig 1 that is, "DE" is prited. 2-11

28 3GL programmig laguage features Strig legths There are two legths associated with a strig: the maximum ad the curret legth. The maximum legth is defied at declaratio of the strig ad the curret legth ca vary, depedig o the cotets of the strig. If a strig is declared as STRING strg(100), the maximum legth of strg is 100. If strg is filled as strg = "hello", the curret legth is 5. If strg is filled as strg(1) = "hello", the curret legth is also is 100, as the remaiig positios are filled with spaces. Whe you specify a start positio, the strig is always filled out with spaces. If a strig is declared as FIXED, the curret legth is always equal to the maximum legth, because the strig is always filled up with spaces. Also, i the case of multi-dimesioal strigs, the curret legth is always equal to the maximum legth. Fixed ad based variables Fixed variables A strig variable ca be declared as fixed so that its curret legth always equals the maximum legth. For example: STRING ame(10) FIXED ame = "adrew" the strig is always filled up with spaces The keyword FIXED is applicable to oe-dimesioal strigs oly. Multidimesioal strig arrays are always fixed ad do ot eed to be declared with the keyword FIXED. Based variables The BASED mechaism is applicable to strigs or arrays of all possible types. It determies that a variable will be based o aother variable. For based variables, o memory space is reserved whe they are declared. At rutime they use the same memory space as the variable o which they are based. So by usig this mechaism, the same sectio of memory ca be accessed via differet ames. You use the followig costructio to base oe variable o aother: BASE var_1 AT var_2 I the case of a strig, the based variable is always fixed. You must esure that the based variable always fits i the variable o which it is based. So it will be safe to declare the basic variable as FIXED. 2-12

29 3GL programmig laguage features Example STRING a(10) FIXED STRING b(5) BASED BASE b AT a(3) This idicates that the space occupied by b is the same as the space for a(3;5) a(4;3) ow also cotais "yes" b(2;3) = "yes" a(1;8) = " " b ow cotais "34567" Variable ad fixed legth strigs The followig poits summarize the rules for variable ad fixed legth strigs: Strigs with variable legth are 1-dimesioal strigs ot declared as based or fixed. All other strigs are fixed that is, database table fields, strig arrays, ad variables declared as FIXED or BASED. Normally, variable legth strigs are ot filled up with spaces except whe a start positio is specified i the assigmet. Fixed legth strigs are always filled up with spaces, except whe a legth is specified. I the latter case, the remaiig positios are ot overwritte by spaces. If a strig (of variable or fixed legth) is filled from a certai start positio, the part of that strig precedig the start positio is filled up with spaces if it was ot filled before. Multibyte strigs A strig variable ca be declared as a multibyte strig, i order to hadle multibyte or bidirectioal characters. For example: STRING mb_str(10,5) MB 5 multibyte strigs of 10 characters I a sigle-byte strig, each byte cotais a sigle character. But i a multibyte strig, characters ca occupy from oe to four bytes. Example This multibyte strig cotais six characters. The fourth character is a TSS (that is, multibyte) character cotaiig 4 bytes. Note that all TSS characters are prefixed with hex 9b. 2-13

30 3GL programmig laguage features NOTES I program scripts, it is ot possible to assig a multibyte character (for example, Chiese) to a multibyte strig. The strig declared as: str(x) MB x is the umber of characters requires a space of x * mb.factor (where mb.factor has bee defied i the user file). A Japaese character for example has a multiplicatio factor of about 2. The strig str(x;1) cotais oe character, ad a size of oe or four bytes. If the character has a size of 4 bytes, it is a TSS character. It is ot advisable to assig a multibyte strig to a ormal strig, as this ca cause problems regardig storage space ad special maipulatios like idexig. You caot use multibyte strigs i combiatio with the BASED mechaism. Bidirectioal strigs Bidirectioal fuctioality is ecessary to support laguages that read ad write from right to left for example, Arabic ad Hebrew. Bidirectioal iput is supported oly o fields of type multibyte strig. A strig is bidirectioal whe it cotais at least oe bidirectioal character. You ca check whether a strig icludes bidirectioal characters by callig mb.hasbidi(). All strigs, icludig bidirectioal, are stored i logic order that is, the first typed character is the leftmost oe i the strig. This meas that all regular strig hadlig fuctios like pos(), ad costructors like the semicolo [;], work correctly. Special attetio must be paid whe cocateatig or splittig strigs. Whe bidirectioal ad o-bidirectioal strigs are cocateated, oe part must be reversed. Commo variables Ulike other variables, which ca be used oly withi the program i which they are declared, commo variables ca be used i more tha oe program. Oly strig variables ca be declared as COMMON. Commo variables are automatically based o a commo memory part that ca be used by several programs. For this reaso they must be declared as BASED. The fact that they are commo must be idicated with the reserved word COMMON. 2-14

31 3GL programmig laguage features Declaratio of commo variables must be located outside every fuctio. So they must be declared as global variables. Example I program 1 ad program 2, the same memory space is used for variables com_1 ad com_2. Withi program 1: STRING com_1(10) BASED, com_2(15) BASED COMMON com_1, com_2 <fuctios which use com_1 ad com_2> Withi program 2: STRING com_1(10) BASED, com_2(15) BASED COMMON com_1, com_2 <fuctios which use com_1 ad com_2> As a alterative to usig commo variables, you ca use import(), export(), get.var() ad put.var() to trasport the values of variables betwee processes. NULL characters i strigs Techically, a strig is a array of characters. The iteral represetatio of a strig has a NULL character [\0] at the ed. The NULL character represets the character with the value zero. Null characters ca occur withi strigs after use of the followig fuctios: seq.read() copy.mem() store.byte() store.short() store.log() store.double() store.float() Whe a ormal strig is copied ito aother strig, it is always copied up to the first NULL character. If the target strig is a fixed strig, the it is filled up with spaces from the NULL character to the ed of the strig. The copy actio ca result from a ormal assigmet, from passig a strig as a call by value parameter to a fuctio, or from the use of the import() ad export() fuctios. There is oe exceptio to this rule. Whe the left or right side i a assigmet is a record buffer (rcd.<table ame>), all bytes i the buffer will be copied. 2-15

32 3GL programmig laguage features For example: table tttadv999 strbuf = rcd.ttadv999 rcd.ttadv999 = strbuf strbuf2 = strbuf NULL characters are copied NULL characters are copied NULL characters are NOT copied I all other cases, if NULL characters are meaigful, use copy.mem(). This copies NULL characters as well as ordiary characters. Expressios ad operators A expressio is a combiatio of variables, costats, ad operators, built up i accordace with certai rules. There are two mai kids of operators: uary ad biary. All operators, except the egatio operators, are biary. Expressios with uary operators have the geeral form: operator operad Expressios with biary operators have the followig form, where each operad ca be aother expressio, variable, or costat: operad_1 operator operad_2 The available operators ca be divided ito four categories: arithmetic, relatioal, logical, ad cotrol operators. Class Operator Descriptio Arithmetic - * / + - \ & Relatioal = r EQ <>or NE > or GT < or LT >= or GE <= or LE egatio multiply/divide/add/subtract remaider after divisio strig cocateatio is equal to is ot equal to is greater tha is less tha is equal to or greater tha is equal to or less tha Logical AND, OR, NOT logical ad, or ad egatio Cotrol? : questio mark expressio 2-16

33 3GL programmig laguage features The questio mark expressio is a special type of expressio. The sytax is: <coditio>? <expr_1> : <expr_2> If the coditio is TRUE, expr_1 is executed. If the coditio is FALSE, expr_2 is executed. For example: lg_1 = (a >= b)? a : b if coditio a >= b is TRUE lg_1 gets the value of a, else lg_1 gets the value of b. For further iformatio o the differet operator types, see the followig sectios. Arithmetic operators Arithmetic operators perform arithmetic operatios o the operads. All arithmetic operators, except strig cocateatio, must have operads of umerical type. If oe of the two operads is a double, the other is also coverted to double, ad the result is also of double type. For example: 45/30 is equal to 1 45 ad 30 are both LONG so the result is LONG 45/30.0 is equal to is a DOUBLE so the result is a DOUBLE The cocateatio operator cocateates expressios, variables, or costats of strig type. Examples LONG lg_1, lg_2 DOUBLE doub STRING strg_1(16), strg_2(50), strg_3(10), strg_4(20) Expressio lg_2 = 8\3 Result The variable lg_2 cotais 2, which is the remaider after dividig 8 by 3. lg_1 = lg_2 + 3 The variable lg_1 ow cotais 5. doub = lg_1 * 2.0 The variable lg_1 is multiplied by 2.0; the result (10.0) is stored i doub. 2-17

34 3GL programmig laguage features doub = 45 / 30 The variable doub ow equals 1.0. Note that 45 ad 30 are both logs, so the result of the expressio is 1. Coverted to double for storig i the result, this becomes 1.0. doub = 45 / 30.0 The variable doub ow cotais 1.5. strg_1 = "hel" & "lo" strg_2 = strg_3 & strg_4 The variable strg_1 ow cotais the value "hello". The cotets of strg_3 ad strg_4 are cocateated ad placed i strg_2. Relatioal operators Relatioal operators compare two operads. If the coditio (equal, greater tha, less tha, ad so o) is satisfied, the result becomes TRUE. If ot, it becomes FALSE. Relatioal operators ca be performed o values of every available type, but the operads of oe expressio must be of the same type. Oe exceptio to that rule is that logs ca be compared to doubles. I the case of strigs, the ASCII values of the strigs are compared o the basis of the followig rules: The compariso is made o the basis of the ASCII value of the strigs, startig at the leftmost character of each strig. If two characters are ot equal, the strig with the lower character value is cosidered to be smaller ad the compariso is termiated. If both strigs cotai the same umber of characters ad the characters agree i all cases, the strigs are equal. If oe strig is shorter tha the other, ad the correspodig characters are equal, the shorter strig is cosidered to be smaller tha the other. Logical operators Logical operators perform logical operatios o their operads. The operator NOT is uary, so it has oly oe operad. The operads of logical operators ca be logical expressios, relatioal expressios, variables, or costats. 2-18

35 3GL programmig laguage features The followig table illustrates the results of logical expressios: A B NOT A A AND B A OR B FALSE FALSE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE Variables or expressios of type LONG ca be used as boolea. If a log expressio results i the value zero, it is evaluated as FALSE. If the result is ot equal to zero, it is evaluated as TRUE Operator precedece A expressio ca iclude a umber of operators, variables, ad costats. The overall result is calculated i accordace with the rules of precedece described here. For example, because multiplicatio has precedece over additio, the result of the expressio (3 + 4 * 5) is 23 ad ot 35. The followig table lists all operators i order of decreasig precedece. Operators with high precedece are evaluated before operators with lower precedece. Operators o the same lie i the table have the same precedece. If they occur i oe expressio, they are evaluated from left to right. Operator Associativity - (egatio) right to left * / \ left to right & left to right + - (mius) left to right = > < <> <= >= oe NOT right to left AND left to right OR left to right?: right to left You ca use paretheses to force a specific precedece. For example: The result of the expressio 3+4*5 is 23 The result of the expressio (3+4)*5 is 35 The result of the expressio 10/2*5 is 25 The result of the expressio 10/(2*5) is

36 3GL programmig laguage features NOTES I case of doubt, always use paretheses. This makes the program easier to read. The operators NOT ad - (egatio) are uary, the others are biary. The relatioal operators are o-associative. This meas that A <= B <= C is ot available. This should be A <= B AND B <= C. Assigmet Operator You use the assigmet operator [=] to store variables, costats, ad the results of expressios i a variable. Examples (geeral) LONG I, J, K(100), L(100) STRING S(50), A, B(10) DOUBLE AMOUNT J = 4 AMOUNT = * J L(20) = 1001 S = "This is a example" I = J The cotets of J are stored i variable I L(2) = L(20) Now L(2) is equal to L(20) A = S(3;1) The character i is placed i A B(1;2) = S(6;2) The word is is placed i the first two positios of B K = L The etire cotet of array L is copied to K Except i the case of doubles ad logs, both operators must be of the same type. For doubles ad logs, the followig rules apply: Left operator log double Right operator ad coversio Ca be iteger or double. The result is coverted to iteger. I case of double, the digits after the decimal poit are trucated. After trucatio the value must be betwee ad Result coverted to double. 2-20

37 3GL programmig laguage features Examples (logs ad doubles) LONG A DOUBLE C A = 3.14 A is set to 3 C = A C ow cotais 3.0 C = 45 / 30 C ow equals 1.0, because this divisio results i a log Trasfer of cotrol The Baa 3GL programmig laguage supports several statemets that chage the flow of cotrol i a program. These eable cotrol to be trasferred either coditioally or ucoditioally to a specified poit i the program. You use the GOTO statemet to trasfer cotrol ucoditioally to a specified poit. You use the IF...THEN...ELSE statemet or the ON CASE statemet for coditioal trasfer. These latter statemets evaluate a specified coditio ad trasfer cotrol if the coditio is TRUE. The GOTO statemet The GOTO statemet trasfers cotrol ucoditioally to a specified poit i the program. You use a label to idicate a positio to which the statemet ca trasfer cotrol. The label ame ca cosist of letters, digits, uderscores [_], ad periods [.]. It must begi with a alphabetic character. Examples of labels: LABEL_1: START_OF_PROCESS_A: Examples of GOTO statemets: GOTO LABEL_1 GOTO START_OF_PROCESS_A Both the GOTO statemet ad the label to which it refers must be withi the same fuctio. You caot trasfer cotrol to a label i aother fuctio. 2-21

38 3GL programmig laguage features The IF... THEN... ELSE statemet The IF statemet eables coditioal trasfer of cotrol. The statemet tests a coditio, ad executes the succeedig statemets oly if the coditio is true. The coditio ca cosist of a expressio, or it ca be a log variable or a fuctio that returs a log. Whe the coditio is a log variable or a fuctio that returs a log, the value zero is evaluated as FALSE ad all other values are evaluated as TRUE. IF...THEN This tests a coditio. If the coditio evaluates to TRUE, the statemets followig the IF...THEN statemet are executed. For example: IF coditio THEN statemet(s) ENDIF IF...THEN...ELSE This tests a coditio. If the coditio evaluates to TRUE, the statemets followig the IF...THEN statemet are executed. If the coditio evaluates to FALSE, the statemets followig the ELSE statemet are executed. For example: IF coditio THEN statemet(s)_1 ELSE statemet(s)_2 ENDIF Examples IF a > b THEN b = b + 1 ENDIF IF preset AND foud THEN cout = cout + 1 do_somethig() ENDIF IF isspace(str1) THEN message("strig is empty") ENDIF IF a > b THEN max_val = a ELSE max_val = b ENDIF 2-22

39 3GL programmig laguage features The ON CASE statemet This statemet has the followig sytax: ON CASE expressio CASE expr_1: statemets_1 break CASE expr_2: statemets_2 break CASE expr_3: statemets_3 break DEFAULT: optioal statemets ENDCASE The ON CASE statemet is a multiple-way decisio table. It evaluates a expressio ad compares the result with the expressios of each specified CASE. Whe a match is foud, cotrol trasfers to that brach ad the code for that particular CASE is executed. If o match is foud, the DEFAULT code is executed. If there is o DEFAULT label, the program cotiues with the first statemet after ENDCASE. CASES ad the DEFAULT label ca occur i ay order. The CASE statemets serve as labels. This meas that after executio of the statemets related to a particular CASE, the remaiig CASES cotiue to be evaluated. However, if two CASE expressios give the same result, oly the first is executed. You ca use the BREAK commad to skip evaluatio of other CASES after the code for the matchig CASE has bee executed. You iclude this commad at the ed of the code for each CASE. Whe the commad is executed, executio of the ON CASE statemet eds. I the case of ested CASES, the BREAK commad cacels executio of the CASE statemets at the same level oly. The ON CASE expressio must be either a log expressio or a strig expressio. Log expressios The expressio after ON CASE is evaluated ad compared with the various CASE expressios that follow. All expressios i the case labels must be of type LONG or STRING. Whe strig expressios are used, the ASCII value of the strig is compared with the ON CASE expressio. 2-23

40 3GL programmig laguage features For example: ON CASE weekday CASE 1: day = "Suday" BREAK CASE 2: day = "Moday" BREAK CASE 3: day = "Tuesday" BREAK DEFAULT: day = "other day" ENDCASE It is also possible to execute a statemet for multiple labels. For example: ON CASE weekday CASE 1: CASE 2: CASE 3: CASE 4: begiweek() BREAK CASE 5: CASE 6: CASE 7: edweek() BREAK ENDCASE Strig expressios The expressio after ON CASE is evaluated ad compared with the various CASE expressios that follow. Normally, whe the ON CASE expressio is a strig expressio, the CASE expressios are also strigs. However, if the ON CASE expressio evaluates to a o-pritable character for example, ESC (=27), this caot be tested agaist a strig costat. I this situatio, the CASE expressios ca be iteger costats that represet ASCII values. The ASCII value of the ON CASE expressio is the compared with the umeric values of the CASE labels. 2-24

41 3GL programmig laguage features For example: ON CASE choice_char CASE "A": CASE "E": abort() CASE "N": ext_scree() BREAK CASE "P": last_scree() BREAK CASE 27: escape() BREAK DEFAULT: message("ukow choice") ENDCASE Iteratios Iterative statemets repeat the associated statemets util a specified coditio becomes FALSE. WHILE statemet This statemet has the followig form: WHILE expressio statemet(s) ENDWHILE The expressio is evaluated. If the result is TRUE (that is, o-zero), the statemets betwee WHILE ad ENDWHILE are executed. The process is the repeated util the expressio is FALSE (that is, zero). Whe the expressio evaluates to FALSE, cotrol passes to the statemet after ENDWHILE. For example: LONG couter couter = 1 WHILE couter <= couter = couter + 1 ENDWHILE 2-25

42 3GL programmig laguage features FOR statemet This statemet has the followig form: FOR um_var = um_expr_1 TO um_expr_2 [STEP um_expr_3] statemet(s) ENDFOR The um_var variable is referred to as the loop variable. Num_expr_1 specifies the iitializatio of the loop variable. Num_expr_2 specifies the ed value of the loop variable. Num_expr_3 specifies the step size for each iteratio. The latter variable is optioal; the default step size is 1. It is possible to use a egative step size. After executio of the statemets withi the loop, um_expr_3 is added to the loop variable. The um_expr_2 expressio is the evaluated. If the loop variable does ot exceed um_expr_2, the statemets are executed agai. This process cotiues util the loop variable exceeds its ed value. For example: LONG total, i FOR i = 1 TO 100 STEP 2 total = total + i ENDFOR REPEAT... UNTIL statemet The REPEAT... UNTIL differs from the WHILE statemet, i that the REPEAT... UNTIL statemet tests the coditio after executio of the loop statemets istead of before executio of the loop statemets. Cosequetly the statemet(s) withi a REPEAT... UNTIL statemets are executed at least oce. The sytax of this statemet is: REPEAT statemet(s) UNTIL expressio The loop iterates as log as the result of the expressio is o-zero. Usig BREAK ad CONTINUE (iteratios) You ca use the BREAK commad i a iterative statemet i order to cacel the loop, regardless of the value of the loop coditio. After a BREAK, cotrol passes to the statemet followig the termiated loop. It is importat to ote that with ested loops the BREAK statemet cacels the iermost loop oly. The CONTINUE commad also iterrupts a iteratio loop. But, i this case, the expressio is immediately evaluated agai for the ext iteratio. 2-26

43 3GL programmig laguage features For example: LONG umbers(100), i FOR i = 1 TO 100 IF umbers(i) <= 0 THEN CONTINUE Next iteratio ENDIF IF NOT process(umbers(i)) THEN BREAK Exit FOR statemet ENDIF ENDFOR The BREAK ad CONTINUE commads ca be very useful i a program, but you should be take great care whe usig them. Fuctios I a program, a fuctio performs a particular task that ca be executed may times, with differet values. The sytax of a fuctio is as follows (parts betwee brackets [] are optioal): FUNCTION [ fuctio_type ] fuctio_ame( [ arglist ] ) { declaratio of local variables statemet(s) RETURN[( retur_value )] } where arglist cosists of oe or more argumet declaratios with the followig sytax: [REFERENCE / CONST] argumet_type argumet_ame Whe icludig more tha oe argumet declaratio, use commas [,] to separate the declaratios. Note that the key word REFERENCE ca be replaced by REF. Fuctio type ad retur value The type declaratio i a fuctio declaratio idicates the type of the fuctio. This must be the same as the type of the retur value. Fuctios ca be of the followig types: log double strig domai void (this meas that o value is retured) 2-27

44 3GL programmig laguage features If you do ot specify a type, the fuctio is of type void by default. I fuctios of type void, the retur statemet caot have ay argumet. For example: FUNCTION add_oe() { cout = cout + 1 RETURN } Local variables this fuctio is of type void cout is a global variable Variables declared withi a fuctio block are local variables. They are accessible oly withi the fuctio i which they are declared. Declaratio, iitializatio, ad scope Poit of declaratio I the fuctio betwee the brackets { }. Sytax of declaratio Iitializatio Scope (validity ad time) Example fuctio void test() { log I for i =1 to edfor retur } <type> ame The value of local variables is udefied with each fuctio call. Local variables must always be iitialized i the fuctio. Oly withi ad durig fuctio executio. Local variable Always to be iitialized by user Static variables You ca declare local variables as static variables. The value of a static variable is saved at the ed of the fuctio ad is used agai the ext time the fuctio is called. A static variable is automatically iitialized at the start of the program. Normal local variables are udefied at each fuctio call, ad are ot iitialized at first call. 2-28

45 3GL programmig laguage features Declaratio, iitializatio, ad scope Poit of declaratio I the fuctio betwee the brackets { }. Sytax of declaratio static <type> ame Iitializatio At program start: umericset to 0 strigs set to "" Scope (validity ad time) Ca be used oly withi the fuctio but they maitai their values throughout program executio. Example 1 fuctio test() { static log started if (ot started) the started = true Actios to be performed oly first time aroud. edif... retur } Example 2 fuctio void spool( log id, ref strig lie() ) { static log save_id static log lf if ( save_id <> id ) the Optimalizatio lf = read_ew_lf( id ) save_id = id edif seq.puts( lie, lf ) } 2-29

46 3GL programmig laguage features Global variables Variables declared outside ay fuctio block are global variables. You ca use them i all fuctios that occur after the variable declaratio. Declaratio, iitializatio, ad scope Poit of declaratio Sytax of declaratio Iitializatio Scope (validity ad time) Outside the fuctios. <type> ame At program start: umericset to 0 strigs set to "" Valid aywhere i the source, throughout the executio. If ay argumets or variables withi a fuctio are declared with the same ame as a global variable, the global variable caot the be accessed withi that fuctio. Example 1 fuctio test() { retur } log glob_var fuctio log dupl() { retur( glob_var * 2 ) } I this example, glob_var is a global variable. It is ot accessible i the test() fuctio as it was declared after that fuctio block. O the other had, glob_var is accessible i fuctio dupl(). Example 2 log i fuctio void test() { } log i i = 10 This is the local variable Nothig happes to the global variable i 2-30

47 3GL programmig laguage features Exteral variables A exteral variable is declared outside the fuctio blocks. You ca use them i all fuctios that occur after the variable declaratio, ad also i other programs (for example, forms, reports, ad rutime expressios). It is possible to declare exteral variables withi a fuctio block but this is ot recommeded. If a local variable has the same ame as a exteral variable, the local variable is used withi the fuctio. The exteral variable is ot affected. Declaratio, iitializatio, ad scope Poit of declaratio Sytax of declaratio Iitializatio Scope (validity ad time) Outside the fuctios. (Or withi a fuctio, but this is ot recommeded.) exter <type> ame At program start: umericset to 0 strigs set to "" Valid aywhere i the source, throughout the executio. Also valid outside the program for example, o forms/reports, i rutime expressios, ad by way of import() ad export(). Example exter log i fuctio void test() { i = 10 This is the exteral variable } 2-31

48 3GL programmig laguage features Fuctio argumets The argumets of a fuctio are the variables declared i the fuctio header. Argumets ca be accessed oly withi the fuctio. Declaratio, iitializatio, ad scope Poit of declaratio I the fuctio betwee the brackets { }. Sytax of declaratio [ref referece] <type> ame Note that array subscripts must be empty for referece argumets. Iitializatio At fuctio call. For value argumets (see below), the values of the fuctio call are copied. For referece argumets, the same variable (or the same memory area) is used as occupied by the variable submitted to the fuctio call. Scope (validity ad time) Oly durig fuctio executio. Value argumets A value argumet gets its value at the time of the fuctio call ad has its ow memory space. For example: FUNCTION log dupl(log val) val is a value argumet { RETURN( val * 2 ) } FUNCTION MAIN() { message("%d", dupl(10)) the argumet val gets value 10 } Referece argumets Referece argumets must be declared i the fuctio header with the keyword REFERENCE or REF. A referece argumet has the same memory space as the variable used i the fuctio call. Cosequetly, all chages made to a referece argumet withi the fuctio block are also accessible after the fuctio call i the variable used i the fuctio call. If a referece argumet has array subscripts, these must be empty i the declaratio as the cotets ad size of the call variable is used. 2-32

49 3GL programmig laguage features If strigs or large arrays are used, it is preferable to use referece argumets istead of returig them with the retur statemet. This avoids copy actios. Example 1 Note that i this example, the referece argumet is empty i the declaratio. FUNCTION LONG read_lie( REF STRING buffer() ) { IF (.... ) THEN buffer = RETURN( 1 ) ELSE buffer = "" RETURN( 0 ) ENDIF } FUNCTION MAIN() { STRING lie(100) IF read_lie(lie) THEN.... ELSE message("no preset lie") ENDIF.... } Example 2 This example uses a multi-dimesioal array: FUNCTION VOID fill_array ( REF LONG array(,) ) { array(1,1) = 10 array(1,2) = } FUNCTION MAIN() { STRING a(5,10) fill_array(a) } 2-33

50 3GL programmig laguage features Costat argumets Costat argumets must be declared with the keyword CONST i the fuctio header. These are similar to referece argumets i that the same memory space is used for the costat argumet ad the variable used i the fuctio call. However, with costat argumets, it is possible to use a strig costat withi the fuctio call. Cosequetly, the value of the argumet after the fuctio call is ot retured i the callig fuctio. You caot chage a costat argumet withi the fuctio. Nor ca you use a costat argumet as referece i aother fuctio call. Oly strigs with oe dimesio ca be used as costat argumets. The array subscript of the costat argumet must be empty i the declaratio because the size of the costat is used. For example: FUNCTION prit_mess( CONST STRING mesg() ) { IF NOT isspace(mesg) THEN message("message: " & mesg) ENDIF } FUNCTION MAIN() {... prit_mess("this is a message")... } Varyig umber of argumets It is possible to pass a (as yet) uspecified umber of argumets to a fuctio defiitio by replacig the actual argumets with.... The fuctio call must cotai the actual argumets required to execute the fuctio. This eables you to use differet argumets (from 0 to approximately 250) each time you call the fuctio. This feature is useful, for example, if you wish to chage some (ot all) of the flags of a process, ad you do ot kow beforehad precisely which flags you are goig to chage. For iformatio o usig this feature, see the arg() fuctios i U7167A US BaaERP Tools: Fuctios referece. 2-34

51 3GL programmig laguage features Fuctio prototypes A fuctio cosists of three parts: Fuctio prototype Fuctio defiitio (fuctio block) Fuctio call The fuctio prototype must be exactly the same as the fuctio header i the fuctio defiitio. The prototype of a fuctio is ot always ecessary. For example, it is ot ecessary i the followig situatios: if the fuctio is of type void ad has o argumets if the defiitio of the fuctio occurs before ay call of that fuctio I all other situatios the prototype of the fuctio must occur before the fuctio call. For example: prototype FUNCTION LONG compr_check( LONG ew_compr ) fuctio call IF compr_check( 999 ) THEN.... ELSE mess("pcge00016", 999) Comp. umber %d ot preset ENDIF defiitio FUNCTION LONG compr_check( LONG ew_compr ) { TABLE tpctst999 } SELECT pctst999.* FROM pctst999 WHERE pctst999.compr = :ew_compr ORDER BY pctst999.compr SELECTDO compr = pctst999.compr SELECTEMPTY RETURN(FALSE) ENDSELECT RETURN(TRUE) From compiler versio bic6.1 owards, it is ot ecessary to use fuctio prototypes withi the same source as the fuctio defiitio. 2-35

52 3GL programmig laguage features Fuctio calls The call of a fuctio must have the same umber of argumets as declared i the fuctio header. Value argumets ca be called usig a costat or a variable; referece argumets ca oly be called usig a variable. If the called fuctio is ot of type void, the fuctio call must be assiged to a variable or used as value argumet i aother fuctio call. It is possible to use recursive fuctio calls. This meas that i a fuctio block a call to the same fuctio is used. However, this is curretly implemeted oly for fuctios without local variables ad argumets. I other situatios, the followig rutime message is geerated: "Recursio ot yet implemeted". Preprocessor The bic6.2 compiler for 3GL program scripts has a built i preprocessor with the followig fuctios: iclude files macro defiitio object idetificatios pragma codes coditioal compilig All preprocessor directives starts with a #. A preprocessor directive must be the first word o a source lie, possibly with leadig spaces or tabs. Iclude files To iclude files, use oe of the followig statemets: #iclude "fileame" #iclude <fileame> Files icluded betwee < ad > are searched for i the directory $BSE/iclude<rel.umber>. This directory is reserved for system headers ad caot be used for applicatios. Normally a file specified betwee quotes is searched for usig the stadard file redirectio method. Note that the preprocessor works oly durig compilatio of a 3GL source, as the stadard geerator std_ge6.2 does ot have a preprocessor pass. So it is ot possible to use 4GL evets i a icluded file. 2-36

53 3GL programmig laguage features Example Suppose the followig etry occurs i $BSE/lib/fd.6.2<package_comb>: ippmmm:/usr/bse/stadard6.2 ad there is a iclude statemet as follows: #iclude "ippmmmheader" The file "/usr/bse/stadard6.21/ippmmm/immmheader0" is icluded. If a / occurs i the fileame, the file is searched usig the specified path ame. Whe a file is icluded twice, the secod iclude is igored. Macro defiitio Use the followig statemet to defie a macro: #defie macroame[(argumets)] Use the folowig statemet to udefie a macro: #udef macroame[(argumets)] Defiig macros The macro ames i the source are expaded to the macro defiitio. If a macro defiitio does ot fit o oe lie, it is possible to cotiue the defiitio o the ext lie(s) by usig the caret symbol ^ at the begiig of each lie. It is possible to use argumets i the macro. For example: #defie a(x, y, z) for i = x to y ^ z() ^ edfor The defiitio a(1, 100, fuc) The ivocatio Macro defiitios with the same ame but with differet umbers of argumets are regarded as differet. For example: #defie x #defie x() #defie x(arg1) #defie x(arg1,arg2) #defie x(...) defiitio without argumets defiitio with 0 argumets defiitio with 1 argumet defiitio with 2 argumets defiitio with udefied umber of argumets Note that there is a differece betwee a macro without argumets ad a macro with zero argumets. I the first case, you must use x i the program script to call the macro. I the secod case, you must use x() to call the macro. 2-37

54 3GL programmig laguage features Udefiig macros The #udef statemet causes the macro defiitio to be igored. The umber of argumets i the #udef call must match the umber of argumets i the defiitio. For example: #defie MAXLENGTH 1000 #defie INCR 1 #defie INCR(i) i=i+incr... #udef MAXLENGTH #defie INCR 2 Redefies INCR... #udef INCR(i) A error occurs if you apply #udef to a ukow macro. To be sure that the macro was defied, use the followig costructio: #ifdef INCR #udef INCR(i) #edif without argumets See Coditioal compilig later i this chapter for a detailed descriptio of #ifdef ad #edif calls. Variable macro argumets You ca use the ellipsis otatio (,... ) to defie the macro with a varyig umber of argumets. For example: #defie fillbuf(buf1, format,...) ^ buf1 = spritf$(format,...) macro call strig buffer(100) log l_val double d_val fillbuf(buffer, "%d. %s = %d %5.2f", 1, "Value", ^ l_val, d_val) The macro defiitio ca cotai a umber of argumets, but the ellipsis otatio must be the last argumet. 2-38

55 3GL programmig laguage features Toke pastig I the macro, you ca eter a part of a variable as a macro argumet. The symbol ## is used to distiguish macro argumets ad the rest of the macro. This is omitted i the macro call. You ca paste more macro argumets together as oe idetifier. This priciple is called toke pastig. It is used to reuse parts of the source code, where usig fuctios is impossible or difficult. Example 1 #defie p(x) #defie q(x,y) #defie r(x,y,z) log var1a, var1b p(1a) p(1b) q(var, 1a) q(var, 1b) r(var, 1, a) r(var, 1, b) message("%d", var##x) message("%d", x##y) message("%d", x##y##z) becomes: message("%d", var1a) becomes: message("%d", var1b) becomes: message("%d", var1a) becomes: message("%d", var1b) becomes: message("%d", var1a) becomes: message("%d", var1b) Example 2 #defie VRC(table,v,r,c) ^ tt##table##.vers = v ^ tt##table##.rele = r ^ tt##table##.cust = c VRC(adv100, "6.2", "a", "") VRC(adv200, "6.2", "a", "") VRC(adv300, "6.2", "a", "") Object idetificatios The compiler always places a default idetificatio i a object, but you ca iclude you ow if you wish. You ca use the UNIX commad what to write all object lies that begi o stadard output. The default idetificatio has the followig cotet: #idet "@(#)<source ame>, YY/MM/DD, [HH/MM], From ${logame}" To set you ow idetificatio use the followig statemet: #idet "@(#)Idetificatio of object" For example: #idet "@(#)<progame>, YY/MM/DD [HH/MM], versio, author" 2-39

56 3GL programmig laguage features Pragma codes Pragma codes represet compiler optios. The followig pragma codes are available: #pragma odebug #pragma debug #pragma owarigs #pragma warigs #pragma otrasactios #pragma warig <text> #pragma fatal <text> #pragma sticky #pragma used <compoet> <code> Do ot show the source while debuggig. Show the source while debuggig. Do ot give warigs about the source. Give warigs about the source. The source cotais oly read actios; there are o trasactios. So, it is sufficiet to start oe database server. The programmer geerates his ow warig. (Warig level 15). See example. The programmer geerates his ow error. Do ot remove the object out of memory whe the process eds. See below. Example #pragma warig This is ot a fie solutio! After compilatio the followig warig appears: <Source(lie)>: Warig(15): This is ot a fie solutio! Where-used list I some cases the where-used list is ot updated automatically. For example, whe a sessio code is etered but ot expected: message("ttadv2130m000") or bms.sed("commad", evet, "ttaad3100m000", pr.id) To put this sessio code ito the where-used list, eter the followig commad lie: #pragma used sessio ttadv2130m000 The followig example illustrates the pragma codes to update the where-used list: #pragma used iclude #pragma used table <file> <table code> 2-40

57 3GL programmig laguage features #pragma used field #pragma used domai #pragma used message #pragma used questio #pragma used sessio #pragma used meu #pragma used dll #pragma used chart <field code> <domai code> <message code> <questio code> <sessio code> <meu code> <dll objectame> <chart code> Usually the where-used list is updated. I the case of fuctios, the where-used list is updated if the fuctio call cotais the strig value. For example: mess("ttadvs0000", 1) Where-used list will be updated str = "ttadvs0000" mess(str, 1) Where-used list will ot be updated #pragma used message ttadvs0000 Locatio of pragma codes You ca place pragma codes aywhere i the source. For example, if you set the followig pragma at the start of the source: #pragma owarigs you ca eter the followig pragma after a umber of lies: #pragma warigs Coditioal compilig Directives The preprocessor provides the followig directives to eable you to compile parts of the source depedig o certai coditios: #ifdef <macro> The source after #ifdef up to #else/#elif/#edif is compiled if <macro> is defied. Otherwise this source is igored. 2-41

58 3GL programmig laguage features #ifdef <macro> #if <costat expressio> #else #elif <costat expressio> #edif #udef <macro> The source after #ifdef up to #else/#elif/#edif is compiled if <macro> is ot defied. Otherwise this source is igored. The source after #if up to #else/#elif/#edif is compiled if <costat expressio> is TRUE. Otherwise this source is igored. If the coditio belogig to #if/#ifdef/#ifdef/#elif is FALSE, the source after #else up to #edif is compiled. If the coditio belogig to #if/#ifdef/#ifdef/#elif is TRUE, the source after #else up to #edif is igored. #elif is a combiatio of #else ad #if. For example: #if <costat expressio>... #else #if <costat expressio>... #else... #edif #edif This is equivalet to the followig: #if <costat expressio>... #elif <costat expressio>... #else... #edif To fiish a part of the source started with #ifdef/#ifdef/#if. To delete a macro defiitio. The macro is ot kow o the ext #ifdef call. 2-42

59 3GL programmig laguage features Notes o usig the directives The <costat expressio> i #if ad #elif is a umeric expressio i which you ca use oly macros of type log ad operators such as +, -, *, /, =, <, >, <=, >=, <>, ad, or, ot,?:, (). It is possible to use ested #if structures. It is possible to defie a macro whe startig the compiler. You use the D optio to do this. For example: bic6.2 -D<macro> o value meas default 1 bic6.2 -D<macro>=<value> bic6.2 -D<macro>= ay toke strig These macros ca also be used i the #if coditios. For example: bic6.2 -DDEBUG -DMYTEST <source> source #if DEBUG ad MYTEST message("some debug iformatio")... #edif bic6.2 -DCUSTOMER_X -DCUSTOMER_Y <source> bic6.2 -DSTANDARD <source> #if STANDARD... #elif ( CUSTOMER_X ad (ot CUSTOMER_Y) )... #edif You ca use #ifdef to make a part of the file iactive. For example: #ifdef OLD #edif The preprocessor works oly durig compilatio of a 3GL source, as the stadard geerator std_ge6.2 does ot have a preprocessor pass. So it is ot possible to use 4GL evets i #if, #ifdef or #ifdef. 2-43

60 3GL programmig laguage features It is ot possible to use a #ifdef statemet withi a embedded SQL query. So, the followig costructio is ot allowed: select * #ifdef STANDARD... from x #else... from y #edif where... selectdo... edselect But the followig costructio is possible: #ifdef STANDARD select * from x where... selectdo... edselect #else select * from y where... selectdo... edselect #edif The followig keywords provide debug iformatio i 3GL sources: FILE : cotais the ame of the curret source LINE : cotais the lie umber of the curret source For example: message("this is at lie %d i the source %s", LINE, FILE ) 2-44

61 3GL programmig laguage features Compiler You compile program scripts with the bic6.2 compiler. The compiler is automatically activated after you have edited your program or report script ad after the use of std_ge6.2 ad repge6.2 at the optio Compile i the data dictioary. You ca also use the compiler to compile 3GL programs The sytax for the compiler is: bic6.2 [-ilpsv] [-ww[level]] [-o <object>] [-d dll[:dll...]] [-D <macro>] [-I <dir>] source -I Assembler output is stored i <source>.i. Do ot specify a object file. -l Object will ru i debug mode. -p Object will ru i profilig mode for time aalysis (see fuctio times.o()). -s Geerate symbol table to stdout; for more iformatio use bic_ifo6.2 -s. -V Prit release iformatio. -w Suppress all warigs. -w Suppress warigs of level. -W Give warigs of level. -o <obj> Specifies the object ame; whe ot specified, oly a sytax check is performed. -d Specifies the DLL(s), separated by a colo ( : ). These are the objects of dyamic-lik libraries ecessary to compile the source program. -D<macro> -I<dir> Specifies a coditio <macro>, see also Preprocessor earlier i this chapter. Specifies a directory where icluded files are located. 2-45

62 3GL programmig laguage features The warigs associated with the various level umbers are as follows: Level Warig 1 Declared but ever used For example, remove the declaratio of the o-used variables. Warigs related to a iclude file ca be preveted by eterig "#pragma owarigs" at the begiig of the iclude file. All warigs caused by the iclude file will the be igored. 2 Fuctio ever used A fuctio is foud but ever called. For istace remove the fuctio. This warig related to a iclude file ca be preveted by eterig "#pragma owarigs". 3 Retur value of fuctio igored Whe a fuctio yields a value, that value must be checked. The reaso is that may fuctios retur TRUE or FALSE, depedig o whether the actio has bee completed successfully or ot. If the retur value is of o importace, a dummy value must be assiged to the fuctio. For example: dummy = ittadv0037.search.label(...) 4 A log divided by a log gives also a log A log divided by a log will result i a log. For example: log a log b a = 1 b = 3 a / b = 0 ad ot

63 3GL programmig laguage features 5 Statemet/Label ot reached Occurs if a statemet caot be reached. For example: fuctio test.a() { if a = 0 the... retur() else... retur() edif a = 1 } The statemet a = 1 will ever be reached, so this warig idicates a programmig error or logical error. 6 Compariso of two float types may yield upredictable results This warig is give whe two double types are compared for equivalece. Please use the fuctio double.cmp() to compare double variables, double domais, ad double fuctios. Note that for double fuctios the warig appears oly if the fuctio has bee prototyped before its actual use. For example: fuctio double d() fuctio mai() { domai tttst.db62 double dbldom a, b if a = b the... edif if d() > a the... edif if a <= dbldom the... edif } All the above expressios may yield upredictable results, as o toleraces have bee specified. 2-47

64 3GL programmig laguage features 9 Exteral variable %s passed as referece to fuctio %s Whe a exteral variable is give as a call by referece to a fuctio, the value of this variable withi the fuctio is ot equal to the local value. Just after the retur, the value of the exteral variable will be chaged. For example: exter log a fuctio mai() { a = 5 make.te(a) message("a = %d", a) results i a = 10 } fuctio make.te( ref log x ) { message("a = %d", a) results i a = 5 x = message("a = %d", a) results i a = 5 } Whe withi the fuctio make.te() aother fuctio is called usig the exteral variable a, the variable a still has the value Passig fixed variable to o-fixed call by referece argumet (or ofixed to fixed) Whe a global variable is declared as fixed, the variable withi a fuctio is still regarded as fixed, although the referece declaratio is ot fixed. For example: strig a(20) fixed fuctio process.variable( ref strig b ) { } If the fuctio is ivoked usig the argumet "a", "b" is cosidered fixed. 2-48

65 3GL programmig laguage features 12 Exteral variable %s added i exteral symbol table A exteral variable is declared withi a fuctio. For example: fuctio test() { exter log a... } 13 System library <bic_stdlib> NOT icluded! 15 Warig give by #pragma <text> This is a warig of your ow format, see Pragma Codes earlier i this chapter. 16 Missig selectdo; automatic break or Missig selectdo; loop util selecteos Whe a selectdo is missig i the select statemet, a automatic break is geerated to prevet uecessary use of cpu time. Whe a selectdo is missig, while a selecteos sectio exists, the select statemet should be executed. Probably this is a o optimal select statemet. 18 Macro '%s' redefied A macro is defied, which was already defied with the same argumets. 19 Fuctio '%s' i DLL '%s' igored take from '%s' A duplicate fuctio occurs i a DLL or program script. A fuctio is searched for i the script first ad ext i the libraries that are liked to the script i the specified order. If a fuctio is foud twice, this warig appears. You ca specify the optios for automatic compilatio i the sessio Maitai Developmet Parameters (tadv0110m000). Whe a error is foud i the program, all warigs after that error are suppressed. 2-49

66 3GL programmig laguage features 2-50

67 3 4GL programmig features Overview This sectio describes the 4GL features of the BAAN programmig laguage. Whe you create a sessio, the sessio geerator geerates a stadard source. This stadard source provides default sessio fuctioality. If the required fuctioality of the sessio is ot fully implemeted by the stadard source, you ca program the additioal fuctioality i a 4GL program script. I previous versios of the software, chages or additios to the default fuctioality for a sessio were programmed i a sigle script that was associated with the sessio. Both user iterface actios ad database actios were programmed i this script. I BaaERP, user iterface actios ad database actios have bee separated. The Data Access Layer (DAL) ow hadles database iteractio. Programmers create a user iterface (UI) script to chage the default behavior of a sessio. They create a DAL script to program all the logical itegrity rules for a particular table. This sectio discusses UI scripts. 4GL script types There are four types of 4GL program scripts: type 1 (with mai table): sigle-occurrece (details) sessio type 2 (with mai table): multi-occurrece (overview) sessio, with group fields type 3 (with mai table): multi-occurrece (overview) sessio, without group fields type 4 (without mai table): prit/processig sessios 3-1

68 4GL programmig features Evet-drive programmig 4GL scripts are evet orieted. They cosist of oe or more evet sectios i which you program actios to be performed at particular states of executio of the stadard program for example, whe a sessio is started, before a form is activated, before iput to a field, after iput to a field, ad so o. It is ot ecessary to program all sectios, oly those for which the stadard program does ot provide the required fuctioality. The statemets programmed i a sectio ca be a combiatio of 3GL/4GL fuctios ad 3GL statemets. For iformatio about the 3GL programmig laguage, see Chapter 2, 3GL programmig laguage features. Evet sectios A 4GL script ca cotai oe or more of the followig types of sectios: Program sectios Form sectios Group sectios Choice sectios Field sectios Zoom sectios Mai table sectios With the exceptio of program sectios, each sectio cosists of a mai sectio ad oe or more subsectios. A mai sectio idicates the object for which the programmed actios must be executed. A subsectio specifies whe the actios must be executed. Program sectios cosist of a mai sectio oly. If you do ot iclude a mai sectio immediately before a subsectio, the subsectio is assiged to the previous mai sectio i the script. For example: form.1: mai sectio iit.form: subsectio executed for form before.form: subsectio executed for form after.form: subsectio executed for form

69 4GL programmig features The followig rules apply to the orderig of sectios withi a script: The declaratio sectio must be the first sectio i the script. The fuctios sectio must be the last sectio i the script. Other sectios ca occur i ay order, but the preferred order is: program sectios, form sectios, group sectios, choice sectios, field sectios, zoom sectios, mai table sectios. Do ot mix sectios of differet types. For example, do ot defie a choice sectio, followed by a field sectio, ad the a choice sectio agai. Exceptios are the declaratio ad fuctios sectios, which must be the first ad last sectios respectively i the script. Variables declared i the declaratio sectio are global variables that you ca use i other sectios. Variables declared withi ay other sectio are local variables that you ca use i that sectio oly. Program sectios You use program sectios to defie fuctios, ad to declare tables ad global variables, that you wat to use i the other sectios i the script. You also use program sectios to program actios that you wat to be executed whe the sessio starts or eds. The followig program sectios are available. They are all mai sectios. There are o subsectios associated with program sectios. Mai sectios declaratio: Use this sectio to declare tables ad global variables that you wat to use i other sectios i the script. See, Declaratios ad Tables i Chapter 2 for details of the declaratio sytax. You also use this sectio to defie fuctio prototypes. before.program: Use this sectio to program actios that must be executed whe the sessio starts. For example, you ca use this sectio to iitialize or import variables or to read a special record. Note that the default values or imported values overwrite the fields of the mai table. 3-3

70 4GL programmig features o.error: Use this sectio to program actios that must be executed at the ed of the sessio, before the after.program sectio. If the sessio is caceled, the actios i this sectio are ot executed. If a error is detected, you ca check the predefied variable e for the error code. after.program: Use this sectio to program actios that must be executed at the ed of the sessio, after the o.error sectio. If the sessio is caceled (with the commad ABORT.PROGRAM), the actios i this sectio are ot executed. after.update.db.commit: Use this sectio to program actios that must be executed immediately after a commit.trasactio() call, if the database is updated. before.display.object: Use this sectio to program actios that must be executed each time the etire record is displayed. fuctios: Use this sectio to defie the fuctios used i the other sectios. This must be the last sectio i the script. The fuctio sytax is the same as for 3GL fuctios. 3-4

71 4GL programmig features Example declaratio: table tpctst999 log var01, ret before.program: if read_parameter() the mess("pctsts0001", 1) Parameter ot preset stop() edif o.error: mess("...", 1) fuctios: fuctio log read_parameter() { select pctst999.* from pctst999 order by pctst999._idex1 as set with 1 rows selectdo retur(0) selectempty retur(1) edselect } Form sectios You use form sectios to program actios that you wat to be executed whe forms are activated or eded. Form sectios cosist of a mai sectio ad a subsectio. The mai sectio specifies the particular form(s) for which the actios are to be executed. The subsectios specify whe the actios must be executed for example, whe the form is activated or whe the form is eded. Mai sectios form.<form umber>: The subsectios associated with this sectio are executed for the specified form. The <form umber> is the sequece umber of the form, as defied i the Maitai Sessios by Package VRC sessio (ttadv2100m000). 3-5

72 4GL programmig features form.all: The subsectios associated with this sectio are executed for all forms of the sessio. form.other: A subsectio associated with this sectio is executed for all forms for which the particular subsectio has ot bee programmed i a form.<form umber> sectio. Subsectios iit.form: The actios programmed i this subsectio are executed the first time the specified form becomes curret, immediately before the subsectio before.form. You use this subsectio to program the first actio to be performed by the system a first.set or first.view, for example. before.form: The actios programmed i this subsectio are executed each time the specified form becomes curret. after.form: The actios programmed i this subsectio are executed each time the specified form is eded. Example: form.1: iit.form: execute(first.set) form.other: iit.form: display("disp3") form.all: before.form: display("disp") Note: Oly the form.all sectio is relevat to dyamic forms. For dyamic forms, use the group sectios istead. 3-6

73 4GL programmig features Group sectios With dyamic forms, the mappig of groups to forms is ot fixed. Cosequetly, the oly form sectio that is relevat to dyamic forms is the form.all sectio. Whe dealig with dyamic forms, you use group sectios istead of form sectios You use group sectios to program actios that you wat to be executed whe particular groups are activated or eded. Group sectios cosist of a mai sectio ad a subsectio. The mai sectio specifies the particular group(s) for which the actios are to be executed. The subsectios specify whe the actios must be executed for example, whe the group is activated or whe the group is eded. Note that a group becomes active whe the form o which it occurs becomes curret. Mai sectio group.<group umber>: This sectio defies the group for which the actios programmed i the group subsectios are executed. The group umber is automatically geerated whe the group is created. Subsectios iit.group: The actios programmed i this subsectio are executed oly the first time the group becomes active, immediately before the before.group subsectio. You use this subsectio to program the first actio to be performed by the system whe the group becomes active. Whe the group is split across two or more forms (because ot all the group fits o oe form or because it is a repeatig group), this subsectio is executed the first time that the first form o which the group occurs becomes curret. Note: the iit.group sectio for group.1 is the former iit.form sectio for form.1. Group umber 1 is ot oe of the groups i the form-defiitio. before.group: The actios programmed i this subsectio are executed each time the specified group becomes active. Whe the group is split across more tha oe form, this subsectio is executed wheever ay form o which it occurs becomes curret. 3-7

74 4GL programmig features after.group: The actios programmed i this subsectio are executed each time the form o which the group occurs is eded. Whe the group is split across more tha oe form, this sectio is executed wheever ay form o which the group occurs is eded. Choice sectios You use choice sectios to program actios that you wat to be executed whe stadard commads are activated or eded. Choice sectios cosist of a mai sectio ad a subsectio. The mai sectio specifies the stadard commad for which the actios must be executed. The subsectios specify whe the actios must be executed. Mai sectio choice.<stadard commad>: The subsectios associated with this mai sectio are executed for the specified stadard commad. You use the Maitai Forms by Package VRC sessio to select the stadard commads (ttadv3100m000) for each form. A list of stadard commads appears at the ed of this help topic. Subsectios before.choice: The actios programmed i this subsectio are executed immediately before the specified commad is executed. You ca use this subsectio, for example, to test data before the commad process cotiues. You ca use the choice.agai() fuctio to stop the commad. o.choice: The actios programmed i this subsectio are executed whe the specified commad is activated. These actios are executed istead of the stadard actio associated with the commad. 3-8

75 4GL programmig features This subsectio is available for the followig commads oly: prit.data ru.job global.delete global.copy bms all commads i type 4 programs (except modify.set, restart.iput, ed.program, abort.program) after.choice: The actios programmed i this subsectio are executed immediately after the specified commad has bee executed. This subsectio is ot available for the ed.program ad abort.program commads. For example: choice.first.view: after.choice: execute(first.set) Stadard commads The followig table lists the available stadard commads ad the types of program i which the various choice subsectios ca be programmed for each commad. No Choice_optio Descriptio Before O After 01 start.set Add/start a ew group i mai table 02 first.view View first group of mai table 03 ext.view View ext group of mai table 04 prev.view View previous group of mai table 05 last.view View last group of mai table 06 def.fid Fid a specific record o key

76 4GL programmig features 07 fid.data Start the set from the curret data i the program script. Use: after import of data i a zoom process. (refresh) 08 first.set View first set of mai table 09 ext.set First execute a update.db ad the view ext set of mai table display.set Ope read-oly details prev.set First execute a update.db ad the view previous set of mai table 12 rotate.curr Show amouts i other currecy (o.choice subsectios are available for this commad oly if o currecies are set) 13 last.set View last set of mai table add.set Isert a ew record update.db First test cosistecy of data ad the (re)write record or set (save) 16 dupl.occur Copy the record to a ew oe 17 recover.set Udo modificatios which are ot yet writte to the database mark.delete Delete selected records mark.occur Select a record o the scree chage.order Chage the search key

77 4GL programmig features No Choice_optio Descriptio Before O After 21 modify.set Chage a record stored i the database 23 prit.data Make a report with the curret data o the form create.job Add sessio i job form.tab.chage Go to aother form i sessio first.frm Go to first form ext.frm Go to ext form prev.frm Go to previous form last.frm Go to last form resize.frm Resize the curret form cmd.optios Show available form optios 34 zoom Zoom to aother sessio/meu 35 iterrupt Do a actio each time iterval 36 ed.program Ed executio of the sessio; the mai table will be updated 37 abort.program Cacel executio of the sessio. The mai table is ot updated text.maager Start the text maager ru.job Ru job of sessio global.delete Delete rage of records global.copy Copy rage of records save.defaults Save values as defaults

78 4GL programmig features No Choice_optio Descriptio Before O After 44 get.defaults Get previous stored defaults start.chart Chart Maager is started start.query Start query by form ask.helpifo Asks for sessio help calculator Calculator will be started caledar Caledar will be started bms A broadcast message is received cmd.whats.this Asks for field help help.idex Asks for the help idex The followig commads are supported for backward compatibility oly. Support is ot guarateed i future versios of the software. 22 restart.iput Restart the iput after givig <Esc> durig iput mode cot.process Start user defied process user.0 User optio user.1 User optio user.2 User optio user.3 User optio user.4 User optio user.5 User optio user.6 User optio user.7 User optio user.8 User optio user.9 User optio

79 4GL programmig features Field sectios You use field sectios to program actios that you wat to be executed for a variety of field evets. Field sectios cosist of a mai sectio ad a subsectio. The mai sectio specifies the field(s) for which the actios must be executed. The subsectios specify whe the actios must be executed. Mai sectios field.<field ame>: The subsectios associated with this mai sectio are executed for the specified field. The field ame you specify must correspod with the ame o the form. field.all: The subsectios associated with this mai sectio are executed for all fields o the form field.other: A subsectio associated with this sectio is executed for all fields for which the particular subsectio has ot bee programmed i a field.<field ame> sectio. Subsectios iit.field: The actios programmed i this subsectio are executed the first time that the form o which the field occurs becomes curret. The subsectio is executed immediately before the iit.form sectio of the form. You ca use this sectio to chage field attributes. before.field: The actios programmed i this subsectio are executed each time the focus moves to the specified field. The subsectio is executed immediately before the before.iput or before.display subsectios. before.iput: The actios programmed i this subsectio are executed immediately before iput to a iput field commeces. This sectio is supported for backward compatibility oly. I BaaERP programs, use eable.fields() ad disable.fields() to eable ad disable fields. 3-13

80 4GL programmig features before.display: The actios programmed i this subsectio are executed each time that the specified field is displayed. You ca use this subsectio, for example, to set the value of a display field or to chage the output format of currecies ad dates (by usig attr.oformat$). before.zoom: Whe a zoom process is started o the specified field, the actios programmed i this subsectio are executed immediately before the zoom process is executed. You ca use this subsectio to chage the zoom attributes. For example, i the field defiitio i the form maager, a default zoom code ca be specified. You ca the use this subsectio to chage the zoom code (by settig the predefied variable attr.zoomcode). before.checks: The actios programmed i this subsectio are executed after iput to the field has bee completed ad the TAB key has bee pressed. The subsectio is executed immediately before the domai ad refereces are checked. You ca use this sectio, for example, to chage the value of the field before the domai ad referece checks. domai.error: The actios programmed i this subsectio are executed if the domai check causes a error after data has bee etered i the field. You ca use this sectio to provide your ow error message istead of the stadard message. ref.iput: The actios programmed i this subsectio are executed if a referece error occurs. If you program this sectio, the stadard program does ot display a message. ref.display: The actios programmed i this subsectio are executed if there is a error i the referece display. 3-14

81 4GL programmig features check.iput: The actios programmed i this subsectio are executed immediately after the domai ad referece checks. You ca use this sectio to test for errors that are ot detected automatically. If the stadard program detects a error, iput is automatically restarted. I a script, you ca use set.iput.error() to display a error message ad start iput agai. This sectio is replaced by DAL fuctioality (if a DAL exists for the table). o.iput: The actios programmed i this subsectio are executed immediately after the check.iput subsectio. You ca use this sectio, for example, to perform some appropriate actio whe the user eters a special character or to display a warig message i certai cases. whe.field.chages: The actios programmed i this subsectio are executed whe the ew value etered i the specified field differs from the old value. after.zoom: The actios programmed i this subsectio are executed whe the zoom process o a specified field eds. You ca use this subsectio, for example, to redisplay ay field that has chaged as a result of the zoom process. after.iput: The actios programmed i this subsectio are executed after all checks have bee performed o iput to the specified field ad after the whe.field.chages subsectio has bee executed. I this subsectio, you ca use the to.field() fuctio if the sequece deviates from the default. after.display: The actios programmed i this subsectio are executed just after display of the specified field. You ca use this subsectio, for example, to read referece tables. 3-15

82 4GL programmig features after.field: This is the last subsectio for a field. The actios programmed i this subsectio are executed after iput to or display of the specified field. This sectio is always executed, eve if the user left the field by pressig ESC, oe of the arrow keys, or a mouse butto. You ca use this subsectio to perform special actios before leavig the field. Example field.pctst099.item: check.iput: select pctst001.* from pctst001 where pctst001.item = :pctst099.item as set with 1 rows selectdo... selectempty pctst001.dsca = "*****" set.iput.error("...") edselect before.iput: if... the attr.iput = false edif after.display: select pctst001.* from pctst001 where pctst001.item = :pctst099.item as set with 1 rows selectempty pctst001.dsca = "*****" edselect field.pctst099.date: before.iput: attr.oformat$ = "%D002,2" 3-16

83 4GL programmig features Zoom.from sectios You use zoom.from sectios to program actios that you wat to be executed whe the curret sessio is activated as a zoom process. A zoom process ca be activated by a form-specific commad of type sessio, by zoomig o a iput field, by pressig CTRL+B, or by callig zoom.to$() i the program script. Zoom.from sectios cosist of a mai sectio ad a subsectio. The mai sectio specifies the process for which the actios must be executed. The subsectios specify whe the actios must be executed. Mai sectios zoom.from.<zoom ame>: Each field has a ame that ca be used as a zoom ame. You ca specify the zoom ame i this mai sectio. The zoom ame idicates which field the curret sessio was zoomed from (whe the subprocess is started from a form commad, the zoom ame is "choice"). The subsectios associated with this mai sectio are executed whe the curret process was zoomed to from the specified process. zoom.from.all: The subsectios associated with this mai sectio are executed for all processes from which the curret sessio ca be zoomed to. zoom.from.other: A subsectio associated with this sectio is executed for all processes for which the particular subsectio has ot bee programmed i a zoom.from.<zoom ame> sectio. Subsectios o.etry: The actios programmed i this subsectio are executed each time the curret process is started from the specified process(es). You ca use this subsectio to import variables. 3-17

84 4GL programmig features o.exit: The actios programmed i this subsectio are executed at the ed of the curret process, if the curret process was started from the process(es) specified i the mai sectio. You ca use this subsectio to export variables. Example zoom.from.all: o.etry: import("globvar", localvar) o.exit: export("globvar", localvar) Mai table sectios You use mai table i/o sectios to program actios that you wat to be executed whe read or write actios occur o the mai table. These sectios are ot relevat to type 4 programs, as such programs do ot have a mai table. Mai table i/o sectios cosist of a mai sectio ad a subsectio. The mai sectio is always mai.table.io. The subsectio idicates whe the actios must be executed. Note that mai.table.io sectios (except the read.view subsectio) are igored whe the correspodig DAL hooks are programmed i a DAL script. Mai sectio mai.table.io: The subsectios associated with this mai sectio are executed either before or after iput to or output from the mai table. The mai table for the curret sessio is defied i the data dictioary. Subsectios before.read: The actios programmed i this subsectio are executed immediately before each read actio o the mai table. 3-18

85 4GL programmig features after.read: The actios programmed i this subsectio are executed after each read actio o the mai table. You ca use this subsectio to call skip.io() i order to skip the record just read ad to read the ext record (if ecessary). before.write: The actios programmed i this subsectio are executed before each write actio o the mai table. A write actio occurs whe a record is iserted. You ca use this subsectio to call skip.io() i order to udo the write actio. after.write: The actios programmed i this subsectio are executed after each write actio o the mai table. A write actio occurs whe a record is iserted. You ca use this subsectio, for example, to write data to tables other tha the mai table. after.skip.write: The actios programmed i this subsectio are executed if a write actio o the mai table has bee skipped as a result of actios programmed i the before.write subsectio. The actios are executed immediately after the skip actio. before.rewrite: The actios programmed i this subsectio are executed immediately before each rewrite of a record i the mai table. A rewrite actio occurs whe a record is chaged. You ca use this subsectio to call skip.io() i order to skip the rewrite actio. after.rewrite: The actios programmed i this subsectio are executed after each rewrite actio o the mai table. A rewrite actio occurs whe a record is chaged. after.skip.rewrite: The actios programmed i this subsectio are executed if a rewrite actio o the mai table has bee skipped as a result of actios programmed i the before.rewrite subsectio. The actios are executed immediately after the skip actio. 3-19

86 4GL programmig features before.delete: The actios programmed i this subsectio are executed immediately before each delete actio o the mai table. You ca use this sectio to call skip.io() i order to skip the delete actio. after.delete: The actios programmed i this subsectio are executed immediately after each delete actio o the mai table. You ca use this subsectio, for example, for deletig refereces, if this is ot doe automatically. after.skip.delete: The actios programmed i this subsectio are executed if a delete actio o the mai table has bee skipped as a result of actios programmed i the before.delete subsectio. The actios are executed immediately after the skip actio. read.view: The actios programmed i this subsectio are executed immediately after a view actio o the mai table (start.set, first.view, ext.view, prev.view or last.view). You ca use this subsectio to call skip.io() i order to skip a etire set of records with the same value i the view fields. Example mai.table.io: before.delete: if (ot pctst099.del) the skip.io("pctsts0001") caot be deleted edif read.view: if strip$(pctst099.cprj) = "" the skip.io("") edif 3-20

87 4GL programmig features Flow of stadard program This sectio presets the geeral flow of the stadard program. It is ot complete, but the most importat actios are icluded. The flow is similar for programs of types 1, 2, 3, ad 4. Ay differeces are idicated by commets. Mai routie The mai routie displays the first form o the scree ad waits for a commad. fuctio mai() { before.program read.form() iit.refereces create.sql.queries if backgroud the get.ref.var(paret) read record edif db.bid(tmai) Not i type 4 if job.process the Oly type 4 before.choice.ru.job execute(cot.process) or o.choice.ru.job after.choice.ru.job execute(ed.program) edif zoom.from.o.etry for each field o form iit.field put.attributes() edfor chage to start idex Not i type 4 iit.form execute start evet before.form while true iput.choice() if update.status ad choice <>... the Not i type 4 o.update.db() See "update database" sectio edif o case choice case <choice.optio> before.<choice.optio> o.<choice.optio> after.<choice.optio> break 3-21

88 4GL programmig features case edcase edwhile Choice sectios The choice sectios above are give as before.choice.optio ad after.choice.optio. I a 4GL program, a choice sectio cosists of the mai sectio choice.choice.optio ad oe of the subsectios before.choice, o.choice, or after.choice. Form sectios Whe chagig from form X to form Y, the form sectios are executed i the followig sequece: after.form for X iit.form for Y (oly the first time) before.form for Y The above subsectios ca be defied, as follows: for all forms : form.all for a specific form : form.<form ame> for forms ot specifically defied : form.other At iit.form the sequece is: form.all: iit.form form.<form ame>: iit.form or form.other: iit.form 3-22

89 4GL programmig features At before.form the sequece is: form.all: before.form form.<form ame>: before.form or form.other: before.form At after.form the sequece is: form.<form ame>: after.form or form.other: after.form form.all: after.form Field sectios There are two groups of field sectios: sectios for which the field.all sectio is executed first: iit.field before.field before.iput before.display before.checks before.zoom check.iput if ot i DAL o.iput sectios for which field.all is executed after field.<field ame> or field.other: after.iput after.display after.zoom ref.iput ref.display domai.error whe.field.chages after.field The geeral flow of iput fields is as follows: Field.iput: before.field if ot iput.field the read.referece if error.referece the ref.display else before.display display.field() after.display edif 3-23

90 4GL programmig features retur edif before.iput if iput disabled the read.referece if error.referece the ref.display else before.display display.field() after.display edif retur edif zoom.ret: do.iput.field() if i.ret = ZOOM the before.zoom zoom.to... after.zoom goto zoom.ret edif if choice = f.to.choice or i.ret = arrow.up/dow/left/right/tab the goto after.field edif before.checks check.domai() if domai.error the domai.error error.message goto field.iput edif check.referece if referece.error the ref.iput error.message goto field.iput edif check.iput if check.iput.error the error.message goto field.iput edif o.iput

91 4GL programmig features whe.field.chages after.iput after.field Ed of program The flow of the ed of the program is as follows. The fuctio ed.of.program() is called whe executig the stadard commad END.PROGRAM. fuctio ed.of.program() { before.ed.program if e the o.error edif after.form after.program if zoomfield <> "" the fill.zoomretur zoom.from.o.exit if record.marked the commit.trasactio() Not i type 4 exit(exit.val) edif edif commit.trasactio() Not i type 4 exit() } Zoom sectios The zoom.from.o.etry ad zoom.from.o.exit sectios are used I the mai routie ad i the ed.of.program() fuctio. I a 4GL program, a zoom sectio cosists of a mai sectio (zoom.from.all, zoom.from.<zoomame>, or zoom.from.other) ad a subsectio (o.etry or o.exit). The sequeces i which the sectios are executed differ for o.etry ad o.exit. For o.etry, zoom.from.all is executed first ad the zoom.from.<zoomame> or zoom.from.other. For o exit, it is the other way aroud. Update database A update of the database is ecessary if a record is added, chaged or deleted. The actual update is executed if oe of the followig actios is activated after a record has bee added, chaged or deleted: start.set, def.fid, fid.data, first.set, ext.set, prev.set, last.set, ext.help, prev.halfset, chage.order, cot.process. 3-25

92 4GL programmig features All these actios first call o.update.db() if a record is added, chaged or deleted. The geeral flow of the o.update.db() is as follows. Note that this fuctio is ot relevat to programs of type 4. o.update.db() { if update.status = add.set or modify.set the for all occurreces check.domais() if domai.error the domai.error error.message retur edif check.refereces if referece.error the ref.iput error.message retur edif for each field of occurrece check.iput if check.iput.error the error.message retur edif edfor edfor edif before.update.db db.retry.poit() for all occurreces before.write / before.rewrite / before.delete if ot skip the write / rewrite / delete record after.write / after.rewrite / after.delete else after.skip.write / after.skip.rewrite / after.skip.delete edif edfor back.to.old.key after.update.db commit.trasactio() after.update.db.commit } 3-26

93 4GL programmig features Mai table i/o sectio Most of the mai table i/o are metioed above. They are ot available i programs of type 4. The read.view sectio is executed immediately after ay view actio o the mai table (oly i type 3 programs). The fuctio skip.io("messcode") ca be used i this sectio. This implies that the ext or previous view is read. Automatic import of variables Whe you zoom from a mai process to a subprocess, i some cases variables are imported automatically. Case 1 From the mai process with mai table X you have zoomed to the subprocess with mai table Y. Table X has a foreig (cross-referece) key to table Y. For example, X = customer table, Y = currecy table. The currecy field i the customer table refers to the currecy table. The stadard program imports the field(s) from table X ad stores them i the primary key fields of table Y. Cosequeces for programmig i script I the script of the subsessio, oly the followig eeds to be programmed: if backgroud the execute(fid.data) (or, sometimes, for type 3 screes: execute(first.set)) else... edif There is o eed to adjust the mai sessio i order to import the variables ito the subsessio. Case 2 From the mai process with mai table X, you have zoomed to the subprocess with mai table Y. A field i table Y refers to table X. (I most cases, there is a idetifyig relatioship betwee table X ad table Y for example, order header (table X) ad order lies (table Y).) The stadard program imports the primary key values from table X ad stores them i the correspodig fields of table Y. 3-27

94 4GL programmig features Example Primary key of table X is Order umber; primary key of table Y is Order umber, positio umber. The stadard program imports the order umber from table X to the correspodig field i table Y. The positio umber i table Y remais, of course, empty. Cosequeces for programmig i script See Case 1 above. Case 3 From the mai process with mai table X, you have zoomed to the subprocess with the same mai table. (For example, a zoom from Maitai Item Data (type 1) to Display Item Data (type 2 or 3).) The stadard program imports the primary key value from table X for the mai process ad stores it i the primary key fields of table X for the subprocess. Cosequeces for programmig i script See Case 1 above. Case 4 From the mai process with mai table X you have zoomed to a subprocess without a mai table (for example, a prit program). The stadard program imports the primary key values of mai table X for the mai process ad stores them i the primary key fields of table X (if available) for the subprocess. Example A zoom from Maitai Item Data to Prit Item Data. The mai table for the mai process is tstpi100. The subprocess imports values of tstpi100.cuo ad tstpi100.item from the mai process ad stores them i the fields of the subprocess. Cosequeces for programmig i script I may cases, you must reprogram the mai process i such a way that the primary key fields of the mai table for the subprocess are filled. 3-28

95 4GL programmig features Case 5 From the mai process without a mai table you have zoomed to a subprocess with mai table X. The stadard program imports the primary key values of table X (if available) for the mai process ad stores them i the primary key fields of the subprocess s mai table. Example A zoom from Prit Item Data to Display Item Data. The mai table for the subprocess is ttstpi100. The stadard program tries to import tstpi100.cuo ad tstpi100.item from the mai process ad stores them i the fields of the mai table for the subprocess. Cosequeces for programmig i script See Case 1 above. I may cases you must reprogram the mai process i such a way that the primary key fields of the mai table for the subprocess are filled. Example field.item.t: before.zoom: tstpi100.cuo = cuo.f tstpi100.item = item.f Case 6 From the mai process with table X you have zoomed to a subprocess with table Y. There is o relatioship betwee table X ad table Y (oe has bee defied i the data dictioary). The stadard program imports the primary key values of table Y for the mai process (if available) ad stores them i the primary key fields of table Y for the subprocess. Cosequeces for programmig i script See Case 1 above. Ofte you will have to reprogram the mai process i such a way that the primary key fields of the mai table for the subprocess are filled. 3-29

96 4GL programmig features Example field.tswoc150.item: before.zoom: tstpi100.cuo = tswoc100.cuo tstpi100.item = tswoc150.item 3-30

97 4 Report scripts Overview BaaERP reports are used to output data from the database to a variety of devices (for example, priters, displays, ad files). The cotets ad layouts of reports are defied i the data dictioary. I additio, you ca lik a report script to a report. I a report script, you ca program actios that you wat to be performed at particular stages of the report executio. For example, you ca create a script to perform calculatios o the report data or to read records from related tables that are ot automatically available to the report. You program report scripts i the same way as you program 4GL program scripts, except that report scripts use differet evet sectios ad some special fuctios. Evet sectios A report script cosists of oe or more evet sectios i which you program actios to be performed at particular states of executio of the report to which the report script is liked. The statemets programmed i a report script sectio cosist of a combiatio of 3GL laguage statemets ad report script fuctios. Report scripts support the followig evet sectios: program sectios report sectios text field sectios Program sectios You use program sectios to defie fuctios, ad to declare tables ad global variables, that you wat to use i the other sectios i the script. You also use program sectios to program actios that you wat executed at the start ad ed of the report ad after the report writer receives a record. The followig program sectios are available. They are all mai sectios. There are o subsectios associated with program sectios. 4-1

98 Report scripts declaratio: Use this sectio to declare tables ad global variables that you wat to use i other sectios i the report script. See Declaratios ad Tables i Chapter 2 for details of the declaratio sytax. Note that there is o eed to declare a table if a field of that table is defied i the report writer as a iput field. The report writer declares such tables automatically. before.program: Use this sectio to program actios that must be executed whe the report is started. For example, you ca use this sectio to iitialize or import variables. after.program: Use this sectio to program actios that must be executed at the ed of the report. For example, you ca use this sectio to close files that were opeed durig executio of the report. after.receive.data: Use this sectio to program actios that must be executed wheever the report writer receives a record. For example, you ca use this sectio to read or modify a variable. fuctios: Use this sectio to defie fuctios that you wat to use i other sectios i the report script. The sytax of fuctios used i a report script is the same as for 3GL fuctios. Whe icluded, this sectio must be the last sectio i the report script. Report sectios A report cosists of a umber of layouts, which defie the cotet ad orgaizatio of the various parts of a report (for example, the header, footer, ad body of the report). There are a umber of possible layout types, as follows: before.report prited oce at begiig of the report (a title page, for example) after.report prited oce at the ed of the report header prited at the top of each page 4-2

99 Report scripts footer prited at the bottom of each page before.field prited before each group of records i reports of type 3; if a group of records spas more tha oe page, the before.field layout is repeated at the top of the ew page after.field prited immediately after each group of records i reports of type 3 detail used for the idividual records icluded i the body of the report The cotet ad arragemet of these layouts are defied i the data dictioary. I the report sectios i a report script, you ca program actios to be performed before ad/or after executio of idividual layouts of these types. Report sectios cosist of a mai sectio ad a subsectio. You use a mai sectio to specify the particular layout for which the programmed actios are to be executed. You must follow a mai sectio with either a before.layout or a after.layout subsectio. These latter specify whether the actios are to be executed before or after the particular layout is prited. Mai sectios before.report.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type before.report. after.report.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type after.report. header.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type header. detail.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type detail. before.<field ame>.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type before.field. 4-3

100 Report scripts after.<field ame>.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type after.field. footer.<layout_umber>: Actios programmed i this sectio are executed for a specified layout of type footer. Subsectios before.layout: Actios programmed i this subsectio are executed before the specified layout is prited. Whe lattr.prit is set to false, the layout is ot prited ad the before.layout ad after.layout sectios are ot executed. If you set lattr.prit to false i the before.layout sectio itself, the layout is ot prited ad the after.layout sectio is ot executed. after.layout: Actios programmed i this subsectio are executed after the specified layout is prited. Text field sectios You use a text field sectio to apply certai actios to all istaces of a particular text field that are icluded i the report. A text field sectio cosists of a mai sectio ad a subsectio. The mai sectio specifies the particular text field to which the actios must be applied. The subsectio specifies that the actios are to be performed before the text field is prited. For example, you could iclude the page(), eed(), ad skip() fuctios i a text field sectio to eforce a page break or to skip a specified umber of lies before the text field is prited. Or you could set lattr.prit i the sectio i order to skip oe text lie before pritig the text field. 4-4

101 Report scripts Mai sectio field.<text_field>: Actios programmed i this sectio are executed for all istaces of the specified text field that are icluded i the report. The text field must have bee defied as a report iput field i the data dictioary. Subsectio before.prit: Actios programmed i this sectio are executed before the specified text field is prited. Predefied variables You ca use the followig predefied variables i a report script. R = read-oly R/W = read ad write lattr.autobefores R/W A boolea idicatig whether or ot before.field layouts are automatically repeated at the top of a page if the page break does ot correspod with a sort break. The default value is true. lattr.autoreset R/W A boolea idicatig whether or ot reset.suppress() is automatically performed i the case of breaks of layouts i sortig fields. The default value is true. lattr.break R A boolea that is set to true durig pritig of before.field layouts whe the layout is prited as the result of a sort field chage. It is set to false whe a before.field layout is prited because of a page break. lattr.eddata R A boolea idicatig whether or ot the ed of the data has bee reached. lattr.header R A boolea that is set to true durig pritig of header layouts ad durig pritig of before.field layouts at the top of a page. lattr.laguage$ R The laguage code of the report. 4-5

102 Report scripts lattr.lieo R The curret lie umber. lattr.multicol R/W Idicates whether or ot multiple colums are used whe more tha oe layout fits o a lie. Possible values are: MULTICOL_NONE Normal output; o colums are used. MULTICOL_ORDER_HORIZONTAL Output is arraged i multiple colums, ordered horizotally. For example: rec_1 rec_2 rec_3 rec_4 rec_5 rec_6 MULTICOL_ORDER_VERTICAL Output is arraged i multiple colums, ordered vertically (per page). For example: rec_1 rec_3 rec_5 rec_2 rec_4 rec_6 lattr.multicol.cout R/W Specifies the umber of colums to use whe multiple colums are specified (see lattr.multicol). The default value is 0. I this case, the report maager calculates the umber of colums based of the report width ad the layout width. lattr.multicol.repeat R/W A boolea idicatig whether headers ad footers are automatically repeated for each colum. The default value is true. The width of the header ad footer layouts width must be equal to or less tha the width of the detail layout. lattr.pageo R/W Curret page umber. lattr.prit R/W Idicates whether or ot a layout is to be prited. lattr.prlie R/W After expasio of a variable i a report, this is filled with the text lie that is prited. lattr.recordtimes R/W Idicates the umber of times the layout will be prited. 4-6

103 Report scripts lattr.textexpad R/W A boolea idicatig whether or ot variables icluded i text fields ca be expaded. The default is false. lattr.textlag$ R/W The laguage code for pritig text. The default is the laguage code of the report. lattr.textlie R A strig cotaiig the source text lie from the text maager. lattr.textlieo R The umber of the lie that must be prited. lattr.textlies.max R/W The maximum umber of lies i the layout. lattr.textlies.mi R/W The miimum umber of lies i the layout. Report script fuctios The statemets programmed i a report script sectio cosist of a combiatio of 3GL laguage statemets ad the followig 4GL report fuctios: layout.agai() eed( expr ) page() reset.suppress() skip( expr ) skip.to( expr ) to.page( expr ) Evaluate ad prit layout agai. Force a page break if the umber of free lies is less tha expr. Start a ew page. It is possible to suppress pritig a value whe it is the same as the previous value. You ca use this fuctio to suppress the value oce (that is, for oe value). Skip expr umber of lies before pritig the ext layout. Skip to the lie umber idicated by expr. Iterveig lies are left blak. If the specified lie umber is less tha the curret page umber, a ew page is started. Start a ew page with umber expr. You caot use eed(), page(), skip(), skip.to(), or to.page() i header ad footer layouts. 4-7

104 Report scripts Expadig text variables Variables or expressios that are icluded i text lies ca be expaded or substituted for report purposes. You must set the variable lattr.textexpad=true if you wat this to happe. Expressios are iterally evaluated by the fuctio expr.compile(). Customers ca use variables i texts. For example, "address", "city", "salary" ad so o. Customers must be iformed about these variables so that they ca use them. Sytax The followig is the sytax for variables ad expressios icluded i text lies: $variable or #variable ${expressio} or #{expressio} Whe the $ symbol if used, the text moves over to accommodate the expaded variable or expressio. Whe the # symbol is used, the expaded variable or expressio overwrites existig text. Example The followig is a example of text created by usig the text maager. The text icludes both variables ad expressios that ca be expaded/substituted for report purposes. To: $surame $christia ame #date, Ede $address $ZIP code $city Dear $christia ame: We have the pleasure of iformig you that, as of $date, your salary has bee raised by 5%. For you this implies a gross amout of ${edit( salary + ( salary * 0.05 ), "ZZZZ9,ZZ" )} per moth. Kid regards, $Mgr. 4-8

105 5 Database hadlig Overview BaaERP data is stored i a relatioal database, which is maaged by a Relatioal Database Maagemet System (RDBMS). The RDBMS acts as the database server for BaaERP applicatios. BaaERP supports the followig RDBMS products: Iformix Oracle Sybase DB2 Microsoft SQL Server The BaaERP architecture icludes a database driver. This provides the applicatio server (that is, the bshell) with a commo iterface to the database server, regardless of which RDBMS product is used. This eables the applicatio server to be database idepedet. The database driver is resposible for traslatig database commads received from the applicatio server ito RDBMS-specific commads. Although, the database driver s iterface with the applicatio server is the same for all RDBMS products, Its iterface with the RDBMS is RDBMS-specific. Therefore, there is a separate database driver for each of the supported RDBMS products. 5-1

106 Database hadlig Database tables A relatioal database presets iformatio to the user i the form of tables. I a table, data is orgaized i colums ad rows. Each colum (also referred to as a field) represets a category of data. Each row (also referred to as a record) represets a uique istace of data for the categories defied by the colums. A field always refers to a domai, which defies a set of values from which oe or more fields ca draw their actual values. For example, the tcweek domai is the set of all itegers greater tha zero ad less tha or equal to 53. Primary keys Every database table has a field, or a combiatio of fields, which uiquely idetify each record i the table. This uique idetifier is referred to as the primary key. Primary keys are fudametal to database operatios, as they provide the oly record-level addressig mechaism i the relatioal model. Primary keys act as refereces to the records i a table. Relatioships/refereces With a relatioal database, you ca store data across multiple tables ad you ca defie relatioships betwee the tables. This meas that idividual tables ca be kept small ad data redudacy ca be miimized. A relatioship exists betwee two tables whe they have oe or more fields i commo. So, for example, a Customer Details table ca be liked to a Orders table by icludig a Customer ID field i both tables. I the Customer Details table, the Customer ID field is the primary key. I the Orders table, it is referred to as a foreig key. By likig the two tables i this way, there is o eed for the Orders table to iclude customer details such as ame ad address. Note that refereces from oe table to aother must always use the primary key. 5-2

107 Database hadlig Combied fields A combied field is a field that cosists of two or more child fields. You ca use combied fields as primary keys, ad you ca also use them for refereces ad idexes. Idexes Idexes facilitate speedy searchig ad sortig of database tables. A idex is a special kid of file (or part of a file) i which each etry cosists of two values, a data value ad a poiter. The data value is a value for some field i the idexed table. The poiter idetifies the record that cotais this value i the particular field. This is aalogous to a covetioal book idex, where the idex cosists of etries with poiters (the page umbers) that facilitate the retrieval of iformatio from the body of the book. Note that it is also possible to costruct a idex based o the values of a combiatio of two or more fields. Every table must have at least oe idex, which is a idex o the primary key field(s). This is referred to as the primary idex. A idex o ay other field(s) is referred to as a secodary idex. Structured Query Laguage (SQL) Baa SQL is the database query laguage that you use to access data i the database tables. Usig Baa SQL, you ca costruct queries to retrieve specific data from the database. The sytax ad usage of Baa SQL is discussed fully i Baa SQL i Chapter

108 Database hadlig Namig covetios The amig sytax for tables, record buffers, ad table fields is as follows: tppmmmxxx table rcd.tppmmmxxx record buffer of table ppmmmxxx.ffffffff logical field of table where t stads for table, pp is the package code, mmm is the module code, xxx is the table umber (rage 000 to 999), ad ffffffff is a field ame (maximum 8 alphaumeric characters, startig with a alphabetic character). Usig tables i program scripts If a table is used i a script it must be declared with the followig statemet: table tppmmmxxx Declaratio of a table implies declaratio of all its fields ad its record buffer. It is ot ecessary to declare these separately. There are o special fuctios for opeig ad closig tables. A table is automatically opeed at the first database call o that table ad it is automatically closed at the ed of the program. You ca use the record buffer of a table to save the cotets of a record i a temporary strig. Ad you ca subsequetly restore the record from the buffer. If a record cotais umeric fields, you ca oly save ad restore records. You caot perform ay other actios o the temporary strig, as the presece of NULL characters will cause loss of data. Data types The data type is the iteral represetatio of table field ad domai data. The followig data types are available: DB.BITSET DB.BYTE DB.COMBINED DB.DATE DB.DOUBLE DB.ENUM DB.FLOAT DB.INTEGER DB.LONG DB.MAIL DB.MULTIBYTE DB.STRING DB.TEXT DB.TIME 5-4

109 Database hadlig Trasactio hadlig With respect to database actios, a trasactio is a sequece of related actios that are treated as a uit. The actios that make up a trasactio are processed i their etirety, or ot at all. A trasactio eds with the fuctio commit.trasactio() (all chages made durig the trasactio are stored i the database) or with the fuctio abort.trasactio() (o chages are stored i the database). A trasactio starts either at the begiig of a process, with the fuctio set.trasactio.readoly(), with the fuctio db.lock.table(), or after the precedig trasactio has eded. A trasactio is automatically rolled back (that is, it is udoe) whe a process is caceled ad if a program eds without a commit.trasactio() or abort.trasactio() after the last database call. Udoig a trasactio is oly possible if the uderlyig database system supports this. Certai database actios caot be placed withi a trasactio, because they caot be rolled back. These actios are: db.create.table(), db.drop.table(), ad set.trasactio.readoly(). These fuctios ca be called oly at the start of a program or after the ed of the precedig trasactio. You ca set a retry poit immediately before a trasactio. I case of a error, the system returs to this poit ad re-executes the trasactio from there. A read-oly trasactio is a trasactio i which you are permitted oly to read records (without lock) from the database. You retai read cosistecy durig the etire trasactio. This meas that durig the trasactio your view of the database does ot chage, eve if other users update the records. A read-oly trasactio starts with the fuctio set.trasactio.readoly() (this must be called after edig the precedig trasactio or at the begiig of the program) ad eds with a commit.trasactio() or abort.trasactio(). A cosistet view cosumes a large amout of memory, so a read-oly trasactio must be as short as possible; user iteractio durig the trasactio is ot recommeded. Lockig Database icosistecies ca arise whe two or more processes attempt to update or delete the same record or table. Read icosistecies ca arise whe chages made durig a trasactio are visible to other processes before the trasactio has bee completed for example, the trasactio might subsequetly be abadoed. 5-5

110 Database hadlig To avoid such icosistecies, BaaERP supports the followig lockig mechaisms: Record/page lockig Table lockig Applicatio lockig Record/page lockig To esure that oly oe process at a time ca modify a record, the database driver locks the record whe the first process attempts to modify it. Other processes caot the update or delete the record util the lock has bee released. However, they ca still read the record. While oe process is updatig a table, it is importat that other processes retai read cosistecy o the table. Read cosistecy meas that a process does ot see ucommitted chages. Updates become visible to other processes oly whe the trasactio has bee closed. Some database systems do ot support read cosistecy, ad so a dirty read is possible. A dirty read occurs whe oe process updates a record ad aother process views the record before the modificatios have bee committed. If the modificatios are rolled back, the iformatio read by the secod process becomes ivalid. Some databases, such as SYBASE, use page lockig istead of record lockig. That is, they lock a etire page i a table istead of a idividual record. A page is a predefied block size (that is, umber of bytes). The umber of records locked partly depeds o the record size. Supported features INFORMIX ORACLE SYBASE DB2 SQL Server lockig row row page row page dirty read yes o * cosistet read o yes * trasactios yes yes yes yes yes * SYBASE will block whe there is a read actio (locked or ot) o a record i a page that has bee locked. 5-6

111 Database hadlig Delayed locks Lockig a record for loger tha required ca result i uecessarily log waitig times. The use of delayed locks solves this problem to a great extet. A delayed lock is applied to a record immediately before chages are committed to the database ad ot earlier. Whe the record is iitially read, it is temporarily stored. Immediately before updatig the database, the system reads the value of the record agai, this time placig a lock o it. If the record is already locked, the system goes back to the retry poit ad retries the trasactio. If the record is ot locked, the system compares the cotet of the record from the first read with the cotet from the secod read. If chages have bee made to the record by aother process sice the first read, the error EROWCHANGED is retured ad the trasactio is udoe. If o chages have occurred, the update is committed to the database. You place a delayed lock by addig the keyword FOR UPDATE to the SELECT statemet (see BAAN SQL later i this chapter). For example: table tpctst999 db.retry.poit() SELECT pctst999.* FROM pctst999 FOR UPDATE SELECTDO pctst999.dsca = "..."... db.update(tpctst999, DB.RETRY) ENDSELECT Table locks BaaERP provides a table lockig mechaism, which eables you to lock all the records i a specified table. A table lock prevets other processes from modifyig or lockig records i the table but ot from readig them. This is useful whe a particular trasactio would otherwise require a large umber of record locks. You use the db.lock.table() fuctio to apply a table lock. Applicatio locks A applicatio lock prevets other applicatios ad users from readig ad/or modifyig a applicatio s data durig critical operatios. It is ot part of a trasactio ad so is ot automatically removed whe a trasactio is committed. Istead, a applicatio lock is removed whe the applicatio eds or whe appl.detete() is called. 5-7

112 Database hadlig NOTE Retry poits A retry poit is a positio i a program script to which the program returs if a error occurs withi a trasactio. The trasactio is the retried. There are a umber of situatios where retry poits are useful: Durig the time that a delayed lock is applied to a record/page, a error ca occur that causes the system to execute a abort.trasactio(). I such cases, all that BaaERP ca do is iform the program that the trasactio has bee aborted. However, if retry poits are used, the system ca automatically retry the trasactio without the user beig aware of this. Some database systems geerate a abort.trasactio() whe a dirty record is read (that is, a record that has bee chaged but ot yet committed). A abort.trasactio() may also be geerated whe two or more processes simultaeously attempt to chage, delete, or add the same record. I all these situatios, BaaERP Tools ca coceal the problem from the user by usig retry poits. It simply retries the trasactio. If there is o retry poit, the trasactio is aborted ad the sessio is termiated. I BaaERP, updates are buffered, so the success or failure of a update is ot kow util commit.trasactio() is called. If a update fails, the commit of the trasactio also fails, ad the etire trasactio must be repeated. If retry poits are used, the system automatically retries the trasactio. Retry poits ca also resolve potetial deadlock problems. If, for example, the system is uable to lock a record, it rolls the trasactio back ad tries agai. It is vital that retry poits are icluded i all update programs. Codig retry poits The retry poit for a trasactio must be placed at the start of a trasactio. The followig example illustrates how you program retry poits: db.retry.poit() set retry poit if db.retry.hit() the... code to execute whe the system goes back to retry poit else... iitializatio of retry poit edif The fuctio db.retry.hit() returs 0 whe the retry poit is geerated that is, the first time the code is executed. It returs a value uequal to 0 whe the system returs to the retry poit through the database layer. 5-8

113 Database hadlig Whe the system goes back to a retry poit, it clears the iteral stack of fuctios, local variables, ad so o that were called durig the trasactio. The program cotiues from where the retry poit was geerated. The value of global variables is NOT reset. Whe a commit fails, the database automatically returs to its state at the start of the trasactio; the program is set back to the last retry poit. It is vital, therefore, that the retry poit is situated at the start of the trasactio. The db.retry.hit() call must follow the db.retry.poit() call. Do ot place it i the SQL loop itself as this makes the code very utrasparet. Whe a retry poit is placed withi a trasactio, the system produces a message ad termiates the sessio. Testig retry poits The followig shell variables eable you to test the operatio of retry poits: TEST_RETRY=X This variable idicates how ofte the system must go back to a retry poit at the momet of committig. This caot be used whe testig differet sessios with retry poits parallel. MAX_RETRY=X This variable idicates how ofte the system may retur to a retry poit as a result of a abort i a update actio. Default: 10 Baa SQL You use Baa SQL (Structured Query Laguage) to retrieve iformatio from the database. With Baa SQL s SELECT statemet, you ca retrieve ay selectio of data from the database, regardless of the umber of tables i which the data is stored. The system does search through all records sequetially. It bases its search o a umber of coditios defied i the SELECT statemet. The SELECT statemet does ot modify the data i the database. It is used simply to query the data. Whereas oly oe user at a time ca modify data, ay umber of users ca query or select the data cocurretly. The SELECT statemet works at the table level; the output is also a table cosistig of 0, 1, or more records. If the query is very specific, the output may cosist of oly oe record. The structure of a SELECT statemet is directly derived from the table structure. It takes the followig geeral form: SELECT colums... FROM table(s)... WHERE each row fulfills the coditio(s)

114 Database hadlig The followig sectios provide iformatio o SQL sytax ad usig SQL. SQL sytax The geeral structure of a SQL query is as follows: SELECT <select list> [ FROM <from list> ] [ WHERE <where coditio> ] [ GROUP BY <group list> [ HAVING <havig coditio> ] ] [ ORDER BY <order by list> [WITH RETRY [REPEAT LAST ROW] ]] [ SET SPECIFICATION ] For full details of ay of the above clauses of the SELECT statemet, see the sectios below. SELECT <select list> The SELECT clause specifies the table fields that must be represeted i the output ad the fuctios (if ay) that must be executed o the selected fields. You ca use the wildcard character [*] to specify all fields of all tables. You ca specify all fields of a particular table by suffixig the table ame by the wildcard character [*]. You ca use the followig fuctios i the SELECT clause: mi(<field ame>) for the miimum value of the field max(<field ame>) for the maximum value of the field sum(<field ame>) for the sum of the values of the field cout(<field ame>) for the umber of fields selected cout(*) for the umber of records selected avg(<field ame>) for the average value of the field. These fuctios cosider all selected records as oe group ad are executed o that group. So they produce a sigle result for example, the average value of a specified table field. You usually use these fuctios i combiatio with the GROUP BY clause. With this clause, you ca group the results ito a umber of subsets. The fuctio is the performed o each subset. 5-10

115 Database hadlig FROM <from list> The FROM clause specifies the ames of the tables from which fields must be selected. The ames of fields specified i the SELECT clause iclude the table ame. It is ot ecessary to iclude these tables i the FROM clause as well. I the FROM clause, you ca defie aliases for table ames. Aliases are ecessary, for example, for double refereces ad for refereces to the mai table. You defie a alias as follows: <table ame> <alias ame> Iclude the keyword FOR UPDATE after a table ame to idicate that the table must be read with delayed lock. If you iclude FOR UPDATE after the keyword SELECT i the SELECT clause, this idicates that all tables must be read with delayed lock. WHERE <where coditio> The WHERE clause specifies oe or more coditios which the selected records must meet. It has the followig format: WHERE <operad1> <operator> <operad2> [<operad3>] Operads Operads 1 ad 2 ca cosist of ay of the followig: umeric costat (for example, 10, ) strig costat (for example, "Joh", "mod") combied costat (for example, { 10, "xyz" }) table field, optioally followed by array idicatio pseudo field for example, for idexes (<table>._idex1, see Combied fields earlier i this chapter) 4GL variable or pseudo variable (see Usig program variables later i this chapter) umeric expressio (i which the operators +, -, *, /, \ are possible) strig expressio (i which the operator & ad a substrig are possible) special field eum costats, date costats (usig the fuctio date.to.um(y,m,d) ad date.um()) 5-11

116 Database hadlig Operad 2 ca also cosist of the followig: subqueries set defiitio (as subquery or a list of costats) Operators The followig operators are possible: compariso operators =, <, <=, >, >=, <>,!= #>, #>=, #<, #<= (for combied fields) IN operator Here, operad2 cotais a set of values (or subquery). The system tests if the value of operad1 is preset i operad2. This operator replaces a umber of expressios separated by the OR operator. For example, both of the followig statemets defie the same coditio: WHERE ttadv200.cpac = "tc" OR ttadv200.cpac = "tt" WHERE ttadv200.cpac IN ( "tc", "tt" ) LIKE operator The LIKE operator compares operad1 with operad2. Operad2 ca cotai wild cards. For example: WHERE ame LIKE "[Tt]rito.*" I this example, "Trito2.1" ad "trito" are legal values. I this case, operad2 is a regular expressio. See the expr.compile() fuctio for a list of the possible features that the expressio ca cotai. BETWEEN / INRANGE operator These operators check whether operad1 falls withi a specified rage of values. Operad2 ad operad3 specify the lower ad upper values of the rage. For example, both of the followig statemets defie the same coditio that is, they defie a rage from "tc" through "ts": WHERE ttadv200.cpac >= "tc" AND ttadv200.cpac <= "ts" WHERE ttadv200.cpac INRANGE "tc" AND "ts" The operators BETWEEN ad INRANGE are idetical, except whe you use combied fields (see SQL ad combied fields later i this chapter). 5-12

117 Database hadlig EXISTS operator This operator tests whether certai records do or do ot occur. It is used i cojuctio with subqueries. The followig example selects oly those items o the order list with a order quatity greater tha 100: select tiitm001.item, tiitm001.dsca from tiitm001 where exists ( select timps052.* from timps052 where timps052.item = tiitm001.item ad timps052.qaa > 100 ) REFERS TO operator See Refereces later i this chapter. GROUP BY <group coditio> The GROUP BY clause groups the records of the output table, based o the fields specified i the clause. It combies similar records, producig a sigle result record for each group of records with the same values for each table field listed i the SELECT clause. All elemets of the <group coditio> must be specified i the <select list> of the SELECT clause. The power of the GROUP BY clause is most apparet whe it is used with the fuctios mi, max, cout, avg, ad sum. I these cases, it produces summary values for each group. For example: SELECT ttadv200.cpac, ttadv200.cmod, ttadv200.cses FROM ttadv200 GROUP BY ttadv200.cpac, ttadv200.cmod, ttadv200.cses Sessios with the same sessio code ad differet VRCs are selected oly oce SELECT ttadv200.cpac, ttadv200.cmod, ttadv200.cses, cout(*) FROM ttadv200 GROUP BY ttadv200.cpac, ttadv200.cmod, ttadv200.cses The program couts the sessios with the same ames but differet VRCs. 5-13

118 Database hadlig HAVING <havig coditio> The HAVING clause sets coditios o groups defied by the GROUP BY clause (that is, HAVING does for groups what WHERE does for records). If you use a HAVING clause, you must specify a GROUP BY clause also. The elemets i the <havig coditio> ca be either elemets from the <select list> i the SELECT clause or fuctios o fields from the <select list>. The <havig coditio> ca cotai arithmetical ad strig expressios. For example: SELECT ttadv200.cpac, ttadv200.cmod, ttadv200.cses, cout(*) FROM ttadv200 GROUP BY ttadv200.cpac, ttadv200.cmod, ttadv200.cses HAVING cout(*) > 1 ORDER BY<order by coditio> The ORDER BY clause has the followig sytax: ORDER BY <order by coditio> [ WITH RETRY [REPEAT LAST ROW] ] This clause determies the order of the records i the output table. I the <order by coditio>, you list oe or more fields from the <select list> i the SELECT clause. The field listed first i the ORDER BY clause takes precedece. You ca list the fields by ame or you ca specify a idex to their positio i the SELECT clause. For each field i the <order by coditio>, you ca idicate if the order is to be ascedig (default) or descedig for example, ORDER BY 1 asc, 2 desc. If retry poits are icluded, you must use ORDER BY to esure that the sequece after retur to the retry poit is idetical to the oe used the first time. After a jump to a retry poit, it is importat that the query cotiues at its positio i the selected set at the time that the retry occurred. By usig the WITH RETRY additio this is easy to realize. By performig a commit.trasactio(), the values for the retry coditios are saved. I case of a jump to a retry poit, the query cotiues, startig from the values saved durig the commit.trasactio(). I the case of WITH RETRY the ew set starts after the saved values. I the case of WITH RETRY REPEAT LAST ROW, the set starts at the saved value; so the last record is read agai. I the case of WITH RETRY REPEAT LAST ROW, eter a commit.trasactio() i the SELECTEOS part of the select statemet to prevet a ew build-up of the query i some cases. 5-14

119 Database hadlig Example (embedded SQL) SELECT tisfc001.* FROM tisfc001 FOR UPDATE WHERE tisfc001.pdo < 100 ORDER BY tisfc001.pdo WITH RETRY SELECTDO tisfc001.proc = tcyeso.yes db.update(tisfc001, DB.RETRY) commit.trasactio() ENDSELECT I this case we do ot use REPEAT LAST ROW, because the momet retry takes place, the value preset at the stage of commit.trasactio() has certaily bee saved. Set specificatio Baa SQL supports the followig optios i relatio to sets: Maximum set size. With this optio you ca idicate the maximum umber of records the query ca produce. The sytax is: SELECT... [from][where] AS SET WITH <umber> ROWS Prepared set. With this optio, the etire set is retrieved before the first record is retured. The set is temporarily stored. This optio is useful whe a process simultaeously selects ad maitais (or deletes or adds) records. I this case, chages must ot be visible i the selected records. The prepared set optio forces a cosistet read. The sytax is as follows: SELECT... [from][where] AS PREPARED SET Maximum set size ad prepared set. You ca combie both optios as follows: SELECT... [from][where] AS PREPARED SET WITH <umber> ROWS Usig program variables As a 4GL query is hadled via the bshell, you ca directly relate program variables to it. Likig program variables is required for both the SELECT clause ad the WHERE clause. 5-15

120 Database hadlig SELECT clause I the <select list> of the SELECT clause, program variables are used to idicate the elemets i which the query results must be stored. You ca do this by explicitly specifyig a program variable. The geeral sytax is: <select part>:<program variable> For example: SELECT ppmod123.field1:my_val1 Or you ca directly use a program variable (a table or field ame) from the callig program i the <select list>. For example: SELECT ppmod123.field1 I the first example, the program places the result i the <program variable>. I the secod example, the ame i the query ad the ame of the program variable are idetical. FROM clause You ca also use program variables i the WHERE clause. Whe evaluatig the query, the program loads the values of the program variables ito the query ad icludes them i the evaluatio. This lik ca be realized by icorporatig a program variable i the query, preceded by a colo [:]. For example: WHERE ppmod123.field1 = :myval1 Note A table field ca be a program variable as well as a query variable. Note that the followig query: select tccom010.* where tccom010.cuo = tccom010.cuo has a differet result from: select tccom010.* where tccom010.cuo = :tccom010.cuo The latter selects oe record; the former selects all records from the table tccom010, as tccom010.cuo by defiitio equals tccom010.cuo for each row. 5-16

121 Database hadlig Refereces Retrievig refereces to a record I the stadard SQL iterface, you ca retrieve refereces to a record as follows: Suppose that tiitm001 has a referece to tccom010 (field cuo ), ad to tccom011 (field suo ) table ttiitm001 table ttccom010 table ttccom011 SELECT tiitm001.*, tccom010.*, tccom011.* FROM tiitm001, tccom010, tccom011 WHERE tiitm001.cuo = tccom010.cuo AND tiitm001.suo = tccom011.suo Retrievig refereces usig REFERS TO To simplify the retrieval of refereces, you ca specify refereces (usig the keyword REFERS TO) i the WHERE clause. Apart from simplifyig the query, this also optimizes query hadlig. As refereces always refer to a primary key, they ca be foud immediately. Moreover, the program fills a field with referece characters if it does ot fid a referece. The followig implemets the previous example by usig REFERS TO: table ttiitm001 table ttccom010 table ttccom011 SELECT tiitm001.*, tccom010.*, tccom011.* WHERE tiitm001.cuo REFERS TO tccom010 AND tiitm001.suo REFERS TO tccom011 OR SELECT tiitm001.*, tccom010.*, tccom011.* WHERE tiitm001 REFERS TO tccom010 AND tiitm001 REFERS TO tccom

122 Database hadlig REFERS TO sytax A REFERS TO statemet has the followig form: <from> REFERS TO <to> [PATH <path> [,<path>...]] [UNREF<mode>] The followig table explais the various parts of the statemet: <from> <to> <path> <mode> The referrig table field or table. The table referred to. The path via which referece is reached (always table fields). If PATH is specified, specifyig a table field for <from> is madatory. For example: WHERE table1.field REFERS TO table4.field PATH table2.field, table3.field A mode idicatig system actio if referece does ot exist; possible values are: SKIP If a referece caot be foud, the record is skipped. CLEAR If a referece is empty or abset, the referrig record is filled with spaces or 0 (umeric). SETUNREF The value of a udefied referece is filled with a udefied referece sig, defied i the data dictioary, or with 0 (umeric). CLEARUNREF The referred record is filled with spaces or 0 (zero) whe referece fields are empty. Whe the referece is udefied the referred record is filled with a udefied referece sig. Depedig o the referece defiitio i the data dictioary, the default referece mode is: referece mode i DD UNREF mode madatory SETUNREF madatory uless empty CLEARUNREF ot madatory CLEAR 5-18

123 Database hadlig Example SELECT ttadv100.* FROM ttadv100, ttadv101 WHERE ttadv101.cmod BETWEEN "aaa" ad "azz" AND ttadv101 REFERS TO ttadv100 UNREF <UNREF_mode> AND ttadv100.cpac BETWEEN " " ad "zz" The evaluatio order of this query is as follows: 1 Fid all rows / records i ttadv101 that match the BETWEEN "aaa" ad "azz" coditio. 2 Fid all refereces from each row from step 1 i table ttadv Fid all rows selected i step 2 which match the BETWEEN " " ad "zz" coditio Whe some referece does ot exist i ttadv100 (step 2 fails), because of the coditio o the refereced table, the whole row is rejected. Usig aliases with REFERS TO You ca use aliases to refer from oe table to aother with two refereces. I the followig example, there are two refereces from ttadv300 to ttaad110, via ttadv300.lal ad via ttadv300.cla. Both are searched for i the followig costructio: strig desc.cla(20), desc.lal(20) table tttadv300 SELECT ttadv300.desi, ttadv300.cfrm, ttadv300.cla, tcla.dsca:desc.cla, ttadv300.lal, tlal.dsca:desc.lal FROM WHERE ttadv300, ttaad110 tlal, ttaad110 tcla ttadv300.desi = :desiger AND ttadv300.cla REFERS TO tcla UNREF SETUNREF AND ttadv300.lal REFERS TO tlal UNREF SETUNREF Usig program variables or costats with REFERS TO You ca also retrieve refereces by usig a program variable or a costat. This avoids the program first readig the <from> table. I the followig example tiitm001 has a referece to tccom010 (field cuo ), ad a referece to tccom011 (field suo ) ad the value of tiitm001 is kow: Table Table ttccom010 ttccom011 SELECT tccom010.*, tccom011.* FROM tccom010, tccom

124 Database hadlig WHERE :tiitm001.cuo = tccom010.cuo AND :tiitm001.suo = tccom011.suo I the followig example, the REFERS TO clause is used to achieve the same result. If the program does ot fid the referece, it fills the field with referece characters. Table Table ttccom010 ttccom011 SELECT tccom010.*, tccom011.* WHERE :tiitm001.cuo REFERS TO tccom010 AND :tiitm001.suo REFERS TO tccom011 I this case the REFERS TO statemet has the followig from: <from> REFERS TO <to> [UNREF <mode>] The followig table explais the various parts of the statemet: <from> <to> <mode> The referrig program variable or costat. If a combied costat is used, all fields must be filled. The table referred to (refers to primary key of the table). This ca also be a field provided that a uique idex to this field exists. A mode idicatig system actio if referece does ot exist; possible values are: SKIP If a referece caot be foud, the record is skipped. CLEAR If a referece is empty or abset, the referrig record is filled with spaces or 0 (umeric). SETUNREF The value of a udefied referece is filled with a udefied referece sig, defied i the data dictioary, or with 0 (umeric). CLEARUNREF The referred record is filled with spaces or 0 (zero) whe referece fields are empty. Whe the referece is udefied the referred record is filled with a udefied referece sig. As o dictioary default is available, SETUNREF has bee defied as the default actio. 5-20

125 Database hadlig Example SELECT tccom010.* FROM tccom010, tiitm001 WHERE tiitm001.cuo = :tiitm001.cuo AND tiitm001.cuo REFERS TO tccom010 This is equal to the followig: SELECT tccom010.* WHERE :tiitm001.cuo REFERS TO tccom010 Compay umbers The compay umber used durig executio of a BAAN 4GL query is the curret compay umber. The curret compay umber is: The default compay umber (defied i the sessio "Maitai User Data" ) A compay umber specified by the compr.check() fuctio The <table._compr field The <table>._compr field eables the use of differet compay umbers. This field specifies the actual compay umber of the table. Whe this field is udefied, the curret compay umber is take as the default. Udefied is deoted by the value -1. Whe a record is selected with select <table>.*, the field <table>._compr i the record cotais the compay umber of the table. Whe isertig a record i a table with a specific compay umber, you must fill <table>._compr with the correspodig compay umber. The fuctio db.isert() takes care of this ad writes the record i the correct (physical) table. No special file poiters are ecessary (for example, by usig db.bid()). Example The record where the field ttadv100._compr = 000 belogs to the (physical) table ttadv The record where the field ttadv100._compr = 200 belogs to the (physical) table ttadv

126 Database hadlig Usig <table>._compr i the WHERE clause You ca also use <table>._compr i the WHERE clause of a Baa SQL statemet. I this case it is used as a search coditio. For example: SELECT ttadv100.* FROM ttadv100 WHERE ttadv100._compr = 200 AND ttadv100.cpac = tt This query lists all records from table ttadv where ttadv100.cpac has the value tt. You ca use <table>._compr i the followig ways: <table>._compr = <umber> or <umber> = <table>._compr where <umber> specifies a iteger umber. The value of <umber> is take as the compay umber. It must be a 3-digit umber. <table>._compr = <strig> where <strig> specifies a list of compay umbers, separated by commas [,]. This costructio ca be used to check a coditio for a rage of compay umbers. The strig ca cotai oly digits ad commas. (So, you specify compay umbers 0 ad 23 by <table>._compr = "000,023"). For example: SELECT ttadv100.* WHERE ttadv100._compr = "200,300" AND <coditio> This query results i a list of the records from the table ttadv100 (with compay umbers 200 ad 300) that match <coditio>. <table>._compr IN <set specificatio> where <set specificatio> is a set of costats or a subquery. Sets must ot cotai duplicate values. See IN operator i WHERE <where coditio> sectio earlier i this chapter. Combiig <table>._compr coditios A list of AND coditios ca cotai oly oe coditio that icludes <table>._compr. So, the followig costructio is possible: WHERE <table>._compr = 100 AND <coditio> but the followig is ot possible: WHERE <table>._compr = 100 AND <table>._compr =

127 Database hadlig I a list of OR coditios, each coditio must have a coditio o <table>._compr, or oe of them. So, the followig costructio is possible: WHERE (<table>._compr = 100 OR <table>._compr = 200) AND <coditio> but the followig is ot possible: WHERE (<table>._compr = 100 OR <other_field> = <value>) AND <coditio> SQL ad combied fields Defiig a query that ca be hadled efficietly by the query hadler is a complex task. This is especially true if there are combied fields (which cosist of a umber of child fields), as each field must be specified separately. Specifyig a combied field As the desiger ca usually judge best which idex should be used for a optimum result, the followig costructio eables the desiger to specify a combied field: WHERE ppmod001.comb1 = {"adv", "099", "123"} A child field ca be a expressio, a BAAN 4GL variable, or a pseudo variable. A compariso operator (=, >, >=, etc.) for a combied field applies to the combiatio of all child fields. For example: suppose the combied field ppmod001.comb1 cosists of the fields ppmod001.modu, ppmod001.tblo ad ppmod001.compo: WHERE ppmod001.comb1 >= {"adv", "000", "100"} The above statemet is equal to the followig statemet WHERE ( ppmod001.modu > "adv" ) OR ( ppmod001.modu = "adv" AND ppmod001.tblo > "000" ) OR ( ppmod001.modu = "adv" AND ppmod001.tblo = "000" AND ppmod001.compo >= "100" ) 5-23

128 Database hadlig Compariso operators for combied fields The compariso operators #>, #>=, #<, #<= for a combied field apply to each child field separately. For example: WHERE ( ppmod001.comb1 #>= {"adv", "000", "100"} AND ppmod001.comb1 #<= {"zzz", "999", "200"} ) This represets the followig: WHERE ppmod001.modu >= "adv" AND ppmod001.modu <= "zzz" AND ppmod001.tblo >= "000" AND ppmod001.tblo <= "999" AND ppmod001.compo >= "100" AND ppmod001.compo <= "200" If a child field of a combied field is ot specified, the value of this field is free ad is ot icluded i the coditio. For example: WHERE ppmod001.comb1 #>= {"adv", "000", "100"} AND ppmod001.comb1 #<= {"zzz", "999"} This represets the followig: WHERE ppmod001.modu >= "adv" AND ppmod001.modu <= "zzz" AND ppmod001.tblo >= "000" AND ppmod001.tblo <= "999" AND ppmod001.compo >= "100" As the field ppmod001.compo has o upper limit, all values greater tha or equal to 100 are fetched. Idexes as combied fields You ca specify a idex as a combied field eve if a combied field is ot preset i the data dictioary. The idex ame is table._idexy where: table is the ame of the table or alias of a table _idex is a prefix to idicate that a idex field is ivolved (a coditio for this sytax is that there are o field ames havig this format) Y is the sequece umber of the idex defied i the data dictioary As a combied field is beig used, the value must always be eclosed by { ad }. For example: WHERE tiitm001._idex1 = { :item } 5-24

129 Database hadlig As with other combied fields, childre of idex fields for which o value is specified are ot icluded i the coditio. However, you ca leave fields uspecified oly at the ed of the idex, ot i the middle. A idex s pseudo field caot be used i the query preceded by :. Meaigs of upper ad lower limits I coectio with combied fields, the combiatio of upper/lower limit ca have two meaigs (compare > ad #> ). Firstly, it ca mea that each field of a record that meets the coditios lies betwee the boudaries specified. For example: WHERE ( ppmod001.comb1 #>= {"adv", "000", "100"} AND ppmod001.comb1 #<= {"zzz", "999", "200"} ) Here, {"adv", "050" "123"} meet the coditios, but the combiatio {"uvw", "123", "300"} does ot, because of the last child field. For this costructio we defie the INRANGE statemet. With INRANGE, the precedig example becomes: WHERE ppmod001.comb1 INRANGE {"adv", "000", "100"} AND {"zzz", "999", "200"} With INRANGE, the boudaries idicated apply to each separate field (usual i prit sessios). Secodly, it ca mea that all records are selected for which the combied field (regarded as oe sigle field) lies betwee the boudaries idicated. For example: WHERE ( ppmod001.comb1 >= {"adv", "000", "100"} AND ppmod001.comb1 <= {"zzz", "999", "200"} ) Here, {"uvw", "123", "300"} meets the coditio as "uvw"&"123"&"300" lies betwee "adv"&"000"&"100" ad "zzz"&"999"&"200" ( & meas cocateatio). For this purpose we use a BETWEEN statemet. With BETWEEN, the precedig example becomes: WHERE ppmod001.comb1 BETWEEN {"adv", "000", "100"} AND {"zzz", "999", "200"} With BETWEEN, the fields i the combied are regarded as oe field; the boudaries apply to the combied field as a whole. 5-25

130 Database hadlig If the field cosists of oe sigle elemet, INRANGE ad BETWEEN are equivalet. SQL subqueries Baa SQL permits the use of subqueries. These are SELECT statemets i the WHERE clause of aother SELECT statemet. Defiig ested queries ca be very difficult. It is best to defie the subquery of the lowest level first ad the mai questio last. Example 1 Select those prices from the item file that are above average. Whe calculatig the average, the system should ot take prices less tha or equal to zero ito accout. SELECT tiitm001.copr cost price FROM tiitm001 WHERE tiitm001.copr > ( SELECT avg(tiitm001.copr) WHERE tiitm001.copr > 0 ) ORDER BY tiitm001.copr I this case, the subquery should oly produce oe result (here the average cost price). If the subquery produces more tha oe result, use the operators IN ad EXISTS. Example 2 Select the umbers ad ames of all suppliers who have yet to deliver. SELECT tccom020.suo, tccom020.ama FROM tccom020 Suppliers WHERE EXISTS ( SELECT * FROM timps053 Purchase orders WHERE timps053.suo = tccom020.suo ) SELECT tccom020.suo, tccom020.ama FROM tccom020 WHERE tccom020.suo IN ( SELECT timps053.suo FROM timps053 GROUP BY timps053.suo ) 5-26

131 Database hadlig SQL programmig There are two ways to use Baa SQL i a Baa 4GL program. You ca embed it i the laguage (embedded SQL), or you ca use Baa 4GL fuctios (dyamic SQL). Embedded SQL Sytax The followig loop structure eables the use of SQL as part of the laguage: SELECT < set defiitio (= actual query, see "SQL Sytax" earlier i this chapter) > [ SELECTBIND ( umber, var) ]... [ WHEREBIND (umber, expressio) ]... [ SELECTDO < operatio(s) o all selected records > ] [ SELECTEOS < operatio(s) after last selected record > ] [ SELECTEMPTY < operatio(s) if othig has bee selected > ] [ SELECTERROR < operatio(s) i case of a error coditio > ] ENDSELECT Descriptio Data is selected o the basis of the coditio specified i the SELECT statemet. The operatios betwee SELECTDO ad ENDSELECT are performed o each record from the selected set. The loop eds either whe the program has hadled the etire set or the program ecouters a BREAK commad. I the case of a error, the program executes the SELECTERROR part. A CONTINUE statemet i the SELECTERROR part causes the ext record to be processed. If there is o SELECTERROR sectio, the program geerates a BREAK as the default actio. Note that errors are retured oly if the shell variable ERROR.BYPASS = 1. The SELECTEOS part is executed after the SELECTDO of the last selected record. The itetio of the SELECTEOS part is that before the program ecouters a break from the loop you ca give a commit.trasactio(), while a commit.trasactio() may cause a retry. If a commit.trasactio(), give after the ENDSELECT part, causes a retry, the the whole query must be regeerated. 5-27

132 Database hadlig If the SELECTDO part is suppressed, the program ecouters a break from the loop after the first selected record. If the SELECTDO part is suppressed but the SELECTEOS part occurs, the program will select the whole set of records. I order to bid pseudo variables, the fuctios SELECTBIND ad WHEREBIND have bee added. Pseudo variables have the form :<umber>. A special bid fuctio is the used to lik a program variable to the pseudo variable. For example: SELECT ppmod123.field1:5, ppmod123.field2:6 SELECTBIND(5, my_val1) SELECTBIND(6, my_val2) SELECTDO... ENDSELECT This is equal to SELECT ppmod123.field1:my_val1, but usig a bid fuctio. It is also possible to use a pseudo variable i the WHERE clause. The WHEREBIND fuctio is the used to lik a value to the pseudo variable. For example: SELECT... WHERE ppmod123.field1 = :1 WHEREBIND(1, 10 + sqrt(a+b)) SELECTDO... ENDSELECT Used BAAN 4GL variables (with : ) are boud automatically. Example table tppmod090 log total, m_val m_val = 25 SELECT ppmod090.fld1, cout(*):1 FROM ppmod090, ppmod091 this lie is optioal WHERE ppmod090.fld2 = ppmod091.fld5 AND ppmod091.fld3 > :m_val GROUP BY ppmod090.fld1 ORDER BY 2 SELECTBIND(1,total) SELECTDO prit_ifo(ppmod090.fld1, total) SELECTERROR message("error %d occurred", db.error) break ENDSELECT 5-28

133 Database hadlig See Dyamic SQL below for a example of the same query executed usig dyamic SQL. Dyamic SQL Dyamic SQL eables a program to form a SQL statemet durig executio, so that the cotets of the statemet ca be determied, for example, by user iput. Fuctios To use Dyamic SQL, the followig fuctios are available: Fuctios sql.parse() sql.set.rds.full() sql.select.bid() sql.where.bid() sql.exec() sql.fetch() sql.break() sql.close() Descriptio Query defiitio. This sets the size of the RDBMS buffer. These fuctios lik program variables to the query's pseudo variable. I Dyamic SQL, all o-exteral program variables used i the query must be liked to a pseudo variable with these fuctios. This fuctio iitializes the query. It gives the variables their proper values. This fuctio executes the query. It reads oe result o which operatios ca be performed. This fuctio must be ivoked for each separate record from the selected set. Stops executio of the query. Ay iterim results are cleared. Deletes (all) iteral iformatio belogig to this query. See the Dyamic SQL fuctios, i U7167A US BaaERP Tools: Fuctios referece, for more iformatio ad a descriptio of the sytax of these fuctios. 5-29

134 Database hadlig Sequece of actios By usig these fuctios a query, oce defied, ca be reused optimally. The sequece of the actios is the: sql.parse, sql.bid, sql.exec, sql.fetch, sql.fetch,..., sql.break sql.bid, sql.exec, sql.fetch, sql.fetch,..., sql.break sql.close I this way you ca prevet expesive sql.parse() calls, while still workig with ew argumets. This flow is automatically geerated from a embedded SQL program by bic6.2. Usually, the programmer will therefore opt for embedded SQL, the more so, sice it automatically bids 4GL variables. Example Table tppmod090 Log sql Log total, m_val m_val = 25 if ( ot sql ) the sql = sql.parse( "select ppmod090.fld1, cout(*):1 " & "from ppmod090, ppmod091 " & "where ppmod090.fld2 = ppmod091.fld5 AND " & "ppmod091.fld3 > :2 " & "group by ppmod090.fld1 " & "order by 2") edif sql.select.bid(sql, 1, total) sql.where.bid(sql, 2, m_val) sql.exec(sql) while ( true ) o case ( sql.fetch(sql) ) case eedfile: break case 0: prit_ifo(ppmod090.fld1, total) cotiue default: error message("error %d occurred", db.error) edcase break edwhile sql.break(sql) 5-30

135 Database hadlig sql.close(sql) sql = 0 After sql.close, a ew sql.parse must be executed to give sql a correct value. If the last two lies are skipped, sql retais a correct value. See Embedded SQL earlier i this chapter for a example of the same query executed usig embedded SQL. SQL ad delayed locks The purpose of delayed lockig is to postpoe the physical lock of a record as log as possible. The program places the physical lock immediately before updatig. Durig updatig, the value of the record at the momet of selectio must be kow, as this is compared to the value at the momet of updatig. Durig compariso, the relatioships betwee fields are take ito accout. For a record to be delayed-locked whe selected, the keyword FOR UPDATE must be icluded i the SELECT statemet. I SQL, 'ormal' record lockig is ot possible. Whe placig a delayed lock o a record, the program fills the field <table>._dlock with a idetificatio umber liked to the record. This field idetifies the origial record. This guaratees a fast search procedure. This field will be overwritte whe chagig the record buffer. Updates i combiatio with SELECT FOR UPDATE are executed with the followig fuctios: db.isert(table, DB.RETRY [, eflag]) db.update(table, DB.RETRY [, eflag]) db.delete(table, DB.RETRY [, eflag]) The DB.RETRY flag idicates that we are dealig here with updates with SELECT FOR UPDATE ad retry poits. This flag esures that the actual update actio is postpoed util the commit. The db.update() ad db.delete() fuctios with the DB.RETRY flag ca be ivoked oly i combiatio with SELECT FOR UPDATE. The use of db.isert() with the DB.RETRY flag, o the other had, is ot liked to the use of SELECT FOR UPDATE. 5-31

136 Database hadlig SQL trace optios It is possible to moitor whether the SQL compiler ad optimizer are takig the right decisios. If the results idicate that the desig is icorrect, the query must be chaged. The optimizer ca ever emulate the programmer. The Baa programmig laguage therefore eables the programmer to istruct the computer what it has to do to a cosiderable degree of detail. You ca defie which idex to use; also, a umber of special (o-stadard SQL) fuctios have bee built i. You ca use the eviromet variable TT_SQL_TRACE to trace what happes iside the SQL processor. TT_SQL_TRACE is used to trace SQL processig i the cliet (that is, bshell6.2), as well as i the server process (that is, bisam_srv6.2). The methods ivolved are differet for cliet ad server. Cliet tracig Whe TT_SQL_TRACE is set, the output from the cliet process is writte to stderr. To keep this iformatio, you must call the bshell with the optios "- keeplog" ad "-logfile <log file ame>". For example: bx keeplog -logfile mylogfile -set TT_SQL_TRACE=02000 This eables TT_SQL_TRACE with value The output is writte to the file "mylogfile" i the curret workig directory. Server tracig Whe TT_SQL_TRACE is set, the output is writte to a file amed "dbs.log". This file is located i the curret workig directory whe the Database Server rus locally (o same host as Display Server). Whe the database is remote, it is writte i the logi directory of the correspodig user o that remote system. To eable loggig of TT_SQL_TRACE i the file "dbs.log", you must also set the eviromet variable DBSLOG, as follows: DBSLOG=02000 The "02000" is a octal value, ad ca be OR-ed with other variables. The meaig of the other values is described i a separate documet (Loggig Database Iformatio (DBSLOG)). 5-32

137 Database hadlig Query idetificatio A QueryIdetifier (QID) idetifies each query. This makes it easy to fid out which output i the Cliet log file is related to the output of the Server log file. Trace optios The followig values for TT_SQL_TRACE are available (C idicates that a optio ca be used for the cliet; S idicates that it ca be used for the server): 1. TT_SQL_TRACE=040 (C) Show queries with their QID 2. TT_SQL_TRACE=02000 (C) Show calls of iteral SQL fuctios 3. TT_SQL_TRACE=0200 (C) Show query executio times 4. TT_SQL_TRACE=04000 (C+S) Show query evaluatio pla 5. TT_SQL_TRACE= (S) Show FullTableSca 6. TT_SQL_TRACE= (S) Show Query Evaluatio Pla You ca combie trace optios by assigig several differet flags to TT_SQL_TRACE at the same time. For example: TT_SQL_TRACE= export TT_SQL_TRACE bshell6.2 2>sql.dbg I sql.dbg, this produces the results of both optios ad TT_SQL_TRACE=040 Shows all queries (query text) which are evaluated. For example: Evaluated Query (QID : 4) select ttadv450.vers, ttadv450.rele, ttadv450.cust, ttadv450.expi, ttadv450.mess where ttadv450._idex1 = {:cla, :1, :2} TT_SQL_TRACE=02000 Shows calls of iteral SQL fuctios, icludig their argumets. For example: [SqlParse: before parse] SqlId : 200db008 - QID : 4 - Status : 0 Tras 1 Mode 0 Query: select ttadv450.vers, ttadv450.rele, ttadv450.cust, ttadv450.expi, ttadv450.mess where ttadv450._idex1 = {:cla, :1, :2} [SqlParse: after parse (e = 0)] SqlId : 200db008 - QID : 4 - Status : 2 [SqlWhereBid for cla] SqlId : 200db008 - QID : 4 - Status : 2 Value(str): 2 [SqlWhereBid for 1] SqlId : 200db008 - QID : 4 - Status : 2 Value(str): tt [SqlWhereBid for 2] SqlId : 200db008 - QID : 4 - Status : 2 Value(str): gfdmucal 5-33

138 Database hadlig [SqlExec (CompNr 000)] SqlId : 200db008 - QID : 4 - Status : 2 [SqlFetch] SqlId : 200db008 - QID : 4 - Status : 3 [SqlFetch returs 0 erro 0 msg ] SqlId : 200db008 - QID : 4 - Status : b 2 Caledar [SqlBreak] SqlId : 200db008 - QID : 4 - Status : 4 WARNING: The lie followig the message "SqlFetch returs.." shows the result of the fetch. The order of the fields is ot always the order as metioed i the SELECT clause. TT_SQL_TRACE=0200 Shows query executio times. For example: ================================================ Fetch times of Query (QID : 12) i SqlBreak : select ttdsk360.* where (ttdsk360.user = :logame$ or ttdsk360.user = :1) order by ttdsk360.user desc, ttdsk360.cpac desc, ttdsk360.rsst desc, ttdsk360.rsid desc Nr Rows Fetched : 39 Fetch Time for 1st Row : sec Max Fetch Time : sec Average Fetch Time : sec Average Fetch Time (except Max) : sec ================================================ A value meas that the time to fetch was too small to be measured. This ca happe whe the result is already available i the cliet. I that case, fetchig is (globally see) oly copyig from oe memory locatio to aother. TT_SQL_TRACE=04000 Show the query evaluatio tree. There is differet output for cliet ad server. The cliet shows how the query is distributed over differet databases (ormally there is oe database). The server shows how the query is evaluated. This ca be differet for differet databases. The example shows the evaluatio i a o-sql database driver. I the examples, the same query is used as i the example of TT_SQL_TRACE=040. Cliet Side: Expressio Tree (QID : 4): [11] flag 011 cost 0 ext_eval 12 ext 12 cost 0 0 r 0 Operad1: Database View Id 0 - Drivers: 5-34

139 Database hadlig Database View - Tables: ttadv450 (dd: ttadv450) flag 1000 cost 0 Database View - Expressio: [10] flag 031 cost 0 ext_eval -1 ext -1 cost 0 0 r 0 Operad1: CombColum: ttadv450._idex1 Combied { (1) ttadv450.cla (2) ttadv450.cpac (3) ttadv450.cmes (4) ttadv450.vers (5) ttadv450.rele (6) ttadv450.cust } Operator: = Operad2: Combied { (1) Host var: cla = 2 (2) Host var: 1 = tt (3) Host var: 2 = gfdmucal } Database View - Host Variables: Host var: cla = 2 Host var: 1 = tt Host var: 2 = gfdmucal Database View - Output Colums: ttadv450.vers ttadv450.rele ttadv450.cust ttadv450.expi ttadv450.mess Database View - RDS Out: Dump Ifo o RDS: MalId 15 - Size Flag 2 [ 1] type 6 dept 1 size 4 offset 0 [ 2] type 6 dept 1 size 2 offset 4 [ 3] type 6 dept 1 size 4 offset 6 [ 4] type 1 dept 1 size 1 offset 10 [ 5] type 7 dept 1 size 132 offset 11 Operator: DBView Operad2: -- AND (011) [12] flag 011 cost 0 ext_eval -1 ext -1 [1] Ed of Query -Ed of Tree -- Server: Geerated Query Executio Tree: Sql id 6 compay 000 sid 1 flag 1 (QID : 4) Output Colums (total 5) [ 0] vers idx 0 type 6 size 4 depth

140 Database hadlig [ 1] rele idx 1 type 6 size 2 depth 1 [ 2] cust idx 2 type 6 size 4 depth 1 [ 3] expi idx 3 type 1 size 1 depth 1 [ 4] mess idx 4 type 7 size 132 depth 1 Rds Out: Dump Ifo o RDS: MalId 6 - Size Flag 2 [ 1] type 6 dept 1 size 4 offset 0 [ 2] type 6 dept 1 size 2 offset 4 [ 3] type 6 dept 1 size 4 offset 6 [ 4] type 1 dept 1 size 1 offset 10 [ 5] type 7 dept 1 size 132 offset 11 All tables ttadv450 flag 12 Query 200a207c flag 00 Tables ttadv450 (a) dep 1 flag 012 ttadv450(a).cmes ttadv450(a).cpac ttadv450(a).cla ttadv450(a).mess ttadv450(a).expi ttadv450(a).cust ttadv450(a).rele ttadv450(a).vers Output Colums (total 5) ttadv450.vers idx 0 type 6 size 4 depth 1 ttadv450.rele idx 1 type 6 size 2 depth 1 ttadv450.cust idx 2 type 6 size 4 depth 1 ttadv450.expi idx 3 type 1 size 1 depth 1 ttadv450.mess idx 4 type 7 size 132 depth 1 View bid vers : type 6 size 4 flag 9 rele : type 6 size 2 flag 9 cust : type 6 size 4 flag 9 expi : type 1 size 1 flag 9 mess : type 6 size 132 flag 9 View expressio [15] flag 011 cost 0 ext_eval 17 ext 17 Table View o ttadv450 Expressio: [14] flag 011 cost 3 ext_eval 16 ext 16 SrchOper for ttadv450 compr 000 idex 1 (mode 0) Field cla: Equal: [=] Bid (Col cla) Value: 2 Field cpac: Equal: [=] Bid (Col cpac) Value: tt Field cmes: Equal: [=] Bid (Col cmes) Value: gfdmucal Field vers: Field rele: 5-36

141 Database hadlig Field cust: AND (011) [16] flag 011 cost 0 ext_eval -1 ext -1 cost 0 0 r 0 Operad1: Operator: QpsPermOper Operad2: -1 AND (011) [17] flag 011 cost 0 ext_eval -1 ext -1 [1] Ed of Query There are a lot of umbers/state values i this tree. Most of them are for iteral use oly. TT_SQL_TRACE= Shows all tables for which FullTableSca is performed. This ca deped o which database is used. For example: FullTableSca for table ttdsk355 (QID : 2) The QID refers to the query. This ca be foud i the cliet trace file. TT_SQL_TRACE= Shows Query Evaluatio Pla (QEP). This also depeds o which database is used. For example: Query Evaluatio Pla (QID : 30) Table tccom000 (alias: a): IdexSearch with coditio(s): SrchOper for tccom000 compr 000 idex 1 (mode 0) Field cmp: Equal: [=] Bid (Col cmp) Value: 812 Forced Order: Ascedig (idex 1) Table tcmcs046 (alias: b): IdexSearch with coditio(s): SrchOper for tcmcs046 compr 000 idex 1 (mode 6) Field cla: Equal: [REF (clear)] Idex Col key 1 mode 5 equal 0 tccom000(a).cla Table tcmcs002 (alias: c): IdexSearch with coditio(s): SrchOper for tcmcs002 compr 000 idex 1 (mode 6) Field ccur: Equal: [REF (clear)] Idex Col key 1 mode 5 equal 0 tccom000(a).ccur ================================================ 5-37

142 Database hadlig The query which belogs to this QEP is show i the cliet log file (TT_SQL_TRACE=040) as follows: Evaluated Query (QID : 30) Select tccom000.*, tcmcs002.*, tcmcs046.* From tccom000, tcmcs002, tcmcs046 Where tccom000.cmp = :compay.r Ad tccom000.ccur refers to tcmcs002 uref clear Ad tccom000.cla refers to tcmcs046 uref clear order by tccom000.cmp From the QEP, the followig iformatio ca be retrieved: 1 There are three tables: tccom000 (alias: a), tcmcs046 (alias: b), tcmcs002 (alias: c). The alias ame is used i case of SQL databases. This alias ame is oly oe or two characters i order to keep the SQL statemet for the SQL database as short as possible. 2 The order of evaluatio of the tables is from top-to-bottom i the QEP, so first tccom000, the tcmcs046, the tcmcs Searchig i tccom000 is doe o the primary idex (idex 1). The field cmp has value 812 ad has bee specified by some = operatio. I the query above, this comes from the lie cotaiig "where tccom000.cmp = :compay.r". 4 The query has a ORDER BY part. The ORDER BY ca be elimiated by readig tccom000 o idex 1, i ascedig order. This is deoted by: "Forced Order: Ascedig (idex 1)". 5 Next table to be read is tcmcs046. Here also idex 1 is used for readig. The key is specified by some "uref clear" operatio. The field cla is filled to search i the table. This field specifies the whole primary key (idex 1). 6 Last evaluated table is tcmcs002, i the same way as tcmcs046. Here, the field ccur is used. 5-38

143 Database hadlig Error hadlig There are two broad categories of errors. Errors geerated by the operatig system (umbers 1-99) ad errors geerated by the database system (umbers ). See Chapter 10, Errors. To keep the messages to be set over the etwork to a miimum, database actios ad messages must be buffered as much as possible. Bufferig updates meas that as few updates as possible retur error codes. These, after all, cause a rollback ad a retur to a retry poit. It is therefore possible to allocate flags to updates idicatig the actio to be take by the system whe a database actio fails. The database server will the o loger execute a rollback, but a follow-up actio. Fatal ad o-fatal errors There are fatal ad o-fatal errors. Fatal errors termiate the sessio. No-fatal errors are those that are temporary (for example, elocked), or that are caused by a multi-user situatio (for example, a record is deleted by two processes, oe process receivig eorec). No-fatal errors cause the program to go back to the last retry poit. If this is missig, the sessio is termiated. Fatal errors are errors caused by: Errors i the (logical) database (for example, eotable, eddcorrupt, eoserver) Errors i the uderlyig (R)DBMS (for example, ebadkey) Program errors (for example, eotirage) The followig error codes result i a retur to the retry poit: elocked (107) record is locked eflocked (113) file (table) is locked emlocked (210) record i mirrorig is locked ereflocked (601) referece record is locked edupl (100) duplicate record eorec (111) record ot preset erowchaged (201) record modified sice last read eabort (850) rollback i (R)DBMS 5-39

144 Database hadlig The eflag For a umber of errors it is possible to idicate which actio the system must carry out whe the error occurs. You ca add these to a database actio with the <eflag>. For example: db.isert(table, DB.RETRY [, eflag]) db.update(table, DB.RETRY [, eflag]) db.delete(table, DB.RETRY [, eflag]) The followig flags are available for eflag: db.exit.o.orec db.skip.orec db.exit.o.dupl db.skip.dupl db.exit.o.rowchaged db.skip.rowchaged db.retur.error * db.retur.orec * db.retur.dupl * db.retur.ref.exists * db.retur.ref.ot.exists * db.retur.rowchaged * stop sessio if o record was foud skip update/delete actio if o record was foud stop sessio if duplicates occur skip update/isert actio if duplicates occur stop sessio if record has bee chaged after delayed lock skip actio if record has bee chaged after delayed lock retur error code retur error code if o record was foud retur error code if duplicates occur retur error code if referece exists retur error code if referece does ot exist retur error code if record has bee chaged after delayed lock * These flags store the cotets of the buffer to the database if a error occurs. The program does ot retur to the retry poit. Note that you ca combie flags by usig the + sig. 5-40

145 Database hadlig Example table ttiitm001 db.retry.poit() SELECT tiitm001.* FROM tiitm001 FOR UPDATE WHERE tiitm001.item betwee :item.f ad :item.t SELECTDO... db.isert(ttiitm001, DB.RETRY, db.skip.dupl) ENDSELECT I this case, the flag db.skip.dupl causes the system either to go back to the retry poit or retur a error code whe addig a already existig record. Hits for usig SQL 1 I the WHERE clause: use as few coditios as possible: use as may coditios with idexes as possible use as may coditios with combied fields as possible use BETWEEN/INRANGE whe a upper ad lower boudary are specified for a field. 2 Use REFERS TO if refereces have bee defied i the data dictioary. 3 Use as few overlappig OR coditios as possible. For the followig: cpac&cmod >= ttadv (oly if there is o idex to cpac&cmod) do ot use the followig costructio: WHERE ttadv200.cpac > tt OR ttadv200.cpac >= tt AND ttadv200.cmod >= adv istead use the followig costructio: WHERE ttadv200.cpac > tt OR ttadv200.cpac = tt AND ttadv200.cmod >= adv Use BETWEEN or INRANGE if there is a idex to cpac&cmod. For example: WHERE ttadv200._idex1 BETWEEN { tt, adv } ad { } 4 Oly select fields of tables ecessary i the flow of the program. 5-41

146 Database hadlig 5 It is ot ecessary to bid exteral variables ad database fields used i the query as substitutio variables. I embedded SQL local variables are boud automatically. 6 The program executes the query the first time the fuctio sql.fetch() is called. If readig i the etire set is uecessary (so o order by, group by, ad so o), the program oly physically retrieves records at each sql.fetch(). This avoids a etire set beig retrieved whe oly part of it is used. Whe the set is o loger ecessary call sql.break() to clear the remaiig records. 7 Use ORDER BY to esure that the records are retrieved i the correct sequece. If a idex ca be used for the ORDER BY, o sort actio will take place beforehad. 8 The program will execute a Full Table Sca (FTS) if the operators NOT INRANGE, IN, LIKE are used or if o idex (or part of a idex) is used. This meas that the system checks beforehad whether all records i the table meet the coditios of the query. This precludes optimizatio. If oly the first part of a idex (combied or ormal field) is used, the system uses that idex to search the table. Whe GROUP BY is used, the system first determies the etire set (prepared set), before producig the first record. The same thig happes if the operator is preceded by a expressio for example, WHERE <table.field1> & <table.field2> = "...". Note that the various subexpressios separated by AND or OR caot be combied for optimizatio. 9 It is possible to have the program carry out commits at certai poits i the select loop. If retry poits are icluded, use of ORDER BY is required to esure that the sequece after retur to the retry poit is idetical to the oe used the first time. See also the practical examples. 10 If a trasactio adds or processes records, it depeds o the database if the same trasactio ca also process ew records without a select beig carried out agai. To esure that ew records are processed i ay case, a commit ad a ew select are required. To esure that ew records are ot processed, defie the set at the poit of the select (prepared set). 11 Whe usig trasactios, the first priority should be that the actios withi the trasactio costitute a logical uit. For reasos of performace, update, isert, ad delete actios ca be combied up to a umber of 256 (this is a average, ot a limit) per trasactio. For example, programs processig orders should execute oe commit.trasactio() for each order. 5-42

147 Database hadlig 12 It may be ecessary to kow how far the program had advaced before it moved back to the retry poit. If the key cosists of more tha oe field, it is probably possible to have the program execute a commit.trasactio() whe a particular key field chages. If a key cosists of order umber ad order lie, for istace, a commit by order umber would be preferable to a commit by order lie. Care should be take i programs that prit ad process data i oe ru. A abort trasactio restores the database but ot the output to the priter. I such cases a commit must be executed for each prit lie to prevet lies beig prited twice. For example: save.oro = start select for update order lie.oro order lie.poo from order lie where order lie.oro >= :save.oro selectdo if ( save.oro <> order lie.oro ) the commit.trasactio() save.oro = order lie.oro edif update actios() edselect commit.trasactio() 13 A db.retry.poit() must be icluded i each update program. Hits for usig db.retry.poit For programs of type 1, 2 or 3, this is geerally the retry.poit of the stadard program which has a retry just after before choice of update.db ad i the read sectio where also the refereces are read. To have clearly structured sources, ever use more tha oe level db.retry.poit(). Oly oe above the first level of select. Use retry i the followig situatios: Situatio for Select Commit per fetch Commit over multiple fetch db.update/db.isert/db.delete 1 2 Collectig 3 3 Combiatio 4 5 A skip back to a retry poit ca be idicated by a problem i: db.update(), db.delete() or db.isert() with argumet db.retry commit.trasactio() 5-43

148 Database hadlig Situatio 1: Oly update actios, commit per fetch The fuctio with retry ca be used here. For example: db.retry.poit() select tisfc001.* from tisfc001 for update where tisfc001.pdo irage :pdo.f ad :pdo.t order by tisfc001._idex1 with retry selectdo tisfc001.proc = tcyeso.yes db.update(ttisfc001,db.retry) commit.trasactio() edselect I this case REPEAT LAST ROW is ot used, because whe retry is doe, the value which was preset at the stage of commit.trasactio() has certaily bee saved. Situatio 2: Oly update actios, commits over fetches I this case we ca also use the with retry optio. For example:(commit per order ad ot per fetch!): save.pdo = 0 db.retry.poit() select ticst001.* from ticst001 for update where ticst001.pdo irage :pdo.f ad :pdo.t order by ticst001._idex1 with retry repeat last row selectdo if ticst001.pdo <> save.pdo the if save.pdo <> 0 the commit.trasactio() edif save.pdo = ticst001.pdo edif ticst001.proc = tcyeso.yes db.update(ticst001,db.retry) selecteos commit.trasactio() edselect Both db.update() ad commit.trasactio() ca result i a retry. So selecteos is used. Notice that REPEAT LAST ROW is used because the preset value at the time of doig the save is already the value of the ext order. 5-44

149 Database hadlig Situatio 3: oly prit / collect actios (o commit) There is o trasactio or depedecy betwee records / fetches. For example: total.quat = 0 select ticst001.* from ticst001 where ticst001.pdo irage :pdo.f ad :pdo.t order by ticst001._idex1 selectdo total.quat = total.quat + ticst001.qua prit.row(1) edselect Situatio 4: Update actios plus prit/collect with commit per fetch For example, update of prit status plus prit ad collect: total.quat = 0 db.retry.poit() select ticst001.* from ticst001 for update where ticst001.pdo irage :pdo.f ad :pdo.t order by ticst001._idex1 with retry selectdo ticst001.proc = tcyeso.yes db.update(ticst001,db.retry) commit.trasactio() total.quat = total.quat + ticst001.qua prit.row() edselect Notice that this works oly whe the db.update() ad commit.trasactio() are doe before the prit ad the collect statemet. A alterative to this solutio is described i situatio 5. Situatio 5: Update actios plus prit/collect with commit over fetches For example, update of prit status plus prit ad collect per order: save.pdo = 0 save.poo = 0 total.select.qua = 0 db.retry.poit() total.order.qua = 0 select ticst001.* from ticst001 for update where ticst001.pdo irage :pdo.f ad :pdo.t 5-45

150 Database hadlig order by ticst001._idex1 with retry repeat last row selectdo if ticst001.pdo <> save.pdo the if save.pdo <> 0 the total.order.qua = 0 commit.trasactio() edif save.pdo = ticst001.pdo edif if ticst001.pdo > lsp.pdo or (ticst001.pdo = lsp.pdo ad ticst001.poo > lsp.poo ) the prit.row() total.select.qua = total.select.qua + ticst001.qua lsp.pdo = ticst001.pdo lsp.poo = ticst001.poo edif total.order.qua = total.order.qua + ticst001.qua ticst001.proc = tcyeso.yes db.update(ticst001,db.retry) selecteos commit.trasactio() edselect lsp stads for last processed. pdo ad poo are together the idex of cst001. The lsp. variables should always be used for this kid of savig withi selects. These variables save which record has already bee prited/collected. The total.order.qua ca always be added because settig to zero is doe for each retry agai. 5-46

151 6 Data Access Layer (DAL) Overview I BAAN applicatios, the stadard program (STP) provides much of the default fuctioality for a sessio. I previous versios of the software, chages or additios to the default fuctioality for a sessio were programmed i a sigle script that was associated with the sessio. Both user iterface actios ad database actios were programmed i this script. I BaaERP, user iterface actios ad database actios have bee separated. The Data Access Layer (DAL) ow hadles database iteractio. Programmers create a user iterface (UI) script to chage the default behavior of a sessio. They create a DAL script to program all the logical itegrity rules for a particular table. So the DAL esures the logical itegrity of the database. As i previous versios of the software, the database server esures the referetial itegrity of the database. The DAL script for a particular table has the same ame as that table. It is implemeted as a DLL that ca be accessed by user iterface scripts (via the stadard program), by other DALs, ad by exteral programs (via the Commo Data Access Server (CDAS). The followig diagram illustrates the overall relatioship of these compoets. 6-1

152 Data Access Layer (DAL) Database itegrity checks The followig are examples of some logical itegrity rules that could be programmed i a DAL script: Whe customers have reached their credit limit, they caot order further items. If the ivoice for a order has bee prited, the order caot be chaged. If the curret VRC of a user is ot equal to the package VRC of the program script, the script caot be compiled. Programmig database itegrity checks i a separate DAL script has two mai advatages: Code reuse: The itegrity rules do ot have to be replicated i each sessio that uses a particular table. Exteral access: Exteral applicatios ca access the database via the CDAS ad the DAL. For a overview of the iteractio betwee the user iterface, the stadard program, ad the DAL, see DAL, UI, ad STP iteractio later i this chapter. Busiess methods I additio to performig data itegrity checks, the DAL provides busiess methods for hadlig o-iteractive database modificatios such as pritig sales orders or postig all orders to history. A busiess method is a fuctio that performs a task that ivolves maipulatig ad/or checkig oe or more tables i the database. The fuctio is programmed i a DAL script ad ca be called directly from a UI script. It must be programmed i the DAL script of the most relevat table. Users ca activate a busiess method with a sigle commad. There is the o further user iteractio. The UI script calls the relevat fuctio i the DAL script. The fuctio performs all operatios to complete the required task. The user must wait util the busiess method fiishes before cotiuig with other tasks. However, if a progress widow is provided, the user ca cacel the busiess method by clickig o the Cacel butto. The UI script starts a busiess method by callig the dal.start.busiess.method() fuctio. 6-2

153 Data Access Layer (DAL) DAL termiology Class Object Object set Property Method Hook A descriptio of a group of objects with similar properties, commo behavior, commo relatioships, ad commo sematics. A DAL class correspods to a BAAN table defiitio. A istace of a class. It cosists of data ad the methods (code) to maipulate the data. The data of a DAL object correspods to a record i a BAAN table. All objects of a class, as stored i the database. A DAL object set correspods to a BAAN table. A attribute of a object. A DAL property correspods to a field i a record i a BAAN table. The implemetatio of a operatio for a particular class. It provides a meas of retrievig ad maipulatig data (properties) i objects. Method is aother ame for a operatio or fuctio. A logic itegrity rule. Hooks are implemeted i the DAL as fuctios. UI, DAL, ad STP iteractio Overview A DAL script cotais all the logic itegrity rules for a particular object set. These rules are referred to as hooks ad they ca be programmed for every possible maipulatio of a object i the object set. For each sessio with a mai table, the stadard program esures that the itegrity rules for the table are checked each time a update, delete, isert, or read operatio is performed o a object of the table. If there is o DAL script for the particular object set beig accessed, o logic itegrity checks are performed (uless they are programmed i the UI script itself). A DAL script ca cotai hooks that prevet access to the database ad hooks that prevet data beig passed back to the user iterface. The former are executed before the database actio. The latter are performed after the database actio. 6-3

154 Data Access Layer (DAL) Example If a user chages the address of a customer o a form, the stadard program chages the address for that customer i the database via the DAL. If you wat certai restrictios to apply to the update actio, you ca program a property hook i the DAL of the sessio s mai table to impose these restrictios. For example: whe the address chages: if chaged ito somethig valid the accept else reject edif UI fuctio calls The UI script ca use either the db.* fuctios or the DAL Data Access Methods (DAM) to maipulate the database. The db.* fuctios are direct database calls. They do ot use the DAL. I this case, ay logic itegrity checks required must be programmed i the UI script itself. This meas that they caot be reused by other sessios. I preferece, use the DAL Data Access Methods. These access the database via the DAL, so all ecessary checks are automatically performed. Fuctio flow Whe the DAL is used to maipulate the database, the mai steps ivolved are as follows: 1 The user issues a commad through the user iterface to access a record i the database. 2 The stadard program loads the appropriate DAL ad calls the hooks i the DAL to check the itegrity rules for the object. 3 If the particular database actio is permitted, the stadard program issues the appropriate database call. 4 After the database has bee updated, the DAL ca perform further checks to determie whether or ot data is passed back to the user iterface. 5 The stadard program passes data back to the user iterface (provided that the itegrity rules permit this). 6-4

155 Data Access Layer (DAL) The followig diagram illustrates this flow: Oe-way iteractio Note that because the DAL ca be used i situatios where there is o user iterface, the DAL caot call fuctios i the UI. DAL hooks A hook is a fuctio, with a predefied ame, that the DAL programmer programs i a DAL script. The fuctio is used to program logic itegrity rules for database access. The DAL script is compiled ito a DLL. Whe a user issues a commad to access the database, the stadard program loads the DAL DLL for the object beig accessed ad calls the hooks to perform the itegrity checks. Provided that a DAL script exists for a object set beig accessed, the stadard program always esures that the hooks i the DAL are called at the appropriate times. A DAL script ca cotai two types of hooks: Property hooks Object hooks 6-5

Baan Tools User Management

Baan Tools User Management Baa Tools User Maagemet Module Procedure UP008A US Documetiformatio Documet Documet code : UP008A US Documet group : User Documetatio Documet title : User Maagemet Applicatio/Package : Baa Tools Editio

More information

Baan Finance Financial Statements

Baan Finance Financial Statements Baa Fiace Fiacial Statemets Module Procedure UP041A US Documetiformatio Documet Documet code : UP041A US Documet group : User Documetatio Documet title : Fiacial Statemets Applicatio/Package : Baa Fiace

More information

BAAN IVc/BaanERP. Conversion Guide Oracle7 to Oracle8

BAAN IVc/BaanERP. Conversion Guide Oracle7 to Oracle8 BAAN IVc/BaaERP A publicatio of: Baa Developmet B.V. P.O.Box 143 3770 AC Bareveld The Netherlads Prited i the Netherlads Baa Developmet B.V. 1999. All rights reserved. The iformatio i this documet is subject

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013 Code Review s Authors: Mika V. Mätylä ad Casper Lasseius Origial versio: 4 Sep, 2007 Made available olie: 24 April, 2013 This documet cotais further details of the code review defects preseted i [1]. of

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

Behavioral Modeling in Verilog

Behavioral Modeling in Verilog Behavioral Modelig i Verilog COE 202 Digital Logic Desig Dr. Muhamed Mudawar Kig Fahd Uiversity of Petroleum ad Mierals Presetatio Outlie Itroductio to Dataflow ad Behavioral Modelig Verilog Operators

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

BEA WebLogic Process Integrator

BEA WebLogic Process Integrator BEA WebLogic Process Itegrator A Compoet of BEA WebLogic Itegratio BEA WebLogic Process Itegrator Studio Olie Help BEA WebLogic Process Itegrator Release 2.0 Documet Editio 2.0 July 2001 Copyright Copyright

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

implement language system

implement language system Outlie Priciples of programmig laguages Lecture 3 http://few.vu.l/~silvis/ppl/2007 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia e-mail: silvis@few.vu.l

More information

The Magma Database file formats

The Magma Database file formats The Magma Database file formats Adrew Gaylard, Bret Pikey, ad Mart-Mari Breedt Johaesburg, South Africa 15th May 2006 1 Summary Magma is a ope-source object database created by Chris Muller, of Kasas City,

More information

1 Enterprise Modeler

1 Enterprise Modeler 1 Eterprise Modeler Itroductio I BaaERP, a Busiess Cotrol Model ad a Eterprise Structure Model for multi-site cofiguratios are itroduced. Eterprise Structure Model Busiess Cotrol Models Busiess Fuctio

More information

One advantage that SONAR has over any other music-sequencing product I ve worked

One advantage that SONAR has over any other music-sequencing product I ve worked *gajedra* D:/Thomso_Learig_Projects/Garrigus_163132/z_productio/z_3B2_3D_files/Garrigus_163132_ch17.3d, 14/11/08/16:26:39, 16:26, page: 647 17 CAL 101 Oe advatage that SONAR has over ay other music-sequecig

More information

Getting Started. Getting Started - 1

Getting Started. Getting Started - 1 Gettig Started Gettig Started - 1 Issue 1 Overview of Gettig Started Overview of Gettig Started This sectio explais the basic operatios of the AUDIX system. It describes how to: Log i ad log out of the

More information

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software Structurig Redudacy for Fault Tolerace CSE 598D: Fault Tolerat Software What do we wat to achieve? Versios Damage Assessmet Versio 1 Error Detectio Iputs Versio 2 Voter Outputs State Restoratio Cotiued

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Web OS Switch Software

Web OS Switch Software Web OS Switch Software BBI Quick Guide Nortel Networks Part Number: 213164, Revisio A, July 2000 50 Great Oaks Boulevard Sa Jose, Califoria 95119 408-360-5500 Mai 408-360-5501 Fax www.orteletworks.com

More information

Java Expressions & Flow Control

Java Expressions & Flow Control Java Expressios & Flow Cotrol Rui Moreira Expressio Separators:. [ ] ( ), ; Dot used as decimal separator or to access attributes ad methods double d = 2.6; Poto poto = ew Poto(2, 3); it i = poto.x; it

More information

Customer Portal Quick Reference User Guide

Customer Portal Quick Reference User Guide Customer Portal Quick Referece User Guide Overview This user guide is iteded for FM Approvals customers usig the Approval Iformatio Maagemet (AIM) customer portal to track their active projects. AIM is

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server:

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server: 3 Usig MySQL Programs This chapter provides a brief overview of the programs provided by MySQL AB ad discusses how to specify optios whe you ru these programs. Most programs have optios that are specific

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS APPLICATION NOTE PACE175AE BUILT-IN UNCTIONS About This Note This applicatio brief is iteded to explai ad demostrate the use of the special fuctios that are built ito the PACE175AE processor. These powerful

More information

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998 Su Microsystems, Ic. 2550 Garcia Aveue Moutai View, CA 94045 415 960-1300 X3T10/95-229, Revisio 0 April 18, 1998 % Su Logo for Joh Lohmeyer Chairperso, X3T10 Symbios Logic Ic. 1635 Aeroplaza Drive Colorado

More information

Data diverse software fault tolerance techniques

Data diverse software fault tolerance techniques Data diverse software fault tolerace techiques Complemets desig diversity by compesatig for desig diversity s s limitatios Ivolves obtaiig a related set of poits i the program data space, executig the

More information

Τεχνολογία Λογισμικού

Τεχνολογία Λογισμικού ΕΘΝΙΚΟ ΜΕΤΣΟΒΙΟ ΠΟΛΥΤΕΧΝΕΙΟ Σχολή Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών Τεχνολογία Λογισμικού, 7ο/9ο εξάμηνο 2018-2019 Τεχνολογία Λογισμικού Ν.Παπασπύρου, Αν.Καθ. ΣΗΜΜΥ, ickie@softlab.tua,gr

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

BEA Tuxedo. Using the BEA Tuxedo System on Windows NT

BEA Tuxedo. Using the BEA Tuxedo System on Windows NT BEA Tuxedo Usig the BEA Tuxedo System o Widows NT BEA Tuxedo Release 7.1 Documet Editio 7.1 May 2000 Copyright Copyright 2000 BEA Systems, Ic. All Rights Reserved. Restricted Rights Leged This software

More information

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 12: Virtual Memory Prof. Yajig Li Uiversity of Chicago A System with Physical Memory Oly Examples: most Cray machies early PCs Memory early all embedded systems

More information

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen COP4020 mig Laguages Compilers ad Iterpreters Prof. Robert va Egele Overview Commo compiler ad iterpreter cofiguratios Virtual machies Itegrated developmet eviromets Compiler phases Lexical aalysis Sytax

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 3 More Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 3.1 Usig Boolea Expressios 3.2 Multiway Braches 3.3 More about C++ Loop Statemets 3.4 Desigig Loops Copyright

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

Avid Interplay Bundle

Avid Interplay Bundle Avid Iterplay Budle Versio 2.5 Cofigurator ReadMe Overview This documet provides a overview of Iterplay Budle v2.5 ad describes how to ru the Iterplay Budle cofiguratio tool. Iterplay Budle v2.5 refers

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 26 Ehaced Data Models: Itroductio to Active, Temporal, Spatial, Multimedia, ad Deductive Databases Copyright 2016 Ramez Elmasri ad Shamkat B.

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

Chapter 3. Floating Point Arithmetic

Chapter 3. Floating Point Arithmetic COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 3 Floatig Poit Arithmetic Review - Multiplicatio 0 1 1 0 = 6 multiplicad 32-bit ALU shift product right multiplier add

More information

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8 The Implemetatio of Data Structures i Versio 5 of Ico* Ralph E. Gr is wo Id TR 85-8 April 1, 1985 Departmet of Computer Sciece The Uiversity of Arizoa Tucso. Arizoa 85721 This work was supported by the

More information

fgrep - Linux Command

fgrep - Linux Command f - CetOS 5.2 - Liux Users Guide f f - Liux Commad SYNOPSIS [optios] PATTE RN [FI LE...] [ optios ] [ -e -f FILE ] [ FILE...] DESCRIPTION Grep searches the amed iput FILE s (or stadard iput if o files

More information

CSI 3140 WWW Structures, Techniques and Standards. Cascading Style Sheets (CSS)

CSI 3140 WWW Structures, Techniques and Standards. Cascading Style Sheets (CSS) CSI 3140 WWW Structures, Techiques ad Stadards Cascadig Style Sheets (CSS) Motivatio whtml markup ca be used to represet Sematics: h1 meas that a elemet is a top-level headig Presetatio: h1 elemets look

More information

BEA Tuxedo. Creating CORBA Client Applications

BEA Tuxedo. Creating CORBA Client Applications BEA Tuxedo Creatig CORBA Cliet Applicatios BEA Tuxedo 8.0 Documet Editio 8.0 Jue 2001 Copyright Copyright 2001 BEA Systems, Ic. All Rights Reserved. Restricted Rights Leged This software ad documetatio

More information

% Sun Logo for Frame. X3T10/95-229, Revision 2. September 28, 1995

% Sun Logo for Frame. X3T10/95-229, Revision 2. September 28, 1995 Su Microsystems, Ic. 2550 Garcia Aveue Moutai View, CA 94045 415 960-1300 X3T10/95-229, Revisio 2 September 28, 1995 % Su Logo for Frame Joh Lohmeyer Chairperso, X3T10 Symbios Logic Ic. 1635 Aeroplaza

More information

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control EE 459/500 HDL Based Digital Desig with Programmable Logic Lecture 13 Cotrol ad Sequecig: Hardwired ad Microprogrammed Cotrol Refereces: Chapter s 4,5 from textbook Chapter 7 of M.M. Mao ad C.R. Kime,

More information

BEA WebLogic Enterprise. Using the WebLogic EJB Deployer

BEA WebLogic Enterprise. Using the WebLogic EJB Deployer BEA WebLogic Eterprise Usig the WebLogic EJB Deployer WebLogic Eterprise 5.0 Documet Editio 5.0 December 1999 Copyright Copyright 1999 BEA Systems, Ic. All Rights Reserved. Restricted Rights Leged This

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as a Itroductio to Objects ad Classes Overview 6.1 Streams ad Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams ad Basic File I/O I/O Streams I/O refers

More information

IMP: Superposer Integrated Morphometrics Package Superposition Tool

IMP: Superposer Integrated Morphometrics Package Superposition Tool IMP: Superposer Itegrated Morphometrics Package Superpositio Tool Programmig by: David Lieber ( 03) Caisius College 200 Mai St. Buffalo, NY 4208 Cocept by: H. David Sheets, Dept. of Physics, Caisius College

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 3: ISA ad Itroductio to Microarchitecture Prof. Yajig Li Uiversity of Chicago Lecture Outlie ISA uarch (hardware implemetatio of a ISA) Logic desig basics Sigle-cycle

More information

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004 8 Programs ad data This publicatio forms part of a Ope Uiversity course M150 Data, Computig ad Iformatio. Details of this ad other Ope Uiversity courses ca be obtaied from the Course Iformatio ad Advice

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

MOTIF XF Extension Owner s Manual

MOTIF XF Extension Owner s Manual MOTIF XF Extesio Ower s Maual Table of Cotets About MOTIF XF Extesio...2 What Extesio ca do...2 Auto settig of Audio Driver... 2 Auto settigs of Remote Device... 2 Project templates with Iput/ Output Bus

More information

Weston Anniversary Fund

Weston Anniversary Fund Westo Olie Applicatio Guide 2018 1 This guide is desiged to help charities applyig to the Westo to use our olie applicatio form. The Westo is ope to applicatios from 5th Jauary 2018 ad closes o 30th Jue

More information

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

Exercise 6 (Week 42) For the foreign students only.

Exercise 6 (Week 42) For the foreign students only. These are the last exercises of the course. Please, remember that to pass exercises, the sum of the poits gathered by solvig the questios ad attedig the exercise groups must be at least 4% ( poits) of

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Cocurrecy Threads ad Cocurrecy i Java: Part 1 What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

Guide to Applying Online

Guide to Applying Online Guide to Applyig Olie Itroductio Respodig to requests for additioal iformatio Reportig: submittig your moitorig or ed of grat Pledges: submittig your Itroductio This guide is to help charities submit their

More information

Goals of the Lecture Object Constraint Language

Goals of the Lecture Object Constraint Language Goals of the Lecture Object Costrait Laguage Object-Orieted Aalysis ad Desig - Fall 1998 Preset the Object Costrait Laguage Ð As best as possible, with the limited iformatio available from UML i a Nutshell

More information

IXS-6600-C IXS-6700-C

IXS-6600-C IXS-6700-C INTEGRATED ROUTING SYSTEM PACK IXS-6600-C IXS-6700-C INTEGRATED ROUTING SYSTEM IXS-6600 IXS-6700 IKS-6030M IKS-A6011 IKS-A6015 IKS-A6050 IKS-A6061 IKS-V6010M IKS-V6010SD IKS-V6050M IKS-V6050SD IKS-V6060M

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Threads ad Cocurrecy i Java: Part 1 1 Cocurrecy What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016 CS 111: Program Desig I Lecture 15: Objects, Padas, Modules Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 13, 2016 OBJECTS AND DOT NOTATION Objects (Implicit i Chapter 2, Variables,

More information

Preface. Objective-C is an object-oriented extension to C. You could call it C with Objects.

Preface. Objective-C is an object-oriented extension to C. You could call it C with Objects. Preface Objective-C is a object-orieted extesio to C. You could call it C with Objects. If you re readig this book, you re probably iterested i learig Objective-C so that you ca write applicatios for Mac

More information

n Learn how resiliency strategies reduce risk n Discover automation strategies to reduce risk

n Learn how resiliency strategies reduce risk n Discover automation strategies to reduce risk Chapter Objectives Lear how resiliecy strategies reduce risk Discover automatio strategies to reduce risk Chapter #16: Architecture ad Desig Resiliecy ad Automatio Strategies 2 Automatio/Scriptig Resiliet

More information

BEA Tuxedo. Using the CORBA Name Service

BEA Tuxedo. Using the CORBA Name Service BEA Tuxedo Usig the CORBA Name Service BEA Tuxedo Release 8.0 Documet Editio 8.0 Jue 2001 Copyright Copyright 2001 BEA Systems, Ic. All Rights Reserved. Restricted Rights Leged This software ad documetatio

More information

End Semester Examination CSE, III Yr. (I Sem), 30002: Computer Organization

End Semester Examination CSE, III Yr. (I Sem), 30002: Computer Organization Ed Semester Examiatio 2013-14 CSE, III Yr. (I Sem), 30002: Computer Orgaizatio Istructios: GROUP -A 1. Write the questio paper group (A, B, C, D), o frot page top of aswer book, as per what is metioed

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation 6-0-0 Kowledge Trasformatio from Task Scearios to View-based Desig Diagrams Nima Dezhkam Kamra Sartipi {dezhka, sartipi}@mcmaster.ca Departmet of Computig ad Software McMaster Uiversity CANADA SEKE 08

More information

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway. Bjare Stroustrup www.stroustrup.com/programmig Chapter 5 Errors Abstract Whe we program, we have to deal with errors. Our most basic aim is correctess, but we must deal with icomplete problem specificatios,

More information

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

Custodial Integrator Automation Guide

Custodial Integrator Automation Guide Custodial Itegrator Automatio Guide Compay Cofidetial Custodial Itegrator Product Versio: V3.8 Documet Versio: 14 Documet Issue Date: April 21, 2017 Techical Support: (866) 856-4951 Telephoe: (781) 376-0801

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 19 Query Optimizatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Query optimizatio Coducted by a query optimizer i a DBMS Goal:

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

BEA WebLogic Commerce Server. Registration and User Processing Package

BEA WebLogic Commerce Server. Registration and User Processing Package BEA WebLogic Commerce Server Registratio ad User Processig Package BEA WebLogic Commerce Server 3.2 Documet Editio 3.2 December 2000 Copyright Copyright 2000 BEA Systems, Ic. All Rights Reserved. Restricted

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns K-NET bus The K-Net bus is based o the SPI bus but it allows to addressig may differet turrets like the I 2 C bus. The K-Net is 6 a wires bus (4 for SPI wires ad 2 additioal wires for request ad ackowledge

More information

the beginning of the program in order for it to work correctly. Similarly, a Confirm

the beginning of the program in order for it to work correctly. Similarly, a Confirm I our sytax, a Assume statemet will be used to record what must be true at the begiig of the program i order for it to work correctly. Similarly, a Cofirm statemet is used to record what should be true

More information

Programming with Shared Memory PART II. HPC Spring 2017 Prof. Robert van Engelen

Programming with Shared Memory PART II. HPC Spring 2017 Prof. Robert van Engelen Programmig with Shared Memory PART II HPC Sprig 2017 Prof. Robert va Egele Overview Sequetial cosistecy Parallel programmig costructs Depedece aalysis OpeMP Autoparallelizatio Further readig HPC Sprig

More information

BAAN IV. BAAN IV Installation Manual for DB2 on Windows NT

BAAN IV. BAAN IV Installation Manual for DB2 on Windows NT BAAN IV BAAN IV Istallatio Maual for DB2 o Widows NT A publicatio of: Baa Developmet B.V. P.O.Box 143 3770 AC Bareveld The Netherlads Prited i the Netherlads Baa Developmet B.V. 1999. All rights reserved.

More information

BEA Tuxedo. Using the BEA Tuxedo Workstation Component

BEA Tuxedo. Using the BEA Tuxedo Workstation Component BEA Tuxedo Usig the BEA Tuxedo Workstatio Compoet BEA Tuxedo Release 7.1 Documet Editio 7.1 May 2000 Copyright Copyright 2000 BEA Systems, Ic. All Rights Reserved. Restricted Rights Leged This software

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

More information