IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Tricky Question in NATURAL


IBM Mainframe Forums -> Java & MQSeries
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
atulrukmangad

New User


Joined: 10 Apr 2006
Posts: 13

PostPosted: Tue May 02, 2006 10:09 am
Reply with quote

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
View user's profile Send private message
skodidine

New User


Joined: 05 Apr 2006
Posts: 6

PostPosted: Tue May 02, 2006 9:53 pm
Reply with quote

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
View user's profile Send private message
rahul_mf
Warnings : 1

New User


Joined: 13 Sep 2005
Posts: 13

PostPosted: Wed May 03, 2006 1:25 pm
Reply with quote

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
View user's profile Send private message
skodidine

New User


Joined: 05 Apr 2006
Posts: 6

PostPosted: Wed May 03, 2006 8:57 pm
Reply with quote

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
View user's profile Send private message
rahul_mf
Warnings : 1

New User


Joined: 13 Sep 2005
Posts: 13

PostPosted: Thu May 04, 2006 8:00 am
Reply with quote

No probs icon_wink.gif
Back to top
View user's profile Send private message
Bidzoniy

New User


Joined: 04 May 2006
Posts: 1

PostPosted: Sat May 06, 2006 7:07 am
Reply with quote

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
View user's profile Send private message
naveen_desireddy

New User


Joined: 29 Aug 2005
Posts: 10
Location: Hyderabad, India

PostPosted: Tue May 23, 2006 1:58 am
Reply with quote

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
View user's profile Send private message
Sid Reddy

New User


Joined: 28 May 2009
Posts: 2
Location: Chennai

PostPosted: Fri May 29, 2009 7:06 pm
Reply with quote

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' .




icon_question.gif 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
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Sat May 30, 2009 10:54 pm
Reply with quote

Sid Reddy - Hello and welcome to the forum.

Have you noticed that you were replying a 3-years post?

O.
Back to top
View user's profile Send private message
Sid Reddy

New User


Joined: 28 May 2009
Posts: 2
Location: Chennai

PostPosted: Mon Jun 01, 2009 8:16 pm
Reply with quote

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
View user's profile Send private message
Steve Robinson

New User


Joined: 14 Nov 2009
Posts: 12
Location: U.S.

PostPosted: Sun Nov 15, 2009 11:07 pm
Reply with quote

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
View user's profile Send private message
monasu1998

Active User


Joined: 23 Dec 2005
Posts: 176
Location: India

PostPosted: Tue Nov 17, 2009 10:28 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Java & MQSeries

 


Similar Topics
Topic Forum Replies
No new posts Question for file manager IBM Tools 7
No new posts question for Pedro TSO/ISPF 2
No new posts question on Outrec and sort #Digvijay DFSORT/ICETOOL 20
No new posts panel creation question TSO/ISPF 12
No new posts IMS DB using Natural Language IMS DB/DC 0
Search our Forums:

Back to Top