html5-img
1 / 73

COBOL Programming

COBOL Programming. DAY 2. Agenda for Day2. Data Movement verbs. Sequence Control verbs. Types of conditions. REDEFINES, RENAMES, USAGE clauses. Design and development of sample programs. MOVE VERB.

lalasa
Télécharger la présentation

COBOL Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COBOL Programming DAY 2

  2. Agenda for Day2 • Data Movement verbs. • Sequence Control verbs. • Types of conditions. • REDEFINES, RENAMES, USAGE clauses. • Design and development of sample programs.

  3. MOVE VERB • TheMOVEcopies data from the source identifier or literal to one or more destination identifiers. • The source and destination identifiers can be group or elementary data items. • When the destination item is alphanumeric or alphabetic (PIC X or A) data is copied into the destination area fromleft to rightwith space filling or truncation on the right. • When data is MOVEd into an item the contents of the item are completely replaced. If the source data is too small to fill the destination item entirely the remaining area is zeroorspace filled.

  4. MOVE verb…

  5. DATA movement verbs… (1) MOVE (2) MOVE . . . CORRESPONDING ( CORR ) (3) MOVE . . . OF . . . TO . . . OF

  6. Before WS00-OUT1 ‘BEST’ WS00-OUT2 1234 Before WS00-OUT1 ‘ ’ WS00-OUT2 0 Before WS00-OUT3 0786 After WS00-OUT3 2345 Before WS00-OUT4 ‘PAYAL PAREKH’ After WS00-OUT4 ‘SHUTI DEY’

  7. MOVE to a numeric item • When the destination item is numeric, or edited numeric, then data is aligned along the decimal point with zero filling or truncation as necessary. • When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character.

  8. Before WS00-OUT1 0000 WS00-OUT2 000000 Before WS00-OUT1 3456 WS00-OUT2 345678 Before WS00-OUT3 000000 After WS00-OUT3 123456 Before WS00-OUT4 00000000 After WS00-OUT4 12345678

  9. MOVE .. example **************************** WS00-OUT1 : HARAYANA WS00-OUT2 : HARAYANA **************************** Output SPOOL

  10. JUSTIFIED RIGHT clause Is used to change the default type movement of alphabetic and alphanumeric data. Example 01 NAME PIC X(10) JUSTIFIED RIGHT. MOVE “KAJOL” TO NAME. Contents of NAME field is bbbbbKAJOL

  11. JUSTIFIED RIGHT clause .. example ********************************************* WS00-OUT1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ WS00-OUT2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ ********************************************* Output SPOOL

  12. MOVE CORRESPONDING • Facilitates movement of value of sub-item of a group item to a similar named sub-item of another group item SyntaxMOVE { CORRESPONDING, CORR } identifier-1 TO identifier-2 where identifier-1 and identifier-2 are group items.

  13. MOVE CORRESPONDING .. example **************************** WS00-GR2 : NISHANT 00000 **************************** Output SPOOL

  14. MOVE . . . OF . . . TO . . . OF Facilitates the movement of a particular field of a record to a particular field of another record. (in other words it facilitates movement of value of a individual/group item of one group item to an individual/group item of another group item). Example: MOVE NAME OF STUD-REC TO WS-NAME OF WS-STUD-REC.

  15. LEGAL MOVES Certain combinations of sending and receiving data types are not permitted. Receiving field Sending field

  16. SEQUENCE CONTROL verbs • GOTO • IF . . . THEN . . . • PERFORM • EVALUATE • STOP RUN

  17. GO TO Verb • Syntax-1 GO TO Paragraph Name. • ExampleGO TO 400-READ-PARA.

  18. IF statement • Syntax-1 IF condition [ THEN ] {statement-1, NEXT SENTENCE} [ELSE {statement-2, NEXT SENTENCE}] [ END-IF ]. • Examples (1) IF MARKS >= 80 THEN MOVE ‘A’ TO GRADE ELSE MOVE ‘B’ TO GRADE END-IF. (2) IF NOT OK-BALANCE THEN MOVE 2 TO BALANCE-CODE ELSE NEXT-SENTENCE END-IF

  19. IF statement • Syntax-2 ( Nested IF ) IF condition-1 [ THEN ] statement-1 ELSE IF condition-2 [ THEN ] statement-2 ELSE statement-3 END-IF END-IF. • Example IF ( Var1 < 10 ) THEN DISPLAY “Zero” ELSE IF Var2 = 14 THEN DISPLAY “First” ELSE DISPLAY “Second” END-IF END-IF.

  20. IF statement -Implied Operands • ExampleIF TIME < 2 AND TIME > 1 THEN MOVE “SLOW” TO SPEED END-IF. Is equivalent toIF TIME < 2 AND > 1 THEN MOVE “SLOW” TO SPEED. • Note: The following statement is invalid. IF TOT-1 OR TOT-2 = 7 THEN DISPLAY “ The Sum is 7.”.

  21. Classification of Conditions • Relational condition • Sign condition • Class condition • Compound condition • Condition-name

  22. Relational condition

  23. Sign condition • Syntax • ExampleIF DISCRIMINANT IS NEGATIVE THEN DISPLAY “The roots are imaginary”.

  24. Class condition • Syntax • Example IF REGNO IS NOT NUMERIC THEN DISPLAY “Records will not be sorted”.

  25. Compound Condition • Syntax Condition-1 { AND, OR } Condition-2 • Examples(1) IF PERCENT > 80 AND TOTAL > 480 THEN MOVE ‘A’ TO GRADE.(2) IF ROW-NUMBER > 24 OR COLUMN > 80 THEN DISPLAY “Page Error ! “.

  26. Condition Names • Are essentially boolean variables. • Are always associated with data names called condition variables. • Is defined in the DATA DIVISION with levelnumber 88. • Syntax88 condition-name {VALUE IS, VALUES ARE } literal-1 [ { THRU, THROUGH } literal-2 ].

  27. Condition-Names .. example Condition Variable 01 MARITAL STATUS PIC 9. 88 SINGLE VALUE IS ZERO. 88 MARRIED VALUE IS 1. 88 WIDOWED VALUE IS 2. 88 DIVORCED VALUE IS 3. 88 ONCE-MARRIED VALUES ARE 1, 2, 3. 88 VALID-STATUS VALUES ARE 0 THRU 3. Condition Names PROCEDURE DIVISION Statements. IF SINGLE SUBTRACT 125 FROM DEDUCTIONS. IF ONCE-MARRIED ADD 300 TO SPECIAL-PAY. IF MARRIED PERFORM B000-MARRIAGE-GIFT.

  28. Defining Condition Names. • Condition Names are defined using the special level number 88 in the DATA DIVISION of a COBOL program. • They are defined immediately after the definition of the data item with which they are associated with. • We can use Condition Names for a group as well as an elementary item. • A condition name takes the value TRUE or FALSE depending on the value of the data item with which it is associated. The VALUE clause of the associated data item is used to identifythe values which make the Condition Name TRUE.

  29. JCL 000100 //ER4857C JOB ,,NOTIFY=&SYSUID,CLASS=B 000500 //STEP1 EXEC PGM=COND88 000700 //STEPLIB DD DSN=OPERN.CICS3.LOADLIB,DISP=SHR 000800 //SYSIN DD * 000900 050 001000 081 001100 /* Before WS00-MARKS 000 WS00-DISP After WS00-MARKS 050 WS00-DISP NOT CLEARED COMPRE Before WS00-MARKS 000 WS00-DISP After WS00-MARKS 081 WS00-DISP PASSED COMPRE

  30. Break

  31. The PERFORM Verb • Iteration constructs are used when we need to repeat the same instructions over and over again in our programs. • Other programming languages have a variety of iteration / looping constructs (e.g. WHILE, FOR, REPEAT). Each of these in turn facilitate the creation of different ‘types’ of iteration structure. • In COBOL we have ‘PERFORM’ verb which is used to create these looping constructs. The PERFORM has several variations each of which simulates different looping constructs of other programming languages.

  32. Paragraphs - Revisited • A PARAGRAPH comprises of one or more sentences. • The paragraph-name indicates the start of a paragraph. The next paragraph or section name or the end of the program text terminates the paragraph. • Paragraph names are either user defined or language enforced. They are followed by a full stop. • B0000-PERF-PARA. • PROGRAM-ID.

  33. Paragraph Example P0000-PROCESS-RECORD. DISPLAY StudentRecord READ StudentFile AT END MOVE HIGH-VALUES TO StudentRecord END-READ. D0000-PRODUCE-OUTPUT. DISPLAY “Here is a message”. NOTE Scope of P0000-PROCESS-RECORD is delimited by the occurrence the paragraph name D0000-PRODUCE-OUTPUT.

  34. PERFORM Verb - variations • Simple PERFORM • In-line PERFORM • Nested PERFORM • PERFORM . . . THRU • PERFORM . . . UNTIL • PERFORM . . . TIMES • PERFORM . . . VARYING

  35. PERFORM Verb - Simple PERFORM • SyntaxPERFORM Paragraph-Name. • ExamplePERFORM 500-PROCESS-PARA. • This is not iterative but instructs the computer to execute the chunk of code inside the mentioned paragraph before reverting back to the sentence following the PERFORM coded.

  36. PERFORM Verb – Simple PERFORM example **************************************** WE ARE INSIDE B000-LAST-PARA WE ARE INSIDE B001-FIRST-PARA WE ARE INSIDE B002-MIDDLE-PARA **************************************** Output SPOOL

  37. PERFORM Verb - In-line PERFORM • SyntaxPERFORM imperative-statements. • ExamplePERFORM MOVE NUM-1 TO MAX IF NUM-2 > MAX THEN MOVE NUM-2 TO MAX DISPLAY “Maximum is ” MAX. END-PERFORM Lets see an example ..

  38. INLINE PERFORM PROGRAM

  39. JCL FOR THE INLINE PERFORM PROGRAM

  40. When SYSIN data satisfies the condition WS-STRING = ‘KARINA’ the scope of the INLINE PERFORM gets terminated

  41. PERFORM Verb – Nested PERFORM • SyntaxParagraph-Name-1.PERFORM Paragraph-Name-2. . . . . . . . . . .Paragraph-Name-2.PERFORM Paragraph-Name-3. . . . . . . . . . .Paragraph-Name-3. MOVE A TO B. . . . . . . . . . .

  42. PERFORM Verb – Nested PERFORM **************************************** WE ARE INSIDE B000-LAST-PARA WE ARE INSIDE B001-FIRST-PARA WE ARE INSIDE B002-MIDDLE-PARA **************************************** Output SPOOL

  43. PERFORM Verb – PERFORM … THRU … • SyntaxPERFORM Paragraph-Name-1 [ { THRU, THROUGH } Paragraph-Name-2 ]. • ExamplePERFORM 300-READ-PARA THRU 600-UPDATE-PARA.

  44. PERFORM … THRU … - example **************************** WE ARE INSIDE B000-DISP-PARA WE ARE INSIDE B001-DISP-PARA WE ARE INSIDE B002-DISP-PARA **************************** Output SPOOL

  45. PERFORM Verb – PERFORM .. UNTIL .. • SyntaxPERFORM Paragraph-Name-1 [ { THRU, THROUGH } Paragraph-Name-2 ] UNTIL condition. • Example PERFORM 300-READ-PARA UNTIL EOF = ‘N’.

  46. PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER OPTION • Syntax PERFORM Paragraph-Name-1 [ { THRU, THROUGH } Paragraph-Name-2 ] [WITH TEST {BEFORE, AFTER}] UNTIL condition. • ExamplePERFORM 300-PROCESS-PARA WITH TEST AFTER UNTIL VALUE NOT = 0.

  47. PERFORM . . UNTIL .. WITH TEST AFTER OPTION • This format is used where the WHILE or REPEAT constructs are used in other languages. • If the WITH TEST BEFORE phrase is used the PERFORM behaves like a WHILE loop and the condition is tested before the loop body is entered. • If the WITH TEST AFTER phrase is used the PERFORM behaves like a REPEAT loop and the condition is tested after the loop body is entered. • The WITH TEST BEFORE phrase is the default and so is rarely explicitly stated.

  48. PERFORM Verb – PERFORM . . UNTIL .. WITH TEST BEFORE **************************** **************************** Output SPOOL

  49. PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER 10 Times!! Why? **************************** WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA WE ARE INSIDE B000-PERF-PARA **************************** Output SPOOL

  50. PERFORM Verb – PERFORM .. TIMES • SyntaxPERFORM Paragraph-Name-1 [ { THRU, THROUGH } Paragraph-Name-2 ] { integer, identifier } TIMES. • Example PERFORM 500-PROCESS-PARA THRU 800-END-PARA 8 TIMES.

More Related