IBM PL/I for AIX
Programming Guide
Ve r s i o n 2.0.0
SC18-9328-00
IBM PL/I for AIX
Programming Guide
Ve r s i o n 2.0.0
SC18-9328-00
Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page 309.
Second Edition (June 2004) This edition applies to IBM PL/I for AIX 2.0.0, 5724-H45, and to any subsequent releases until otherwise indicated in new editions or technical newsletters. Make sure you are using the correct edition for the level of the product. Order publications through your IBM representative or the IBM branch office serving your locality. Publications are not stocked at the address below. A form for readers’ comments is provided at the back of this publication. If the form has been removed, address your comments to: IBM Corporation, Department HHX/H1 555 Bailey Ave San Jose, CA, 95141-1099 United States of America 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. ©International Business Machines Corporation 1998,2004. All rights reserved.
Contents
Figures ...... vii COMPILE ...... 47 COPYRIGHT ...... 48 CURRENCY ...... 48 Part 1. Introducing PL/I on your DEFAULT ...... 48 workstation ...... 1 EXIT...... 54 EXTRN ...... 54 Chapter 1. About this book ...... 3 FLAG ...... 55 FLOATINMATH...... 55 Chapter 2. How to read the syntax GONUMBER ...... 56 GRAPHIC ...... 56 diagrams ...... 5 IMPRECISE ...... 56 INCAFTER ...... 57 Chapter 3. Porting applications between INITAUTO ...... 57 platforms ...... 9 INITBASED ...... 57 Getting mainframe applications to compile on the INITCTL ...... 58 workstation...... 9 INITSTATIC ...... 58 Choosing the right compile-time options . . .10 INCDIR ...... 58 Language restricted...... 10 INSOURCE ...... 58 Using the macro facility to help port programs 13 LANGLVL...... 59 Getting mainframe applications to run on the LIMITS ...... 60 workstation ...... 14 LINECOUNT ...... 60 Data representations causing run-time differences 14 LIST ...... 61 Environment differences affecting portability . .16 MACRO ...... 61 Language elements causing run-time differences 17 MARGINI ...... 61 MARGINS...... 62 MAXMEM...... 62 Part 2. Compiling and linking your MAXMSG ...... 63 program ...... 19 MAXSTMT ...... 64 MAXTEMP ...... 64 Chapter 4. Introducing PL/I for AIX. . .21 MDECK ...... 64 Introducing PL/I for AIX ...... 21 MSG...... 64 Features available with PL/I for AIX . . . . .21 NAMES ...... 65 A short practice exercise ...... 22 NATLANG ...... 65 Becoming familiar with AIX ...... 22 NEST ...... 65 Creating PL/I source programs...... 24 NOT...... 66 NUMBER ...... 66 Chapter 5. Compiling, linking, and OPTIMIZE...... 67 OPTIONS ...... 67 running your program ...... 29 OR ...... 67 Compiling, linking, and running your program . .29 PP ...... 68 Invoking the PL/I for AIX compiler . . . . .29 PPTRACE ...... 69 Specifying compile-time options ...... 35 PRECTYPE ...... 69 Invoking the linkage editor ...... 38 PREFIX ...... 69 Running a program...... 38 PROCEED ...... 70 REDUCE ...... 71 Chapter 6. Compile-time option RESEXP ...... 71 descriptions ...... 41 RESPECT ...... 72 Compile-time option descriptions ...... 41 RULES ...... 72 Rules for using compile-time options ...... 43 SEMANTIC ...... 75 AGGREGATE ...... 44 SOURCE ...... 76 ATTRIBUTES ...... 44 STATIC ...... 76 BIFPREC ...... 45 SPILL ...... 76 BLANK...... 46 STMT ...... 77 CHECK ...... 46 STORAGE ...... 77 CMPAT...... 46 SYNTAX ...... 77 CODEPAGE ...... 47 SYSPARM ...... 78 iii
SYSTEM ...... 78 Unexpected program termination...... 138 TERMINAL ...... 78 Other unexpected program results . . . . . 139 TEST ...... 79 Compiler or library subroutine failure . . . . 139 USAGE...... 79 System failure ...... 140 WIDECHAR ...... 79 Poor performance ...... 140 WINDOW ...... 80 XINFO ...... 80 Part 4. Input and output...... 141 XREF ...... 81
Chapter 7. PL/I preprocessors. . . . .83 Chapter 10. Using data sets and files 143 Types of data sets ...... 143 Include preprocessor ...... 84 Native data sets ...... 144 Examples: ...... 84 Additional data sets ...... 145 Include preprocessor options in the configuration Establishing data set characteristics ...... 146 file ...... 84 Records ...... 146 Macro preprocessor...... 85 Record formats ...... 146 Macro preprocessor options ...... 85 Data set organizations ...... 146 Macro facility options in the configuration file. .86 Specifying characteristics using the PL/I SQL support ...... 87 ENVIRONMENT attribute ...... 147 Programming and compilation considerations . .87 Specifying characteristics using DD_ddname SQL preprocessor options...... 87 environment variables ...... 152 Abbreviations: ...... 89 Associating a PL/I file with a data set . . . . . 161 SQL preprocessor options in the configuration Using environment variables ...... 162 file ...... 92 Using the TITLE option of the OPEN statement 162 Coding SQL statements in PL/I applications . .93 Attempting to use files not associated with data Large Object (LOB) support ...... 98 sets...... 163 User defined functions sample programs . . . 100 How PL/I finds data sets ...... 163 CICS support ...... 107 Opening and closing PL/I files ...... 163 Programming and compilation considerations 107 Opening a file ...... 163 CICS preprocessor options ...... 108 Closing a file ...... 163 Abbreviations: ...... 109 Associating several data sets with one file . . . . 164 Coding CICS statements in PL/I applications 109 Combinations of I/O statements, attributes, and Writing CICS transactions in PL/I . . . . .110 options ...... 164 DISPLAY statement input and output . . . . . 166 Chapter 8. Compilation output . . . . 111 PL/I standard files (SYSPRINT and SYSIN) . . . 167 Compilation output ...... 111 Redirecting standard input, output, and error Using the compiler listing ...... 111 devices ...... 167 Compiler output files...... 121 Chapter 11. Defining and using Part 3. Running and debugging consecutive data sets...... 169 your program ...... 123 Printer-destined files ...... 169 Using stream-oriented data transmission . . . . 170 Chapter 9. Testing and debugging Defining files using stream I/O ...... 171 your programs ...... 125 ENVIRONMENT options for stream-oriented data transmission ...... 171 Testing your programs ...... 125 Creating a data set with stream I/O . . . . . 171 General debugging tips ...... 126 Accessing a data set with stream I/O . . . . 173 PL/I debugging techniques...... 127 Using PRINT files ...... 175 Using the Distributed Debugger tool . . . . 127 Using SYSIN and SYSPRINT files . . . . . 179 Using compile-time options for debugging . . 127 Controlling input from the console ...... 180 Using footprints for debugging ...... 128 Using files conversationally ...... 181 Using dumps for debugging ...... 129 Format of data ...... 181 Using error and condition handling for Stream and record files ...... 181 debugging ...... 133 Capital and lowercase letters ...... 182 Error handling concepts ...... 134 End of file ...... 182 Common programming errors ...... 136 Controlling output to the console...... 182 Logical errors in your source programs. . . . 136 Format of PRINT files ...... 182 Invalid use of PL/I ...... 137 Stream and record files ...... 182 Calling uninitialized entry variables . . . . . 137 Example of an interactive program . . . . . 182 Loops and other unforeseen errors . . . . . 137 Using record-oriented I/O ...... 183 Unexpected input/output data ...... 138 Defining files using record I/O ...... 184 iv PL/I for AIX: Programming Guide
ENVIRONMENT options for record-oriented Chapter 14. Using user exits . . . . . 229 data transmission ...... 185 Using the compiler user exit ...... 229 Creating a data set with record I/O . . . . . 185 Procedures performed by the compiler user exit 229 Accessing and updating a data set with record Activating the compiler user exit ...... 230 I/O...... 185 The IBM-supplied compiler exit, IBMUEXIT . . 230 Customizing the compiler user exit . . . . . 231 Chapter 12. Defining and using Using data conversion tables ...... 234 regional data sets ...... 191 Defining files for a regional data set ...... 193 Chapter 15. Improving performance 237 Specifying ENVIRONMENT options . . . . 193 Selecting compile-time options for optimal Essential information for creating and accessing performance...... 237 regional data sets ...... 194 OPTIMIZE ...... 237 Using keys with regional data sets . . . . . 194 IMPRECISE ...... 238 Using REGIONAL(1) data sets ...... 194 GONUMBER ...... 238 Dummy records ...... 194 RULES ...... 238 Creating a REGIONAL(1) data set . . . . . 195 PREFIX ...... 239 Example ...... 195 DEFAULT ...... 239 Accessing and updating a REGIONAL(1) data Summary of compile-time options that improve set ...... 197 performance...... 242 Sequential access ...... 197 Coding for better performance ...... 242 Direct access...... 198 DATA-directed input and output ...... 243 Example ...... 198 Input-only parameters ...... 243 String assignments ...... 243 Chapter 13. Defining and using Loop control variables ...... 244 workstation VSAM data sets . . . . . 201 PACKAGEs versus nested PROCEDUREs . . . 244 REDUCIBLE functions ...... 245 Remote file access ...... 201 DEFINED versus UNION ...... 246 Workstation VSAM organization ...... 202 Named constants versus static variables . . . 246 Creating and accessing workstation VSAM data Avoiding calls to library routines ...... 247 sets...... 202 Determining which type of workstation VSAM data set you need ...... 202 Chapter 16. Using PL/I in Accessing records in workstation VSAM data mixed-language applications. . . . . 251 sets...... 202 Matching data and linkages ...... 251 Using keys for workstation VSAM data sets . . 203 What data is passed ...... 252 Choosing a data set type ...... 204 How data is passed ...... 253 Defining files for workstation VSAM data sets . . 204 Where data is passed ...... 255 Specifying options of the PL/I ENVIRONMENT Maintaining your environment ...... 255 attribute ...... 205 Invoking non-PL/I routines from a PL/I MAIN 255 Adapting existing programs for workstation Invoking PL/I routines from a non-PL/I main . . 256 VSAM...... 205 Using ON ANYCONDITION ...... 256 Using workstation VSAM sequential data sets . . 208 Using a sequential file to access a workstation Chapter 17. Using sort routines . . . 259 VSAM sequential data set ...... 209 Comparing S/390 and workstation sort programs 259 Defining and loading a workstation VSAM Preparing to use sort ...... 260 sequential data set...... 209 Choosing the type of sort ...... 261 Workstation VSAM keyed data sets ...... 211 Specifying the sorting field ...... 263 Loading a workstation VSAM keyed data set 213 Specifying the records to be sorted . . . . . 264 Using a SEQUENTIAL file to access a Calling the sort program ...... 264 workstation VSAM keyed data set . . . . . 215 PLISRT examples ...... 264 Using a DIRECT file to access a workstation Determining whether the sort was successful 265 VSAM keyed data set ...... 215 Sort data input and output ...... 266 Workstation VSAM direct data sets ...... 218 Sort data handling routines...... 266 Loading a workstation VSAM direct data set 220 E15 — input-handling routine (sort exit E15) 266 Using a SEQUENTIAL file to access a E35 — output-handling routine (sort exit E35) 269 workstation VSAM direct data set . . . . . 222 Calling PLISRTA ...... 271 Using a DIRECT file to access a workstation Calling PLISRTB ...... 272 VSAM direct data set...... 223 Calling PLISRTC ...... 274 Calling PLISRTD, example 1 ...... 275 Part 5. Advanced topics...... 227 Calling PLISRTD, example 2 ...... 276
Contents v
Chapter 18. Using the SAX parser . . 277 Supported EBCDIC code pages ...... 283 Overview...... 277 Supported ASCII code pages ...... 284 The PLISAXA built-in subroutine...... 278 Specifying the code page ...... 284 The PLISAXB built-in subroutine ...... 278 Exceptions ...... 285 The SAX event structure...... 278 Example ...... 286 start_of_document...... 279 Continuable exception codes ...... 297 version_information ...... 279 Terminating exception codes ...... 301 encoding_declaration ...... 279 standalone_declaration ...... 279 Part 6. Appendixes ...... 305 document_type_declaration...... 279 end_of_document ...... 279 Product specifications and service 307 start_of_element ...... 280 attribute_name ...... 280 Product specifications and service ...... 307 attribute_characters ...... 280 Specified operating environment ...... 307 attribute_predefined_reference...... 280 Installing PL/I for AIX ...... 307 attribute_character_reference ...... 280 Shipping shared runtime libraries . . . . . 307 end_of_element...... 280 start_of_CDATA_section ...... 280 Notices ...... 309 end_of_CDATA_section ...... 281 Programming interface information ...... 310 content_characters ...... 281 Macros for customer use ...... 310 content_predefined_reference ...... 281 Trademarks ...... 311 content_character_reference...... 281 processing_instruction ...... 281 Bibliography...... 313 comment ...... 281 Enterprise PL/I publications ...... 313 unknown_attribute_reference ...... 282 DB2 UDB for OS/390 and z/OS ...... 313 unknown_content_reference ...... 282 CICS Transaction Server ...... 313 start_of_prefix_mapping...... 282 end_of_prefix_mapping ...... 282 Glossary ...... 315 exception ...... 282 Parameters to the event functions . . . . . 282 Coded character sets for XML documents . . . . 283 Index ...... 329
vi PL/I for AIX: Programming Guide
Figures
1. Sample configuration file ...... 33 22. Loading a workstation VSAM direct data set 221 2. The PL/I declaration of SQLCA...... 93 23. Updating a workstation VSAM direct data set 3. The PL/I declaration of an SQL descriptor area 94 by key ...... 224 4. TOWERS program compiler listing . . . . 111 24. PL/I compiler user exit procedures . . . . 230 5. PL/I code that produces a formatted dump 131 25. Example of an IBMUEXIT.INF file . . . . 231 6. Example of PLIDUMP output ...... 132 26. Flow of control for the sort program . . . . 262 7. Static and dynamic descendant procedures 134 27. Skeletal code for an input procedure 268 8. Creating a data set with stream-oriented data 28. When E15 is external to the procedure calling transmission ...... 173 PLISRTx ...... 269 9. Accessing a data set with stream-oriented 29. Skeletal code for an output-handling data transmission ...... 175 procedure...... 270 10. Creating a print file via stream data 30. PLISRTA—Sorting from input data set to transmission ...... 177 output data set ...... 271 11. Declaration of PLITABS ...... 178 31. PLISRTB—Sorting from input-handling 12. PL/I structure PLITABS for modifying the routine to output data set ...... 272 preset tab settings ...... 179 32. PLISRTC—Sorting from input data set to 13. A sample interactive program ...... 183 output-handling routine ...... 274 14. Merge Sort—Creating and accessing a 33. PLISRTD—Sorting input-handling routine to consecutive data set ...... 187 output-handling routine ...... 275 15. Printing record-oriented data transmission 190 34. PLISRTD—Sorting input-handling routine to 16. Creating a REGIONAL(1) data set . . . . 196 output-handling routine ...... 276 17. Updating a REGIONAL(1) data set . . . . 199 35. Sample XML document ...... 279 18. Creating a workstation VSAM keyed data set 207 36. PLISAXA coding example - type declarations 286 19. Defining and loading a workstation VSAM 37. PLISAXA coding example - event structure 287 sequential data set ...... 210 38. PLISAXA coding example - main routine 288 20. Defining and loading a workstation VSAM 39. PLISAXA coding example - event routines 289 keyed data set ...... 214 40. PLISAXA coding example - program output 297 21. Updating a workstation VSAM keyed data set 216
vii
viii PL/I for AIX: Programming Guide
Part 1. Introducing PL/I on your workstation
1
2 PL/I for AIX: Programming Guide
Chapter 1. About this book
This Programming Guide is designed to help use the PL/I for AIX compiler to code and compile PL/I programs.
If you have typically used mainframe PL/I and are interested in moving your programs to the AIX platform, Chapter 3, “Porting applications between platforms,” on page 9 should be particularly useful. Other information in this guide is designed to help you understand basic AIX features as well as compile, link, and run a PL/I program using the PL/I for AIX compiler.
A number of chapters on PL/I input and output are included as well as general debugging information. Since a lot of system information is available in existing documentation, it is not repeated in this guide. For the complete titles and order numbers of related publications, see the “Bibliography” on page 313.
3
4 PL/I for AIX: Programming Guide
Chapter 2. How to read the syntax diagrams
The following rules apply to the syntax diagrams used in this book: Arrow symbols Read the syntax diagrams from left to right, from top to bottom, following the path of the line. ─── Indicates the beginning of a statement. ─── Indicates that the statement syntax is continued on the next line. ─── Indicates that a statement is continued from the previous line. ─── Indicates the end of a statement.
Diagrams of syntactical units other than complete statements start with the ─── symbol and end with the ─── symbol.
Diagrams of syntactical units other than complete statements start with the >--- symbol and end with the ---> Conventions v Keywords, their allowable synonyms, and reserved parameters appear in uppercase. These items must be entered exactly as shown. v Variables appear in lowercase italics (for example, column-name). They represent user-defined parameters or suboptions. v When entering commands, separate parameters and keywords by at least one blank if there is no intervening punctuation. v Enter punctuation marks (slashes, commas, periods, parentheses, quotation marks, equal signs) and numbers exactly as given. v Footnotes are shown by a number in parentheses, for example, (1). v A symbol indicates one blank position. Required items Required items appear on the horizontal line (the main path).