### Example: Prepare PTF Package Installation using Shell Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-preparing-ptf-package-installation This example demonstrates the complete process of preparing a PTF package for installation. It includes changing to the update directory, uncompressing and extracting the package, and generating the `.toc` file, all using standard AIX shell commands. ```shell cd /compiler/update zcat cobol.51.YYMMDD.tar.Z | tar -xvf - inutoc . ``` -------------------------------- ### Install COBOL Runtime to Specific Directory with Log (AIX) Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-installing-cobol-runtime-environment This example demonstrates installing all COBOL runtime environment filesets into `/runtime/usr/sys/inst.images` and directing the installation log to `/tmp/install.log`. This provides a concrete example of using the `installp` command with specific paths. ```shell installp -e /tmp/install.log -YaXgd /runtime/usr/sys/inst.images all ``` -------------------------------- ### Example: Prepare and Install PTF Package on AIX Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=uicrea-preparing-ptf-package-installation This example demonstrates the complete process of preparing a PTF package for installation. It includes changing to the update directory, uncompressing and extracting the package using 'zcat' and 'tar', and then generating the '.toc' file using 'inutoc'. ```bash cd /runtime/update zcat cobol.runtime.51.YYMMDD.tar.Z | tar -xvf - inutoc . ``` -------------------------------- ### Preview COBOL Runtime Installation with installp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=bicrea-previewing-installation-license-agreements This command previews the installation of all available runtime environment filesets from a specified source directory. It does not perform the actual installation but logs the preview process to a specified log file. This is useful for verifying installation steps before committing. ```shell installp -e /tmp/install.log -paXgd cdrom/runtime/usr/sys/inst.images all ``` -------------------------------- ### Preview COBOL Compiler Installation with installp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-previewing-installation-license-agreements This command previews the installation of all available COBOL compiler filesets from a specified source directory to a target location without actually performing the installation. It also logs the preview process to a specified file. This is useful for verifying installation steps and configurations before a live installation. ```bash installp -paXgd /cdrom/usr/sys/inst.images -e /tmp/install.log all ``` -------------------------------- ### Install PTF filesets with logging using installp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=uica-using-installp Installs all available PTF filesets from a specified directory to default locations and logs the installation process to a specified log file. It uses the -a, -X, -g, -d, and -e flags of the installp command. ```bash installp -aXgd PTF_filesets_location -e logfile fileset_names ``` ```bash installp -aXgd /compiler/update/ -e /tmp/install.log all ``` -------------------------------- ### Create a COBOL 'Hello World' Program Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-testing-installation-cobol This COBOL program, 'hello.cbl', is a simple 'Hello World!' example used to test the COBOL compiler and runtime environment. It defines the necessary divisions and procedures to display a message and terminate successfully. ```cobol 000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. HELLO. 000300 AUTHOR. JOE PROGRAMMER. 000400 ENVIRONMENT DIVISION. 000500 DATA DIVISION. 000600 PROCEDURE DIVISION. 000700 MAINLINE. 000800 DISPLAY 'Hello World!'. 000900 STOP RUN. ``` -------------------------------- ### Install COBOL Runtime Environment for AIX with Logging Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=icrea-using-installp This command installs all available COBOL Runtime Environment filesets from the specified directory and writes the installation output to a log file. The `-aXYgd` flags ensure all latest and prerequisite filesets are applied and committed, licenses are accepted, and installation images are used. The `-e logfile` flag directs output to a specified log file. The `all` argument indicates all filesets should be attempted. ```bash installp -aXYgd install_images_location -e logfile all ``` -------------------------------- ### Install PTFs with installp Command Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=uicrea-using-installp This command installs all available PTF filesets from a specified directory, logs the installation to a specified file, and attempts to expand the file system if space is insufficient. It requires the PTF filesets location, a log file path, and the fileset names (or 'all'). ```bash installp -aXgd PTF_filesets_location -e logfile fileset_names ``` ```bash installp -aXgd /runtime/update/ -e /tmp/install.log all ``` -------------------------------- ### Preview COBOL Runtime Installation and License Agreement (AIX) Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-installing-cobol-runtime-environment This command previews the COBOL Runtime Environment for AIX installation process and logs the output to a file. The `-E` flag specifically includes previewing the license text, which is useful for review before full installation. ```shell installp -e logfile -EpaXgd install_images_location all ``` -------------------------------- ### COBOL START Statement for File Positioning Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=files-reading-records-from-file Demonstrates how to use the START statement in COBOL to position the file indicator for sequential reading. This is useful for initiating reads from a specific point in the file, especially when using alternate keys. ```COBOL START file-name KEY IS EQUAL TO ALTERNATE-RECORD-KEY ``` -------------------------------- ### Install COBOL Runtime Environment (AIX) Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-installing-cobol-runtime-environment This command installs the COBOL Runtime Environment for AIX and logs the installation output to a specified file. The `-Y` flag accepts all prompts, and `-aXgd` are standard installp options for installation. ```shell installp -e logfile -YaXgd install_images_location all ``` -------------------------------- ### COBOL Dynamic File Assignment Example Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=files-example-cobol-coding This COBOL example illustrates dynamic file assignment using the `ASSIGN USING` clause. It shows how a file, 'inventory-file', can be associated with a system file-name at runtime by moving the path to a data item. This method allows for flexible file location management. ```COBOL SELECT inventory-file ASSIGN USING a-file . . . . FD inventory-file . . . . 77 a-file PIC X(25) VALUE SPACES. . . MOVE "/user/inventory/parts" TO a-file OPEN INPUT inventory-file ``` -------------------------------- ### Preview COBOL Compiler License Text with installp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-previewing-installation-license-agreements This command previews the license text for the COBOL compiler from a specified source directory. The preview process is logged to a specified file, allowing review of the license terms before installation. This command does not install any software. ```bash installp -EpaXgd /cdrom/usr/sys/inst.images -e /tmp/install.license.log all ``` -------------------------------- ### COBOL INVOKE Statement Syntax and Examples Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=client-invoking-methods-invoke Demonstrates the syntax for invoking static and instance methods using the INVOKE statement in COBOL for AIX. It includes examples of passing arguments by value and handling returned values. ```COBOL Invoke Account "createAccount" using by value 123456 returning anAccount. Invoke anAccount "credit" using by value 500. ``` ```COBOL Invoke objRef "literal-name" . . Invoke objRef identifier-name . . ``` -------------------------------- ### Example: Calling SQLConnect Function Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=ppaaioc-example-passing-pointers-as-arguments-in-odbc-calls Provides two examples for calling the SQLConnect function in COBOL for AIX, showing different approaches to passing parameters. ```APIDOC ## CALL SQLConnect Examples ### Description These examples demonstrate how to invoke the `SQLConnect` function in COBOL for AIX, with variations in how string parameters are passed. ### Method `CALL` (COBOL statement) ### Endpoint N/A (This is a function call within a program) ### Parameters #### Common Parameters for both examples: - **ConnectionHandle** - Handle to the connection. - **ServerName** (Data Structure) - Name of the server. - **UserIdentifier** (Data Structure) - User ID for connection. - **AuthentificationString** (Data Structure) - Password or authentication string. - **SQL-NTS** (numeric literal) - Null Terminator String constant. - **SQL-RC** (numeric) - Return code. ### Request Example 1: Using BY VALUE and BY REFERENCE directly ```cobol . . . CALL "SQLConnect" USING BY VALUE ConnectionHandle BY REFERENCE ServerName BY VALUE SQL-NTS BY REFERENCE UserIdentifier BY VALUE SQL-NTS BY REFERENCE AuthentificationString BY VALUE SQL-NTS RETURNING SQL-RC . . . ``` ### Request Example 2: Using Pointers for String Parameters ```cobol . . . SET Ptr-to-ServerName TO ADDRESS OF ServerName SET Ptr-to-UserIdentifier TO ADDRESS OF UserIdentifier SET Ptr-to-AuthentificationString TO ADDRESS OF AuthentificationString CALL "SQLConnect" USING BY VALUE ConnectionHandle Ptr-to-ServerName SQL-NTS Ptr-to-UserIdentifier SQL-NTS Ptr-to-AuthentificationString SQL-NTS RETURNING SQL-RC . . . ``` ### Response #### Success Response - **SQL-RC** - Indicates successful connection (e.g., SQL-SUCCESS or SQL-SUCCESS-WITH-INFO). #### Response Example (Indicated by the successful return code in `SQL-RC` after the `CALL` statement.) ``` -------------------------------- ### COBOL Unstring, Upper-case, Log10, and Max Function Examples Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=data-using-intrinsic-functions-built-in-functions Demonstrates the syntax for invoking COBOL intrinsic functions such as Unstring, Upper-case, Log10, and Max. These examples show how to pass arguments and assign the returned values. ```COBOL Unstring Function Upper-case(Name) Delimited By Space Into Fname Lname Compute A = 1 + Function Log10(x) Compute M = Function Max(x y z) ``` -------------------------------- ### COBOL General Arithmetic Examples Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=arithmetic-fixed-point-contrasted-floating-point Demonstrates the use of general arithmetic statements in COBOL, including exponentiation, addition, and assignment. These examples illustrate how to perform basic calculations within a COBOL program. ```cobol compute report-matrix-col = (emp-count ** .5) + 1 add report-matrix-min to report-matrix-max giving report-matrix-tot ``` -------------------------------- ### Example STRING Statement in COBOL Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=string-example-statement Demonstrates the COBOL STRING statement to format data from a record into an output line. It utilizes `DELIMITED BY SIZE` and `DELIMITED BY DEC-POINT` clauses, and the `WITH POINTER` option. The example shows how data is moved into the receiving field `RPT-LINE` starting at a specified position. ```COBOL 01 RCD-01. 05 CUST-INFO. 10 CUST-NAME PIC X(15). 10 CUST-ADDR PIC X(35). 05 BILL-INFO. 10 INV-NO PIC X(6). 10 INV-AMT PIC $$,$$$.99. 10 AMT-PAID PIC $$,$$$.99. 10 DATE-PAID PIC X(8). 10 BAL-DUE PIC $$,$$$.99. 10 DATE-DUE PIC X(8). 77 RPT-LINE PIC X(120). 77 LINE-POS PIC S9(3). 77 LINE-NO PIC 9(5) VALUE 1. 77 DEC-POINT PIC X VALUE ".". STRING LINE-NO SPACE CUST-INFO INV-NO SPACE DATE-DUE SPACE DELIMITED BY SIZE BAL-DUE DELIMITED BY DEC-POINT INTO RPT-LINE WITH POINTER LINE-POS. ``` -------------------------------- ### COBOL LENGTH Function Example Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=functions-finding-length-data-items Demonstrates the usage of the COBOL `LENGTH` function to get the length of a customer name for moving it into a record field. The `LENGTH` function returns the length of the argument in character positions. ```COBOL Move Customer-name To Customer-record(1:Function Length(Customer-name)) ``` -------------------------------- ### COBOL Data Declaration for String Manipulation Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=items-example-arithmetic-expressions-as-reference-modifiers Declares three data fields in COBOL: LEFTY for left-justified output, RIGHTY for right-justified input, and I as a binary integer for counting. This setup is essential for the subsequent string manipulation example. ```COBOL 01 LEFTY PIC X(30). 01 RIGHTY PIC X(30) JUSTIFIED RIGHT. 01 I PIC 9(9) USAGE BINARY. ``` -------------------------------- ### Move Substring and Get Character Count using UNSTRING (COBOL) Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=strings-manipulating-null-terminated This example shows how to use the UNSTRING statement to move characters from a null-terminated source string to a target area and simultaneously capture the count of moved characters. It includes error handling for overflow conditions. ```COBOL WORKING-STORAGE SECTION. 01 source-field PIC X(1001). 01 char-count COMP-5 PIC 9(4). 01 target-area. 02 individual-char OCCURS 1 TO 1000 TIMES DEPENDING ON char-count PIC X. . . . PROCEDURE DIVISION. UNSTRING source-field DELIMITED BY X"00" INTO target-area COUNT IN char-count ON OVERFLOW DISPLAY "source not null terminated or target too short" END-UNSTRING ``` -------------------------------- ### Preview COBOL Runtime License Text with installp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=bicrea-previewing-installation-license-agreements This command previews only the license text associated with the COBOL Runtime Environment from a specified source directory. It logs the license text to a specified log file without initiating any installation. This is helpful for reviewing license agreements. ```shell installp -e /tmp/install.license.log -EpaXgd cdrom/runtime/usr/sys/inst.images all ``` -------------------------------- ### COBOL Client Program for Account Class Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=client-example-defining This COBOL program acts as a client to the Account class. It demonstrates invoking a factory method to create an Account object, calling instance methods to credit the account and print its status. It requires the Account class to be defined elsewhere. ```cobol cbl thread,pgmname(longmixed) Identification division. Program-id. "TestAccounts" recursive. Environment division. Configuration section. Repository. Class Account is "Account". Data Division. * Working data is declared in LOCAL-STORAGE instead of * WORKING-STORAGE so that each thread has its own copy: Local-storage section. 01 anAccount usage object reference Account. * Procedure division. Test-Account-section. Display "Test Account class" * Create account 123456 with 0 balance: Invoke Account "createAccount" using by value 123456 returning anAccount * Deposit 500 to the account: Invoke anAccount "credit" using by value 500 Invoke anAccount "print" Display space * Stop Run. End program "TestAccounts". ``` -------------------------------- ### COBOL Example: CEEDATM Usage Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=services-ceedatm-convert-seconds-character-time-stamp A COBOL code example demonstrating how to call the CEEDATM service to convert a date represented in Lilian seconds to a character timestamp format. ```APIDOC ## COBOL Example: CEEDATM Usage ### Description This COBOL program demonstrates calling the CEEDATM service to convert a specific date and time into a formatted character string. It first uses CEESECS to get the Lilian seconds representation of '06/02/88 10:23:45 AM', and then uses CEEDATM to format these seconds into 'MM/DD/YY HH:MI:SS AP' format. ### Method CALL 'CEESECS' then CALL 'CEEDATM' ### Request Example ```cobol ************************************************* ** ** ** Function: CEEDATM - convert seconds to ** ** character time stamp ** ** ** ** In this example, a call is made to CEEDATM ** ** to convert a date represented in Lilian ** ** seconds (the number of seconds since ** ** 00:00:00 14 October 1582) to a character ** ** format (such as 06/02/88 10:23:45). The ** ** result is displayed. ** ** ** ************************************************* IDENTIFICATION DIVISION. PROGRAM-ID. CBLDATM. DATA DIVISION. WORKING-STORAGE SECTION. 01 DEST PIC S9(9) BINARY VALUE 2. 01 SECONDS COMP-2. 01 IN-DATE. 02 Vstring-length PIC S9(4) BINARY. 02 Vstring-text. 03 Vstring-char PIC X OCCURS 0 TO 256 TIMES DEPENDING ON Vstring-length of IN-DATE. 01 PICSTR. 02 Vstring-length PIC S9(4) BINARY. 02 Vstring-text. 03 Vstring-char PIC X OCCURS 0 TO 256 TIMES DEPENDING ON Vstring-length of PICSTR. 01 TIMESTP PIC X(80). 01 FC. 02 Condition-Token-Value. COPY CEEIGZCT. 03 Case-1-Condition-ID. 04 Severity PIC S9(4) COMP. 04 Msg-No PIC S9(4) COMP. 03 Case-2-Condition-ID REDEFINES Case-1-Condition-ID. 04 Class-Code PIC S9(4) COMP. 04 Cause-Code PIC S9(4) COMP. 03 Case-Sev-Ctl PIC X. 03 Facility-ID PIC XXX. 02 I-S-Info PIC S9(9) COMP. * * PROCEDURE DIVISION. PARA-CBLDATM. ************************************************* ** Call CEESECS to convert time stamp of 6/2/88** ** at 10:23:45 AM to Lilian representation ** ************************************************* MOVE 20 TO Vstring-length of IN-DATE. MOVE '06/02/88 10:23:45 AM' TO Vstring-text of IN-DATE. MOVE 20 TO Vstring-length of PICSTR. MOVE 'MM/DD/YY HH:MI:SS AP' TO Vstring-text of PICSTR. CALL 'CEESECS' USING IN-DATE, PICSTR, SECONDS, FC * * ************************************************* ** Call CEEDATM to convert Lilian seconds to ** ** character time stamp ** ************************************************* MOVE 20 TO Vstring-length of PICSTR. MOVE 'MM/DD/YY HH:MI:SS AP' TO Vstring-text of PICSTR. CALL 'CEEDATM' USING SECONDS, PICSTR, TIMESTP, FC * * ************************************************* ** Display the results ** ************************************************* IF Severity = 0 THEN DISPLAY "Input seconds: " SECONDS DISPLAY "Output timestamp: " TIMESTP ELSE DISPLAY "CEEDATM failed with severity " Severity DISPLAY "Message number: " Msg-No END-IF. GOBACK. ``` ### Response Example ``` Input seconds: [seconds value] Output timestamp: 06/02/88 10:23:45 AM ``` ``` -------------------------------- ### Create GDG Catalog in DB2 File System using gdgmgr Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=groups-creating-generation-data This example shows how to create a GDG catalog in the DB2 file system. It involves initializing the DB2 environment, setting the DB2DBDFT environment variable to the target database, and then using the gdgmgr command with -F DB2 and -c flags. The schema is specified directly in the catalog name. ```shell . /home/db2inst1/sqllib/db2profile export DB2DBDFT=database gdgmgr -F DB2 -c cics.dbGroup ``` -------------------------------- ### Verify Required Filesets Installation using lslpp Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=aix-system-prerequisites This command checks for the presence of essential operating system runtime and locale filesets required for IBM COBOL for AIX V5.1. It utilizes the 'lslpp' utility to list installed software packages matching the specified patterns. Ensure these filesets are installed before proceeding with the COBOL installation. ```bash lslpp -L bos.loc.* bos.rte bos.rte.libc ``` -------------------------------- ### Create GDG Catalog in SFS File System using gdgmgr Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=groups-creating-generation-data This demonstrates creating a GDG catalog in the SFS file system. It shows how to use a fully qualified SFS name or an abbreviated form by setting the CICS_TK_SFS_SERVER environment variable and using the -F flag. It also covers overriding the default GDG home directory. ```shell gdgmgr -c /.:/cics/sfs/sfsServer/baseName ``` ```shell export CICS_TK_SFS_SERVER=/.:/cics/sfs/sfsServer gdgmgr -F SFS -c baseName ``` ```shell export gdg_home=~/groups/forSFS gdgmgr -c /.:/cics/sfs/sfsServer/myGroup ``` -------------------------------- ### Calculate Loan Annuity Payment in COBOL Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=arithmetic-examples-numeric-intrinsic-functions Determines the equal installment payment amount (annuity) required to repay a loan principal and interest over a specified period. This function is suitable for loans with equal payment periods and interest rates. The example calculates the monthly payment for a $15,000 loan over three years at a 12% annual interest rate using the Annuity intrinsic function. ```COBOL 01 Loan Pic 9(9)V99. 01 Payment Pic 9(9)V99. 01 Interest Pic 9(9)V99. 01 Number-Periods Pic 99. . . . Compute Loan = 15000 Compute Interest = .12 Compute Number-Periods = 36 Compute Payment = Loan * Function Annuity((Interest / 12) Number-Periods) ``` -------------------------------- ### Initialize DB2 Environment Profile Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=files-using-db2 Executes the DB2 profile script to initialize the DB2 environment for a specific instance. This is a prerequisite for interacting with DB2 databases. ```shell . /home/db2inst1/sqllib/db2profile ``` -------------------------------- ### Check File System Status Codes in COBOL Source: https://www.ibm.com/docs/en/cobol-aix/5.1_topic=codes-example-checking-file-system-status This COBOL program reads an indexed file dynamically, checks file status codes after OPEN, START, and READ operations. It displays the file status codes if they are not '00' and performs a subroutine to display extended file system codes. The program reads records sequentially until the end of the file or an error occurs. ```COBOL IDENTIFICATION DIVISION. PROGRAM-ID. EXAMPLE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FILESYSFILE ASSIGN TO FILESYSFILE ORGANIZATION IS INDEXED ACCESS DYNAMIC RECORD KEY IS FILESYSFILE-KEY FILE STATUS IS FS-CODE, FILESYS-CODE. DATA DIVISION. FILE SECTION. FD FILESYSFILE RECORD 30. 01 FILESYSFILE-REC. 10 FILESYSFILE-KEY PIC X(6). 10 FILLER PIC X(24). WORKING-STORAGE SECTION. 01 RETURN-STATUS. 05 FS-CODE PIC XX. 05 FILESYS-CODE PIC X(6). PROCEDURE DIVISION. OPEN INPUT FILESYSFILE. DISPLAY "OPEN INPUT FILESYSFILE FS-CODE: " FS-CODE. IF FS-CODE NOT = "00" PERFORM FILESYS-CODE-DISPLAY STOP RUN END-IF. MOVE "000005" TO FILESYSFILE-KEY. START FILESYSFILE KEY IS EQUAL TO FILESYSFILE-KEY. DISPLAY "START FILESYSFILE KEY=" FILESYSFILE-KEY " FS-CODE: " FS-CODE. IF FS-CODE NOT = "00" PERFORM FILESYS-CODE-DISPLAY END-IF. IF FS-CODE = "00" PERFORM READ-NEXT UNTIL FS-CODE NOT = "00" END-IF. CLOSE FILESYSFILE. STOP RUN. READ-NEXT. READ FILESYSFILE NEXT. DISPLAY "READ NEXT FILESYSFILE FS-CODE: " FS-CODE. IF FS-CODE NOT = "00" PERFORM FILESYS-CODE-DISPLAY END-IF. DISPLAY FILESYSFILE-REC. FILESYS-CODE-DISPLAY. DISPLAY "FILESYS-CODE ==>", FILESYS-CODE. ```