READ ... THRU with superdescriptor
Posted: Tue Nov 24, 2009 11:46 am
On November 11, a question was posted at IBMMAINFRAMES.com Support Forums -> NATURAL & MQSERIES, regarding a Natural/Adabas interview question. Wanting to respond to the posting, I registered with the forum, but after a week, my account is still inactive. Perhaps I didn't fill out the form properly. Nonetheless, here is my response. Perhaps someone will cross-post to the other forum.
The posting quoted an interviewer as asking, "Why ENDING AT/THRU can not be used with superdescriptor?"
There were only two responses, discussing how the interviewer must have been referring to hyperdescriptors. You should review that thread before you continue reading here.
================================================
Well, the poster and the two respondents all failed the interview! Well, this particular question, anyway.
First, as to hyperdescriptors, their values may be generated in a non-Natural way (a user exit coded in Assembler), but they are treated by Natural just like a superdescriptor, and can be used anywhere a super is used.
The interviewer's question applies not only to superdescriptors, but also to subdescriptors and hyperdescriptors. It probably was phrased, "When can THRU not be used with a superdescriptor?", rather than why.
Here's a working example of FROM/THRU, using subdescriptor DEPARTMENT in the EMPLOYEES demo file.
For the THRU clause (I find the synonym ENDING AT too wordy), Natural needs memory locations in which to place the "retrieved" descriptor value, so that a comparison can be made to the value provided ('ADMA'). In this example, it means that the subdescriptor, DEPARTMENT, must be included in the view.
What happens when the UPDATE statement is reinstated? Adabas will try to update each field in the view, but Natural knows that the subdescriptor does not actually exist as a field in the EMPLOYEES file, so he issues error NAT0633 at compile-time.
To answer the interviewer's question, "You cannot code THRU with a sub/super/hyper-descriptor in an update READ loop."
To keep the UPDATE, the corrective action is to remove the descriptor from the view. For Natural 3, you replace the THRU with an IF ... ESCAPE BOTTOM statement block to test for the end of range. For Natural 4, you replace the THRU with TO, which does not require the descriptor definition in the view because Adabas tests for the end of range.
The posting quoted an interviewer as asking, "Why ENDING AT/THRU can not be used with superdescriptor?"
There were only two responses, discussing how the interviewer must have been referring to hyperdescriptors. You should review that thread before you continue reading here.
================================================
Well, the poster and the two respondents all failed the interview! Well, this particular question, anyway.
First, as to hyperdescriptors, their values may be generated in a non-Natural way (a user exit coded in Assembler), but they are treated by Natural just like a superdescriptor, and can be used anywhere a super is used.
The interviewer's question applies not only to superdescriptors, but also to subdescriptors and hyperdescriptors. It probably was phrased, "When can THRU not be used with a superdescriptor?", rather than why.
Here's a working example of FROM/THRU, using subdescriptor DEPARTMENT in the EMPLOYEES demo file.
DEFINE DATA LOCAL
1 EMP VIEW EMPLOYEES
2 PERSONNEL-ID
2 DEPT
2 DEPARTMENT /* For use by THRU
END-DEFINE
R.
READ EMP BY DEPARTMENT FROM 'ADMA'
THRU 'ADMA'
DISPLAY DEPT (AL=4)
PERSONNEL-ID
* UPDATE (R.)
END-READ
END
1 EMP VIEW EMPLOYEES
2 PERSONNEL-ID
2 DEPT
2 DEPARTMENT /* For use by THRU
END-DEFINE
R.
READ EMP BY DEPARTMENT FROM 'ADMA'
THRU 'ADMA'
DISPLAY DEPT (AL=4)
PERSONNEL-ID
* UPDATE (R.)
END-READ
END
For the THRU clause (I find the synonym ENDING AT too wordy), Natural needs memory locations in which to place the "retrieved" descriptor value, so that a comparison can be made to the value provided ('ADMA'). In this example, it means that the subdescriptor, DEPARTMENT, must be included in the view.
What happens when the UPDATE statement is reinstated? Adabas will try to update each field in the view, but Natural knows that the subdescriptor does not actually exist as a field in the EMPLOYEES file, so he issues error NAT0633 at compile-time.
To answer the interviewer's question, "You cannot code THRU with a sub/super/hyper-descriptor in an update READ loop."
To keep the UPDATE, the corrective action is to remove the descriptor from the view. For Natural 3, you replace the THRU with an IF ... ESCAPE BOTTOM statement block to test for the end of range. For Natural 4, you replace the THRU with TO, which does not require the descriptor definition in the view because Adabas tests for the end of range.