Example: using cob2 to compile and link under z/OS UNIX

The following examples illustrate the use of cob2.

  • To compile one file called alpha.cbl, enter:
    
    cob2 -c alpha.cbl
    

    The compiled file is named alpha.o.

  • To compile two files called alpha.cbl and beta.cbl, enter:
    
    cob2 -c alpha.cbl beta.cbl
    

    The compiled files are named alpha.o and beta.o.

  • To link two files, compile them without the -c option. For example, to compile and link alpha.cbl and beta.cbl and generate gamma, enter:
    
    cob2 alpha.cbl beta.cbl -o gamma
    

    This command creates alpha.o and beta.o, then links alpha.o, beta.o, and the COBOL libraries. If the link step is successful, it produces an executable program named gamma.

  • To compile alpha.cbl with the LIST and NOADATA options, enter:
    
    cob2 -qlist,noadata alpha.cbl
    
  • To compile alpha.cbl with the SQL option so that the database request module (DBRM) is written to member "alpha" of the existing PDS data set USER.COBOL.DBRMLIB, enter:
    
    cob2 -qsql alpha.cbl -o alpha -dbrmlib=USER.COBOL.DBRMLIB
    
    Note: The SQL coprocessor must be in your STEPLIB in order for this to work.
  • To compile alpha.cbl with the SQL option so that the database request module (DBRM) is written to z/OS® UNIX file alpha.dbrm, enter:
    cob2 -qsql alpha.cbl -o alpha -dbrmlib
    
    Note: The SQL coprocessor must be in your STEPLIB in order for this to work, and you need to use the SQL coprocessor for Db2® 12 with APAR PI88171 applied.