Program Communication Statements Interview Questions
What is program communication statements?
Program communication statements manage interactions between program components, different programs, or external entities.
What are the program communication statements?
The program communication statements are –
- CALL Statement
- Cancel Statement
- STOP RUN Statement
- EXIT PROGRAM Statement
- GOBACK Statement
- GO TO Statement
What is the main program or calling program?
Main program or calling program calls the sub program to execute a specific task.
What is the sub program or called program?
Sub program or called program that is called by some program to perform a specific task.
CALL Statement -
What is the use of CALL statement?
A CALL statement is used to invoke a subprogram to complete a task.
What are the ways of calling the subprogram?
CALLs are two types based on how the subprogram is called from main program -
- Static call
- Dynamic call
What is the static calling?
CALL statement with SUBPROG name in quotes makes the call as STATIC CALL.
What is the dynamic calling?
A CALL statement with a variable that contains the SUBPROG name makes the call as DYNAMIC CALL.
Tell us about Static and Dynamic linking?
Main program calls sub program statically are linked statically. Main program calls sub program dynamically are linked dynamically.
What are different ways to pass the parameters from Main program to sub program?
There are three ways of passing parameters from MAINPROG to SUBPROG, and those are -
- BY REFERENCE
- BY VALUE
- BY CONTENT
What is Call By Reference?
It is used to pass the memory location of the actual data, not a copy of the data. If the SUBPROG modifies the value of the passing input variable, the new value is reflected in the MAINPROG.
What is Call By Content?
It is used to pass the copy of the data to the SUBPROG.
What is Call By Value?
It is used to pass the copy of the data to the subprogram. If the SUBPROG modifies the value of the passing input variable, the new value is not reflected in the MAINPROG.
CANCEL Statement -
What is the Cancel statement?
CANCEL is used to release the resources associated with a previously called subprogram.
STOP RUN -
What is the use of STOP RUN in COBOL program?
STOP RUN is used to terminate the execution of a program. Once it is executed, control returns to the operating system.
Is STOP RUN mandatory in COBOL?
Yes. It always uses the main or calling program.
If the STOP RUN is coded in the sub program, what will happen?
Control not returned to the main program.
EXIT PROGRAM -
What is the use of EXIT PROGRAM in COBOL program?
EXIT PROGRAM marks the end of a subprogram (called program) processing and returns control to the main program (calling program).
Is EXIT PROGRAM mandatory in COBOL?
No. If it is coded, it always uses the sub or called program.
If the EXIT PROGRAM is not coded in the sub program, what will happen?
Compilation error occured.
GOBACK -
What is the use of GOBACK in COBOL program?
GOBACK defines the logical end of a program and gives the control back from where it was received.
Is GOBACK mandatory in COBOL?
No. It can code in both the main program and subprogram.
If the GOBACK is not coded in the program, what will happen?
Compilation error occured.
GO TO -
What is the use of the GO TO statement in COBOL?
GO TO transfers control to another part of the program, allowing the program to "jump" to a different paragraph or section.
How many types of GO TO statements?
Other ways of using the GO TO statement are -
- Unconditional GO TO
- Conditional GO TO
What is conditional GO TO?
It is used to transfer control unconditionally to another part of the program.
What is unconditional GO TO?
It is advised to use with conditional statements like IF and EVALUATE.
Common Questions -
What is the contrast between main(calling) and sub(called) programs in programming?
Main(calling) program | Sub(called) program |
---|---|
Main program or calling program calls the sub program to execute a specific task | Sub program or called program that is called by some program to perform a specific task |
CALL Statement should be used | CALL Statement shouldnot used |
Uses STOP RUN or GOBACK | Uses GOBACK or EXIT PROGRAM |
What are the difference between Static calls and dynamic calls?
Static calls | Dynamic calls |
---|---|
STATIC CALL attaches the SUBPROG load module to the MAINPROG load module to increase processing speed | DYNAMIC CALL removes the compilation dependency of MAINPROG when the SUBPROG is modified |
Load modules of MAINPROG and SUBPROG are stored together | Load modules of MAINPROG and SUBPROG are separately stored |
Compiler option should be NODYNAM | Compiler option should be DYNAM |
Its execution is faster | Its execution is a little slower when compared with STATIC CALL |
Can be used on request basis nowadays | It is the most used one nowadays |
What are Call By Reference and Call By Content in COBOL?
Call By Reference | Call By Content |
---|---|
It passes the address of the parameter memory location to the SUBPROG | It is used to pass the copy of the data to the SUBPROG |
SUBPROG receives the pointer to the parameter memory location | SUBPROG receives a copy of the variable's data at the time of the execution |
If the SUBPROG modifies the value of the passing parameter, the new value will be reflected in the MAINPROG | If the SUBPROG modifies the value of the passing input variable, the new value will not reflect in the MAINPROG |
Difference between GOBACK and STOP RUN?
STOP RUN | GOBACK |
---|---|
Control returns to the operating system | Control returns back from where it was received |
It should always be coded in the main program | It can code in both the main program and sub-program |
Frequently Asked Questions -
What is the difference between a called and calling program?
State the difference between GOBACK and STOP RUN?
What will happen if you code GO BACK instead of STOP RUN in a stand-alone COBOL program i.e. a program which is not calling any other program?
Explain the difference between STOP RUN, GOBACK and EXIT PROGRAM in COBOL?
What is the difference between static call and dynamic call?What do you understand by static and dynamic linking?
Explain the differences between static and dynamic calls in COBOL?
What Is the Difference Between A Dynamic And Static Call In COBOL?
How Can I Tell If A Module Is Being Called Dynamically Or Statically?
How can we find that module can be called – whether DYNAMICALLY or STATICALLY?
Explain what you understand by passing BY VALUE?
What is the difference between Call By Content and Call By Reference?
What do you understand by passing by reference and passing by content?
What is significance of Cancel Statement?
Where the STOP RUN is coded?
Where the EXIT PROGRAM is coded?
Where the GOBACK is coded?
How can GO TO be used to implement non-structured programming constructs?