"SET KEY" statements in maps?

In a Natural-MAP, it’s possible to code a so called PF-KEY rule. Imagine the following PF-KEY rule:

if *PF-KEY = 'PF24'
  #cv-hidden-information := (AD=D)
  reinput 'Hidden information displayed...'
end-if

In the program which calls the map, a “SET KEY PF24” is necessary.
My (stupid) question: Is it possible to include this “SET KEY PF24” into the map? That would be better than coding the “SET KEY PF24” in every calling program…

Why do you not use “SET KEY ALL” in the calling program or in the main program?

As I wrote:

That means: Currently I am using “SET KEY PF24” in every calling program and it works. But today I was just wondering, if it’s possible to do it in the map. I need this KEY only inside the map. At the moment my coding looks like this:

SET KEY PF24
INPUT USING MAP
SET KEY PF24=OFF

The statement “SET KEY PF24=OFF” can be moved to the PF-KEY-Rules inside the map. But what about the “SET KEY PF24”?

It can’t, because the SET KEY would have to be executed before the INPUT statement.

Two points.

First, REINPUT FULL, not just REINPUT, otherwise you will not see the hidden information.

Now for the fun stuff.

Natural has the equivalent of a “pre-processing rule” where you could place the SET KEY statement. I have used this technique many times, but never with a PF key, so you will have to be the guinea pig.

In the Map, you will want to have specified a Dynamic Layout, call it MYSTART for example. MYSTART must have a single non displayable field otherwise Natural ignores the Layout. Define a PF Key processing rule for the Layout which has the SET KEY statement.

Step 1) Create and STOW MYSTART

Step 2) Change your Map to have the Layout MYSTART and re-stow.

Step 3) Keep fingers crossed and try it.

steve

p.s. would love to claim credit for this technique, but Andreas showed it to me.

@Wolfgang Winter:

Yes, I understand. But if you have a look at the real coding of a map, there are some format-settings done before the input-statement. So I wondered if could put my “SET KEY” there.

@Steve: Thanks for the tip. I’ll try it out. But it’s sounds a bit “dirty” to me :wink:

Your (or Andreas’) idea doesn’t work. Here are my codes to check, whether I did it right or not.

define data local
01 #a10 (A10)
end-define
*
set key all
set key PF24=OFF
input using map 'TST-MAP1'
end

TST-MAP1 is:

* MAP2: PROTOTYPE              --- CREATED BY WNT 6.1.1 ---
* INPUT USING MAP 'XXXXXXXX'
*     #A10
DEFINE DATA PARAMETER
1 #A10 (A010)
END-DEFINE
FORMAT PS=005 LS=021 ZP=OFF SG=OFF KD=OFF IP=OFF
SET CONTROL 'Q' ' ' INPUT USING MAP 'LAYOUT  '
* MAP2: MAP PROFILES *****************************        200***********
* .TTAAAMMOO   D I D I N D I D I        ?_)^&:+(                       *
* 005020LAYOUT  N0YNUCN             X        01 SYSDBA  NR             *
************************************************************************
INPUT NO ERASE (     IP=OFF                                           /*
                                                                       )
/
 003T '#a10'
 009T #A10  (AD=DLMFHT' ' ) /*.99U010 A010 .
/
/
/
* MAP2: VALIDATION *****************************************************
RULEVAR F00*PF-KEY
INCDIC                                 ;
display *PF-KEY
* MAP2: END OF MAP *****************************************************
END

LAYOUT is:

* MAP2: PROTOTYPE              --- CREATED BY WNT 6.1.1 ---
* INPUT USING MAP 'XXXXXXXX'
FORMAT PS=005 LS=021 ZP=OFF SG=OFF KD=OFF IP=OFF
* MAP2: MAP PROFILES *****************************        200***********
* .TTAAAMMOO   D I D I N D I D I        ?_)^&:+(                       *
* 005020        N0NNUCN             X        01 SYSDBA  NR             *
************************************************************************
INPUT          (     IP=OFF                                           /*
                                                                       )
/
/
/
 011T *USER  (AD=NLOFHT ) /*.01S008 A008 .
/
* MAP2: VALIDATION *****************************************************
RULEVAR F00*PF-KEY
INCDIC                                 ;
write 'SET KEY PF24'
SET KEY PF24
* MAP2: END OF MAP *****************************************************
END

During lunch, I thought about the layout-trick again. Now it’s clear to me, why a PF-KEY-Setting in a Layout-MAP doesn’t work.

Once upon a time in a SAG-training, I’ve learned that an INPUT USING MAP is a kind of CALLNAT with automatic parameter. And in a CALLNAT it’s also impossible to do a PF-KEY-Setting for the calling program.

SET KEY ALL
SET KEY PF24=OFF
callnat 'TST-PF24' 
* code of TST-PF24:
*    SET KEY PF24
*    END
*
input 'Press a PF-KEY!'
write *PF-KEY
end

But maybe in future I can use this Layout-thing for other purposes.
So thanks anyway!

[quote="Wilfried B

The quickest is to provide a button. The PFKEY is set in the botton.

And the layout map will do the trick:

  1. The first processing rule in the layout map issues: SET CONTROL ‘Q’ (or ‘QS’ or ‘N’)
  2. In the other map you have a local variable #PF24-IS-ON(L) which is initially FALSE
  3. Then there is the first processing rule in the map which contains:
IF NOT #PF24-IS-SET
  SET KEY PF24
  #PF24-IS-SET := TRUE
  REINPUT *0
END-IF
  1. In one of the following processing rules you can catch the keypress.

How does it work?

When you INPUT the map Natural first issues an INPUT for the layout map, but with a preceding SET CONTROL ‘Q’ (or ‘QS’)) which does a “keypress” for you (without showing the map). Then the processing rules of the layout map are executed which also issue a SET CONTROL ‘Q’. Then the desired map is executed. As there is a pending SET CONTROL ‘Q’, a keypress is simulated and the processing rules of the map are executed. To show the map, the REINPUT is required.

Caveats:

  1. You have to add addition code to show the correct message (if a message should be shown),
  2. You have to add additional code to position the cursor if you want to
  3. You may have problems with REINPUT in the calling program!

…and to set the button a PF-KEY has to be set… :?

[quote="Wilfried B

And how comes the button onto the map? (We are talking about maps, not dialogs)

[quote="Wilfried B

You wanted a trick and you have got a trick :wink:

SAG introduced the trick with SET CONTROL ‘Q’ to enable dynamic map layouts. I only behaved like a Japanese: copied and improved the trick.

BTW. A trick becomes a technique if it is used more than once! :lol:

You can add a comment with a link http://natural.forums.softwareag.com/viewtopic.php?t=371#1622 to this thread into your coding to remind you (and any other maintainer) of this “dirty trick”. :slight_smile:

[quote="Wilfried B