Stack top data ' '

6 week old noobie asks: I see this statement used all the time. And yet it can have strange results like causing a FETCH’d program to fall thru an INPUT USING MAP statement TWICE (the fetched program uses a SET CONTROL ‘Q’ statement in its INITS). What are the various uses of this STACK TOP DATA ’ ’ statement - I know it puts a blank record at the top of the stack - but what are the various reasons that one wants to do this ?

How do INPUT USING MAP statements (or other INPUT statements that display a formatted screen for input ) affect the stack ? Is clearing the entire stack a better idea - in general - in the main program before fetching/calling another module ?

Can one place multiple blank records at the TOP of the stack and what expected effects will this have on a run of the mill program ?

This is a moderately advanced topic, so I can understand your confusion.

The general purpose for using the
STACK TOP DATA ’ ’
is to simulate an “Enter” (it can also be done with a SET CONTROL ‘N’ - you may see that in some places also). The next INPUT statement will be displayed and processed as if the user pressed enter immediately. This can be done to initialize the page - force one pass through the post-INPUT code - do de-code lookups, apply edits to the data, etc.

SET CONTROL ‘Q’ suppresses display of the next INPUT statement, eliminating the “flash” of the first INPUT statement. Thus, the first time the user actually sees the screen, it has already been executed once.

An INPUT statement will pull data from the next stack line. (The system variable *DATA will show a non-zero count if there are data items in the next stack line or -1 if the next stack line is a command.)

If an application needs to regularly clear the stack before proceeding, then it probably has not been designed well or subsequent maintainers have not adhered to the original design intent.

You can execute the STACK TOP DATA multiple times. This will supply data to the next multiple INPUT statements executed. I can’t think of a good reason to do this offhand.

Thanks, Douglas. That explains A LOT of what I am seeing with the debugger …

A follow up: if a program has executed a STACK TOP DATA ’ ', will ANY of the input values of the map be changed as a result of the program falling thru an INPUT USING MAP statement?

What about the case of a SET CONTROL ‘N’?

Thanks again.

Hi,

set control ‘N’ triggers the next logical output page. It does not distinguish between INPUT or WRITE.
This is different for Stack top ’ ', were the data is popped from the stack in case of an INPUT. WRITE won’t be affected.

Regards
Arthur

The nice thing with NATURAL is: you can check it yourself with a small program like this: (input delimiter is semicolon, adapt it to your input delimiter, see the GLOBALS-command):

DEFINE DATA                                        
LOCAL                                              
1 MAPCV (C)                                        
1 FIELDN (N1) INIT <9>                             
1 FIELDA (A1) INIT <'A'>                           
END-DEFINE                                         
  STACK TOP DATA ' '      /* no modification       
* STACK TOP DATA '1'      /* change FIELDN         
* STACK TOP DATA ';B'     /* change FIELDA , ID=;!       
* STACK TOP DATA ' '  'B' /* FIELDN: 0, FIELDA: 'B'
* STACK TOP DATA '1;B'    /* FIELDN: 1, FIELDA: 'B', ID=;!
INPUT (AD=M CV=MAPCV)                              
  FIELDN /                                         
  FIELDA                                           
IF MAPCV MODIFIED                                  
  PRINT 'modified'                                 
ELSE                                               
  PRINT 'not modified'                             
END-IF                                             
PRINT                                              
  '=' FIELDN /                                     
  '=' FIELDA                                       
END                                                

Watch the results when you (de)activate the different STACK TOP DATA statements.

Thanks so much, Wilfried. I just saw your post. I will try your test program soon …

good day,
I would like to know if it is possible in natural to display the stack information (both the data and commands) without using a debugger.

Is there perhaps a system variable (not *DATA as this only gives u the number of data items or -1 if the next is a command) that can printout the entire stack.

the scenario we have is that if data is coming from an external source and as per the natparm, a stack is executed which has certain commands, we are trying to establish the data and commands coming into natural.

Three user exits (USR4003N, USR6303N, and USR8222N) can show you the contents of the top stack entry. The only way to see the second entry is to pop the stack. That is, remove the top entry, then re-execute the user exit.

Thanks a million, will invoke them to get the stack data