Showing posts with label cobol tutorials. Show all posts
Showing posts with label cobol tutorials. Show all posts

Friday, December 17, 2010

ADD operator in COBOL example

Syntax
ADD A B GIVING RESULT

If you would like the final result of arithmetic to be stored in a separate resultant variable, you can always write a GIVING clause at the end. Thus, if A=5 and B=10, the sum(addition of A and B), would yield 15. This sum 15 is stored in the RESULT Variable. On omitting the GIVING Clause, the sum is stored in one of the operands being added. GIVING Clause allows you to specify a separate destination(receiving variable) which shall hold the final result of computation.
Example
Image14[2]

Result
Image15[1]

COBOL Tutorial – Arithmetic Operators

Q. How do you perform Arithmetic in COBOL? For example, how do you write a simple program that calculates the Interest to be paid on a Principal p?

You often need to do Math in COBOL. You can perform Arithmetic in COBOL using Arithmetic Operators. When you perform some arithmetic on two or more numeric quantities, such an expression is called an Arithmetic Expressions. There are 4 main Arithmetic Operators in COBOL – ADD, SUBTRACT, MULTIPLY and DIVIDE.

You can even write complex arithmetic expressions by using the COMPUTE verb. I have written about the syntax of each operator, followed by examples and some results. 

Monday, December 28, 2009

Introduction to COBOL Programming-Cobol Tutorial Programming Guide

COBOL is a high-level programming language first developed by the CODASYL Committee (Conference on Data Systems Languages) in 1960. Since then, responsibility for developing new COBOL standards has been assumed by the American National Standards Institute (ANSI).
Three ANSI standards for COBOL have been produced: in 1968, 1974 and 1985. A new COBOL standard introducing object-oriented programming to COBOL, is due within the next few years.
The word COBOL is an acronym that stands for COmmon Business OrientedLanguage. As the the expanded acronym indicates, COBOL is designed for developing business, typically file-oriented, applications. It is not designed for writing systems programs. For instance you would not develop an operating system or a compiler using COBOL.

Saturday, December 12, 2009

How COBOL FLAT files(Index,Sequential) are very secure for huge data?If not, How will you migrate with any Database with Frond end COBOL?

Question: How COBOL FLAT files(Index,Sequential) are very secure for huge data?If not, How will you migrate with any Database with Frond end COBOL?


Answer:


Well if you are using flat file you have advantage as well as disadvantages.
Advantage-It is Secure Physically edited.
Disadvantage - Logically speaking performance is slow difficult to find the particular record.

What is difference between Object oriented COBOL & MicroFocus COBOL?

Question :What is difference between Object oriented COBOL & MicroFocus COBOL?


Answers :
There is only one thing we can use Java or C++ in Mainframe instead of CICS



How will work GOBACK statement & STOP RUN & EXIT-PROGRAM in COBOL ?

Question :How will work GOBACK statement & STOP RUN & EXIT-PROGRAM in COBOL ?


Answers :


goback 
- When specified in main program, will act like stop run. i.e give control back too O.S
- When specified in sub-program, will give control back to main program

Exit-program
- When specified in main program, will throw abend4038 (compilation) error, since it wont give the control back to the O.S
- When specified in sub-program, will give control back to main program

stop run 
- Will stop the current program and give control back to O.S (even in sub-program)



Answer2:


GOBACK gives the controll to main program if we have called the subprogram from the main program.

STOP RUN: This statement halts the execution of the object program and returns control to the system.

EXIT-PROGRAM: This statement specifies the end of a called program and returns control to the calling program.

COBOL Tutorial – Arithmetic Operators

Q. How do you perform Arithmetic in COBOL? For example, how do you write a simple program that calculates the Interest to be paid on a Principal p?

You often need to do Math in COBOLYou can perform Arithmetic in COBOL using Arithmetic Operators. When you perform some arithmetic on two or more numeric quantities, such an expression is called an Arithmetic Expressions. There are 4 main Arithmetic Operators in COBOL – ADD, SUBTRACT, MULTIPLY and DIVIDE.

You can even write complex arithmetic expressions by using the COMPUTE verb. I have written about the syntax of each operator, followed by examples and some results. 

2. How’z the ADD Operator used in COBOL
The ADD operator can be used to add two or more quantities. In the assembly language, we write the instruction ADD A B to find the sum of A and B. The final sum is stored in A. On the same lines, the ADD Operator in COBOL has the following syntax :

Syntax

ADD one-quantity TO second-quantity

The final sum result is stored in the second-variable. For example, if A=10, and I write

ADD 5 TO A
After performing the above step, the computer adds 5 to the value of A, so A=15. Suppose a variable B=5, then I may also write

ADD B TO A


Syntax

ADD A B C TO SUM

In this case, all the three group of numbers A B and C, would be added to SUM. So, assuming A=10, B=15, and C=20, if initially RESULT = 100, after addition of A, B and C to SUM, the value of RESULT = 100 + (10+15+20) = 145.