Skip to content

Commit 4f81092

Browse files
committed
Add content for Enterprise COBOL APIs section
Signed-off-by: MikeBauerCA <[email protected]>
1 parent 93c7be5 commit 4f81092

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

COBOL Programming Course #2 - Advanced Topics/COBOL Programming Course #2 - Advanced Topics.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,93 @@ Business application solutions were architected decades ago using programming la
4040
- **Using VSCode and Zowe Explorer**
4141

4242
## Enterprise COBOL APIs
43+
IBM mainframe flagship operating system, z/OS, includes software that has enabled large scale business applications for decades. The software is frequently referred to as 'middleware'. Examples of z/OS 'middleware' is Db2, a relational database, CICS, transactional processor, IMS, both transactional and hierarchical database, and MQSeries, a mechanism to store and forward data between systems asynchonously.
4344

4445
### z/OS Middleware
46+
A fundamental capability of z/OS middleware software is communication enablement of programming languages. The z/OS middleware software includes documentation and examples of how any specific programming language can communicate with the specific z/OS middleware software. A programming language, such as Enterprise COBOL, would use documented interfaces and techniques to initiate services and pass data between the COBOL application program and the middleware.
4547

4648
### COBOL API Communication with Middleware
49+
Each middleware has unique reserved words available to Enterprise COBOL.
50+
51+
Enterprise COBOL unique API reserved words are in Example 1.
52+
53+
```
54+
EXEC SQL
55+
EXEC CICS
56+
CALL 'MQ...'
57+
CALL 'CBLTDLI'
58+
```
59+
*Example 1. COBOL API Reserved Words*
60+
61+
Each of the above COBOL API's enable the program to communcate with Db2, CICS, MQSeries, and IMS respectively. When the COBOL source program is compiled, the API reserved words expand the number of lines in the COBOL source code. The expanded lines of code does not need to be fully understood by the COBOL programmer. The COBOL programmer uses an API to accomplish a task within the logic and the middleware expanded code follows through with accomplishing the task.
4762

4863
### COBOL EXEC SQL
64+
SQL, Structured Query Language, is the documented standard for communicating will all relational databases. Enterprise COBOL is capable of including Db2 for z/OS SQL. A few simple COBOL EXEC SQL reserved words are shown in Example 2.
65+
66+
```
67+
WORKING-STORAGE SECTION.
68+
*****************************************************
69+
* SQL INCLUDE FOR SQLCA *
70+
*****************************************************
71+
EXEC SQL INCLUDE SQLCA END-EXEC.
72+
*****************************************************
73+
* SQL DECLARATION FOR VIEW ACCOUNTS *
74+
*****************************************************
75+
EXEC SQL DECLARE my-acct-tbl TABLE
76+
(ACCTNO CHAR(8) NOT NULL,
77+
LIMIT DECIMAL(9,2) ,
78+
BALANCE DECIMAL(9,2) ,
79+
SURNAME CHAR(20) NOT NULL,
80+
FIRSTN CHAR(15) NOT NULL,
81+
ADDRESS1 CHAR(25) NOT NULL,
82+
ADDRESS2 CHAR(20) NOT NULL,
83+
ADDRESS3 CHAR(15) NOT NULL,
84+
RESERVED CHAR(7) NOT NULL,
85+
COMMENTS CHAR(50) NOT NULL)
86+
END-EXEC.
87+
*****************************************************
88+
* SQL CURSORS *
89+
*****************************************************
90+
EXEC SQL DECLARE CUR1 CURSOR FOR
91+
SELECT * FROM my-acct-tbl
92+
END-EXEC.
93+
94+
PROCEDURE DIVISION.
95+
*------------------
96+
LIST-ALL.
97+
EXEC SQL OPEN CUR1 END-EXEC.
98+
EXEC SQL FETCH CUR1 INTO :CUSTOMER-RECORD END-EXEC.
99+
PERFORM PRINT-AND-GET1
100+
UNTIL SQLCODE IS NOT EQUAL TO ZERO.
101+
EXEC SQL CLOSE CUR1 END-EXEC.
102+
```
103+
*Example 2. COBOL SQL Statements*
49104

50105
### COBOL Data Items
106+
While the EXEC SQL is expanded into additional lines of code at compile time,
107+
COBOL needs data items to manage the data passed between the COBOL program and Db2 table.
108+
109+
The fields in the Db2 table record were defined using CREATE TABLE SQL. The EXEC SQL DECLARE in Table xx describes the Db2 table format within the COBOL program. The COBOL programmer with knowledge of the Db2 table format can code the table format or let Db2 for z/OS generate the code using a DCLGEN utility.
110+
111+
Observe ":CUSTOMER-RECORD" in the EXEC SQL FETCH statement. A colon (:) precedes COBOL program defined variables that are used in SQL statements so that Db2 can distinguish a variable name from a column name. Example 3. shows the COBOL program data items describing the COBOL program variable names.
112+
113+
```
114+
*****************************************************
115+
* STRUCTURE FOR CUSTOMER RECORD *
116+
*****************************************************
117+
01 CUSTOMER-RECORD.
118+
02 ACCT-NO PIC X(8).
119+
02 ACCT-LIMIT PIC S9(7)V99 COMP-3.
120+
02 ACCT-BALANCE PIC S9(7)V99 COMP-3.
121+
02 ACCT-LASTN PIC X(20).
122+
02 ACCT-FIRSTN PIC X(15).
123+
02 ACCT-ADDR1 PIC X(25).
124+
02 ACCT-ADDR2 PIC X(20).
125+
02 ACCT-ADDR3 PIC X(15).
126+
02 ACCT-RSRVD PIC X(7).
127+
02 ACCT-COMMENT PIC X(50).
128+
```
129+
*Example 3. COBOL Data Item for storing variables where Db2 is the data source*
51130

52131
## SQL Capability within Enterprise COBOL
53132

0 commit comments

Comments
 (0)