1 / 83

Contents

Contents. Data Movement verb. Arithmetic Verbs. Sequence Control Verbs. Input and Output Verbs. Conditional Verb: IF CATEGORIES OF COBOL STATEMENTS. DATA MOVEMENT VERB. It is possible to move data from one place in the memory to another place.

hyun-chong
Télécharger la présentation

Contents

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. Contents • Data Movement verb. • Arithmetic Verbs. • Sequence Control Verbs. • Input and Output Verbs. • Conditional Verb: IF • CATEGORIES OF COBOL STATEMENTS.

  2. DATA MOVEMENT VERB • It is possible to move data from one place in the memory to another place. • This is done with the help of the MOVE verb. There are, • Numeric MOVE • Nonnumeric or alphanumeric MOVE • To perform a MOVE operation ,the PIC clauses of both fields must be identical.

  3. MOVE Statement • MOVE identifier-1 TO identifier-2 • Copies contents of identifier-1 To identifier-2 • identifier-1 is sending field • identifier-2 is receiving field FORMAT 1

  4. MOVE Statement Example • Move Qty-In To Qty-Out • Contents of Qty-Out replaced by contents of Qty-In • If Qty-In = 253, contents of Qty-Out = 253 after MOVE executed • Qty-In remains unchanged Example

  5. MOVE Statement • MOVE literal-1 TO identifier-2 • Value of literal-1 copied to identifier-2 • Data type of literal and identifier should match • Move numeric literals to numeric fields • Move nonnumeric literals to alphanumeric fields FORMAT 2

  6. MOVE Statement Examples • 05 Qty-Out Pic 999.05 Color-Out Pic X(4). Move 100 To Qty-Out Move 'Blue' To Color-Out • Contents of Qty-Out replaced with 100 • Contents of Color-Out replaced with 'Blue' Examples

  7. Multiple Moves • MOVEidentifier-1TO identifier-2 …literal-1 Move 0 To Total-1, Total-2, Total-3 • Move may have multiple receiving fields • Contents of all three total fields set to 0 Full Format

  8. Moving Figurative Constants • ZEROS may be moved to numeric or alphanumeric field • Moves 0 to every position of receiving field • SPACES moved only to alphanumeric field • Moves space or blank to every position of receiving field. MOVE ZEROS TO TOTAL-OUT.

  9. Numeric MOVE • Numeric field or literal is moved to numeric receiving field • When PIC clauses of both fields identical, sending and receiving fields same after MOVE • Previous contents of receiving field are replaced by MOVE

  10. Numeric MOVE Rules • Decimal alignment always maintained • If 86.52 is moved to a field • 86 always treated as integer part of number • .52 always treated as decimal part of number • Digits in integer part moved right to left starting at decimal point • Digits in decimal part moved left to right starting at decimal point

  11. Numeric MOVE Example • Operation: Move Amt-1 To Amt-2Amt-1Amt-2 Picture 99V99 Picture 99V99 Contents 12^34 Contents 67^89 • Digits in integer part moved so that • 2 replaces 7, 1 replaces 6 • Digits in decimal part moved so that • 3 replaces 8, 4 replaces 9

  12. Numeric MOVE Example • Operation: Move Amt-1 To Amt-2Amt-1Amt-2 Picture 99V99 Picture 99V99 Contents 12^34 Contents 67^89 • After MOVE, contents of Amt-2 = 12^34

  13. Numeric MOVE Rules • If receiving field has more integer positions than sending field • Unfilled high-order (leftmost) integer positions filled with zeros • If receiving field has more decimal positions than sending field • Unfilled low-order (rightmost) decimal positions filled with zeros

  14. Numeric MOVE Example • Operation: Move Amt-3 To Amt-4Amt-3Amt-4 Picture 9V9 Picture 99V99 Contents 3^4 Contents 56^78 • Digits in integer part moved so that • 3 replaces 6, 0 replaces 5 • Digits in decimal part moved so that • 4 replaces 7, 0 replaces 8

  15. Numeric MOVE Example • Operation: Move Amt-3 To Amt-4Amt-3Amt-4 Picture 9V9 Picture 99V99 Contents 3^4 Contents 56^78 • After MOVE, contents of Amt-4 = 03^40

  16. Numeric MOVE Rules • If receiving field has fewer integer positions than sending field • High-order (leftmost) digits truncated • If receiving field has fewer decimal positions than sending field • Low-order (rightmost) digits truncated

  17. Numeric MOVE Example • Operation: Move Amt-5 To Amt-6Amt-5Amt-6 Picture 99V99 Picture 9V9 Contents 12^34 Contents 5^6 • Digits in integer part moved so that 2 replaces 5, 1 not moved • Digits in decimal part moved so that 3 replaces 6, 4 not moved

  18. Numeric MOVE Example • Operation: Move Amt-5 To Amt-6Amt-5Amt-6 Picture 99V99 Picture 9V9 Contents 12^34 Contents 5^6 • After MOVE, contents of Amt-6 = 2^3

  19. Nonnumeric MOVE • Sending field is alphanumeric field or nonnumeric literal • Receiving field is alphanumeric field

  20. Rules for Nonnumeric MOVE • Characters moved from left to right • If receiving field longer, low-order (rightmost) positions replaced with spaces • If receiving field shorter, low-order characters in sending field truncated

  21. Nonnumeric MOVE Example • Operation: Move Code-1 To Code-2Code-1Code-2 Picture X(3) Picture X(6) Contents abc Contents mnopqr • Characters abc replace mno • Remaining three positions in Code-2 replaced with blanks

  22. Nonnumeric MOVE Example • Operation: Move Code-3 To Code-4Code-3Code-4 Picture X(5) Picture X(3) Contents vwxyz Contents efg • Characters vwx replace efg • y and z are not moved since all positions in Code-4 are filled

  23. Group Moves • When receiving field is group item, alphanumeric MOVE rules followed • If subfields are numeric, invalid data may be stored in subfields

  24. Group Move Example • Operation: Move "ABCD" To WS-Code 01 WS-Code. 05 WS-Part-1 Pic XX. 05 WS-Part-2 Pic 99. • After MOVE, value of WS-Part-1 is AB, WS-Part-2 is CD • Causes error if WS-Part-2 then used in arithmetic operation

  25. MOVE Operations • Avoid using sending field with different data type than receiving field • Move numeric fields, numeric literals or ZEROS to numeric fields • Move alphanumeric fields, nonnumeric literals, ZEROS or SPACES to alphanumeric fields

  26. Basic Arithmetic Verbs • ADD, SUBTRACT, MULTIPLY, DIVIDE COMPUTE • All require fields operated on to • Have numeric PICTURE clauses • Contain numeric data when statements executed

  27. ADD … TO Statement identifier-1 ADD … TO identifier-2 ... literal-1 • identifier-1 or literal-1 added to identifier-2 • Result stored in identifier-2 Format 1

  28. ADD … TO Examples Assume X, Y and Z are numeric fields X = 5, Y = 3 and Z = 7 ADD StatementResult Expression Add X To Y Y = 8 Y=X+Y Add X, 9 To Y Y = 17 Y=X+9+Y Add X, 6, Y To Z Z = 21 Y=X+6+Y+Z

  29. ADD … TO Statement • Identifiers preceding TO are unchanged • Value of identifier after TO • Used in ADD operation • Original value replaced with ADD result

  30. ADD … GIVING Statement identifier-1 ADD … GIVING identifier-2 ... literal-1 • Identifiers and literals preceding GIVING added together • Result stored in identifier-2 Format 2

  31. ADD … GIVING Examples Assume X, Y and Z are numeric fields X = 5, Y = 3 and Z = 7 ADD StatementResultExpression Add X, Y Giving Z Z = 8 Z=X+Y Add X, 10 Giving Y Y = 15 Y=X+10 Add X, 4, Y Giving Z Z = 12 Z=X+4+Y

  32. ADD … GIVING Statement • Identifiers preceding GIVING are unchanged • Value of identifier after GIVING • Not part of ADD operation • Original value replaced with ADD result • May be report-item with edit symbols

  33. ADD … GIVING Statement • TO may be included before last identifier or literal preceding GIVING • For example: Add X, 4 To Y Giving Z • Adds values of X, 4 and Y together • Stores result in Z

  34. ADD Statement • Comma followed by one space may be used to separate operands • Result of ADD always placed in field(s) after TO or GIVING • Result field must be data-name, not a literal

  35. Producing More Than One Sum • Several ADD operations can be done in single statement • Assume X, Y and Z are numeric fields X = 5, Y = 3 and Z = 7 ADD StatementResult Add X To Y, Z Y = 8, Z = 12 Add X, 6 Giving Y, Z Y = 11, Z = 11

  36. ADD … TO vs ADD … GIVING • Use ADD … TO when original contents of result operand • Need to be included in operation • But are not needed after operation • Use ADD … GIVING when • Original contents of all operands except result field are to be retained

  37. SUBTRACT Statement identifier-1 SUBTRACT … FROM identifier-2 ... literal-1 • identifier-1 or literal-1 subtracted from identifier-2 • Result stored in identifier-2 Format 1

  38. SUBTRACT Examples Assume A, B and C are numeric fields A = 6, B = 2 and C = 18 SUBTRACT StatementResult Subtract A From C C = 12 C=C-A Subtract B, 5 From C C = 11 C=C-(B+5) Subtract B From A, C A = 4, C = 16 A=A-B C=C-B

  39. SUBTRACT Statement Rules • All identifiers and literals must be numeric • Data-name, not a literal, must follow FROM • All fields, literals preceding FROM added together • Sum subtracted from field after FROM • Result stored in field after FROM

  40. SUBTRACT … GIVING Statement identifier-1 identifier-2 SUBTRACT … FROM literal-1 literal-2 GIVING identifier-3 ... • identifier-1 or literal-1 subtracted from identifier-2 or literal-2 • Result stored in identifier-3 Format 2

  41. SUBTRACT … GIVING Examples Assume A, B and C are numeric fields A = 6, B = 2 and C = 18 SUBTRACT StatementResult Subtract B From A Giving C C = 4 Subtract A From 15 Giving C C = 9 Subtract A, 4 From C Giving B B = 8 B=C-(A+4)

  42. SUBTRACT … GIVING Rules • All identifiers, literals before FROM must be numeric • GIVING must be followed by data-name • May be numeric or report-item • All fields, literals preceding FROM added together • Sum subtracted from field after FROM • Result stored in field after GIVING

  43. MULTIPLY Statement identifier-1 MULTIPLYBY identifier-2 ... literal-1 • identifier-1 or literal-1 multiplied by identifier-2 • Result stored in identifier-2 Format 1

  44. MULTIPLY Examples Assume Q, R and S are numeric fields Q = 4, R = 7 and S = 5 MULTIPLY StatementResult Multiply Q By R R = 28 R=R*Q Multiply 10 By S S = 50 S=10*S Multiply 2 By R, S R = 14, S = 10 R=2*R, S=S*2

  45. MULTIPLY … GIVING Statement identifier-1 identifier-2 MULTIPLYBY literal-1 literal-2 GIVING identifier-3 ... • identifier-1 or literal-1 multiplied by identifier-2 or literal-2 • Result stored in identifier-3 Format 2

  46. MULTIPLY … GIVING Examples Assume Q, R and S are numeric fields Q = 4, R = 7 and S = 5 MULTIPLYStatementResult Multiply Q By R Giving S S = 28 Multiply Q By 3 Giving S S = 12 Multiply 6 By Q Giving R, S R = 24 S = 24

  47. MULTIPLY Statement • Only two operands can be multiplied • To obtain product of 3 operands requires two instructions To find Price x Qty x Discount Multiply Price By Qty Giving Amt Multiply Discount By Amt

  48. DIVIDE Statement identifier-1 DIVIDEINTO identifier-2 ... literal-1 • identifier-1 or literal-1 divided into identifier-2 • Result stored in identifier-2 Format 1

  49. DIVIDE Examples Assume X, Y and Z are numeric fields X = 2, Y = 12 and Z = 8 DIVIDEStatementResult Divide X Into Y Y = 6 Y=Y/X Divide 3 Into Y Y = 4 Y=Y/3 Divide 2 Into Y, Z Y = 6, Z = 4 Y=Y/2, Z=Z/2

  50. DIVIDE … GIVING Statement identifier-1 INTO identifier-2 DIVIDE literal-1 BY literal-2 GIVING identifier-3 ... • identifier-1 or literal-1 divided into or by identifier-2 or literal-2 • Result stored in identifier-3 Format 2

More Related