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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling SubPrograms

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Can someone please take a look at the code below and tell me if I am even using sub-programs correctly? I am not quite sure why my program is not working. I am just a beginner and the code below is just parts of the source code. Thanks!!!

SUB PROGRAM:

INDENTIFICATION DIVISION.
AUTHOR-ID. VALSSN.

DATA DIVISION.

LINKAGE SECTION.
01 DATA-RECORDS.
05 DATA-NAME PIC X(20).
05 DATA-SSN PIC 9(9).

01 VALIDATION-RESULTS PIC 99.
88 NON-NUMERIC-SSN VALUE 21.
88 NO-SSN-PRESENT VALUE 22.
88 SSNISVALID VALUE 20.

PROCEDURE DIVISION USING DATA-RECORDS, VALIDATION-RESULTS.
0000-MAIN.
EVALUTATE TRUE
WHEN DATA-SSN = SPACES
SET NO-SSN-PRESENT TO TRUE.
WHEN DATA-SSN NOT NUMERIC
SET NON-NUMERIC-SSN TO TRUE.
WHEN OTHER
SET SSNISVALID TO TRUE.
END-EVALUATE.




DRIVER PROGRAM:

INDENTIFICATION DIVISION.
AUTHOR-ID. MAIN.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DATA-FILE ASSIGN TO IFILE.
SELECT VALID-FILE ASSIGN TO OFILE.
SELECT ERROR-FILE ASSIGN TO OFILE2.

DATA DIVISION.
FD DATA-FILE
RECORDING MODE IS F
RECORD CONTAINS 56 CHARACTERS
DATA RECORD IS DATA-RECORDS.
01 DATA-RECORDS.
05 DATA-NAME PIC X(20).
05 DATA-SSN PIC 9(9).

WORKING-STORAGE SECTION.
01 VALIDATION-RESULTS PIC 99.
88 NON-NUMERIC-SSN VALUE 21.
88 NO-SSN-PRESENT VALUE 22.
88 SSNISVALID VALUE 20.

PROCEDURE DIVISION.
//THERE IS OF COURSE OTHER STUFF IN HERE, BUT THIS IS THE CALL
CALL 'VALSSN' USING BY CONTENT DATA-RECORDS
BY REFERENCE VALIDATION-RESULTS.

0510-WRITE-RECORDS.
EVALUATE TRUE
WHEN NON-NUMERIC-SSN
MOVE E-NON-NUMERIC-SSN TO ERR-MESSAGE
MOVE DATA-SSN TO ERR-CONTENTS
PERFORM 0520-WRITE-ERROR-LINE
WHEN NO-SSN-PRESENT
MOVE E-NO-SSN-PRESENT TO ERR-MESSAGE
MOVE SPACES TO ERR-CONTENTS
PERFORM 0520-WRITE-ERROR-LINE
WHEN OTHER PERFORM 0530-WRITE-VALID-LINE
END-EVALUATE.

//BLAH BLAH

 
I'm only a beginner too but I think this is your problem...

01 VALIDATION-RESULTS PIC 99.
88 NON-NUMERIC-SSN VALUE 21.
88 NO-SSN-PRESENT VALUE 22.

I believe it should read something like....

01 VALIDATION-RESULTS.
88 VR-NON-NUMERIC-SSN VALUE 21.
88 VR-NO-SSN-PRESENT VALUE 22.

01 VALIDATION-RESULTS.[add period] delete this [red]PIC 99.[/red]

I've also noticed it in your WORKING-STORAGE SECTION too. That might also be a problem area as well.

Hope this is right, and sorry if I'm wrong, as I said I'm a beginner too.

--MiggyD
 
In your sub-program, there should not be any periods between the EVALUATE and the END-EVALUATE that goes with it. (In fact, there should never be any periods between any verb and its corresponding scope terminator.) Other than that, the usage in your CALL and in your sub-program are correct. Your problem probably lies elsewhere. You could prove that to yourself by temporarily inserting the following DISPLAY right after the CALL.

DISPLAY DATA-RECORDS " has returned a value of " VALIDATION-RESULTS.

This will show you the data you passed to the routine and the code it returned right after it happened, so you can be sure that it's right.

Betty Scherber
Brainbench MVP for COBOL II
 
miggyD,

Your confusing Conditions with a Group Item. His code of
01 VALIDATION-RESULTS PIC 99.
88 NON-NUMERIC-SSN VALUE 21.
88 NO-SSN-PRESENT VALUE 22.
is correct. Level 88 represents a condition of Validation-Results, not an elementary item. Hope this helps.

MikeR Turin
 
Now I'm not trying to be funny here but.......it would really help if and when you post a problem you actually tell us what the problem is. There's too many problems posted that only say 'my program doesn't work', 'what am I doing wrong' etc etc. If you had a live program and a user rang you and said 'your program isn't working' how would you feel? Well, you'd say 'typical users, how do they expect me to fix it with next to no info'. Furthermore, did you ever manage to compile the sub program?

I know we all have to start somewhere but this isn't rocket science, the secret to everything you'll do is information, facts and examples.

Cheers
 
Some words about your subprogram:

> INDENTIFICATION DIVISION.
> AUTHOR-ID. VALSSN.
> DATA DIVISION.
> LINKAGE SECTION.
> 01 DATA-RECORDS.
> 05 DATA-NAME PIC X(20).
> 05 DATA-SSN PIC 9(9).
> 01 VALIDATION-RESULTS PIC 99.
> 88 NON-NUMERIC-SSN VALUE 21.
> 88 NO-SSN-PRESENT VALUE 22.
> 88 SSNISVALID VALUE 20.
if you want to use boolean variables its definition
must be: (at least at IBM COBOL 2 - microfocus cobol - rm-cobol)
88 NON-NUMERIC-SSN PIC X VALUE 'Y' WHEN FALSE 'N'.
the when you set it to true it's value is 'Y' and otherwise 'N'.

> PROCEDURE DIVISION USING DATA-RECORDS, VALIDATION-RESULTS.
> 0000-MAIN.
> EVALUTATE TRUE
> WHEN DATA-SSN = SPACES
> SET NO-SSN-PRESENT TO TRUE.
> WHEN DATA-SSN NOT NUMERIC
> SET NON-NUMERIC-SSN TO TRUE.
> WHEN OTHER
> SET SSNISVALID TO TRUE.
> END-EVALUATE.
evaluating DATA-SSN = SPACES and DATA-SSN NOT NUMERIC
is not redundant?
if you want to set both variables NO-SSN-PRESENT and
NON-NUMERIC-SSN you must use IFs.

HTH
Pablo Loyber
 
Pablo,

I haven't seen "when false" in IBM's COBOL2 yet, I'm hoping it will show up in the next releases of their OS370/390/MVS/VM (or whatever) compiler.

But I do agree that CBLHELP needs a way to reset his SSN 88 levels since there's no indication that his sub pgm is being reinitialized at each call.
I usually use a RESET-VALIDATION-RESULTS like condition name to do this.

His "when" structure looks ok (except for the periods).
I think his intent was to treat a "not provided" condition (spaces) differently than an "invalid SSN" (not numeric).
Granted "spaces" is non numeric, but it may not be invalid, thus the two separate tests.

Given the way eval works there is no danger of picking up "spaces" in the 2nd "when" clause because the evaluation stops and the statement is exited upon satisfaction of the 1st condition tested. If he reversed the condition tests in the statement he'd run into a problem.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top