INFORMIX-4GL by Example - genci/Vyucba/DBS/5296.pdf · ii INFORMIX-4GL by Example Published by INFORMIX

  • View
    216

  • Download
    1

Embed Size (px)

Text of INFORMIX-4GL by Example - genci/Vyucba/DBS/5296.pdf · ii INFORMIX-4GL by Example Published by...

  • INFORMIX-4GLby Example

    Version 7.3July 1999Part No. 000-5451

  • ii INFORMIX-4GL by Ex

    Published by INFORMIX Press Informix Corporation4100 Bohannon DriveMenlo Park, CA 94025-1032

    1999 Informix Corporation. All rights reserved. The following are trademarks of Informix Corporation or itsaffiliates:

    Answers OnLineTM; CBT StoreTM; C-ISAM; Client SDKTM; ContentBaseTM; Cyber PlanetTM; DataBlade; DataDirectorTM; Decision FrontierTM; Dynamic Scalable ArchitectureTM; Dynamic ServerTM; Dynamic ServerTM,Developer EditionTM; Dynamic ServerTM with Advanced Decision Support OptionTM; Dynamic ServerTM withExtended Parallel OptionTM; Dynamic ServerTM with MetaCube ROLAP Option; Dynamic ServerTM withUniversal Data OptionTM; Dynamic ServerTM with Web Integration OptionTM; Dynamic ServerTM, WorkgroupEditionTM; FastStartTM; 4GL for ToolBusTM; If you can imagine it, you can manage itSM; Illustra; INFORMIX;Informix Data Warehouse Solutions... Turning Data Into Business AdvantageTM; INFORMIX-EnterpriseGateway with DRDA; Informix Enterprise MerchantTM; INFORMIX-4GL; Informix-JWorksTM; InformixLink;Informix Session ProxyTM; InfoShelfTM; InterforumTM; I-SPYTM; MediazationTM; MetaCube; NewEraTM;ON-BarTM; OnLine Dynamic ServerTM; OnLine for NetWare; OnLine/Secure Dynamic ServerTM; OpenCase;ORCATM; Regency Support; Solution Design LabsSM; Solution Design ProgramSM; SuperView; UniversalDatabase ComponentsTM; Universal Web ConnectTM; ViewPoint; VisionaryTM; Web Integration SuiteTM. TheInformix logo is registered with the United States Patent and Trademark Office. The DataBlade logo isregistered with the United States Patent and Trademark Office.

    Documentation Team: Elaina Von Haas, Adam Barnett, Mary Leigh Burke, Mary Kraemer, Eileen Wollam

    GOVERNMENT LICENSE RIGHTS

    Software and documentation acquired by or for the US Government are provided with rights as follows:(1) if for civilian agency use, with rights as restricted by vendors standard license, as prescribed in FAR 12.212;(2) if for Dept. of Defense use, with rights as restricted by vendors standard license, unless superseded by anegotiated vendor license, as prescribed in DFARS 227.7202. Any whole or partial reproduction of software ordocumentation marked with this legend must reproduce this legend.

    ample

  • INFORMIX-4GLby Example

    Introduction 15

    About This Manual 15Summary of Chapters 16How to Use This Manual 18

    How to Use The Examples 18Typographical Conventions 19

    The Demonstration Database and Application Files 19Creating the Demo Database on Informix Dynamic Server 20Creating the Demo Database on INFORMIX-SE 21Copying the Example Files 22Running an Example 22Files Used in Each Example 24

    Naming Conventions 25Using the Examples with Prior Releases 25Additional Documentation 26

    Documentation Included with 4GL 26On-Line Manuals 27On-Line Help 27On-Line Error Messages 27Related Reading 28

    Informix Welcomes Your Comments 28

    Example 1 Writing a Simple 4GL Program 31Displaying Information Using a Form 32The MAIN Function 32The DISPLAY Statements 33Function Overview 33The f_logo Form Specification 34The MAIN Function 36The dsply_logo() Function 36

  • Example 2 Displaying a Message Window 43Defining Global Variables 44The MAIN Function 44Displaying Messages in a Window 44Function Overview 45The GLOBALS Statement and MAIN Function 46The message_window() Function 48The init_msgs() Function 52

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

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

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

    4 Table of Contents

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

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

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

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

    Table of Contents 5

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

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

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

    6 Table of Contents

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

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

    Example 13 Calling a C Function 291The Interface Between C and 4GL 291

    The Argument Stack 291Passing Arguments to a C Function 292Returning Values from a C Function 292

    The fglgets.c Module 293Using fglgets() 293The Design of fglgets() 294Returning Both a Value and a Code 294Handling Arguments 296

    Running the Example 297Creating the Executable Files 298Calling the Executable File 299

    C Module Overview 300Function Overview 301The f_name Form 302The MAIN Function 304The fdump() Function 306

    Table of Contents 7

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

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

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

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

    8 Table of Contents

  • Example 17 Using the DATETIME Data Type 373Redefining the DATETIME Data Entry 373Conserving Screen Space 375Function Overview 376The f_custcall Form 378The f_edit Form 380The DATABASE and GLOBALS Statements 382The MAIN Function 384The cust_menu2() Function 384The browse_custs2() Function 386The next_action3() Function 386The open_calls() Function 388The call_menu() Function 388The addupd_call() Function 390The input_call() Function 392The browse_calls() Function 404The nxtact_call() Function 406The get_timeflds() Function 408The get_datetime() Func