Natural Statements - MASK or IS

Hi,

I am trying to find a variable length by using MASK parameter, but its not working.

eg:
Local
01 #INPUT (a8)
end-define

IF #INPUT EQ MASK(AAAAAAAA)
write stmts
else
write stmts
END-IF

The #INPUT value may have 5 or 8 byte of alpha numeric data. If its 5 byte of data, then it should fall on else part. But its not happening. Kindly advice

#INPUT (a 8)

#INPUT (a 8 )

To get the length of the contents of a variable use EXAMINE.

DEFINE DATA LOCAL
1 #A (A8)   INIT <'12345'>
1 #L (I4)
END-DEFINE
EXAMINE #A FOR PATTERN '.' GIVING LENGTH #L
DISPLAY #A #L
END
Page     1                                                   02/04/19  09:25:11
 
   #A        #L
-------- -----------
 
12345              5

Thanks… Is it not possible do via MASK stmt

If valid values were restricted to alphabetic characters or numeric digits, then MASK could be used, as long as there were no leading or embedded spaces.

DEFINE DATA LOCAL
1 #A (A8) INIT <'AbCdEf'>
1 #L (I4)
END-DEFINE
IF  #A = MASK (AAAAAAAA)
  THEN
    WRITE 'length is 8'
  ELSE
    IF  #A = MASK (AAAAA'   ')
      THEN
        WRITE 'length is 5'
      ELSE
        WRITE 'length is bad'
    END-IF
END-IF
END
DEFINE DATA LOCAL
1 #A (A8) INIT <'1234567'>
1 #L (I4)
END-DEFINE
IF  #A = MASK (nnnnnnnn)
  THEN
    WRITE 'length is 8'
  ELSE
    IF  #A = MASK (nnnnn'   ')
      THEN
        WRITE 'length is 5'
      ELSE
        WRITE 'length is bad'
    END-IF
END-IF
END

But you can’t mix alpha and numeric because the mask for alphanumeric, C, includes ‘space’ as a valid character.

If there is a value of five characters are the last three characters always blanks?

If so, the most efficient solution would be:

1 #INPUT (a8)
1 redefine #input
2 filler 5x
2 #lastthree (a3)

:::
IF #lastthree = ’ ’ /* three blanks in the apostrophes
** guaranteed a five character value
else
guaranteed an eight character value
end-if

Thanks Ralph & Steve

Hi Steve,

Nope, the value on the field sometimes carries 3 or 5 or 8 byte of data and cant guarantee last characters with blank.

May be I can move the value to left justified and try it out

Hi Prakash,

Originally you posed your problem with just 5 or 8 characters. You just changed that to 3, 5, or 8.

So which is it , 5-8 or 3-5-8 ?

If the last three characters are not blank for a 5 character value, how can you differentiate 5 from 8 characters? Can the first three characters be blank and the next 5 characters the value?

If it is really a 3-5-8 problem and not a 5-8 problem, what are the possibilities?

Would a three character value always have 5 leading blanks or 5 trailing blanks? Or, could it be, for example, bbXXXbbb, where X is a character and b a blank.

Please clarify the problem.