set control 'N' doesn't work sometimes

Hello!

The following program waits for user input, even though there are set-contol-statements.

define data local
01 #i4 (I4)
01 #for1-limit (i4) init <11>
01 #for2-limit (i4) init <10>
end-define
format (0) PS=20
for #i4 = 1 to #for1-limit
  set control 'n'
  write notitle 'for loop 1   line' #i4
end-for
for #i4 = 1 to #for2-limit
  set control 'n'
  write notitle 'for loop 2   line' #i4
end-for
end

The crazy thing is: The whole thing works if you change #for2-limit to 11.
Why?

Which Natural version are we talking about ?

I’ve run this numerous times now and it NEVER asked for input, I only see the final “for loop 2 line 10” message.

I have run the program on 6.1, 6.2, 6.3. All produce the same output as Wolfgang observed.

Matthias, where does your program request input? and what version are you running?

steve

I got 6.1.1.17@Solaris and 6.1.1.21@WinXP here. Both versions got the same behaviour.

Sorry! Maybe I have to explain a bit more…
I wrote in my fist post: “the program waits for user input”. But I ment: The program waits for the user to press ENTR. What I expect is, that the SET CONTROL ‘N’ skips that waiting for ENTR. So you should see the final “for loop 2…:” message only for a very short time. Maybe it’s too fast to see anyway.

Aha. No I understand what you were “complaining” about.

Add a SET CONTROL ‘N’ just before your END statement.

Actually, you only need one %N per page, not per line as you have it.

The last SET CONTROL ‘N’ is just to take care of the final page that is “forced out” at the END of the program.

steve

To see that you only need one %N per page, comment out your SET CONTROL statements. Then add one just before the first FOR loop, and just before the END.

If I want to go into “skim” mode with some output, I code
AT END OF PAGE
set control ‘n’
end-endpage
*
If you do the at end of page in your code, you do not need any other SET CONTROL’s.

steve

If you want the user to see the whole page of output for some length of time, code:

1 #DELAY (I2) INIT <4>
::::
AT END OF PAGE
CALL ‘CMROLL’ #DELAY /* 4 second delay
SET CONTROL ‘N’
END-ENDPAGE

This works regardless of the sequence of the CALL and the SET CONTROL.
#DELAY must be formatted I2.

steve

Yes, I know that. But my question was: Why is this additional Set control ‘N’ necessary before the end of program? It doen’t make sense to me. The SET CONTROL ‘N’ before the write (even if it is executed more than once) should be enough.

Please try other values for #for2-limit (e.g. 11) without a SET CONTROL Statement just before the end…

The crazy thing is: The whole thing works if you change #for2-limit to 11.
Why?

Forgot this question.

Try changing #for1-limit to 10; that works as well. It is the timing of what causes the page to be sent to the screen (and hence whether there is a SET CONTROL ‘N’ in “effect” for the page being sent to the screen).

steve

The Natural documentation for %N says:

It says “next logical output screen”. … so it should make no difference if I code the SET CONTROL before the write statment (as I did) or after the write (as you suggested).

Hi Matthias;

Bear with me on this, it is a bit complicated. Here is your second loop:

FOR #I4 = 1 TO #FOR2-LIMIT
SET CONTROL ‘n’
WRITE NOTITLE ‘for loop 2 line’ #I4
END-FOR

Natural doesn’t “send” a page to the screen until the following WRITE. So, given the data you have, there is a full screen waiting to be sent BEFORE the last WRITE statement. Now you give the redundant %N, then the final WRITE. This causes the first screen to be sent. HOWEVER, you do not give a %N for the second page (which is what you are seeing.

Take your second FOR loop and change it as follows:

FOR #I4 = 1 TO #FOR2-LIMIT
WRITE NOTITLE ‘for loop 2 line’ #I4
SET CONTROL ‘n’
END-FOR

This will work the way you want it to. The WRITE statement sends the first page to the screen. Now there is a %N for the second page.

I have a classic way to win a glass of wine from a Natural class. I ask them what NEWPAGE does in Natural. It does NOT start a new page. Instead, it sets a flag. The next WRITE (or DISPLAY/PRINT) is what actually starts the new page.

What you are seeing is similar. You fill a page, but do not send it to the screen. It is the following WRITE which sends the page to the screen. The way you have the code, the last %N is “consumed” by the first screen.

You need to issue a %N for the following screen.

steve

Hi Steve Robinson!

Thanks for your time and your patience.

I think that’s the point! Now I got it.

It works for 20 lines (i.e. #FOR1-LIMIT := 10 and #FOR2-LIMIT := 10), because I only need one SET CONTROL ‘N’ as the program reaches its end (in my sample Program the SET CONTROL ‘N’ before the 20th WRITE does that).
It works for 22 lines (i.e. #FOR1-LIMIT := 11 and #FOR2-LIMIT := 11), because I need one SET CONTROL ‘N’ before the 21st WRITE plus one SET CONTROL ‘N’ as the program reaches its end (in my sample Program it is the SET CONTROL before the 22nd WRITE).
It doesn’t work for 21 lines (i.e. #FOR1-LIMIT := 11 and #FOR2-LIMIT := 10), because I need one SET CONTROL ‘N’ at the 21st WRITE. But this is the last WRITE statement processed and there is no more SET CONTROL ‘N’ processed before the program reaches the end.

Right, this is what the Natural-Documentation of NEWPAGE says. But maybe, that’s not the whole truth.

Next Example:

set control 'N'
write 'write'
set control 'N'
input 'input'
end

This code doesn’t work, because the write does the output at the time when the INPUT-Statement is executed. So you have to simulate two ENTR at once - and that’s impossible (… “next logical page”).

But: Why does the following code work? I seems to me like the NEWPAGE is performed at once.

set control 'N'
write 'write'
newpage
set control 'N'
input 'input'
end

Hi Matthias;

First, here is a program and output which shows the timing of NEWPAGE

  • THIS PROGRAM DEMONSTRATES THAT NEWPAGE DOES NOT IMMEDIATELY
  • START A NEWPAGE. IT MERELY SETS A FLAG WHICH IS CHECKED BEFORE
  • NATURAL WRITES ANYTHING. IN THE EXAMPLE BELOW SEE IF YOU CAN
  • FIGURE OUT WHAT THE VALUE OF #A WILL BE AT THE TOP OF THE
  • SECOND PAGE
  • SURPRISED? EVEN THOUGH THE XYZ WAS MOVED TO #A AFTER THE
  • NEWPAGE, THE NEWPAGE COMMAND MERELY SET A FLAG WHICH
  • DID NOT CAUSE A NEWPAGE UNTIL THE WRITE STATEMENT TO PAGE TWO

DEFINE DATA LOCAL
1 #A (A3) INIT <‘ABC’>
END-DEFINE
*
AT TOP OF PAGE
IF *PAGE-NUMBER = 1
WRITE NOTITLE ‘=’ (25) ’ OUTPUT ’ ‘=’ (25) /
5T ‘PAGE #’ *PAGE-NUMBER (NL=2)
35T 'DATE: ’ *DATV /
5T ‘PROGRAM:’ *PROGRAM
35T ‘LIBRARY:’ *LIBRARY-ID //
10T ‘#A IS’ #A

ELSE
WRITE ‘-’ (60) /
5T ‘PAGE #’ *PAGE-NUMBER (NL=2)
35T 'DATE: ’ *DATV /
5T ‘PROGRAM:’ *PROGRAM
35T ‘LIBRARY:’ *LIBRARY-ID //
10T ‘#A IS’ #A

END-IF
END-TOPPAGE
*
WRITE 5/10 ‘THIS IS PAGE ONE OUTPUT’
NEWPAGE
MOVE ‘XYZ’ TO #A
WRITE 5/10 ‘THIS IS PAGE TWO OUTPUT’
*
END

========================= OUTPUT =========================
PAGE # 1 DATE: 16-SEP-2007
PROGRAM: NEWPAG02 LIBRARY: SNDEMO

     #A IS ABC




     THIS IS PAGE ONE OUTPUT

PAGE #   2                    DATE:    16-SEP-2007
PROGRAM: NEWPAG02             LIBRARY: SNDEMO

     #A IS XYZ




     THIS IS PAGE TWO OUTPUT

Now to your code: Lets start with

set control ‘N’
write ‘write’
set control ‘N’
input ‘input’
end

You can issue as many %N as you want while you are on one page; Natural still only has one %N applied to the WRITE. There is no %N available for the INPUT.

I must confess I am guessing about what follows. Here is the code:

set control ‘N’
write ‘write’
newpage
set control ‘N’
input ‘input’
end

If I am Natural, when I see the NEWPAGE, I know I must perform an AT END OF PAGE clause (there is none in your code). I am guessing that this is when Natural “applies” the %N, rather than waiting for the next WRITE.

If that is not the case, my second guess would be that the NEWPAGE tells Natural that the second %N must be applied to the second page that is sent to the screen.
I will play a bit when I get a chance and report back.

steve

Hi Matthias;

First, here is a program and output which shows the timing of NEWPAGE

  • THIS PROGRAM DEMONSTRATES THAT NEWPAGE DOES NOT IMMEDIATELY
  • START A NEWPAGE. IT MERELY SETS A FLAG WHICH IS CHECKED BEFORE
  • NATURAL WRITES ANYTHING. IN THE EXAMPLE BELOW SEE IF YOU CAN
  • FIGURE OUT WHAT THE VALUE OF #A WILL BE AT THE TOP OF THE
  • SECOND PAGE
  • SURPRISED? EVEN THOUGH THE XYZ WAS MOVED TO #A AFTER THE
  • NEWPAGE, THE NEWPAGE COMMAND MERELY SET A FLAG WHICH
  • DID NOT CAUSE A NEWPAGE UNTIL THE WRITE STATEMENT TO PAGE TWO

DEFINE DATA LOCAL
1 #A (A3) INIT <‘ABC’>
END-DEFINE
*
AT TOP OF PAGE
IF *PAGE-NUMBER = 1
WRITE NOTITLE ‘=’ (25) ’ OUTPUT ’ ‘=’ (25) /
5T ‘PAGE #’ *PAGE-NUMBER (NL=2)
35T 'DATE: ’ *DATV /
5T ‘PROGRAM:’ *PROGRAM
35T ‘LIBRARY:’ *LIBRARY-ID //
10T ‘#A IS’ #A

ELSE
WRITE ‘-’ (60) /
5T ‘PAGE #’ *PAGE-NUMBER (NL=2)
35T 'DATE: ’ *DATV /
5T ‘PROGRAM:’ *PROGRAM
35T ‘LIBRARY:’ *LIBRARY-ID //
10T ‘#A IS’ #A

END-IF
END-TOPPAGE
*
WRITE 5/10 ‘THIS IS PAGE ONE OUTPUT’
NEWPAGE
MOVE ‘XYZ’ TO #A
WRITE 5/10 ‘THIS IS PAGE TWO OUTPUT’
*
END

========================= OUTPUT =========================
PAGE # 1 DATE: 16-SEP-2007
PROGRAM: NEWPAG02 LIBRARY: SNDEMO

     #A IS ABC




     THIS IS PAGE ONE OUTPUT

PAGE #   2                    DATE:    16-SEP-2007
PROGRAM: NEWPAG02             LIBRARY: SNDEMO

     #A IS XYZ




     THIS IS PAGE TWO OUTPUT

Now to your code: Lets start with

set control ‘N’
write ‘write’
set control ‘N’
input ‘input’
end

You can issue as many %N as you want while you are on one page; Natural still only has one %N applied to the WRITE. There is no %N available for the INPUT.

I must confess I am guessing about what follows. Here is the code:

set control ‘N’
write ‘write’
newpage
set control ‘N’
input ‘input’
end

If I am Natural, when I see the NEWPAGE, I know I must perform an AT END OF PAGE clause (there is none in your code). I am guessing that this is when Natural “applies” the %N, rather than waiting for the next WRITE.

If that is not the case, my second guess would be that the NEWPAGE tells Natural that the second %N must be applied to the second page that is sent to the screen.
I will play a bit when I get a chance and report back.

steve

  • SURPRISED? :wink:

Would be a nice explanation. Sounds good. But I guess you got no chance to prove it…

BTW: Today I realized that CLOSE PRINTER (0) behaves like NEWPAGE. The only difference is the Page number…