O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

APIs at Work, Second Edition

Book Description

Application Program Interfaces (APIs) are powerful, built-in tools used to solve business problems. Many System i programmers, however, do not have a working knowledge of the APIs available within i5/OS. Worse still, programmers who are familiar with the use of APIs may not be taking full advantage of the APIs and processing techniques available to them.

In this book, author and noted IBM API expert Bruce Vining is your guide to making sense, and effectively mastering, the wide variety of APIs available with System i. Each chapter is full of real business-world examples that you can modify and use in your own environment.

In recent years, the business programmer has had to integrate applications—often from different operating systems and programming platforms—using different languages to integrate business rules and requirements. APIs allow you to gain access to the underlying structure of an application. With this book you will soon realize that APIs are among the most powerful tools in your toolbox.

New for this edition:

• New chapters covering topics such as exit point concepts, Integrated File System, date and time, cryptographic services, TCP/IP, and more

• Sorting, character data conversion, and user application information

• APIs are covered in depth

• Fully updated code on previous APIs to bring them up to newer standards

• Updates to API changes since the previous edition

• Modernized RPG code to demonstrate current coding style

• An Appendix with COBOL examples and implementation including API equivalents for RPG support of memory management, bit testing, edit words, and more

• Check Your Knowledge tasks at the conclusion of each chapter with solutions provided in RPG and COBOL Write client and server applications that enable your System i to communicate

with other systems, such as PCs, using sockets

Table of Contents

  1. Copyright
  2. Acknowledgments
  3. API Fundamentals
    1. Begin with the Basics
      1. Where to Get Information about APIs from IBM
    2. About the Examples
    3. Pass the Data, Please...
    4. Data Types
    5. Data Values
    6. Telling an API What to Return
    7. Keyed Interface
    8. Returning Data
    9. Receiver Variables
    10. APIs and User Spaces
    11. Two Methods to Access Data from a User Space
    12. Automatically Extendable User Spaces
    13. A Handy User-Space Procedure
    14. Exits
    15. Continuation Handles
    16. Domains
    17. Offsets and Displacements
    18. Error Handling
    19. Common Errors to Avoid
    20. Find an Error?
    21. Summary
    22. Check Your Knowledge
  4. Retrieve APIs
    1. Static Receiver Variables
    2. More on Error-Handling
    3. Dynamic Receiver Variables
    4. Summary
    5. Check Your Knowledge
  5. List APIs
    1. General Data Structure
    2. Generic Header Data Structure
    3. Header Section
    4. Input Parameter Section
    5. List Data Section
    6. Program to Find Files with Deleted Records
    7. Comparing Methods to Access the List Information
    8. Open-List APIs
    9. Using an Open List to Find Files with Deleted Records
    10. Combining Fixed-Size QSYSINC Structures with Variable-Length Fields
    11. Initializing Input Structures
    12. Processing Lists with Variable-Length Entries
    13. Summary
    14. Check Your Knowledge
  6. Command-Processing APIs
    1. Defining the QCMDEXC API
    2. Using QCMDEXC to Run RGZPFM
    3. Using QCMDEXC to Run OPNQRYF
    4. Using QCMDEXC to Override Printer Parameters
    5. Using QCMDEXC to Submit a Job to a Job Queue
    6. Using the System Function Instead of Calling QCMDEXC
    7. The QCMDCHK API
    8. A Complete Command-Processing API
    9. The IBM Command-Line API
    10. The Command-Analyzer Retrieve Exit Program
    11. Summary
    12. Check Your Knowledge
  7. Object APIs
    1. To Exist or Not to Exist, That Is the Question
    2. An Alternative to DSPLIBD and DSPLIB
    3. Summary
    4. Check Your Knowledge
  8. Data-Queue APIs
    1. Queuing Your Data
    2. Using Data Queues for Job-Related Information
    3. Using the Receive Data Queue API (QRCVDTAQ)
    4. Using the Send Data Queue API (QSNDDTAQ)
    5. Using the Retrieve Data Queue Description API (QMHQRDQD)
    6. Summary
    7. Check Your Knowledge
  9. Database File APIs
    1. Triggers
    2. Get a List of File Members
    3. Get a List of Fields in a File
    4. Retrieve File Description
    5. Summary
    6. Check Your Knowledge
  10. Date and Time APIs
    1. Using the Convert Date and Time Format API (QWCCVTDT)
    2. Converting a System Timestamp Using the QWCCVTDT API
    3. Converting Time Values from One Time Zone to Another Using QWCCVTDT
    4. Adjusting the System Time
    5. ILE CEE Date and Time APIs
    6. Adding 30 Days to a Date
    7. ILE CEE Feedback Error Handling
    8. Summary
    9. Check Your Knowledge
  11. Character Conversion APIs
    1. Monocasing Character Data Using the Convert Case API
    2. Converting Character Data Using ICONV
    3. Summary
    4. Check Your Knowledge
  12. Message APIs
    1. Watch Exit Programs
    2. Starting a Watch
    3. Sending Program Messages
    4. The sleep API
    5. Sending Program Messages with Replacement Data
    6. Using Retrieve Message to Read Message Descriptions
    7. Summary
    8. Check Your Knowledge
  13. Cryptographic Services APIs
    1. Encrypting Data
    2. Creating a Key Context
    3. Generating a Pseudorandom Number
    4. Decrypting Data
    5. Using Key-Management APIs
    6. Loading a Master Key
    7. Setting a Master Key
    8. Creating a Key Store File
    9. Generating a Key Record
    10. Encrypting Data Using a Key Store
    11. Decrypting Data Using a Key Store
    12. Summary
    13. Check Your Knowledge
  14. Security APIs
    1. Swapping the Active User Profile
    2. Retrieving Encrypted Passwords
    3. Knowing When a User Profile Is Changed
    4. Retrieving User Information
    5. Summary
    6. Check Your Knowledge
  15. Work-Management APIs
    1. Getting a List of Jobs and Selected Job Attributes
    2. The Change Job API, QWTCHGJB
    3. Retrieve System Status (QWCRSSTS)
    4. Summary
    5. Check Your Knowledge
  16. Integrated File System APIs
    1. Opening an Integrated File System Stream File
    2. Accessing Errno
    3. Writing to an Integrated File System Stream File
    4. Closing an Integrated File System Stream File
    5. Opening an Integrated File System Stream File for Reading
    6. Reading from an Integrated File System Stream File
    7. Opening, Writing, Reading, and Closing an Integrated File System Stream File
    8. Working with Directories
    9. Opening a Directory
    10. Reading a Directory Entry
    11. Closing a Directory
    12. Opening, Reading, and Closing a Directory
    13. Opening, Reading, and Closing a Directory Using the QLG APIS
    14. Using Qlgopen to Create the Π File
    15. Summary
    16. Check Your Knowledge
  17. Socket APIs
    1. Using the SOCKET API
    2. Using the BIND API
    3. Using the LISTEN API
    4. Using the ACCEPT API
    5. Using the RECV API
    6. Using the SEND API
    7. Using the close API
    8. Putting All of the APIs Together with a File Server
    9. A Few Words of Warning
    10. Putting All of the APIs Together with a File Server Client
    11. Using the GETHOSTBYNAME API
    12. Running the File Transfer Programs
    13. Putting All of the APIs Together with a Distributed Processing Server
    14. Building a Better Server
    15. Using the Getservbyname API
    16. Create a Routing Server
    17. Using the GIVEDESCRIPTOR API
    18. Using the TAKEDESCRIPTOR API
    19. Communicating Internal Job IDs
    20. Using the SETSOCKOPT API
    21. Defining a TCP Server
    22. A Simple Telnet Server
    23. Receiving Data without Waiting
    24. Summary
    25. Check Your Knowledge
  18. Odds and Ends
    1. The Sort API, QLGSORT
    2. User Application Information APIs
    3. The Update User Application Information API, QsyUpdateUserApplicationInfo
    4. The Retrieve User Application Information API, QsyRetrieveUserApplicationInfo
    5. Determining the System Release with the Retrieve Product Information API, QSZRTVPR
    6. The List Save File API, QSRLSAVF, and Continuation Handles
    7. Using a Subfile to Display List API Entries
    8. Summary
    9. Check Your Knowledge
  19. The Examples
  20. Fixed Form ILE RPG Examples
  21. ILE COBOL Examples
    1. Compiling the Source Code
    2. Some Additional APIs
  22. Answers
    1. Solution for Chapter 1
    2. Solution for Chapter 2
    3. Solution for Chapter 3
    4. Solution for Chapter 4
    5. Solution for Chapter 5
    6. Solutions for Chapter 6
    7. Solution for Chapter 7
    8. Solution for Chapter 8
    9. Solution for Chapter 9
    10. Solutions for Chapter 10
    11. Solutions for Chapter 11
    12. Solution for Chapter 12
    13. Solution for Chapter 13
    14. Solution for Chapter 14
    15. Solutions for Chapter 15
  23. About the Code on the Web
    1. Transferring the Source Code
    2. Compiling the Source Code
  24. Your Information Resource for System i