TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Advance Concepts

In this Chapter, We will see introduction about some of the advance concepts in COBOL Prorgamming. However, these topics are beyond the scope of COBOL information.

Developing COBOL programs for DB2 environment:

In general, the coding for your COBOL program will be the same if you want the program to access a DB2 database. However, to retrieve, update, insert, and delete DB2 data and use other DB2 services, you must use SQL statements.

To communicate with DB2, do these steps:
  • Code any SQL statements that you need, delimiting them with EXEC SQL and END-EXEC statements.
  • Either use the DB2 stand-alone precompiler, or compile with the SQL compiler option and use the DB2 coprocessor.

Developing COBOL programs for CICS:

COBOL programs that are written for CICS can run under CICS Transaction Server. CICS COBOL application programs that use CICS services must use the CICS command-level interface.

When you use the CICS compiler option, the Enterprise COBOL compiler handles both native COBOL statements and embedded CICS statements in the source program. You can still use the separate CICS translator to translate CICS statements to COBOL code, but use of the integrated CICS translator is recommended instead.

After you compile and link-edit your program, you need to do some other steps such as updating CICS tables before you can run the COBOL program under CICS.

Developing Oject-Oriented Programs:

When you write an object-oriented (OO) program, you have to determine what classes you need and the methods and data that the classes need to do their work.
  • Object-oriented (OO) programs are based on objects (entities that encapsulate state and behavior) and their classes, methods, and data.

  • A class is a template that defines the state and the capabilities of an object. Usually a program creates and works with multiple object instances (or simply, instances) of a class, that is, multiple objects that are members of that class.

  • The state of each instance is stored in data known as instance data, and the capabilities of each instance are called instance methods.

  • A class can define data that is shared by all instances of the class, known as factory or static data, and methods that are supported independently of any object instance, known as factory or static methods.

Using Enterprise COBOL, you can:
  1. Create instances of Java and COBOL classes.

  2. Invoke methods on Java and COBOL objects.

  3. Write classes that inherit from Java classes or other COBOL classes.

  4. Define and invoke overloaded methods.


You can process XML input in a COBOL program by using the XML PARSE statement.

Processing XML input involves passing control between the XML parser and a processing procedure in which you handle parser events.

The XML PARSE statement is the COBOL language interface to either of two high-speed XML parsers. You use the XMLPARSE compiler option to select the appropriate parser for your application:
  • XMLPARSE(XMLSS) selects the z/OS XML System Services parser.
    This option provides enhanced features such as namespace processing, validation of XML documents with respect to an XML schema, and conversion of text fragments to national character representation (Unicode UTF-16).

  • XMLPARSE(COMPAT) selects the XML parser that is built into the COBOL library.
    This option provides compatibility with XML parsing in Enterprise COBOL Version 3.

To transform COBOL data to XML, use the XML GENERATE statement as in the example below.

    DISPLAY 'XML generation error ' XML-CODE
    DISPLAY 'XML document was successfully generated.'

In the XML GENERATE statement, you first identify the data item (XML-OUTPUT in the example above) that is to receive the XML output. Define the data item to be large enough to contain the generated XML output, typically five to 10 times the size of the COBOL source data depending on the length of its data-name or data-names.

In the DATA DIVISION, you can declare the receiving identifier as alphanumeric (either an alphanumeric group item or an elementary item of category alphanumeric) or as national (either a national group item or an elementary item of category national).

Next you identify the source data item that is to be transformed to XML format (SOURCE-REC in the example). The source data item can be an alphanumeric group item, national group item, or elementary data item of class alphanumeric or national.

If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal