Informix 4gl by Example

  • View
    1.650

  • Download
    13

Embed Size (px)

Text of Informix 4gl by Example

IBM Informix 4GL by Example

Version 7.3 January 2002 Part No. 000-5451A

Note: Before using this information and the product it supports, read the information in the appendix entitled Notices.

This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. Copyright International Business Machines Corporation 1996, 2002. All rights reserved. US Government User Restricted RightsUse, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

ii IBM Informix 4GL by Example

INFORMIX-4GL by ExampleIntroduction 15 About This Manual 15 Summary of Chapters 16 How to Use This Manual 18 How to Use The Examples 18 Typographical Conventions 19 The Demonstration Database and Application Files 19 Creating the Demo Database on Informix Dynamic Server Creating the Demo Database on INFORMIX-SE 21 Copying the Example Files 22 Running an Example 22 Files Used in Each Example 24 Naming Conventions 25 Using the Examples with Prior Releases 25 Additional Documentation 26 Documentation Included with 4GL 26 On-Line Manuals 27 On-Line Help 27 On-Line Error Messages 27 Related Reading 28 Informix Welcomes Your Comments 28

20

Example 1

Writing a Simple 4GL Program

3132

Displaying Information Using a Form The MAIN Function 32 The DISPLAY Statements 33 Function Overview 33 The f_logo Form Specication 34 The MAIN Function 36 The dsply_logo() Function 36

Example 2

Displaying a Message Window

43

Dening Global Variables 44 The MAIN Function 44 Displaying Messages in a Window 44 Function Overview 45 The GLOBALS Statement and MAIN Function The message_window() Function 48 The init_msgs() Function 52

46

Example 3

Populating a Ring Menu with Options

55

Opening a Menu 55 Demonstrating the Choice of a Menu Option 56 Executing a Command Supplied by the User 56 Function Overview 56 The MAIN Function 58 The dsply_option() Function 62 The bang() Function 64 The hlpmsgs Message File 66

Example 4

Displaying a Row on a Form

69

Dening Records 70 Returning Values from Functions 70 Entering Information on a Form 71 Selecting Database Information 71 Recovering from Runtime Errors 72 Function Overview 73 The f_custkey and f_custsum Forms 74 The DATABASE and GLOBALS Statements The MAIN Function 76 The cust_summary() Function 78 The get_custnum() Function 80 The get_summary() Function 84 The dsply_summary() Function 86 The tax_rates() Function 88 The prompt_window() Function 88

76

Example 5

Programming a Query by Example 95Constructing Criteria from the Users Entry Executing an SQL Query Dynamically 97 Accessing Multiple Rows with Cursors 97 Handling User Interrupts 98 Utility Functions 100 Function Overview 100 96

4

Table of Contents

The f_customer Form 102 The GLOBALS Statement and MAIN Function The query_cust1() Function 106 The answer_yes() Function 114 The msg() Function 114

104

Example 6

Querying and Updating

117

Modifying the Rows Qualied by a Query 117 Checking for Dependent Rows 118 Function Overview 118 The GLOBALS Statement and MAIN Function 120 The query_cust2() Function 120 The browse_custs Function 124 The next_action() Function 126 The change_cust() Function 128 The update_cust() Function 130 The delete_cust() Function 130 The verify_delete() Function 132 The clear_lines() Function 134

Example 7

Validating and Inserting a Row

137138

Validating Data Entry 137 Retrieving Information from Multiple Tables Function Overview 138 The f_stock Form 140 The GLOBALS Statement 142 The MAIN Function 142 The input_stock() Function 144 The unique_stock() Function 146 The insert_stock() Function 148

Example 8

Displaying a Screen Array in a Popup WindowDisplaying Information in an Array Form Triggering Form Actions with Keys 153 Function Overview 153 The f_manufsel Form 154 The input_stock2() Function 156 The manuf_popup() Function 158 152

151

Table of Contents 5

Example 9

Accessing a Table with a Single-Row FormFunction Overview 166 The f_statesel Form 168 The MAIN Function 170 The cust_menu1() Function 170 The browse_custs1() Function 172 The next_action2() Function 172 The addupd_cust() Function 174 The state_popup() Function 180 The insert_cust() Function 182

165

Example 10

Accessing a Table with a Multi-Row FormModifying Information in an Array Form 186 Handling Empty Fields 186 Identifying Keystrokes 187 Function Overview 189 The f_manuf Form 190 The DATABASE and GLOBALS Statements 192 The MAIN Function 192 The dsply_manuf() Function 194 The valid_null() Function 204 The reshufe() Function 206 The verify_mdel() Function 208 The choose_op() Function 210 The insert_manuf() Function 210 The update_manuf() Function 212 The delete_manuf() Function 212 The verify_rowid() Function 214 The save_rowid() Function 214

185

Example 11

Implementing a Master-Detail RelationshipProgram Overview 217 Function Overview 222 The f_orders Form 224 The f_custsel Form 226 The f_stocksel Form 226 The f_ship Form 228 The DATABASE and GLOBALS Statements The MAIN Function 232 The add_order() Function 232 The input_cust() Function 234 The cust_popup() Function 238 The input_order() Function 240 The input_items() Function 242

217

230

6

Table of Contents

The renum_items() Function 248 The stock_popup() Function 250 The dsply_taxes() Function 252 The order_amount() Function 254 The ship_order() Function 254 The input_ship() Function 256 The order_tx() Function 258 The insert_order() Function 260 The insert_items() Function 260

Example 12

Displaying an Unknown Number of RowsPaging Through Rows Using Array Form Function Overview 265 The f_ordersel File 266 The GLOBALS Statement 268 The MAIN Function 268 The nd_order() Function 270 The cust_popup2() Function 276 The order_popup() Function 282 The calc_order() Function 288 The upd_order() Function 288 264

263

Example 13

Calling a C Function

291

The Interface Between C and 4GL 291 The Argument Stack 291 Passing Arguments to a C Function 292 Returning Values from a C Function 292 The fglgets.c Module 293 Using fglgets() 293 The Design of fglgets() 294 Returning Both a Value and a Code 294 Handling Arguments 296 Running the Example 297 Creating the Executable Files 298 Calling the Executable File 299 C Module Overview 300 Function Overview 301 The f_name Form 302 The MAIN Function 304 The fdump() Function 306

Table of Contents 7

The fgiusr.c Module 308 The fglgets.c Module 310 The getquote() Function 312 The fglgetret() Function 312 The fglgets() Function 314

Example 14

Generating a Report

319

The Program Model 320 Steps in Generating a Report 320 Basic Parts of a Report 321 Directing a Report to the Screen 323 Function Overview 323 The MAIN Function 324 The manuf_listing() Function 324 The manuf_rpt() Report Function 326

Example 15

Reporting Group Totals

329

Choosing a Report Destination 329 The Report Contents 331 Function Overview 332 The DATABASE and GLOBALS Statements The MAIN Function 334 The add_order2() Function 336 The invoice() Function 338 The report_output() Function 340 The invoice_rpt() Report Function 342

334

Example 16

Creating Vertical Menus

351

A Hard-Coded Vertical MenuExample 16a 352 A Generic Vertical MenuExample 16b 353 Example 16a: The f_menu Form 356 The DATABASE and GLOBALS Statements 358 The MAIN Function 358 The main_menu() Function 358 The cust_maint() Function 360 The Remaining maint() Functions 360 Example 16b: The f_menu2 Form 362 The DATABASE and GLOBALS Statements 364 The MAIN Function 364 The dsply_menu() Function 364 The init_menu() Function 366 The init_opnum() Function 368 The choose_option() Function 3688 Table of Contents

Example 17

Using the DATETIME Data Type 373Redening the DATETIME Data Entry 373 Conserving Screen Space 375 Function Overview 376 The f_custcall Form 378 The f_edit Form 380 The DATABASE and GLOBALS Statements 382 The MAIN Function 384 The cust_menu2() Function 384 The browse_custs2() Function 386 The next_action3() Function 386 The open_calls() Function 388 The call_menu() Function 388 The addupd_call() Function 390 The input_call() Function 392 The browse_calls() Function 404 The nxtact_call() Function 406 The get_timeds() Function 408 The get_datetime() Function 410 The init_time() Function 410 The edit_descr() Function 412 The insert_call() Function 414 The update_call() Function 416

Example 18

Using TEXT and VARCHAR Data Types

419419

Verifying the Database Type 419 Positioning the DATABASE Statement in a Program Using Parallel Arrays to Manage Information 421 Handling VARCHAR Data 422 Handling TEXT Data 422 Handling BYTE Data 423 Function Overview 424 The f_catalog Form 426 The f_catadv Form 428 The f_catdescr Form 430 The DATABASE and GLOBALS Statements 432 The MAIN Function 432 The is_online() Function 434 The load_arrays() Function 436 The open_wins() Function 440

Table of Contents 9

The close_wins() Function 440 The dsply_cat() Function 440 The show_advert() Function 442 The show_descr() Function 446 The upd_err() Function 448

Example 19

Browsing with a Scroll Cursor