I began to learn the CL program. I have a little problem in the CL program. The question is to check the file name and library name whether you exit or not.
This is the code:
PGM (&FILE &LIB &FOUND) DCL &FILE *CHAR 10 DCL &LIB *CHAR 10 DCL &FOUND *CHAR 1 CHGVAR VAR(&FOUND) VALUE('Y') CHKOBJ OBJ(&LIB/&FILE) OBJTYPE(*FILE) IF COND(&FOUND *EQ 'N') THEN(DO) CHGVAR VAR(&FOUND) VALUE('N') GOTO **************************** ENDDO ENDPGM
I code the error message in the display file. Which is indicator 90. N90 DSPATR(UL) N90 DSPATR(HI) 90 ERRMSG('OBJECT NOT FOUND' 90)
My problem is "How can I combine them together?"
If I am reading your question correctly, you want to check for the existence of an object then returns to a program that will turn on an indictor. I am going to copy your code below, and put in some changes that should help. PGM (&FILE &LIB &FOUND) DCL &FILE *CHAR 10 DCL &LIB *CHAR 10 DCL &FOUND *CHAR 1 CHGVAR VAR(&FOUND) VALUE('0') CHKOBJ OBJ(&LIB/&FILE) OBJTYPE(*FILE) MONMSG(CPF9801) EXEC(DO) CHGVAR (&FOUND) VALUE('1') ENDDO /* Delete this line */ IF COND(&FOUND *EQ 'N') THEN(DO) /* Delete this line */ CHGVAR VAR(&FOUND) VALUE('N') GOTO **************************** /* Delete this line */ ENDDO ENDPGM
If the object is not found, the program will return the message of CPF9801. If you monitor for this, you can trap the error and set the values you want. Also your program will not end abnormally. To see all the possible error messages you can get from ANY command, type in the command press F4 place the cursor on line two (Just under the command name) then press F1. You will see all the messages and what they mean. You may notice that I changed the values on &FOUND from Y/N to 0/1. This way you can pass the indictor and this program will turn it on or off as needed. The CALLER will not need to interpret the value of &FOUND, just pass the value directly into the indictor. You can code the screen into this program if you wish, but this program could be very useful as a stand alone program if you need to check for the existence of objects from other places with in your application. I hope this helps.
Dig Deeper on iSeries skills
Related Q&A from John Brandt
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.