Saturday, 30 August 2014

COBOL Evaluate Statement | EVALUATE statement in COBOL [COBOL Evaluate Examples].


Evaluate statement

COBOL Evaluate statement.


Welcome back to today's session on "COBOL Evaluate Statement". In this session, you'll learn the basics of Evaluate statement in COBOL. Also, you'll go through a couple of examples to re-enforce your COBOL Evaluate knowledge. Let's get started with an introduction to COBOL Evaluate Statement. 

COBOL Evaluate Statement - Agenda. 

  • Introduction to COBOL Evaluate Statement.
  • COBOL Evaluate Statement Syntax.
  • COBOL Evaluate Example. 
  • Different Forms Of Evaluate Statement.
  • Evaluate in COBOL - Youtube.
  • Conclusion.

Introduction to COBOL Evaluate Statement.

COBOL Evaluate statement is similar to SWITCH, CASE statement of any other programming language for example VB 6.0 macro programming language. In this Evaluate in COBOL Tutorial, I would explain the usage of the COBOL EVALUATE statement with syntax and example.

Evaluate statement in COBOL is used to implement the case structure. It tests for series of values. 
The Evaluate statement became available with COBOL-85. It has a complicated syntax that lets you use this statement for a variety of purposes. No matter how you code it, though, it always has one entry point and one exit point, so it is a valid structure for structured programming.

COBOL EVALUATE is better than Nested-ifs in terms of performance and it improves the readability of the COBOL program. COBOL Evaluate statement can be used in different forms for example: Evaluate True in COBOL, Evaluate Thru in COBOL, Evaluate WHEN in COBOL, etc.

COBOL Evaluate Statement Syntax.  

Evaluate statement in COBOL is pretty simple and easy to understand. In fact, the COBOL Evaluate statement is more flexible as compare to the COBOL Ifs statement. Here is the simple format of COBOL Evaluate Syntax.

* The syntax of the Evaluate statement as an If-statement alternative.

EVALUATE TRUE
    WHEN Condition-1
         Statement ... 
    WHEN OTHER 
         Statement- ... 
END-EVALUATE. 

 
Evaluate statement in COBOL, COBOL Evaluate

COBOL evaluate statement Syntax

Each time an Evaluate statement is executed, the conditions in the When clauses are tested in sequence, starting with the first When clause. When a condition in a When Clause is true, the statements in that clause are executed and the Evaluate statement ends without evaluating the other conditions.

#1 COBOL Evaluate Statement Example.

The following COBOL Evaluate statement example reveals how you can code multiple conditions by using the when clause in the COBOL Evaluate statement (i.e. COBOL evaluate true).  
                                                         
EVALUATE                     EVALUATE SQLCODE ALSO FILE-STATUS
   WHEN A=B AND C=D             WHEN 100 ALSO ‘00’
        imperative stmt              imperative stmt
   WHEN (D+X)/Y = 4             WHEN -305 ALSO ‘32’
        imperative stmt              imperative stmt
   WHEN OTHER                   WHEN OTHER
        imperative stmt              imperative stmt
END-EVALUATE                 END-EVALUATE 

#2 COBOL Evaluate Statement Example.




COBOL Evaluate statement Example


The Evaluate statement can be used to implement a case structure for one or more fields. When you work with more than one field, you use the word ALSO before each additional field. Then, in the When clauses, you use the word ALSO before each additional value.

Different Forms Of Evaluate Statement.

The COBOL Evaluate Statement has formats to suits the need of programmers. You can use the EVALUATE statement in COBOL to combine multiple conditions instead of nested ifs. Following are the different types of COBOL Evaluate.

  • COBOL Evaluate WHEN TRUE.
  • COBOL Evaluate WHEN TRUE ALSO TRUE.
  • COBOL Evaluate using Thru phrase.
  • COBOL Evaluate using multiple WHEN.
Do check out the "Different Forms Of Evaluate Statement In COBOL" post for a detailed explanation of COBOL Evaluate Statement types

COBOL EVALUATE Statement - Youtube.



Conclusion. 

Finally, this marks an end to the COBOL Evaluate Statement. COBOL Evaluate statement goes hand in hand and you got an alternative to COBOL Ifs statements. Evaluate statement in COBOL is better than IFs statement in terms of performance. Do check out COBOL LEVEL 88 Condition.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™
Share COBOL
COBOL Evaluate Statement.

Thursday, 14 August 2014

COBOL Perform Statement | In-Line Perform Statement.

Perform Statement
COBOL Perform Statement Tutorial.

The PERFORM statement transfers control explicitly to one or more procedures and implicitly returns control to the next executable statement after execution of the specified procedure(s) is completed. 

The PERFORM statement can be of one of the following two types.


Inline Perform
COBOL Perform Statement

An out-of-line PERFORM statement. In this case a Procedure-name is specified.

An in-line PERFORM statement. In this case the Procedure-name is omitted. An in-line PERFORM must be delimited by the END-PERFORM phrase.
There are four formats of PERFORM statements. They are:
Times phrase PERFORM
COBOL Perform Statement.

COBOL Subtract Statement | SUBTRACT STATEMENT Example.


Numerical calculation is one of the most critical part of programming language. In-fact most of the programming language provide various functions that can be used to implement business calculation logic. 

Similarly, COBOL also provide various clause such as SUBTRACT, MULTIPLY, ADD, DIVIDE, COMPUTE etc to perform various calculation

In this tutorial, I would focus on various format of SUBTRACT clause available in COBOL. I would try to explain syntax with few examples.

The SUBTRACT statement subtracts one numeric item, or the sum of two or more numeric items, from one or more numeric items and stores the result. Subtract has three different format which is applicable in various situation. 

Format : 1
Subtract
COBOL Subtract From.
Example: 

Add a note hereAdd a note hereSUBTRACT 1 FROM WS-COUNTER.

Here, all identifiers or literals preceding the key word FROM are added together and this sum is subtracted from and stored immediately in identifier-2. This process is repeated for each successive occurrence of identifier-2, in the left -to-right order in which identifier-2 is specified.
Format : 2
Subtract in COBOL
COBOL Subtract From Giving
Example:
SUBTRACT WS-HOURS FROM TOT-HOURS GIVING OVERTIME-HRS. 
Here, all identifiers or literals preceding the key word FROM are added together and this sum is subtracted from identifier-2 or literal-2. The result of the subtraction is stored as the new value of each data item referenced by identifier-3.
Format : 3
COBOL Tutorial
Subtract From in COBOL
Example:

SUBTRACT WS-AMT1 WS-AMT2 WS-AMT3 FROM GRS-PAY GIVING NET-PAY.
Here, the elementary data items within identifier-1 are subtracted and stored in the corresponding elementary items within identifier-2.

COBOL TUTORIAL

Check-out my tutorial on COBOL BLANK WHEN ZERO Clause.

COBOL REDEFINE Clause | REDEFINE in COBOL Example and rules.

COBOL
COBOL REDEFINE Tutorial
Another important statement/feature of COBOL in REDEFINES clause. The Redefines clause lets you define a field in storage in two or more ways. 

When used, this clause must have the same level number as the data item it is redefining and it must come right after that item.

The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.   

Always remember, the definition and the redefinition both refer to the same bytes of storage, you can code a Value clause only on the original definition. 
Syntax : 
01-49  data-name-1 REDEFINES data-name-2

Example 1: A Redefines clause that redefines a date field

Add a note hereAdd a note here05  WS-TDY-DTE       PIC 9(08).
05  WS-TDY-DTE-X     REDEFINES WS-TDY-DTE.
    10  TDY-YR       PIC 9(04).
    10  TDY-MNTH     PIC 9(02).
    10  TDY-DAY      PIC 9(02).

Example 2 : A Redefines clause that redefines a print field

Add a note hereAdd a note here05  WS-CHG-PERNT     PIC ZZ9.9-.
05  WS-CHG-PERNT-X   REDEFINES WS-CHG-PERNT
                     PIC X(6).

Example 3 : A Redefines clause that redefines alphanumeric with numeric.

     05  WS-EMP-REC       PIC X(20).
  05  WS-SAL-AMT       REDEFINES     WS-EMP-REC.
      10 WS-EMP-SALE   PIC 9(05)v99. 
      10 WS-EMP-TAX    PIC 9(02)v99. 

Rule : 
  1. Level number, data-name-1, and FILLER are not part of the REDEFINES clause itself and are included in the format only for clarity.
  2. Level-numbers of data-name-1 and data-name-2 must be identical and must not be level 66 or level 88.
  3. Data-name-1, FILLER identifies an alternate description for the same area and is the redefining item or the REDEFINES subject.
  4. Data description entry for the redefined item cannot contain an OCCURS clause.
  5. More than one redefinition of the same storage area is permitted. The entries giving the new descriptions of the storage area must immediately follow the description of the redefined area without intervening entries that define new character positions.
  6. Multiple redefinitions must all use the data-name of the original entry that defined this storage area.
  7. Redefining entry (identified by data-name-1) and any subordinate entries, must not contain any VALUE clauses.

START CLAUSE EXAMPLE

Have a look of COBOL Start Statement?



COBOL Terminal Input / Output Verb.

Interactive Processing : A mode of processing where data is operated on as soon as it is transacted or generated. 

In interactive processing data is entered in at the operator console. Refer below figure.

COBOL Rounded Clause | ROUNDED in COBOL Example [COBOL ROUNDED Statement].

COBOL ROUNDED Phrase, COBOL Rounding

COBOL ROUNDED Phrase

Welcome back to today's session on "COBOL Rounded Clause" or "COBOL Rounding". In this session, you'll learn the basics of the COBOL ROUNDED statement and why you use COBOL rounding in your application programs.  You'll go through the COBOL rounding up an example for better understanding. Let's get started with the COBOL Rounded Phrase introduction.  
Agenda. 
  • Introduction. 
  • What is COBOL ROUNDED Clause (i.e. COBOL ROUNDED Statement)?
  • COBOL ROUNDED Syntax. 
  • COBOL ROUNDED Example. 
    • ROUNDING in COBOL Example.
  • ROUNDED in COBOL Rules.
  • Conclusion.

Introduction. 

The capability of rounding up or rounding down is another important feature of any programming language. There are many business scenarios where monetary transaction value is either round-up or rounded down based on the requirement. COBOL ROUNDED Phrase (i.e. COBOL ROUNDED statement) is used to implement rounding in COBOL programs. In COBOL, you do not have any default rounding. You've to specify the rounding in your program. 
 

COBOL Rounding Rule of Thumb. 

  • If the ending value is 5 or more then round Up (i.e. COBOL round up).
  • If the ending value is 4 or less then round Down (i.e. COBOL round down).

What is COBOL ROUNDED Clause (i.e. COBOL ROUNDED Statement)?


COBOL ROUNDED Clause, ROUNDED in COBOL

COBOL ROUNDED CLAUSE
Once the decimal point is aligned, the number of places given for the fraction of the resultant identifier is compared to the number of places in the fraction of the product of an arithmetic operation. 

Unless the COBOL ROUNDED phrase is known, truncation occurs when the size of the fractional result exceeds the number of places given for its storage.

When the COBOL ROUNDED verb is used, the resulting identifier's least significant digit is increased by 1 if the excess's most significant digit is greater than or equal to 5.

COBOL Rounding or truncation occurs relative to the rightmost integer position for which storage is allocated when the resultant identifier is defined by a PICTURE clause containing the rightmost Ps and the number of places in the measured result exceeds the number of integer positions stated.

Important: The COBOL ROUNDED phrase has no effect in a floating-point arithmetic operation; the output of a floating-point operation is always rounded.

COBOL ROUNDED Syntax. 

The syntax of ROUNDED in COBOL is pretty simple and straightforward. You need to specify the ROUNDED keyword as illustrated in the following figure.  
COBOL ROUNDED, ROUNDED in COBOL
ROUNDED  in COBOL Example.

When the result is truncated on either the left or right side after decimal point alignment, this is known as a size error message. Let's look at the following COBOL round down and COBOL rounds up examples.

ROUNDED in COBOL Example. 

Destination Field   |  Actual Result   | Truncated Result | Rounded Result
PIC 9(03)v9.     123.26         123.2          123.3
PIC 9(03)v9.     234.54         234.5          234.5 
PIC 9(03).       456.25         456            456 

Important Point: Division by 0 always leads to SIZE ERROR. 

ROUNDED in COBOL Example: 

COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT * .0785


Rounded in COBOL Rules:

  1. ROUNDED in COBOL can be used with any arithmetic operation. 
  2. Data will be truncated if you did not specify COBOL Rounded Clause and the resultant fields is not sufficient to store the decimal data. 
  3. When the COBOL ROUNDED phrase is used, the output will be rounded to the PICTURE specification of the destination field.
  4. When ROUNDED in COBOL and REMAINDER are used in the same operation then DIVIDE, ROUNDED must be defined first.
You can code the Rounded clause whenever the result of a calculation can have more decimal places than is specified in the picture of the result field. If you don’t use the Rounded clause, the extra decimal places are truncated

Conclusion.

Finally, this marks an end to our today's COBOL ROUNDED clause. In this session, you learn what is COBOL rounding or COBOL ROUNDING Function. You learned COBOL ROUNDED Statement syntax along with COBOL round-up and COBOL round-down examples for better understanding.  


COBOL Tutorial

Have a look at CICS Top 100 Interview Questions Part II.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™


Tuesday, 12 August 2014

COBOL Exit Verb | COBOL EXIT Statement.

In today's blog I'll be discussing about COBOL EXIT statement. I will explain EXIT verb with sample. So. lets start with the tutorial. 

In layman term EXIT means, leaving a place, room, building. In COBOL EXIT statement means breaking flow control (i.e. no operation required in paragraph).

The EXIT statement return control from existing paragraph to a calling paragraph. It provides a common end point for a series of procedures.

COBOL EXIT statement syntax. 

EXIT. 

COBOL EXIT Paragraph example: 
 

PROCEDURE DIVISION.
.
.
     A010-READ-EMPMAST-FILE
            PERFORM  B020-WRITE-PAYROL
               THRU   B020-EXIT
     A099-EXIT.
          EXIT.

EXIT in COBOL Example: 

COBOL Exit STATEMENT
COBOL Exit Verb.

Note: Similar to the GO TO verb, the EXIT verb should be used only under inevitable circumstances.

NEXT SENTENCE in COBOL and CONTINUE in COBOL [COBOL Tutorial].

CONTINUE in COBOL, COBOL Tutorial, Next Sentence in COBOL
CONTINUE and NEXT STATEMENT in COBOL

Welcome back to today's session on NEXT SENTENCE in COBOL or CONTINUE in COBOL. In this session, you'll learn the basics of COBOL NEXT Sentence and COBOL CONTINUE Statement. You'll also learn how to use NEXT Sentence, COBOL Continue with examples. Let's get started with the NEXT Sentence or COBOL Continue Statement. 

Agenda. 
  • Introduction. 
  • What is the Next Sentence in COBOL?
    • Next Sentence in COBOL Syntax.
    • Next Sentence in COBOL Example. 
  • What is the Continue in COBOL?
    • Continue in COBOL Syntax. 
    • Continue in COBOL Example.
  • COBOL Next Sentence VS COBOL CONTINUE Statement.
  • Summary. 

Introduction. 

You can code any structured program using three basic structures: the sequence, selection, and iteration structures. Each structure has just one entry point and one exit point, and a program composed of these structures is a proper program. 

Now that you know how to code conditions, you can learn more about the selection and iteration structures that use those conditions. Since the If statement implements the selection structure and the Perform Until implements the iteration structure, you already know how to code the simple forms of these structures. 

In the topics that follow, you’ll see some other coding options such as NEXT SENTENCE in COBOL, CONTINUE in COBOL. So, without wasting time let's start with the tutorial of COBOL NEXT SENTENCE and COBOL CONTINUE verbs.

What is the NEXT SENTENCE in COBOL? 

The NEXT SENTENCE in COBOL simply transfers control to an implicit CONTINUE statement immediately following the next separator period. In case the NEXT SENTENCE in COBOL is specified with the END-IF statement, then control does not pass to the statement following the END-IF. However, control passes to the statement after the closest following period.

NEXT SENTENCE in COBOL syntax. 

IF condition-1 THEN
   {statement-1 ...    | NEXT SENTENCE}
.

COBOL NEXT SENTENCE example.

IF SALES-AMOUNT = ZERO
   NEXT SENTENCE
ELSE
   COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT * .0785.

COBOL NEXT SENTENCE, COBOL CONTINUE
NEXT SENTENCE in COBOL. 

What is the CONTINUE in COBOL?

The CONTINUE in COBOL statement allows you to specify a no-operation statement. COBOL CONTINUE statement indicates that no executable instruction is present and control will be transfer control to the next executable instruction after an explicit scope terminator (i.e. END-IF etc.).

CONTINUE in COBOL syntax.

IF condition-1 THEN
   {statement-1 ...    | CONTINUE}
[ELSE {statement-2 ... | CONTINUE}]
[END-IF]

CONTINUE in COBOL example.

IF SALES-AMOUNT = ZERO
   CONTINUE
ELSE
   COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT * .0785
END-IF.


COBOL CONTINUE
CONTINUE in COBOL. 


CONTINUE in COBOL

Note: In laymen, term both NEXT SENTENCE in COBOL and CONTINUE in COBOL simply transfer control to the next executable statement. 

Important Points: regarding the usage of Next Sentence in COBOL and CONTINUE in COBOL. 

  • Don’t use the NEXT SENTENCE if you are using END-IF as the delimiter (and you should). The Use of NEXT SENTENCE causes execution to continue with the next closest period, which is probably the end of the paragraph. 
  • NEXT SENTENCE is prominently used in COBOL 75. However, CONTINUE is used predominately in COBOL 85. 
  • The NEXT SENTENCE / CONTINUE statement can be used anywhere a conditional statement or an imperative-statement can be used. 

COBOL Next Sentence VS COBOL Continue Statement. 

This COBOL Tutorial is associated with a youtube video, that clearly explain the COBOL Next Sentence and COBOL Continue Statement with example. Do watch this video for details understanding. 

Summary.

You also can code the words NEXT SENTENCE in the If or Else portion of an If statement, but we don’t recommend that. When executed, NEXT SENTENCE causes the program to continue with the statement that starts after the period that ends the If statement, which is equivalent to a Go-To statement that provides a second exit to the structure. 



Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™

New In-feed ads