Return code from a COBOL-DB2 module



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Return code from a COBOL-DB2 module

Postby narasi_433 » Thu Apr 17, 2014 1:27 pm

hi,

Can anyone explain why the MAXCC = 0 even when any file operation fails and it is non-zero when the DB2 operation fails? Does this depend on the pogram or is it a general behavior of mainframe?

i have mentioned a sample flow of the program.
Eg:

open file
if status = '00' OR '10'
continue
else
go to 999-abend-para


for DB2 query:

exec sql
-----------
----------
end-exec

EVALUATE SQLCODE
WHEN '00'
continue
WHEN OTHER
go to 999-abend-para
END-EVALUATE


999-abend-para
CALL CEE3ABD using +3000,1.
STOP RUN.

in the above mentioned flow, when any error occurs either for file operation or for DB2 operation, i am calling the abend-aid module. But, only for DB2 error i could see MAXCC is set to non-zero value.
in JESMSGLG if i check the RC for the step calling this module shows '0' even though the file operation has failed.but, for DB2 error, i could c RC='12' or some value.

Could anyone explain why is it so?

Thanks
narasi_433
 
Posts: 6
Joined: Thu Apr 17, 2014 12:29 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Return code from a COBOL-DB2 module

 

Re: Return code from a COBOL-DB2 module

Postby NicC » Thu Apr 17, 2014 2:15 pm

Hello, welcome to the forum.

For the record MAXCC is ONLY relevant to IDCAMS. What you are referring to is the Return Code.

Also, for DB2, an SQLCODE of 100 is good - it is the equivalent of end-of-file so you should not error on that unless you are absolutely 100% sure that you should have a row returned from a SELECT.

As to the file status I do not know although reading your post has made us realise why some of our programs are not abending on a non-zero status code from our file activities.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Return code from a COBOL-DB2 module

Postby BillyBoyo » Thu Apr 17, 2014 6:53 pm

In a COBOL program, unless you set the return-code to something, the result will be zero (assuming you don't manage to overwrite the return-code field, anyway).

There is nothing automatic to give you a "non-zero" if something goes wrong. Unless conditional processing in the JCL is required (with COND or IF) then we don't tend to set the return-code.

To set a return-code in COBOL:
MOVE something TO RETURN-CODE


Where "something" is best as a meaningful data-name which has the value that you want the return-code to be.

MAXCC is shown on the message from the NOTIFY statement, but as NicC has pointed out, there is no actual MAXCC as something with a value except in IDCAMS.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Return code from a COBOL-DB2 module

Postby narasi_433 » Thu Apr 17, 2014 7:27 pm

Hi,
Thank you BillyBoyo and NicC for your reply. As you said, we want to set explicitly the return code in a cobol module when something goes wrong.
Let me be more precise in my questions
1) when db2 error occurs say sqlcode -180, i am calling abend para and program stops with return code of 12. In the same program if i get file status say 46 and if the same abend para is called the return code is still zero. Why is it happening? Can u pl tell is this because of my code or is it the Actual behavior of the system?
2) as u said, in my jcl step1 is the cobol-db2 module and i want to execute the remaining steps only if step1 i.e this module is successful. So i have a if condition like if ( step1.rc eq 0 )
3) wat happens is, when the module abends due to file status error the return code of step1 is still 0. So all the remaing steps also gets executed and the final file is having less records. Thats y i asked does it depend on the program or system is like that......

4) i even tried setting rc to 12 in the abend para but it didnt work.
999-abend-para.
Move 12 to return-code
Call CEE3ABD using +3000,1
Stop run.

This didnt work. Is it because of having a cobol call after setting rc? I even tried placing that move statement after CEE3ABD call. then also it didnt work.

Hope iam clear. Sorry if iam wrong somewhere.
narasi_433
 
Posts: 6
Joined: Thu Apr 17, 2014 12:29 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Return code from a COBOL-DB2 module

Postby BillyBoyo » Thu Apr 17, 2014 7:32 pm

You can't have an abend-code and a return-code at the same time. There is no point in setting the return-code if you are abending the program.

As a tip, don't "GO TO" your abend routine, but PERFORM it. This can aid optimisations if using compile option OPT(STD) or OPT(FULL).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Return code from a COBOL-DB2 module

Postby narasi_433 » Fri Apr 18, 2014 8:29 pm

Thanks for the guidance
narasi_433
 
Posts: 6
Joined: Thu Apr 17, 2014 12:29 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post