COBOL
Official website
COBOL isn’t governed by a single organization that maintains an “official” website. Instead, it’s a standardized programming language with its specifications maintained by international standards organizations such as ISO (International Organization for Standardization) and IEC (International Electrotechnical Commission). For example, the most recent ISO/IEC standard for COBOL (ISO/IEC 1989) is what defines the language today.
That said, there are several reputable resources and vendor sites related to COBOL:
• ISO/IEC 1989 Information: You can search for the ISO/IEC 1989:2014 standard through the ISO website or through national standards bodies—but note that obtaining the full standard document usually requires a purchase.
• GNU COBOL: Formerly known as OpenCOBOL, GNU COBOL is a free COBOL compiler. Its project page can be found here:
https://www.gnu.org/software/gnucobol/
• Vendor/Commercial Sites:
– Micro Focus provides COBOL tools and support, and you can explore their COBOL offerings at:
https://www.microfocus.com/en-us/products/cobol-general-purpose-platform/overview
– IBM offers COBOL compilers as part of its enterprise solutions, and more information is available on their website.
In summary, if you’re looking for the “official” source of COBOL standards, your best bet is to refer to the ISO/IEC documentation. For practical implementations and community resources, the GNU COBOL website or vendor sites like those of Micro Focus and IBM are good references.
Static typing
Yes, COBOL is considered a statically typed language. In COBOL, you declare all variables in the DATA DIVISION with specific types (such as numeric, alphanumeric, etc.) and sizes before they are used. This means that type checking occurs at compile time rather than at runtime. Some characteristics to note are:
- Variables and their data types must be defined upfront.
- The compiler checks that operations involving these variables respect their declared types.
- Although COBOL’s type system can be less strict compared to some modern languages, the types (e.g., numeric, alphanumeric) are still established statically.
So while COBOL might be seen as having a simpler or more limited type system, it is indeed statically typed.
Example code
Below is an example of a COBOL program that implements a binary search tree search algorithm. In COBOL you do not have built‐in pointer types as in other languages—but you can simulate dynamic data structures using the POINTER data type and by defining your own records. In this example, we define a record for a tree node that contains a numeric value and two pointer fields (for the left and right children). The binary search “find” routine starts at the root node and traverses left or right depending on whether the search key is less than or greater than the current node’s value.
Note that this example assumes that the tree has been built already (perhaps by another part of your system) and that you have a pointer to the root node. The search algorithm uses the standard binary search tree lookup method.
Below is the complete COBOL code:
IDENTIFICATION DIVISION.
PROGRAM-ID. BST-SEARCH.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
* Define the search value we are looking for.
77 SEARCH-VALUE PIC S9(4) COMP VALUE 1234.
* Flag to indicate whether the value was found.
77 VALUE-FOUND PIC X VALUE 'N'.
* Pointer for traversing the tree.
77 CURRENT-NODE USAGE IS POINTER.
* Declaration of a tree node record.
* For this example the node contains:
* - VALUE: the numeric value stored at the node.
* - LEFT-CHILD and RIGHT-CHILD: pointers to other nodes.
01 TREE-NODE.
05 TN-VALUE PIC S9(4) COMP.
05 TN-LEFT USAGE IS POINTER.
05 TN-RIGHT USAGE IS POINTER.
* For simulation, assume we have a static tree in memory.
* In a real dynamic application, these nodes would be allocated dynamically.
01 ROOT-NODE USAGE IS POINTER.
* We create some dummy nodes to simulate a pre-built tree.
01 NODE-A.
05 NODE-A-VALUE PIC S9(4) COMP VALUE 1000.
05 NODE-A-LEFT USAGE IS POINTER VALUE NULL.
05 NODE-A-RIGHT USAGE IS POINTER VALUE NULL.
01 NODE-B.
05 NODE-B-VALUE PIC S9(4) COMP VALUE 2000.
05 NODE-B-LEFT USAGE IS POINTER VALUE NULL.
05 NODE-B-RIGHT USAGE IS POINTER VALUE NULL.
01 NODE-ROOT.
05 NODE-ROOT-VALUE PIC S9(4) COMP VALUE 1500.
05 NODE-ROOT-LEFT USAGE IS POINTER.
05 NODE-ROOT-RIGHT USAGE IS POINTER.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
* Construct a simple binary search tree:
* 1500
* / \
* 1000 2000
*
* Link the nodes together.
MOVE ADDRESS OF NODE-A TO NODE-ROOT-LEFT.
MOVE ADDRESS OF NODE-B TO NODE-ROOT-RIGHT.
MOVE ADDRESS OF NODE-ROOT TO ROOT-NODE.
* Start at the root node.
MOVE ROOT-NODE TO CURRENT-NODE.
PERFORM UNTIL CURRENT-NODE = NULL OR VALUE-FOUND = 'Y'
* Dereference the CURRENT-NODE pointer into TREE-NODE structure.
PERFORM GET-NODE-DATA
IF TN-VALUE = SEARCH-VALUE
MOVE 'Y' TO VALUE-FOUND
ELSE
IF SEARCH-VALUE < TN-VALUE
MOVE TN-LEFT TO CURRENT-NODE
ELSE
MOVE TN-RIGHT TO CURRENT-NODE
END-IF
END-IF
END-PERFORM.
IF VALUE-FOUND = 'Y'
DISPLAY "Value " SEARCH-VALUE " FOUND in the tree."
ELSE
DISPLAY "Value " SEARCH-VALUE " NOT FOUND in the tree."
END-IF.
STOP RUN.
* The GET-NODE-DATA routine moves the data from the node at CURRENT-NODE
* into the working storage buffer TREE-NODE. In COBOL, pointer dereferencing is
* achieved by a CALL to a routine that uses the ADDRESS OF clause.
* However, for demonstration purposes, we simulate this by using a linkage mechanism.
GET-NODE-DATA.
PROCEDURE DIVISION USING CURRENT-NODE.
EVALUATE TRUE
WHEN CURRENT-NODE = ADDRESS OF NODE-ROOT
MOVE NODE-ROOT-VALUE TO TN-VALUE
MOVE NODE-ROOT-LEFT TO TN-LEFT
MOVE NODE-ROOT-RIGHT TO TN-RIGHT
WHEN CURRENT-NODE = ADDRESS OF NODE-A
MOVE NODE-A-VALUE TO TN-VALUE
MOVE NODE-A-LEFT TO TN-LEFT
MOVE NODE-A-RIGHT TO TN-RIGHT
WHEN CURRENT-NODE = ADDRESS OF NODE-B
MOVE NODE-B-VALUE TO TN-VALUE
MOVE NODE-B-LEFT TO TN-LEFT
MOVE NODE-B-RIGHT TO TN-RIGHT
WHEN OTHER
DISPLAY "Error: Unknown node address."
MOVE NULL TO TN-VALUE
MOVE NULL TO TN-LEFT
MOVE NULL TO TN-RIGHT
END-EVALUATE.
EXIT.
Explanation:
-
The program defines a binary search tree with three nodes. The root has the value 1500 with left child 1000 and right child 2000.
- The SEARCH-VALUE is defined as 1234. When you run the program, the search algorithm starts from the root and compares:
- Since 1234 is less than 1500, it moves to the left subtree.
- At the left child, whose value is 1000, 1234 is greater than 1000 so it would move to the right.
- Since NODE-A’s right pointer is NULL, the loop will end and indicate that the value was not found.
-
The GET-NODE-DATA routine simulates pointer dereferencing by comparing the CURRENT-NODE to known addresses (using ADDRESS OF the static nodes). In a full implementation where you dynamically allocate nodes, you would use system services or a runtime library to properly manage the memory and dereference pointers.
- Finally, the program displays whether the searched value was found.
This example should compile using a COBOL compiler. Adjust the pointer and memory management details according to your system’s COBOL implementation if dynamic memory allocation is available or needed.