Showing posts with label COBOL Interview Questions. Show all posts
Showing posts with label COBOL Interview Questions. Show all posts

Friday, December 17, 2010

How do I setup the Assemble-Link Job(JCL)?

Before you start writing Programs, you need to set up an Assemble-Link job(JCL), that'll help assemble your program into a Load Module. Once you have a Load-Module ready, you can run it and see the magic.

Most installations have ready-to-use PROCS such as ASMHC to assemble a Program, ASMHCL to assemble-and-link a Program and ASMHCLG to Assemble-Link-Go(Run) the program. If these aren’t found at your shop, try looking for ASMAC, ASMACL and ASMACLG. Better even ask your System Programmer for a JCL. The Assembler-software on Mainframes is the Program ASMA90. This is how I have setup my Assemble-link Job. I am going to use the ready-made PROC ASMACL.  There are two important customizations or overrides you need to do. ASMACL expects you to supply two Files – //SYSIN, the Input Source Program, and //SYSLMOD, the output Load Module. I have stored my Source-Program in the Member ASPROGR01 under the Library SYSADM.DEMO.SRCLIB. I hooked up and attached SYSIN inlet to this file SYSADM.DEMO.SRCLIB(ASPROG01). The Assembler internally passes its output to the Linker. The Linker-Software HEWL, produces an Output Load Module and stores it in the SYSLMOD File. I would like the Executable Load Module ASPROG01 to be created under SYSADM.DEMO.LOADLIB. Hence, SYSLMOD output is hooked to the File SYSADM.DEMO.LOADLIB(ASPROG01).

What are the differences between COBOL and Assembler?

Assembler Language differs from all of the other languages such as COBOL, PL/I, RPG etc. It resembles the actual machine-instructions that you are likely to find on a Mainframe. Assembler-Language is a Low-level language. For performing a complex-task, you need to write several instructions. On the other hand, COBOL and other modern platforms such as Java or C# are High-Level Languages(HLL). In these languages, its possible to represent a complex task by one single-instruction.

COBOL looks more English-like. Its quite verbose. Writing a program in Assembler requires a different line-of-thinking, different thought pattern. Unlike COBOL, Assembler-Language statements don’t terminate with a period. Assembler language commands don’t even come close to English.

Alright, now let's keep this between you, me and the gatekeeper – COBOL Programs are actually transformed to Machine code. In fact, you can see the equivalent Machine-code corresponding to your COBOL-Program, for yourself when you run the Compiler IGYCRCTL with the PARM='LIST' Option. You would find that 1 COBOL Instruction generates several Machine-Instructions. By contrast, 1 Assembler-Instruction generates only one single Machine-Instruction. Guess what, you need to code several lines-of-Assembler to achieve the same effect as one line-of-COBOL.

Another paradigm-shift of thinking is needed, with the order of operands. COBOL does a MOVE A TO B, or ADD 1 TO COUNTER, take the first thing and do something to the second. In Assembler, you’d have to code MVC B,A or AP COUNTER,=P'1', the second operand normally does something on the first.

COBOL Programs are broken down into divisions, sections and para's – its strictly organized and structured. In Assembler, you just start coding. You decide your own custom-organization and enforce it, follow it throughout the program.

How does the SUBTRACT Operator work in COBOL?

When you want to find the difference of two or more quantities in COBOL, you use the SUBTRACT operator. The SUBTRACT operator subtracts one quantity from another, and finds out the result. In its simplest form, SUBTRACT has the following syntax :
Syntax
SUBTRACT one-quantity FROM second-quantity

For example,

SUBTRACT WS-VAR-2 FROM WS-VAR-1

Consider the variable WS-VAR-1 = 10, WS-VAR-2=30, subtracting WS-VAR-2 from WS-VAR-1 would result in the difference between 30 and 10. The answer is 20. This final result is stored in WS-VAR-2. SUBTRACT B FROM A is equivalent to the statement A = A – B.

Image03[2] 

The example above is shown in the code snippet below :

Image04[2]

COBOL ADD Operator Example

Syntax
ADD A B C GIVING D E
The GIVING Clause may also specify a list of destination/receiving variables. In that case, sum(addition) is copied to the each of the variables mentioned in the GIVING Clause. For example,
Assume that A = 10, B = 15 and C=20.

Now the sum of A B C = 10 + 15 + 20 = 45. The sum 45 is stored in each of the variables mentioned in the list(D, E). Thus,
D = 45 and E = 45, after the above statement is executed.

Example :

Image16[2]
Result :

Image17[1]

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 part 2

How is the 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.

Example 

Image12[1] 

Result 

Image13[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. 

Saturday, December 12, 2009

What are the differences between COBOL and COBOL II?


What are the differences between COBOL and COBOL II?
There are at least five differences: COBOL II supports structured programming by using in line PERFORMs and explicit scope terminators, it introduces new features (EVALUATE, SET .. TO TRUE, CALL .. BY CONTEXT, etc), it permits programs to be loaded and addressed above the 16 megabyte line, it does not support many old features (READY TRACE, REPORT-WRITER, ISAM, etc.), and it offers enhanced CICS support. 

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.