Extended Class Validation - Padding Key Value

Started by bbssupport, July 25, 2024, 10:10:13 PM

Previous topic - Next topic

bbssupport

I'm looking at using the extended class validation feature define some data classes for use in a grid.

Lets say i create a class for 'Customer Code' which links to the customer file in the extended validation feature to verify the customer code is valid. I'm facing an issue with being able to specify that the value entered should be padded with spaces up to the maximum field length before checking the customer file (eg user enters 'CASH' but the key on the customer file is 'CASH  ' because all customer codes are padded to 6 characters.

Is there a way that I can't see to achieve this?

Susan Cryderman

Thanks for the explanation.  Unfortunately, I don't think that there is currently any way to achieve this. 

However, can you tell me if you are using the Data Dictionary and if so - what is the Format for the element that is used for the key? 

Patrick Denny

In the Dictionary, if you define the field with a Length of 6 characters and the Type as "LAST SUBSTRING", it will be automatically padded when written.

I use "LAST SUBSTRING" when CUST_NUMBER$ is the KEY FIELD or when it is a field within the record.

If you're NOT using the embedded IOLIST when opening the file, it bypasses the padding.

Assuming:
KEY =   6 character Invoice Number  (Field Type = LAST SUBSTRING)
Field = 6 character Customer Number (Field Type = LAST SUBSTRING)

OPEN (1,IOL=*,REC=INVOICE$)"INVOICE"
!---
READ DATA FROM "",REC=INVOICE$ TO IOL=IOL(1)   !--- Initialize fields to blank
!---
LET INVOICE.INVOICE_NUMBER$ = "123456"
LET INVOICE.CUST_NUMBER$ = "CASH"   !--- Note: Only 4 characters here
!---
WRITE (1,KEY="123456")    <=== If Using External Key
    or
WRITE (1)    <=== If Using Internal Key

READ (1,KEY="123456")
PRINT INVOICE.CUST_NUMBER$
  Should print "CASH  "    !--- Note: Written padded, 6 characters


Patrick Denny

I feel like this is not what you are looking for, but... (since I already typed it up).
And there are probably other and better ways, and may need to add "error trapping".
Also, seems to me there is a "Dictionary Object" available?  You might be able to extract something from that.

Playing around a bit, you might determine the pad length using:

Assuming the "Customer Number" is defined in the dictionary with a Length of 6 characters and the Type as "LAST SUBSTRING".

OPEN(1,IOL=*)"INVOICE"   !--- Use OPEN INPUT (1,IOL=*)"INVOICE" if file will not be written to.
LET INVIOL$= LST(IOL(1))

LET P=POS("CUST_NUMBER$:[LEN(SEP,SIZ=" = INVIOL$)
!--- Note that "CUST_NUMBER$:[LEN(SEP,SIZ=" is 26 characters long. So P+26 is used in "READ DATA".

READ DATA FROM INVIOL$(P+26),SEP=")" TO L

PRINT L
 Should print 6.