{"id":22572819,"url":"https://github.com/gaurav-van/working-with-cobol","last_synced_at":"2026-02-11T06:01:10.793Z","repository":{"id":245022143,"uuid":"817028333","full_name":"Gaurav-Van/Working-With-COBOL","owner":"Gaurav-Van","description":"This repository contains basic information and concepts of COBOL. It also includes some practice programs I completed while learning COBOL. Why COBOL? I had a brain fart and decided to learn the basics of it, so here we are. Enjoy!","archived":false,"fork":false,"pushed_at":"2024-06-18T22:20:13.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-23T01:38:24.506Z","etag":null,"topics":["cobol","cobol-example","cobol-language","cobol-notes","cobol-programming","cobol-programs","report-generator","tic-tac-toe"],"latest_commit_sha":null,"homepage":"","language":"COBOL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gaurav-Van.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-18T21:53:49.000Z","updated_at":"2024-06-18T22:31:18.000Z","dependencies_parsed_at":"2024-06-19T03:58:08.081Z","dependency_job_id":"cca585e5-dc28-4cf8-891c-c8cca23238dc","html_url":"https://github.com/Gaurav-Van/Working-With-COBOL","commit_stats":null,"previous_names":["gaurav-van/working-with-cobol"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gaurav-Van/Working-With-COBOL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaurav-Van%2FWorking-With-COBOL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaurav-Van%2FWorking-With-COBOL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaurav-Van%2FWorking-With-COBOL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaurav-Van%2FWorking-With-COBOL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gaurav-Van","download_url":"https://codeload.github.com/Gaurav-Van/Working-With-COBOL/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaurav-Van%2FWorking-With-COBOL/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29327814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cobol","cobol-example","cobol-language","cobol-notes","cobol-programming","cobol-programs","report-generator","tic-tac-toe"],"created_at":"2024-12-08T02:12:55.811Z","updated_at":"2026-02-11T06:01:10.765Z","avatar_url":"https://github.com/Gaurav-Van.png","language":"COBOL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Working with COBOL\n\nThis repository contains basic information and concepts of COBOL. It also includes some practice programs I completed while learning COBOL. Why COBOL? I had a brain fart and decided to learn the basics of it, so here we are. Enjoy!\n\n### Column Structure of COBOL\n\n![image](https://github.com/Gaurav-Van/Working-With-COBOL/assets/50765800/e6a780b9-18c8-4f91-ae70-641b4256bd0d)\n\n1. **Sequence Number Area (Columns 1-6)**:\n   \n   * This area is used for numbering the lines of code within a COBOL program. It helps with reference, sorting, and debugging.\n   * Typically, each line of code starts with a sequence number (e.g., 100, 200, etc.). These numbers are essential for maintaining program flow and readability.\n\n2. **Indicator Area (Column 7)**:\n   \n   * Column 7 is reserved for specific indicators:\n     * `*`: Denotes a comment line.\n     * `-`: Indicates continuation from the previous line.\n     * `/`: Marks a new page or form feed in printed reports.\n   * These indicators provide additional context and control over the program.\n\n3. **Area A (Columns 8-11)**:\n   \n   * Also known as the “A Area,” this section is where you define division, section, and paragraph names.\n   * It’s essential for organizing your COBOL program into logical sections.\n   * Statements related to program structure (e.g., `IDENTIFICATION DIVISION`, `DATA DIVISION`, etc.) often appear here.\n\n4. **Area B (Columns 12-72)**:\n   \n   * The bulk of your COBOL code resides in this area.\n   * It includes statements, data manipulation, calculations, and logic.\n   * Always adhere to the strict column-based formatting rules within this area.\n\n5. **Identification Area (Columns 73-80)**:\n   \n   * Historically, this area was used for identification purposes (e.g., program name, author, date).\n   * In modern COBOL, it’s less commonly used due to changes in coding practices.\n   * Some legacy systems still rely on this area for specific information\n\n\u003chr\u003e\n\n### Heirarchical Code Structure of COBOL\n\n![image](https://github.com/Gaurav-Van/Working-With-COBOL/assets/50765800/645a84fc-0118-41ce-a4ee-617997c22245)\n\n* **Divisions**: The topmost level of the hierarchy, divisions are the largest units in a COBOL program. There are four main divisions:\n  \n  * **Identification Division**: Provides the program’s name and other identification details.\n  * **Environment Division**: Specifies the computer and peripheral devices the program will use.\n  * **Data Division**: Defines all the variables and data structures the program will manipulate.\n  * **Procedure Division**: Contains the actual code that performs the program’s tasks.\n\n* **Sections**: Within each division, sections break down the code into smaller, logical groupings. Each section serves a specific purpose related to its division, such as the `FILE SECTION` in the Data Division, which describes file layouts.\n\n* **Paragraphs**: Sections are further divided into paragraphs, which are named blocks of code that perform a particular function. Paragraphs make the code easier to navigate and modify.\n\n* **Sentences**: A sentence is a string of COBOL statements terminated by a period. Sentences are the executable instructions within paragraphs.\n\n* **Statements**: The smallest unit of the hierarchy, statements are the individual COBOL commands that carry out operations, like `MOVE`, `ADD`, or `READ`.\n\n\u003chr\u003e\n\n### Data Types\n\nwe use `Picture Clause` or `PIC`. It sets the Datatype and length of the variable. `PIC Datatype(Length)`\n\n#### Numeric\n\n`PIC 9` Single numeric value. *9* here represents numeric datatype. \n\n`PIC 9(4)` four numeric values \n\n#### Alphabetic\n\n`PIC A` Single Alphabetic Character. \n\n#### Alphanumeric\n\n`PIC X` Single Alphanumeric Character \n\n`PIC X(8)` Eight Alphanumeric Character\n\n#### Decimal Position\n\n`V` represents decimal position\n\n#### Represent Symbols in the value\n\n`PIC 9(4)V99` used to represents number like 2857.96 or 1234.56\n\n-----\n\n### COBOL Data Types\n\nCOBOL primarily deals with two types of data: numeric and alphanumeric.\n\n1. **Numeric Data**: These are numbers that can be used for arithmetic operations.\n2. **Alphanumeric Data**: These can contain letters, numbers, and special characters.\n\n#### Picture Clause (PIC)\n\nThe PIC clause is used to define the data type and size. It specifies the type and format of the data item.\n\n* **9**: Represents a numeric digit. \n* **X**: Represents an alphanumeric character.\n* **A**: Represents an alphabetic character (A-Z and a-z).\n* **S**: Indicates a signed numeric value.\n* **V**: Implied decimal point.\n\nExamples:\n\n* `PIC 9(5)`: A numeric value with up to 5 digits.\n* `PIC X(10)`: An alphanumeric string with up to 10 characters.\n* `PIC S9(4)V99`: A signed numeric value with 4 digits before the decimal and 2 digits after.\n\n### COMP (Computational) Usage\n\nCOBOL uses several types of computational storage formats, each optimized for specific types of data processing.\n\n#### COMP-1 (Single-precision floating-point)\n\n* **Usage**: For single-precision floating-point numbers.\n* **Storage**: Typically 4 bytes.\n* **Representation**: Usually conforms to the IEEE 754 standard for floating-point representation.\n* **Range**: Approximately 7 decimal digits of precision.\n\n#### COMP-2 (Double-precision floating-point)\n\n* **Usage**: For double-precision floating-point numbers.\n* **Storage**: Typically 8 bytes.\n* **Representation**: Usually conforms to the IEEE 754 standard for double-precision floating-point representation.\n* **Range**: Approximately 15-16 decimal digits of precision.\n\n#### COMP-3 (Packed Decimal)\n\n* **Usage**: For numeric data stored in a packed decimal format.\n* **Storage**: Each digit is stored in a half-byte (4 bits), with the sign in the last nibble.\n* **Representation**: BCD (Binary Coded Decimal) format.\n* **Example**: The number 1234 might be stored as 0x123C (C indicates a positive sign).\n\n#### COMP-4 (Binary - similar to COMP)\n\n* **Usage**: For numeric data stored in a binary format.\n* **Storage**: The size is typically determined by the compiler (e.g., 2, 4, or 8 bytes).\n* **Representation**: Pure binary format.\n* **Note**: Often considered synonymous with COMP in many COBOL implementations.\n\n#### COMP-5 (Native Binary)\n\n* **Usage**: For numeric data stored in the native binary format of the machine.\n* **Storage**: Similar to COMP-4 but often optimized for the specific hardware.\n* **Representation**: Pure binary format, ensuring more efficient computation.\n* **Note**: Designed for better performance on specific hardware.\n\n### Character Encoding: EBCDIC vs. ASCII\n\n#### EBCDIC (Extended Binary Coded Decimal Interchange Code)\n\n* **Usage**: Primarily used in IBM mainframes.\n* **Character Set**: An 8-bit character encoding.\n* **Storage**: Each character is stored in 1 byte.\n* **Range**: 256 possible characters.\n* **Example**: The letter 'A' is represented as 0xC1.\n\n#### ASCII (American Standard Code for Information Interchange)\n\n* **Usage**: Widely used in various computing environments.\n* **Character Set**: A 7-bit character encoding (often stored as 8-bit with a leading zero).\n* **Storage**: Each character is stored in 1 byte.\n* **Range**: 128 possible characters (standard ASCII), extended ASCII uses the full 256 range.\n* **Example**: The letter 'A' is represented as 0x41.\n\n\u003chr\u003e\n\n### Literals\n\nValues that have multiple use cases but needs to be define and initialized only once. They do not change. Cobol has some figurative literals built-in \n\n`ZERO / ZEROES`\n\n`SPACE / SPACES`\n\n`LOW-VALUE`\n\n`HIGH-VALUE`\n\n`NULL / NULLS`\n\n\u003chr\u003e\n\n### Keywords and Paragraphs\n\n1. **COBOL Keywords (Top 15)**:\n   \n   * **ACCEPT**: Reads input data into a variable.\n   * **ADD**: Performs addition.\n   * **DISPLAY**: Outputs data to the screen.\n   * **DIVIDE**: Performs division.\n   * **IF**: Conditional statement for branching.\n   * **MOVE**: Assigns a value to a variable.\n   * **PERFORM**: Executes a sequence of statements (similar to a loop or function call).\n   * **READ**: Reads records from files.\n   * **SUBTRACT**: Performs subtraction.\n   * **COMPUTE**: Evaluates arithmetic expressions.\n   * **DISPLAY-1**: Used for formatted output.\n   * **STOP**: Halts program execution.\n   * **STRING**: Concatenates strings.\n   * **UNSTRING**: Splits a string into components.\n   * **INITIALIZE**: Sets variables to initial values.\n\n2. **Paragraphs in COBOL**:\n   \n   * A paragraph is a named block of code within a COBOL program.\n   * It’s similar to a function or method in other languages but without parameters or return values.\n   * Paragraphs provide a way to organize code logically.\n   * Each paragraph has a unique name and contains a sequence of COBOL statements.\n   * You can invoke a paragraph using the `PERFORM` keyword.\n   * Unlike functions, paragraphs don’t have parameters or local variables.\n\n\u003chr\u003e\n\n### Paragraphs and Perform\n\n##### `COBOL Paragraphs`\n\n* **What are Paragraphs?**\n  \n  * In COBOL, a paragraph is a named block of code within a program.\n  * Think of it as a reusable code segment that performs a specific task.\n  * Unlike functions in other languages, paragraphs don’t have parameters or return values.\n  * Each paragraph has a unique name (similar to a function name).\n\n* **Purpose of Paragraphs:**\n  \n  * Organize code logically: You can group related statements together in a paragraph.\n  * Improve readability: Descriptive paragraph names make code easier to understand.\n  * Encapsulate functionality: A paragraph represents a specific action or operation.\n\n* **Example of a COBOL Paragraph:**\n  ```cobol\n      IDENTIFICATION DIVISION.\n      PROGRAM-ID. MYPROGRAM.\n      \n      DATA DIVISION.\n      WORKING-STORAGE SECTION.\n      01 NUM1 PIC 9(3) VALUE 100.\n      01 NUM2 PIC 9(3) VALUE 50.\n      \n      PROCEDURE DIVISION.\n          PERFORM CALCULATE-SUM\n          DISPLAY \"Sum: \" NUM1\n          STOP RUN.\n      \n      CALCULATE-SUM.\n          ADD NUM2 TO NUM1.\n  ```\n  \n\n`PERFORM` Statement (Similar to Loops):\n---------------------------------------\n\n* **What is `PERFORM`?**\n  \n  * The `PERFORM` statement executes a sequence of statements (like a loop).\n  * It invokes a paragraph by name, causing its code to run.\n  * Acts as a control flow mechanism.\n\n* **Usage of `PERFORM`:**\n  \n  * Execute a paragraph once or repeatedly (like a loop).\n  * Specify the paragraph name after `PERFORM`.\n\n* **Example of `PERFORM`:**\n  ```cobol\n      IDENTIFICATION DIVISION.\n      PROGRAM-ID. LOOPSAMPLE.\n      \n      DATA DIVISION.\n      WORKING-STORAGE SECTION.\n      01 COUNTER PIC 9(2) VALUE 1.\n      \n      PROCEDURE DIVISION.\n          PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER \u003e 10\n              DISPLAY \"Counter: \" COUNTER\n          END-PERFORM\n          STOP RUN.\n  ```\n\n\u003chr\u003e\n\n### Program Linkage\n\n`CALL` keyword. \n\n* **What is Program Linkage?**\n  \n  * Program linkage refers to the interaction between different COBOL programs or subprograms.\n  * It allows one program (the **calling program**) to invoke another program (the **called program** or **subprogram**).\n  * The purpose is to modularize code, improve maintainability, and reuse common functionality.\n\n* **How Does Program Linkage Work?**\n  \n  * The **CALL** statement is used to invoke a subprogram from the calling program.\n  * The called program can be a separate COBOL program or a specific section within the same program.\n  * Data can be passed between the calling program and the called program using parameters.\n\n* **Types of Program Linkage:**\u003cbr\u003e\u003cbr\u003e\n `Static Linkage`\n\n     * The called program is a separate COBOL program with its own source code.\n     \n     * The calling program references the called program by name.\n     \n     * The linkage is established during compilation.\n     \n     * Example:\n       \n       ```\n       CALL 'MYPROG' USING data-parameters\n       ```\n\n  `Dynamic Linkage`\n   \n   * The called program is dynamically loaded at runtime (e.g., as a shared library or DLL).\n   \n   * The calling program specifies the program name or library.\n   \n   * The linkage is resolved during execution.\n   \n   * Example:\n     \n     ```\n     CALL 'MYLIBRARY' USING data-parameters\n     ```\n\n---------------\n\n#### Linkage Section in COBOL\n\n* The **Linkage Section** serves as an interface between different COBOL programs or subprograms.\n* Its primary role is to declare variables that can be accessed by another program (usually the calling program).\n* When one program calls another using the `CALL` statement, data can be passed between them through the linkage section.\n* It helps in:\n  * Sending data from the calling program to the called program.\n  * Receiving data from the called program back to the calling program.\n\n![image](https://github.com/Gaurav-Van/Working-With-COBOL/assets/50765800/122c5279-3d57-455a-87b0-9883f43e2618)\n\n\u003chr\u003e\n\n### File Output and Reports\n\n`FILLER` Add things in between. Keyword in cobol. \n`FILLER     PIC X(05) VALUE SPACES` adds 5 spaces. \n\n![image](https://github.com/Gaurav-Van/Working-With-COBOL/assets/50765800/b6fdba13-a0c3-4f04-bcb2-95d7fb0ecd32)\n\n\u003chr\u003e\n\n### Conditional Expressions\n\n```\nIF Condition DO/DISPLAY/ACTION_KEYWORD action\n    ELSE DO/DISPLAY/ACTION_KEYWORD action\nEND-IF\n```\n\n##### Evaluate-When (Switch-case)\n\nIn COBOL, the **WHEN** keyword is commonly used within the **EVALUATE** statement to handle multiple conditions. Let’s explore how it works:\n\n1. **EVALUATE Statement**:\n   \n   * The **EVALUATE** statement is similar to a switch or case statement in other languages.\n   * It allows you to evaluate an expression and perform different actions based on its value.\n   * Within the **EVALUATE**, you can use the **WHEN** keyword to specify conditions.\n\n```cobol\nEVALUATE expression\n    WHEN condition-1\n        PERFORM action-1\n    WHEN condition-2\n        PERFORM action-2\n    ...\n    WHEN OTHER\n        PERFORM default-action\nEND-EVALUATE\n```\n\n\u003chr\u003e\n\n### Intrinsic Functions\n\nintrinsic functions (also known as built-in functions) provide a set of predefined operations that allow you to perform specific tasks. These functions simplify coding by providing a shorthand way to execute complex operations.\n\n`ABS` Returns the absolute value of a numeric argument. `ANNUITY` Calculates the ratio of an annuity payment to an initial value. `Upper-case` `Lower-case` | `FV` Calculates the future value of an investment. `PV` Computes the present value of future cash flows. `RATE` Determines the interest rate for an investment.\n\n![image](https://github.com/Gaurav-Van/Working-With-COBOL/assets/50765800/1bdcd6b0-6470-444b-be0f-e5cfaa6d7084)\n\n\u003chr\u003e\n\n### Extra\n\n```cobol\nENVIRONMENT DIVISION.\n      *--------------------\n       INPUT-OUTPUT SECTION.\n       FILE-CONTROL.\n           SELECT PRINT-LINE ASSIGN TO PRTLINE.\n           SELECT ACCT-REC   ASSIGN TO ACCTREC.\n      *-------------\n       DATA DIVISION.\n      *-------------\n       FILE SECTION.\n       FD  PRINT-LINE RECORDING MODE F.\n       01  PRINT-REC.\n           05  ACCT-NO-O      PIC X(8).\n           05  ACCT-LIMIT-O   PIC $$,$$$,$$9.99.\n           05  ACCT-BALANCE-O PIC $$,$$$,$$9.99.\n           05  LAST-NAME-O    PIC X(20).\n           05  FIRST-NAME-O   PIC X(15).\n           05  COMMENTS-O     PIC X(50).\n      *\n       FD  ACCT-REC RECORDING MODE F.\n       01  ACCT-FIELDS.\n           05  ACCT-NO            PIC X(8).\n           05  ACCT-LIMIT         PIC S9(7)V99 COMP-3.\n           05  ACCT-BALANCE       PIC S9(7)V99 COMP-3.\n           05  LAST-NAME          PIC X(20).\n           05  FIRST-NAME         PIC X(15).\n           05  CLIENT-ADDR.\n               10  STREET-ADDR    PIC X(25).\n               10  CITY-COUNTY    PIC X(20).\n               10  USA-STATE      PIC X(15).\n           05  RESERVED           PIC X(7).\n           05  COMMENTS           PIC X(50).\n```\n\nThe **RECORDING MODE F** in COBOL refers to a fixed-length format for physical records in a QSAM (Queued Sequential Access Method) file. Let me break it down for you:\n\n1. **RECORDING MODE F (Fixed)**:\n   \n   * All records in the file have the same fixed length.\n   * Each record is wholly contained within one block.\n   * Blocks can contain more than one record.\n   * There are no record-length or block-descriptor fields.\n   * This mode is commonly used when records have a consistent size.\n   * It’s ideal for situations where you know the exact length of each record.\n   * In your example, the `FD PRINT-LINE RECORDING MODE F` specifies that the file “PRINT-LINE” contains fixed-length records.\n\n2. **FD (File Description)**:\n   \n   * The `FD` (File Description) section defines the characteristics of a file.\n   * It includes information about the file’s organization, access mode, and record format.\n   * In your code snippet, `FD PRINT-LINE` declares the file named “PRINT-LINE.”\n   * The `RECORDING MODE F` indicates that the records in this file are of fixed length.\n   \n   \u003chr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaurav-van%2Fworking-with-cobol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaurav-van%2Fworking-with-cobol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaurav-van%2Fworking-with-cobol/lists"}