Open In App

COBOL – Basic Syntax

Cobol is a high-level language, which has its own compiler. The COBOL compiler translates the COBOL program into an object program, which is finally executed. A Syntax refers to the rules and regulations for writing any statement in a programming language. It is related to the grammar and structure of the language.

Program Syntax Rules of COBOL:

COBOL Character Set:

Cobol is based on an EBCDIC character set which has the following:



COBOL Coding Sheet: 

The below table describes the code layout, for writing working executable COBOL code.  

Columns Number with a record length of 80 bytes:



S.No Column specification Short Description  Description
1. 1-6 Sequence Number  it is used to identify each line of the source program, can contain any character in the system character set  
2. 7 Reserved for special character

it is an indicator area used for specifying.

  • * ⇒ Comment
  • – ⇒ Continuation
  • / ⇒ Form Feed
3. 8-11 Area A Cobol divisions, sections, paragraphs being written in columns 8-11
4. 12-72 Area B Space for Writing Cobol Statements
5. 73-80 System generated Number  For programmer use 

Let’s take an example and understand how to COBOL syntax and program works:

Example:




IDENTIFICATION DIVISION.
PROGRAM-ID. YOUR-PROGRAM-NAME.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 NUM1 PIC 9(4) VALUE 1458
01 MESSAGE PIC X(11) VALUE 'HELLO WORLD'.   
PROCEDURE DIVISION.
MAIN-PROCEDURE.
          
**********This is a comment in Cobol***************
        
DISPLAY NUM1.
DISPLAY MESSAGE.
STOP RUN.
END PROGRAM YOUR-PROGRAM-NAME.

Output:

COBOL Code Explanation:

JCL for compiling the COBOL:

//JOBNAME JOB ACCTNO,NAME,MSGCLASS=1
//S001                 EXEC IGYWCL
//COBOL.SYSIN  DD   DSN = LOCATION_OF_CODE,DISP= SHR
//COBOL.SYSLIB DD   DSN = COPYBOOK_LOCATION,DISP = SHR
//LKED.SYSMOD DD   DSN = LOADLIB_PATH(YOUR-PROGRAM-NAME),DISP=SHR

RUN JCL – For running program:

//JOBNAME JOB ACCTNO,NAME,MSGCLASS=1
//* JCL TO RUN COBOL PROGRAM*
//STEP01    EXEC PGM= YOUR-PROGRAM-NAME
//STPLIB     DD   DSN = LOADLIB_PATH,DISP=SHR
//SYSOUT   DD SYSOUT = *

Article Tags :