0% found this document useful (0 votes)
35 views10 pages

Cobol

Program language

Uploaded by

oladokunstephen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
35 views10 pages

Cobol

Program language

Uploaded by

oladokunstephen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
>... COMMERCIAL PROGRAMMING using OOCOROL OBJECT ORIENTED PROGRAMMING (OOP) Comeninal_ programming. using hghievel_ languages. such as, FORTRAN, COBOL. BASIC, ALGOL, PASCAL anf Ce commonly ‘own as Prcedre Oriented Programming (POP) an he anaes a ciled Procedural Programming. Languages (PPL3) ee fines Tingunges Ih the pocedre-vened pyrene, he problem viewed 4 Seger of thing to be done sich sean callting td pring A ‘number of fants are writen to acomplia thew tk The ey focus cn fictions. While we concmtte on Ue development of fons. vey ile enon iver to the dla hae being aed By ‘What happens 1 the aa? How ae hey affced by he fins tat ‘srk on them Inaction rogram, many ego dts wea fe place a gla so hat they ay Be Socesed by al he fein, Each fencion may have te own Ivana Glos dn ve more ‘usable oan inadvertent change bys faction Ina large pope 8 ‘ve ica to ett what ats wsed by whieh fincton In are We ‘eed to revise an ela ds stucre, we aso teed to eve a fancions tat acess the data. This ponies an opportunity Er bg creep. Are serious dcack wth th procera apptac i that ‘doesnot model eal werd problems very well This i ease factors Se action-oriented and do ot relly sorespa othe Bement of te ObjechOriemed Languages ae aaron of fnctiona langage, In ‘object-oriented langage, he cde used to wrt the program andthe at frowssed bythe program ae grouped together ino uns cle ables ‘Onjects ae fumher grouped ito lover which define the ati ‘objets must have. Objects have cen fintons acid wih them, ‘led methods. The Computer cress an objet ough the use of one Of the objets methods. The method perfoms some ation 1 the data the object and ret tis valve othe Computer Classes of objects cn als be further grouped int Merarchle,in which objec oe sean linkers etvods fom anater els. The stcure povided in Object COrered Languages makes tem very” usefel” for complied ‘ropramming iss ‘Objects: An objec sa guering together of items of information that belong together, andthe fnctions that work on them Objet share vo Characteristics: Sate and Behavior. A software objet maintain esate in one oF more vrlaler. A verlale i an tem of dts named by an “demir R software bjes implements ts Beanie mith meh Imethod is 4 fncon, procedure or woe twcied wan objeee “Therefore, am object 2 software bundle of variables and seated Imethods When» pogram in eke the anes eras Py Sending IRewapes 10 ene another Ths ilomaton i pesed lng wat be Cases: A class a collection of bjs sna type The syn sed tocreate an objects not diferent om the stan used cree an meget fbject in C1 frat has ben defined 3 cats the sateen! ‘mango wilcrente a objec mang belonging the a fat cl {tprowope or blueprint, which defines the variables und the methods ‘Common fal bjs of certain pe. Iniroductin COBOL, (COBOL i am seroym Fr Common Business Ore Langage: ts 2 highlevel language One art understand the way COBOL works Computers only understand machine cade, binary steam of and {COBOL cae mut be covered ta machine code sings comple Ruy the progam sure ough a comple. The compiler fst hes fray sal ors and then conver into machine angunge. The compet ‘teats an out fle which fe hoown se lead mode This our Te ‘tains execuble coe in the form of Os ahd Ts, COW, ea Doganming Linge paca aimed a sssingYasnes wblers {COBOL solves aot more than just buns problems and an solution o may data roering problems Evolution of COBOL During 1950s, when he business were rowing in the west par of the worl, thee was a need to automate various pacer reat Of eran an his gave birth oa highest programming guns mt foebusnedaapecesing. In 1959, COBOL was developed by CODASYL (Conferense on Dat ‘Systems Language), coavend in 1959 bythe Deparment sf Dees COBOL compilers tecame. avaiable in 1960, but they wer mt sandarize. The text version, COBOL was vlesed a 961 wi Soe eevisins. ln 1968, COBOL wat approved by ANSL 2 a sand lunging for commercial we (COBOL 48) The Language was ese ant updated by ANS in 1974 and 1985 to develop subcyuet ern 8h COBOL and COBOLSS respervel” Most compen 2M ‘COBOL'RS standard, bt here sll ae 3 few COBOL versions at ‘eed as rz 2002, Object-Oriented COBOL was released, which could use ‘encapsulated objects asa normal part of COBOL programming, IMPORTANCE OF COBOL ‘+ COBOL was the fist widely used high-level programming language. It fs an Englsh-like language which is user friendly, and. all the instructions can be coded in simple English words. ‘+ COBOL is also used a a self. documenting language ‘+ COBOL can handle huge data processing. ‘+ COBOL is compatible wth its previous versions. ‘+ COBOL has effective eror messages, so resolution of bugs is easie, FEATURES OF COBOL, ‘Standard Language COBOL is standard language that can be compiled and executed on ‘machines such as IBM AS/400, personal computer, ete. Business Oriented COBOL was designed for business-oriented applications related to financial domain, defense domain, etc. It can handle huge volumes of data ‘because of its advanced file handling capat Robust Language COBOL is # robust language as its numerous debugging and testing tools ae available for almost all computer platforms. Structured Language Logical control structures are available in COBOL which makes it easier to read and modify. COBOL has different divisions, so itis easy to debus, ‘STRUCTURE OF COBOL PROGRAM ‘A COBOL program structure can be sub-divided into the following: PROGRAM I DIVISIONS: 1 ‘SECTIONS Th PARAGRAPHS: I ‘SENTENCES zi STATEMENTS I (CHARACTERS | Divisions: a COBOL program i divided into about fur (4) diferent divisions. ‘Sections are the logical subdivision of program logic. A section is a collection of paragraphs. Paragraphs are the subdivision of section or division. Is either a user-defined ora predefined name followed by a period, and consists of ‘zzt0 of more sentencsslentes Sentences are the combination of one or more statements. Sentences appear only in the Procedure division, A sentence must end wih apesiod ‘Statements are meaningful COBOL statements that perform some processing. ‘Characters ae the lowest inthe hierarchy and cannot be divisible. DIVISIONS. ‘A.COBOL program consists of four divisions dentification Division Its the first and only mandatory division of every COBOL program. The ‘Programmer andthe compiler use this division to identify the program. In ATA eH 5 s-smeer ic x08). > ELOMTRY TBA 66 ws-crTy nic 48). > RIE TEM 5 6-contey PIC A(AS) VALE “ODA --> ELAR STEN Picture Clause Picture clause is used to define the following tems: ‘+ Datatype can be numeric, alphabetic, or alphanumeric. Numeric type consists of only digits 0 to 9. Alphabetic type consists of| letters A to Z and spaces. Alphanumeric ype consists of digits eters, and special characters Sign can be used with numeri data It can be ether + or ~ Decimal point position can be used with numeric data. Assumed Postion i the postion of decimal point and not included inthe (ata, Length defines the number of bytes used by the data item, Symbols used ina Picture clause: agen. v s ‘Sign ° ‘Assumed Decimal 1 Clause ‘Vale clause isan optional clase which ie used onalie the data tems. ‘The values can be numeric teal, alphanumeric Iter, or figurative ‘constant. tan be wed with both group and elementary tems Example ‘The following example shows the ue of VALUE clase: TOENTIFICATION DIVISION. PROGRAN-ID. HELLO, DATA oIvistoM. WORKING STORAGE SECTION. (1 WS-MML PIC 59V9 VALUE TS 3.5. (81 WS-NAME PIC A(6) VALUE “ABCD. (01 WS-ID PIC 99 VALUE ZERO. BASIC VERBS : 7 ‘COBOL verbs are used in the procedure division fo FSS statement always stats with a COBOL verb. There a verb with different types of actions ae InpuvOuput verbs are used to get data from the user and display the ‘output of COBOL programs. The following two verbs are used for this process: ‘Accept Verb Accept verb is used to get data such as date, time, and day fom the operating system or directly from the user. Ifa program is accepting data ‘rom the user, then it needs to be passed through JCL. While geting data fiom the operating system, FROM option is included as shown in the following example: ‘ACCEPT W5-STUDENT-NAME. ACCEPT WS-DATE FROM SYSTEM-DATE, Display Verb Display verb is used to display the output of a COBOL program, DISPLAY WS-STUDENT-NAME, DISPLAY “System date is : * WS-DATE. COBOL PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. @1 MS-STUDENT-NAME PIC X(25). @1 WS-DATE PIC X(10). PROCEDURE DIVISION. ACCEPT \S-STUDENT_NAME.. ‘ACCEPT WS-DATE FROM DATE. DISPLAY “Name : " WS-STUDENT_NAME. DISPLAY “Date : * WS-DATE. STOP RUN. Initiale Verb Initialize ver is used to initialize a group item or an elementary iter, Data ‘ames with RENAME clause cannot be initialized. Numeric data items are replaced by ZEROES. Alphanumeric o alphabetic data items are replaced by SPACES. If we include REPLACING term, then data items can be initialized tothe given replacing value as shown in the folowing example: TDEATIFICATION DIVISION. PROGRAN-ID. HELLO. ‘ata oTviston.. WoRKING-STORGE SECTION, 01 WS-MAME PIC A(30) VALUE “ABCDEE*, 1 W6-10 PIC 915). 1 -A00RESS, 05 NS-HOUSE-MMBER PIC 9(3) 5 WS-COMTRY PIC X(15). (5 WS-PINCOOE PIC 9(6) VALUE 123456, PROCEDURE DIVISION. 1000-FIRST-PARA. INITIALIZE W6S-WAME, ¥5-ADORESS. TMITIALIZE WS-10 REPLACING MERIC OATA BY 12345. DISPLAY “Wy name ss SHAME toate tae Sina ron ne on ae hae | est DISPLAY “Country + “WS-CONTRY. tre a — Move Verb “Move ver is used to copy d be used on both element is used. In try it option, MOVE. ‘CORR is not working; but on a mainframe server, i will work, fey moving data from a string, MOVE(&) is used where xis the sarting Postion and Is the length, Data wil be trunested if the destination dy, ‘tem PIC clause is less than the source data item PIC clause, Ifthe destination data item PIC clause is more than the source data tem PIG clause, then ZEROS or SPACES will be added in the extn byes, The following example makes it clear. ee IDENTIFICATION DIVISION. PROGRAM-1D. HELLO. DATA DIVISION. WORKING-STORAGE SECTION. ere 1 WS-MIMG PIC 9(9). 1 WS-MUM2 PIC 9(9), 1 WS-MIMB PIC 9(5). @1 WS-MMA PIC 9(6). 1 WS-ADORESS. 5 WS-HOUSE-MUMBER PIC 9(3). 5 WS-COUNTRY PIC X(5). 5 WS-PINCODE PIC 9(6). 1 WS-ADDRESS1. (5 WS-HOUSE-NUMBERI PIC 9(3). 5 WS-COUNTRYA PIC x(5). @5 WS-PINCODE PIC 9(6). PROCEDURE DIVISION. ‘AQ00-FIRST-PARA. MOVE 123456789 TO WS-wuna. (MOVE WS-MUR TO WS-MUMZ WS MUS. HOVE WS-NURG(3:6) TO Ws-MUMA. ‘MOVE 123 TO WS-HOUSE-MUMBER, MOVE ‘INDIA’ TO WS-COUNTRY. ‘MOVE 112233 TO WS-PINCODE. MOVE WS-ADORESS TO WS-ADORESS1., DISPLAY "HS-MURL =: * WS-MuML DISPLAY *WS-MuR 7 ws-muee DISPLAY "WS-MuM3, + sms DISPLAY “WS-numa Wome DISPLAY “WS-ADORESS : ~ WS-ADORESS DISPLAY “WS-ADORESS1. : * WS-ADORESS STOP RUN. Legal Moves ‘The following table gives information abou the legal moves: ‘Alphabetic Alphanumeric Numerle ‘Alphabetic Not Posie ‘Alphanumeric esse Numerte ane ae ‘Aad Verb ‘Add ver is used toad two or more numbers and store the result in the estination operand Syntax: Given below isthe syntax to Add two or more numbers OR BTOED m0 8 ¢ 10 0 Givin $00 COM W-cRUPH TO WS -coenPE Insyntax, A,B,C are added andthe result is stored in €(CA+B4C), ‘A.B, D ate add and the result is stor ed in D (D=A+B+D). In'symtax-2, A, B,C, Dare added andthe result is stored iE (E-AsBNCAD), In syntax-3, sub-group items within WS-GROUP1 and WS.GROUP? ae teded andthe result is stored in WS-GROUP2, Subtract Verb ‘Subiract verb is use for subtraction operations Syntax: Given below is the syntax for Subtract operations: ‘SUBTRACT A @ FROM € SUETIACT A 8 © ROH D GIVING SUBTRACT COR NS -GROUPL TO WS-GROUP? In syntax, A and B are added and subtracted from C. The result is stored in€ (C-C-(AYB)) A and B are added and subirated from D. The esl is ‘sored in D (D=D-(A+B)) In syntax-2, A,B,C are added and subtracted {fom D. The results store in E(E=D(AB4C)) In syta-3,sub-ro op items within WS-GROUPI and WS-GROUP? are subtracted and the result is stored in WS-GROUPD, ultiply Verb Multiply verb is used for multiplication operations Syntax Given below isthe syntax to multiply to or more numbers MULTIPLY A BY BC PULTIPLY A BY 8 GIVING € {In syntae-1, A and are mulled andthe results stored in B (BAB) ‘Aand Care multiplied and the result is stored in € (C= A*C)Insyoene ‘A and B are multiplied and the result is sored in E (E=ACt Divide Verb Divide veri used for division operations. Syntax: Given below isthe syntax fo division operations es DIVIDE A INTO 6 DIVIDE A BY B GIVING C REMAINDER R In symtax, B s divided by A andthe result ie stored in B (B-B/A). In sytx-2, Ais divided by 8 andthe result i toned in C (C-AVB) and the remainder i stored in R. WORKING-STORAGE SECTION. (1 wenn PIC 9(9) VALUE 5. 01 Ws-mre PIC 9(9) VALUE 250. 1 W5-MOMA PIC 9(9) VALUE 100, 1 Ws-mNw PIC 9(5) VALUE 15. 01 Ws-t0MC PIC 9(9), 1 Ws-eH PIC 9(9). PROCEDURE DIVISION. DIVIDE 45-MIMI INTO WS-MRO. DIVIDE HS-MIMA BY KS-MMG GIVING S-MINC AENATIOER W5-#0% DISPLAY "ws-mw : * MS- MIL >| DISPLAY “WS: sme DISPLAY "WS-MUMA = MS-NNA DISPLAY “¥S-RUNE * she DISPLAY WS-UMC nd DISPLAY "WS-REM =: * WS-REM ‘STOP RUN. ‘When you compile and execute the abo ve Pog it produces the following result: . cr wena: 090080050 ws-mma 990080300 ws-mme——-: eo0s0e015 ws-mumc —: eoeeee0e6 ws-nen eove0ee18 Compute Statement ‘Compute statement is used to write arithmetic expressions in COBOL. ‘This isa replacement for Add, Subtract, Multiply, and Divide Example IDENTIFICATION O1VISTON. PROGRAN-ID. HELLO. ‘Ta DIVISION. Worxins-sTonace secraon. 21 WS-m PIC 9(9) VALUE 10, 01 W6-mR2 PIC 9(9) VALUE 10, 01 MS-MID PIC 9(9) VALUE 10, 01 HS-MIA PIC 9(9) VALUE Se, 01 Ws-MNB PIC 9(9) VALUE 10. 01 M6-MUME PIC 9(9). PROCEDURE OIVESION COnPUTE WS-WC (S-MUNL © WS-MURD) = (WS-IRR / WS-HOB) + WS-1UHD ne 8 CONDITIONAL STATEMENTS Conditional statements are used to chan ‘on certain conaitions specified bythe will always evaluat to tue or false and Perform statements. The differ ‘IF Condition Statement + Relation Condition + Sign Condition + Class Condition + Condition-Name Condition + Negated Condition + Combined Condition IF Condition Statement IF statement checks for conditions. fa condition is tre, the IF block is executed; and ifthe condition is false, the ELSE block is executed [ENDAIF is used to end the IF block’ To end the IF block, a prio can be vwsed instead of END-IF. But itis always preferable to use ENDIF for multiple IF blocks. Nested-1F: IF blocks appearing inside another IF block. There i no limit to the depth of nested IF statements Syntax Following ie te symax of TF condition statements: Bt the excetion flow depending Programmer. Conditional statements Conditions are used in IF, Evaluate, ent types of conditions ae as follows IF [condition] THEN {coBOL statements) ELSE {cOBOL statements] Bo-1F. Page 20

You might also like