View previous topic :: View next topic
|
Author |
Message |
atulrukmangad
New User
Joined: 10 Apr 2006 Posts: 13
|
|
|
|
This was asked in an interview.
What will be the result of the following and why ?
READ (10) EMPLOY-VIEW WITH EMPLOY-ID = '3'
ACCEPT IF EMPLOY-ID = '3'
REJECT IF EMPLOY-ID ='3'
WRITE EMPLOY-ID
END-READ
Assume that EMPLOY-ID =3 exists in the EMPLOYEE table. |
|
Back to top |
|
|
skodidine
New User
Joined: 05 Apr 2006 Posts: 6
|
|
|
|
if records exist with EMPLOY-ID = '3' within the first 10 READS, then they will be written because:
"If an ACCEPT condition is satisfied, the record will be accepted and consecutive ACCEPT/REJECT statements will be ignored."
Sanjay |
|
Back to top |
|
|
rahul_mf Warnings : 1 New User
Joined: 13 Sep 2005 Posts: 13
|
|
|
|
Sanjay , you are absolutely right.
But I dont know why you have written:-
"if records exist with EMPLOY-ID = '3' within the first 10 READS"
Because the statement :-
READ (10) EMPLOY-VIEW WITH EMPLOY-ID = '3'
Means that it will read those first 10 records which satisfy the condition
EMPLOY-ID = '3' . |
|
Back to top |
|
|
skodidine
New User
Joined: 05 Apr 2006 Posts: 6
|
|
|
|
ooops!! Sorry, didnt read the statement correctly, yes it will pick up the first 10 records that have EMPLOY-ID = '3'. My mistake.
Sanjay |
|
Back to top |
|
|
rahul_mf Warnings : 1 New User
Joined: 13 Sep 2005 Posts: 13
|
|
|
|
No probs |
|
Back to top |
|
|
Bidzoniy
New User
Joined: 04 May 2006 Posts: 1
|
|
|
|
Can somebody provide the list of the possible Natural/Adabas interview questions (at leat some of them) or point me where I can find them
Thanks |
|
Back to top |
|
|
naveen_desireddy
New User
Joined: 29 Aug 2005 Posts: 10 Location: Hyderabad, India
|
|
|
|
if records exist with EMPLOY-ID = '3' within the first 10 READS, then they will be written because:
"If an ACCEPT condition is satisfied, the all the record's will be accepted
irrespective of other conditions |
|
Back to top |
|
|
Sid Reddy
New User
Joined: 28 May 2009 Posts: 2 Location: Chennai
|
|
|
|
Rahul, for your below quote/issue i think its a bit incorrect... it does not mean that it will read first 10 records mtching employ id =3. it will start reading from employ id=3
Quote: |
But I dont know why you have written:-
"if records exist with EMPLOY-ID = '3' within the first 10 READS"
Because the statement :-
READ (10) EMPLOY-VIEW WITH EMPLOY-ID = '3'
Means that it will read those first 10 records which satisfy the condition
EMPLOY-ID = '3' . |
i think you got the concept of read incorrectly... i understand that even you give the statement "EQUAL TO" it is equivalent to "starting from"
hope i am correct... in that case the first answer stand correct.... will display 3 if the record is found in first 10 read loops.
Please correct me if i am wrong |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Sid Reddy - Hello and welcome to the forum.
Have you noticed that you were replying a 3-years post?
O. |
|
Back to top |
|
|
Sid Reddy
New User
Joined: 28 May 2009 Posts: 2 Location: Chennai
|
|
|
|
ofer71 wrote: |
Sid Reddy - Hello and welcome to the forum.
Have you noticed that you were replying a 3-years post?
O. |
Yes,
I knew it. I just wanted to correct something that I felt was guiding people wrong... many of my friends visited this site and pointed to this... |
|
Back to top |
|
|
Steve Robinson
New User
Joined: 14 Nov 2009 Posts: 12 Location: U.S.
|
|
|
|
Sad to say, but every answer to this question is incorrect.
Lets see why.
READ (10) EMPLOY-VIEW WITH EMPLOY-ID = '3'
The more readable version of the READ would be:
READ (10) EMPLOY-VIEW BY EMPLOY-ID STARTING FROM '3'
Although legal syntax, WITH is very misleading here. STARTING FROM is the self explanatory syntax.
ACCEPT IF EMPLOY-ID = '3'
REJECT IF EMPLOY-ID ='3'
This is the tricky piece of the code. Whenever there are two or more ACCEPT/REJECTs together the code works totally different than if the statements were not contiguous.
What happens is:
Natural does the first ACCEPT/REJECT. If true, Natural does the "action" part of the statement, then skips the remainder of the tests in the "group". If false, Natural proceeds to the next test and repeats this action.
HENCE, ALL records pass these two statements.
WRITE EMPLOY-ID
END-READ
So, the output might look like:
3
3
3
3
4
4
4
5
5
6
There will ALWAYS be ten lines of output (the limit factor of ten on the READ). The numbers will be in ascending sequence since we are reading by EMPLOY-ID. They might all be 3's, or none of them might be 3.
steve
[/i] |
|
Back to top |
|
|
monasu1998
Active User
Joined: 23 Dec 2005 Posts: 176 Location: India
|
|
|
|
Hi Steve,
I had a wrong thought about consecutive Accept/reject statements.
But after reading thru your post, I am clear.
I never thought of the DISPLAYs for the EMP-ID NOT = 3. |
|
Back to top |
|
|
|