Exercises — Chapter 39: Real-Time Integration
Exercise 39.1: JSON GENERATE Basics
Objective: Practice generating JSON from COBOL data structures.
Tasks: 1. Create a COBOL program with a customer record containing: customer-id, first-name, last-name, email, phone, account-balance, account-type, active-flag. 2. Use JSON GENERATE to create JSON output with camelCase field names (customerId, firstName, etc.). 3. Populate three different customer records and generate JSON for each. 4. Add a table (OCCURS) of recent transactions (date, amount, description) and generate JSON with a nested array.
Deliverables: - Complete COBOL program - JSON output for three customers - JSON output with transaction array
Exercise 39.2: JSON PARSE
Objective: Parse incoming JSON data into COBOL structures.
Tasks: 1. Create a COBOL program that reads JSON strings from an input file (one JSON object per line). 2. Define a COBOL data structure matching the JSON layout. 3. Use JSON PARSE to populate the COBOL structure. 4. Handle parsing errors gracefully — write failed records to an error file with the error details. 5. Process valid parsed records (e.g., accumulate totals, write a summary report).
Test Data: Create at least 10 JSON records, including 2-3 with intentional errors (missing fields, malformed JSON).
Exercise 39.3: XML GENERATE and PARSE
Objective: Work with XML data in COBOL.
Tasks: 1. Create a COBOL program that generates XML from an insurance claim record (claim-id, patient-name, provider-id, service-date, diagnosis-code, charged-amount). 2. Use XML GENERATE with XML-DECLARATION. 3. Write a second program (or section) that parses the generated XML using XML PARSE with a processing procedure. 4. Verify that the parsed values match the original data.
Deliverables: - XML generation program - XML parsing program with event handler - Sample XML output - Verification results
Exercise 39.4: Simulated MQ Request/Reply
Objective: Implement the MQ request/reply pattern using files as a simulation.
Tasks: 1. Write a client program that creates request messages (as JSON records in a file), each with a unique correlation ID. 2. Write a server program that reads request messages, processes them (e.g., looks up an account), builds response messages (JSON), and writes them to a response file, preserving the correlation ID. 3. Write a client receive program that reads the response file and matches responses to requests using the correlation ID.
This simulates the MQ request/reply pattern: - Request file = request queue - Response file = reply queue - Correlation ID = message correlation
Exercise 39.5: Data Transformation Layer
Objective: Build a reusable data transformation module.
Tasks: 1. Create a COBOL program (or subprogram) that converts between COBOL record format and JSON-friendly format: - COMP-3 amounts to display format with proper decimal placement - COBOL dates (YYYYMMDD) to ISO 8601 format (YYYY-MM-DD) - Trimming trailing spaces from character fields - Converting status codes to human-readable strings 2. Test with at least 5 different record types. 3. Make the transformation configurable — use a control table to define which fields to include and their JSON names.
Exercise 39.6: Event-Driven Message Router
Objective: Implement a message routing pattern.
Tasks: 1. Create a message file containing different types of "events" in JSON format: - ACCOUNT_OPENED events - TRANSACTION_POSTED events - ACCOUNT_CLOSED events - FRAUD_ALERT events 2. Write a COBOL message router that reads each message, identifies its type, and routes it to the appropriate processing paragraph. 3. Each processing paragraph writes to a separate output file. 4. Implement a dead letter handler for unrecognized message types. 5. Produce a routing summary report showing counts by message type.
Exercise 39.7: End-to-End API Simulation
Objective: Build a complete API simulation with request processing and response generation.
Scenario: Build a "Student Grade Inquiry API" simulation: 1. Create a student master file with: student-id, name, major, GPA, enrollment-status, credits-earned. 2. Write a program that reads JSON request messages containing a student ID. 3. Look up the student in the master file. 4. Generate a JSON response with the student's information. 5. Handle errors: student not found, invalid student ID format, system errors. 6. Include proper HTTP-style status codes in the response (200, 404, 400, 500).
Deliverables: - Student master file creation program - API simulation program - Sample requests (including error cases) - Sample responses showing success and error scenarios
Exercise 39.8: Integration Architecture Design (Analysis Exercise)
Objective: Design an integration architecture for a given business scenario.
Scenario: A university registrar's office runs a COBOL system for student records. They need to: - Expose a real-time transcript request API for students - Send enrollment notifications to the financial aid system - Receive grade submissions from faculty through a web portal - Provide real-time course availability checks
Tasks (written analysis, no coding required): 1. Draw an architecture diagram showing all components. 2. For each integration point, specify: synchronous vs. asynchronous, message format (JSON/XML), expected volume, response time requirement. 3. Identify which integration points would use MQ and which would use REST APIs. 4. Design the COBOL COMMAREA layout for the transcript request program. 5. Identify potential failure modes and how each would be handled.