Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question: help with subprograms

Status
Not open for further replies.

Nance67

Programmer
Jul 9, 2008
5
0
0
US
I program in other languages but not COBOL and have inherited a COBOL program, which I am trying to understand.

I think it involves subprograms.

First, I am looking for some validation that what I am looking at is indeed a subprogram. Second, I want to understand the process flow when there is a subprogram.

Here is part of the program:

MOVE ZERO TO HOLD-CD.
IF (ST-C > ZERO) AND (ST-C < 64)
MOVE ST-C TO HOLD-CD GO TO CHECK-5.
IF (S-SUP > ZERO) AND (S-SUP < 64)
MOVE S-SUP TO HOLD-CD GO TO CHECK-5.
MOVE ZERO TO HOLD-CD.
CHECK-CODE.
IF HOLD-CD = 05 OR 16 OR 22 OR 29 OR 52
NEXT SENTENCE ELSE GO TO SET-CODE.
*
IF (HUN = HOLD-HUN) AND (EST-PD = HOLD-EST)
NEXT SENTENCE ELSE MOVE 0 TO CK-CNTR
GO TO CHECK-5.
IF CK-CNTR = 0 GO TO CHECK-5.
IF CK-CNTR = 1 MOVE 'B' TO FT-1
MOVE HOLD-TOA TO TOA
GO TO SET-CODE.
CHECK-5.
more statements here

So, first, I want to know if "check-code" is the start of a subprogram.

Second, if the program reaches and executes the second "Move zero to hold-cd" statement, will it then proceed to execute the "check-code" subprogram (assuming that this is a subprogram)? Or will it only execute the "check-code" subprogram when it is called using a go to statement or some other method of calling subprograms?

I hope this is clear.
 
Lance, this looks like a very old Cobol program. Back in the 70's and before, Cobol programmers used very little structure or process flow other than start at the top and finish at the bottom. There may or may not have been sections or paragraphs that were 'performed'. Instead, the programmer often coded paragraph names and GO TO instructions. These quite literally directed the flow of the program to that paragraph, where other flow (further GO TOs) instructions were to be found.

In your program it looks as if CHECK-CODE is a paragraph name. It can be entered via a GO TO CHECK-CODE or could be entered from the code above depending on how that code has been executed. It's conceivable that the code above is part of a PERFORMed paragraph and will exit when it hits the CHECK-CODE paragraph. The alternative is that it is straight sequentially executed code and when the 2nd "Move zero to hold-cd" statement is reached, it drops thru into the CHECK-CODE statement.

Hope this helps. If not, or if you have further question, please get back to us.

Marc
 
Marc, you hit the nail on the head when you said this was a very old COBOL program from "back in the 70s and before"!

I know it does not have the syntax PERFORM anywhere in the program, so based on the other alternatives that you presented, it must drop thru to CHECK-CODE? Is there any other information that I can provide that would help you determine if this is truly the case or not? Or is it just matter of testing it with limited data? (I won't have access to the data for awhile so I'm working conceptually here for now).

Thanks, Nance
 
Nance, from the code, it cetainly is possible for it to drop through, for instance if ST-C and S-SUP both equal 0.

Issue a find on CHECK-CODE and see if there are any 'GO TO CHECK-CODE' references. If not, then it must drop through!


Marc
 
If the statement in question was calling a subprogram it would be coded with a CALL statement such as CALL "CHECK-CODE". I agree with Marc that it is more likely a paragraph name that is referenced by a GO TO.

From your code, it does look like it will run the second MOVE ZERO TO HOLD-CD followed by the code after CHECK-CODE. That is providing that the program doesn't branch to CHECK-5 in the IF statements.

What platform is this for? I'm familiar with COBOL On AS400/iSeries/i, although I haven't coded it in years.

I had to look at a COBOL program first written in 1981 today. All straight-line code and GO TO's everywhere. What a mess!

 
Knowing very little about COBOL, I searched the internet and found the word "SUBPROGRAM" and thought that might apply in my situation. But I am grateful that you and Marc recognized the fact that this is not a subprogram but a paragraph (so that I get my language straight!) and for helping me to distinguish the difference between the two.

After getting feedback, I am almost 100 percent confident that it will not skip CHECK-CODE but sequentially execute it. What I do find curious now that I've examined the code some more is that HOLD-CD will always be zero when it hits the CHECK-CODE paragraph and thus will never reach the second, third, and fourth IF statements. It must be some legacy code that they decided to keep just in case.

In answer to your question, it is run on the mainframe platform (not sure of any specifics beyond that except we use PCOM/TSO environment). Don't know if that has any meaning to anyone outside of where I work.
 
in COBOL (excluding OO COBOL) a subprogram is ALWAYS "CALL"'ED.

So everything you see inside a program source belongs, with some exceptions, to that program, and is either subject to a perform, a go to or a fall through code.

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Nance,
If this is an old program, it's highly likely that you are looking at a piece of code that was either poorly written, or that a GO TO CHECK-CODE was originally coded and then subsequent removed for business reasons sometime in 1978 :)

It could well be that if it was removed, the person that did so did not deem it necessary to remove the associated code.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top