Exercises — Chapter 40: COBOL and the Modern Stack
Exercise 40.1: Dockerize a COBOL Program
Objective: Create a Docker container that compiles and runs a COBOL program.
Tasks: 1. Write a COBOL program that reads a data file, processes records, and writes output. 2. Create a multi-stage Dockerfile: Stage 1 compiles with GnuCOBOL, Stage 2 runs the binary with only the runtime library. 3. Build the container and run it with mounted data volumes. 4. Compare the container image sizes of the single-stage build vs. the multi-stage build.
Deliverables: - COBOL program source - Dockerfile (multi-stage) - Build and run commands documented - Image size comparison
Exercise 40.2: GitHub Actions CI Pipeline
Objective: Set up continuous integration for a COBOL project.
Tasks: 1. Create a GitHub repository with the standard COBOL project structure. 2. Write at least three COBOL programs that use shared copybooks. 3. Create a GitHub Actions workflow that compiles all programs, runs tests, and reports status. 4. Push a change with a syntax error and verify the pipeline catches it. 5. Push a fix and verify the pipeline succeeds.
Deliverables: - GitHub repository URL - Screenshots of successful and failed pipeline runs - Workflow YAML file
Exercise 40.3: VS Code COBOL Setup
Objective: Configure VS Code as a productive COBOL development environment.
Tasks: 1. Install VS Code with the IBM Z Open Editor extension (or alternative COBOL extension). 2. Configure settings.json for COBOL: copybook paths, column rulers, file associations. 3. Open a COBOL program and demonstrate: syntax highlighting, COPY member navigation, paragraph outline. 4. Create a task that compiles the current file using GnuCOBOL. 5. (Optional) Install Zowe Explorer and connect to a mainframe or mock environment.
Deliverables: - settings.json configuration - Screenshots showing VS Code COBOL features - tasks.json for compile task
Exercise 40.4: COBOL-Check Unit Testing
Objective: Write unit tests for a COBOL program using COBOL-Check.
Tasks: 1. Write a COBOL program with at least four testable paragraphs (e.g., validate input, calculate result, format output, handle errors). 2. Write COBOL-Check test cases covering: normal processing, boundary conditions, error handling, edge cases. 3. Run the tests and verify all pass. 4. Introduce a bug and verify the tests catch it.
Deliverables: - COBOL program - COBOL-Check test file (.cut) - Test execution results
Exercise 40.5: Kubernetes Deployment
Objective: Deploy a containerized COBOL application to Kubernetes (local or cloud).
Tasks: 1. Build a Docker image for a COBOL program (from Exercise 40.1 or new). 2. Create Kubernetes manifests: Deployment (3 replicas), Service, ConfigMap. 3. Deploy to a local Kubernetes cluster (minikube, kind, or Docker Desktop). 4. Verify the pods are running and the service is accessible. 5. Scale the deployment up and down and observe the behavior.
Deliverables: - Kubernetes YAML manifests - Commands to deploy and verify - Screenshots showing running pods
Exercise 40.6: API-First Design
Objective: Design an API contract and implement the COBOL backend.
Tasks: 1. Write an OpenAPI 3.0 specification for a "Student Records" API with endpoints: GET /students/{id}, POST /students, PUT /students/{id}/gpa. 2. Implement the COBOL backend using COMMAREA-style linkage sections that match the API contract. 3. Write a thin wrapper (shell script, Python, or Node.js) that accepts HTTP requests and calls the COBOL program. 4. Test the API using curl or Postman.
Deliverables: - OpenAPI specification (YAML) - COBOL program with LINKAGE SECTION - Wrapper code - curl test commands and results
Exercise 40.7: Infrastructure as Code (Analysis Exercise)
Objective: Design an Ansible playbook for COBOL deployment.
Tasks (written analysis): 1. Given a scenario where a new COBOL program needs to be deployed to z/OS, list all the steps required: upload source, compile, link-edit, define to CICS, install, verify. 2. Write an Ansible playbook (pseudocode is acceptable if you do not have access to z/OS) that automates these steps using the ibm.ibm_zos_core collection. 3. Add error handling: what should the playbook do if compile fails? If CICS install fails? 4. Add a rollback task that restores the previous version if the new deployment fails.
Exercise 40.8: End-to-End Modernization Project
Objective: Combine all techniques from this chapter into a complete project.
Tasks: 1. Choose a simple COBOL application (3-5 programs). 2. Set up Git repository with proper structure. 3. Create a Dockerfile for containerization. 4. Write unit tests with COBOL-Check. 5. Create a CI/CD pipeline (GitHub Actions or Jenkins). 6. Write an OpenAPI specification for the main program. 7. Deploy to a local Kubernetes cluster. 8. Document the entire setup in a README.
This is a multi-week project suitable for a term assignment.