SQL/MP Programming Manual for COBOL
Total Page:16
File Type:pdf, Size:1020Kb
HP NonStop SQL/MP Programming Manual for COBOL Abstract This manual documents the programming interface to HP NonStop™ SQL/MP for COBOL. It is intended for application programmers who are embedding SQL statements and directives in COBOL programs. Product Version NonStop SQL/MP G06 and H01 Supported Release Version Updates (RVUs) This publication supports J06.03 and all subsequent J-series RVUs, H06.03 and all subsequent H-series RVUs, G06.20 and all subsequent G-series RVUs, and D46.00 and all subsequent D-series RVUs until otherwise indicated by its replacement publications. Part Number Published 529758-003 August 2012 Document History Part Number Product Version Published 429326-002 NonStop SQL/MP G06 May 2003 429326-003 NonStop SQL/MP G06 December 2003 429326-004 NonStop SQL/MP G06 December 2004 529758-001 NonStop SQL/MP G06 April 2005 529758-002 NonStop SQL/MP G06 and H01 August 2010 529758-003 NonStop SQL/MP G06 and H01 August 2012 Legal Notices © Copyright 2012 Hewlett-Packard Development Company, L.P. Legal Notice Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor’s standard commercial license. The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein. Export of the information contained in this publication may require authorization from the U.S. Department of Commerce. Microsoft, Windows, and Windows NT are U.S. registered trademarks of Microsoft Corporation. Intel, Pentium, and Celeron are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Java® is a registered trademark of Oracle and/or its affiliates. Motif, OSF/1, UNIX, X/Open, and the "X" device are registered trademarks, and IT DialTone and The Open Group are trademarks of The Open Group in the U.S. and other countries. Open Software Foundation, OSF, the OSF logo, OSF/1, OSF/Motif, and Motif are trademarks of the Open Software Foundation, Inc. OSF MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE OSF MATERIAL PROVIDED HEREIN, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. OSF shall not be liable for errors contained herein or for incidental consequential damages in connection with the furnishing, performance, or use of this material. © 1990, 1991, 1992, 1993 Open Software Foundation, Inc. The OSF documentation and the OSF software to which it relates are derived in part from materials supplied by the following:© 1987, 1988, 1989 Carnegie-Mellon University. © 1989, 1990, 1991 Digital Equipment Corporation. © 1985, 1988, 1989, 1990 Encore Computer Corporation. © 1988 Free Software Foundation, Inc. © 1987, 1988, 1989, 1990, 1991 Hewlett-Packard Company. © 1985, 1987, 1988, 1989, 1990, 1991, 1992 International Business Machines Corporation. © 1988, 1989 Massachusetts Institute of Technology. © 1988, 1989, 1990 Mentat Inc. © 1988 Microsoft Corporation. © 1987, 1988, 1989, 1990, 1991, 1992 SecureWare, Inc. © 1990, 1991 Siemens Nixdorf Informationssysteme AG. © 1986, 1989, 1996, 1997 Sun Microsystems, Inc. © 1989,1990, 1991 Transarc Corporation.OSF software and documentation are based in part on the Fourth Berkeley Software Distribution under license from The Regents of the University of California. OSF acknowledges the following individuals and institutions for their role in its development: Kenneth C.R.C. Arnold, Gregory S. Couch, Conrad C. Huang, Ed James, Symmetric Computer Systems, Robert Elz. © 1980, 1981, 1982, 1983, 1985, 1986, 1987, 1988, 1989 Regents of the University of California. This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org). HP NonStop SQL/MP Programming Manual for COBOL Index Examples Figures Tables Legal Notices What’s New in This Manual xi Manual Information xi New and Changed Information xi About This Manual xiii Who Should Read This Guide xiii Related Manuals xiii Notation Conventions xvi HP Encourages Your Comments xix 1. Introduction Advantages of Using Embedded SQL Statements 1-1 Development of a COBOL Program 1-2 Host Variables 1-2 SQL/MP Statements and Directives 1-2 SQL/MP System Procedures 1-4 Program Compilation and Execution 1-4 Error and Status Reporting 1-5 Dynamic SQL Operations 1-6 SQL/MP Version Management 1-7 COBOL in the Open System (OSS) Environment 1-7 Effect on Conformance to ISO/ANSI Standards 1-8 2. Host Variables Specifying a Declare Section 2-1 Coding Host Variable Names 2-2 Using Corresponding SQL and COBOL Data Types 2-2 Specifying Host Variables in SQL Statements 2-6 Using the COBOL PICTURE Clause 2-7 Fixed-Length Character Data 2-7 Variable-Length Character Data 2-7 Hewlett-Packard Company—529758-003 i Contents 2. Host Variables (continued) 2. Host Variables (continued) Numeric Data 2-8 Using COBOL Data Description Clauses 2-9 Using Date-Time and INTERVAL Data Types 2-9 Using Indicator Variables for Null Values 2-11 Inserting a Null Value 2-11 Testing for a Null Value 2-12 Retrieving Rows With Null Values 2-13 Creating Host Variables Using the INVOKE Directive 2-14 Advantages of Using an INVOKE Directive 2-14 COBOL Record Descriptions 2-15 Embedded Sign in a Decimal Data Type 2-18 System-Defined Primary Key (SYSKEY) 2-18 Date-Time and INTERVAL Data Types 2-19 Using Indicator Variables With the INVOKE Directive 2-22 Using INVOKE With SQLCI 2-24 Associating a Character Set With a Host Variable 2-25 Treatment in COBOL Statements 2-26 VARCHAR Data Type 2-26 3. SQL/MP Statements and Directives Embedding SQL Statements 3-1 Coding SQL Statements and Directives 3-1 Placing SQL Statements and Directives 3-2 Finding Information 3-3 4. Data Retrieval and Modification Opening and Closing Tables and Views 4-2 Causes of SQL Error 8204 (Lost Open Error) 4-2 Recovering From SQL Error 8204 4-3 Single-Row SELECT Statement 4-4 Using a Column Value to Select Data 4-4 Using a Primary Key Value to Select Data 4-5 Using IN SHARE MODE or IN EXCLUSIVE MODE 4-6 INSERT Statement 4-6 Inserting a Single Row 4-7 Inserting a Null Value 4-7 Inserting a Timestamp 4-8 UPDATE Statement 4-8 HP NonStop SQL/MP Programming Manual for COBOL—529758-003 ii Contents 4. Data Retrieval and Modification (continued) 4. Data Retrieval and Modification (continued) Updating a Single Row 4-9 Updating Multiple Rows 4-9 Updating Columns With Null Values 4-10 DELETE Statement 4-10 Deleting a Single Row 4-11 Deleting Multiple Rows 4-11 Using SQL Cursors 4-12 Steps for Using a Cursor 4-13 Access Requirements for Cursors 4-13 Cursor Position 4-14 Cursor Stability 4-14 Virtual Sequential Block Buffering (VSBB) 4-15 DECLARE CURSOR Statement 4-15 OPEN Statement 4-16 FETCH Statement 4-17 Multirow SELECT Statement 4-19 UPDATE Statement 4-20 Multirow DELETE Statement 4-22 CLOSE Statement 4-23 Using Foreign Cursors 4-23 5. SQL/MP System Procedures COBOLEXT File 5-2 Guardian System Procedures 5-2 SQL Message File 5-2 SQLADDR 5-3 SQLCA_DISPLAY2_ 5-4 Using SQLCA_DISPLAY2_ With an Error Table 5-7 Additional Considerations for SQLCA_DISPLAY2_ 5-7 Generating Meaningful Messages 5-11 SQLCA_TOBUFFER2_ 5-11 Using SQLCA_TOBUFFER2_ With an Error Table 5-15 Additional Considerations for SQLCA_BUFFER2_ 5-16 SQLCAFSCODE 5-17 SQLCAGETINFOLIST 5-17 SQLGETCATALOGVERSION 5-24 SQLGETOBJECTVERSION 5-25 SQLGETSYSTEMVERSION 5-26 HP NonStop SQL/MP Programming Manual for COBOL—529758-003 iii Contents 5. SQL/MP System Procedures (continued) 5. SQL/MP System Procedures (continued) SQLSADISPLAY 5-27 Superseded Procedures 5-30 SQLCADISPLAY 5-30 SQLCATOBUFFER 5-34 6. Explicit Program Compilation Compilation Methods 6-1 TNS Mode Compilation 6-2 Native Mode Compilation for TNS/R Systems 6-4 Preparing for Compilation 6-5 Requirements for Compiling a COBOL Program 6-6 SQL Compiler Directive 6-7 Copying Source Code Into a Compilation Unit 6-9 Setting DEFINEs 6-9 Using PARAM Commands 6-11 Running the HP COBOL Compilers 6-12 Running HP COBOL Compilers in the Guardian Environment 6-13 Running HP COBOL Compilers in the OSS Environment 6-16 Running the Native COBOL Cross Compilers in a PC Host Environment 6-21 Binding and Linking 6-21 The Binder Program 6-22 The nld or ld Utility 6-23 Acceleration of TNS HP COBOL Programs 6-23 The Accelerator 6-24 Running the SQL Compiler 6-25 Required Access Authority 6-25 SQL Compiler Functions 6-25 Running the SQL Compiler in the Guardian Environment 6-27 Running the SQL Compiler in the OSS Environment 6-35 Using Current Statistics 6-35 SQL Compiler Messages 6-36 SQL Program File Format 6-38 SQL Compiler Listings 6-39 Using the EXPLAIN Utility 6-40 Using CONTROL Directives 6-42 Static SQL Statements 6-43 Dynamic SQL Statements 6-44 Using Compatible Components 6-45 HP NonStop SQL/MP Programming Manual for COBOL—529758-003 iv Contents 6. Explicit Program Compilation (continued) 6. Explicit Program Compilation (continued) HP COBOL Compiler 6-45 SQL Compiler 6-45 SQL Program File 6-45 7. Program Execution Required Access Authority 7-1 Using DEFINEs 7-2 Entering the TACL RUN Command 7-2 Using the CREATEPROCESS Routine 7-3 Using the CLU_PROCESS_CREATE_ Routine 7-4 Running a Program in the OSS Environment 7-5 Running a Program at a Low PIN on a D-Series or Later Node 7-5 Interactive Commands 7-6 Programmatic Commands 7-6 Pathway Environment 7-7 Determining Compatibility With the SQL Executor 7-7 8.