Chain with DOW–Reason behind the Infinite Loop process

320 pts.
Tags:
AS/400
FChainFile IF E K Disk
DWkName S 4A

/Free

Wkname = 'DDDD';

Chain (WkName) ChainFile;

DoW %Found(Chainfile) or Not %Eof(Chainfile);

Dsply WkName;
ReadE wKName Chainfile;

EndDo;

*Inlr = *on;

/End-Free
My Question was, I have a file field have value as:
AAAA

BBBB

CCCC

DDDD

DDDD

DDDD

EEEE
Here the code goes in Infinite loop and display the value as 'DDDD'. Please give me the reason why it goes in infinite loop.
I have said them the answer, that DOW will be start from beginning of the loop every time, so its goes in infinite loop.
But they said like that is not an answer? So please help me.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

You are setting the key wkname to ‘DDDD’ outside of your do loop.

Inside you are doing a reade.
It will only pick up the ‘DDDD’ records.
You can change your DOW to just check the EOF condition to simplify things. 
The or in the test is also another problem point, the %found test will always happen

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb
    is this a question for a recruiter?
    54,090 pointsBadges:
    report
  • srivijay1
    Yes..Is this one of the Recruiter question....
    320 pointsBadges:
    report
  • ToddN2000
    It's been a long time since I interviewed for a job. Is this just a general question on that was actually given to you to answer on an interview or aptitude test? Was it given in advance on on the spot? Just curious.
    136,240 pointsBadges:
    report
  • hunshabbir7
    I think 

    DoW %Found(Chainfile) or Not %Eof(Chainfile);

    There should be AND between two conditions. As on last iteration it will keep Last record so first condition will be always true.
    2,900 pointsBadges:
    report
  • hunshabbir7
    Or you can skip %Found condition. Just check %EOF
    2,900 pointsBadges:
    report
  • TheRealRaven
    The %FOUND() should be an IF-condition outside of the DOW-loop. The DOW-loop shouldn't need to test it on every iteration and there's no point in entering the loop if the record isn't found.

    Since CHAIN sets it on and READE doesn't set %FOUND() at all, it will be on forever. The OR condition then evaluates to true forever.
    36,880 pointsBadges:
    report
  • srivijay1
    Thanks for the valuable answers..
    320 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: