# set control 'N' doesn't work sometimes

**URL:** <https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [July 8, 2008, 6:07pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510 "2008-07-08T18:07:06Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 8, 2008, 6:07pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/1 "2008-07-08T18:07:06Z")

</div>

Hello!

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 8, 2008, 7:20pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/2 "2008-07-08T19:20:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 8, 2008, 10:30pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/3 "2008-07-08T22:30:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 9, 2008, 11:43am UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/4 "2008-07-09T11:43:01Z")

</div>

> [@Wolfgang Winter](#):
>
> Which Natural version are we talking about ?

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

> [@](#):
>
> I’ve run this numerous times now and it NEVER asked for input, I only see the final “for loop 2 line 10” message.

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2008, 6:23pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/5 "2008-07-09T18:23:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2008, 6:30pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/6 "2008-07-09T18:30:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2008, 6:36pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/7 "2008-07-09T18:36:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 9, 2008, 6:46pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/8 "2008-07-09T18:46:12Z")

</div>

> [@Steve Robinson](#):
>
> 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.

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…

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2008, 6:46pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/9 "2008-07-09T18:46:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 9, 2008, 6:54pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/10 "2008-07-09T18:54:07Z")

</div>

> [@Steve Robinson](#):
>
> 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).

The Natural documentation for %N says:

> [@](#):
>
> This terminal command is used with a SET CONTROL statement and causes the next logical output screen to be displayed without requiring any user response for processing to continue.

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2008, 7:50pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/11 "2008-07-09T19:50:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 10, 2008, 7:16pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/12 "2008-07-10T19:16:37Z")

</div>

Hi Steve Robinson!

Thanks for your time and your patience.

> [@Steve Robinson](#):
>
> 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).

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.

> [@Steve Robinson](#):
>
> 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.

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

Next Example:

```auto
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.

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 10, 2008, 11:19pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/13 "2008-07-10T23:19:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 10, 2008, 11:45pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/14 "2008-07-10T23:45:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [July 11, 2008, 1:01am UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/15 "2008-07-11T01:01:59Z")

</div>

> [@Steve Robinson](#):
>
> 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

- SURPRISED? 😉

> [@](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 14, 2008, 1:54pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/16 "2008-08-14T13:54:53Z")

</div>

> [@Steve Robinson](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:50pm UTC](https://techcommunity.softwareag.com/t/set-control-n-doesnt-work-sometimes/78510/17 "2021-04-02T14:50:36Z")

</div>


