Monday, May 25, 2020

Syntax

Character Set :-  same as other programming language 
                                        A,b,7,&,* etc

Coding Sheet :-  80 character position-format accepted by compiler

 Position     Field Description
1-6    Column Numbers   Reserved for Line Numbers    
 7 Indicator Have *, comment, slash /
 8-11 Area A All COBOL divisions, sections, paragraphs and some special entries begin here
 12-72 Area B All COBOL statements must begin in area B.
73-80  Identification Area as needed by Programmer


000100 IDENTIFICATION DIVISION.                                          000100
000200 PROGRAM-ID. HELLO.                                                   000101
000250* THIS IS A COMMENT LINE                                          000102
000300 PROCEDURE DIVISION.                                                000103
000350 A000-FIRST-PARA.                                                           000104
000400     DISPLAY “Coding Sheet”.                                           000105
000500 STOP RUN.                                                                       000106


Character String 

Comment :- does not effect execution of program

000360/ First Para Begins - Documentation Purpose                       000106
        
Literal :- Constant that is hard coded in program

DISPLAY 'Hello World'.   //Hello World is Literal  

Types:-

Alphanumeric Literals :- This is valid
Numeric Literals :-  100,+10.9, -1.9 etc

COBOL word :- character string that can be reserved or user-defined

Reserved :- file , data, paragraph names etc
Used-Defined :-  ADD,MOVE,+,-, ZEROES,SPACES etc

Figurative Constants :-
HIGH-VALUES , LOW-VALUES , ZERO/ZEROES , SPACES, QUOTES, ALL literal


Division of Cobol

Identification Division :-   mandatory

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.                 //used to Identify the programs

Environment Division :-   Input and output files used in programs

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
   SOURCE-COMPUTER. XXX-ZOS.   //System used to compile program
   OBJECT-COMPUTER. XXX-ZOS.    //System used to execute program

INPUT-OUTPUT SECTION.
   FILE-CONTROL.                                //Provide information of external dataset used in program
   SELECT FILEN ASSIGN TO DDNAME
   ORGANIZATION IS SEQUENTIAL.


I-O control -  provides info of files used in program  //extra

Data Division :-   define variables used in programs

DATA DIVISION.
   FILE SECTION.               //define record structure of file
   FD FILEN
   01 NAME PIC A(25).
   
   WORKING-STORAGE SECTION.  //define temporary variables used in programs
   01 WS-STUDENT PIC A(30).
   01 WS-ID PIC 9(5).

LOCAL-STORAGE SECTION. // same as working storage -variable allocated everytime 
   01 LS-CLASS PIC 9(3).           //when program execution start
   
   LINKAGE SECTION.    //describe the data name received from external programs
   01 LS-ID PIC 9(5).


Procedure Division :- Include logic of programs

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   DISPLAY 'Hello World'.
   MOVE 'TutorialsPoint' TO WS-NAME.
   DISPLAY "My name is : "WS-NAME.
   DISPLAY "My ID is : "WS-ID.
STOP RUN.







Basics of Cobol

Simple Cobol Code :-

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   DISPLAY 'Hello World'.
STOP RUN.

Program Structure :-

Programs
Division
Sections
Paragraphs
Sentences
Statements
Characters

PROCEDURE DIVISION.
A0000-FIRST-PARA SECTION.
FIRST-PARAGRAPH.
ACCEPT WS-ID            - Statement-1  -----|
MOVE '10' TO WS-ID      - Statement-2       |-- Sentence - 1
DISPLAY WS-ID           - Statement-3  -----|



.