MainframeSupports
tip week 46/2002:

When you are using ISPF-panels there are a lot of different possibilities on how to validate the contens of the input fields. On the other hand it is quite difficult to determine if a variabel contains a certain character. But it is possible.

There is a function called TRUNC that is available in assignment statements only. Parameters to TRUNC are at first a variable and secondly a numeric value or a character in quotes. For instance &JOHN = TRUNC(&PETER,2) will make &JOHN equal to the first two characters of &PETER, while &LISA = TRUNC(&DAISY, '*') will make &LISA equal to all characters in &DAISY up until the first * in &DAISY. The * will not be copied to &LISA. There are certain limitations in the use of TRUNC. You can read about them in the ISPF manuals.

I guess most of you ISPF experts are pretty bored by now. Let us try to investigate if the characters % and/or _ are part of the contens of a variable. That is not possible using any normal ISPF panel functions, but you can use TRUNC for this. In the following example we are going to determine whether &FINDSTR contains % or _:

&NOPCTSTR = TRUNC(&FINDSTR, '%')
&NOUSCSTR = TRUNC(&FINDSTR, '_')
IF(&NOPCTSTR = &FINDSTR & &NOUSCSTR = &FINDSTR)
  /* Neither _ nor % in &FINDSTR */
ELSE
  /* Either _ or % or both in &FINDSTR */

It is unfortunately not possible to write IF(TRUNC(&FINDSTR, '*') = &FINDSTR ...) because TRUNC as mentioned earlier only can be used in assignments. Therefore we have to use a work field. After a call to TRUNC the special ISPF variable .TRAIL contains the remaining part of the truncated value. Back to the first example (about &JOHN) .TRAIL will contain the rest of &PETER starting with the third character. In the &DAISY example .TRAIL will contain all characters after the first * but not including it.

Previous tip in english        Sidste danske tip        Tip list