"Error occurred when compiling validation expression"

KMoody

Member
I created a program that can receive parameter values and use dynamic queries and buffers to create a browse widget in a popup window:

Code:
/* ***************************  Definitions  ************************** */

ROUTINE-LEVEL ON ERROR UNDO, THROW.

/* ********************  Preprocessor Definitions  ******************** */
DEFINE INPUT PARAMETER titleText AS CHAR.
DEFINE INPUT PARAMETER instructions AS CHAR format "X(150)".
DEFINE INPUT PARAMETER tableName AS CHAR.
DEFINE INPUT PARAMETER queryString AS CHAR.
DEFINE INPUT PARAMETER browseColumns AS CHAR.
DEFINE INPUT PARAMETER tempTableAlias AS CHAR.
DEFINE INPUT PARAMETER canSelectMultiple AS LOGICAL.
DEFINE OUTPUT PARAMETER  bhTempTable  AS HANDLE  NO-UNDO.

DEF  VAR  i  as integer.

DEFINE VARIABLE hBrowsePopup  AS HANDLE  NO-UNDO.
DEFINE VARIABLE hPopupQuery  AS HANDLE  NO-UNDO.
DEFINE VARIABLE hPopupBuffer  AS HANDLE  NO-UNDO.   
DEFINE VARIABLE hBrowseColumn AS HANDLE  NO-UNDO.
DEFINE VARIABLE bufferField  AS HANDLE  NO-UNDO.

DEFINE VARIABLE hTempTable  AS HANDLE  NO-UNDO.
DEFINE VARIABLE qhTempTable  AS HANDLE  NO-UNDO.
   
DEFINE VARIABLE ohQuery  AS HANDLE  NO-UNDO.   
   
   
CREATE BUFFER hPopupBuffer FOR TABLE tableName.
CREATE QUERY hPopupQuery.
hPopupQuery:SET-BUFFERS(hPopupBuffer).

hPopupQuery:QUERY-PREPARE(queryString).
hPopupQuery:QUERY-OPEN.   
   
CREATE TEMP-TABLE hTempTable.   
hTempTable:ADD-FIELDS-FROM(hPopupBuffer,browseColumns).

hTempTable:TEMP-TABLE-PREPARE(tempTableAlias).
bhTempTable = hTempTable:DEFAULT-BUFFER-HANDLE.

   
DEFINE FRAME popupFrame

  WITH SIZE 55 BY 45 CENTERED TITLE titleText VIEW-AS DIALOG-BOX NO-LABELS.

   
CREATE BROWSE hBrowsePopup
  ASSIGN
  FRAME = FRAME popupFrame:HANDLE
  QUERY = hPopupQuery
  TITLE = "Select"
  COLUMN = 1
  ROW = 1
  WIDTH-CHARS = 50
  HEIGHT-CHARS = 25
  DOWN = 25
  SENSITIVE = TRUE
  READ-ONLY = TRUE
  COLUMN-SCROLLING = TRUE
  SEPARATORS = YES
  MULTIPLE = canSelectMultiple   
  VISIBLE = FALSE
  REFRESHABLE  = TRUE
   
  TRIGGERS:

  END TRIGGERS.   

DEF VAR aTemp AS CHAR EXTENT.
aTemp = string_util:split(browseColumns, ",").   
DO i = 1 to extent(aTemp):
  hBrowseColumn = hBrowsePopup:ADD-LIKE-COLUMN(aTemp[i]).
end.
   

ENABLE ALL WITH FRAME popupFrame.

   
WAIT-FOR CLOSE OF THIS-PROCEDURE.

CATCH e AS Progress.Lang.Error:
  DO i = 1 TO e:NumMessages:
  MESSAGE e:GetMessage(i) VIEW-AS ALERT-BOX BUTTONS OK.
  END.
END CATCH.

I ran the program like this:

Code:
DEFINE var  resultsTable  AS HANDLE.
run show_popup.p(
"Item Selection",
"Select the item.",
"item",
"FOR EACH item NO-LOCK",
"item.part-num,item.description,item.prod-code",
"TTX",
no,
OUTPUT resultsTable).

Then I received the following errors:

Code:
Error occurred when compiling validation expression for dynamic FILL-IN PROD-CODE: can-find(PRODMSTR of ITEM) . . (9154)

Code:
Unable to read record buffer because it is empty.

(Note: When I removed "item.prod-code" from my browseColumns parameter, I did not get this error.)

I was unable to find much documentation on Error 9154. What does it mean by "validation expression," and where did "can-find(PRODMSTR of ITEM)" come from?

Do widgets automatically try to validate their queries? If so, is there a way to make validation less strict?
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
Have a look in your schema, in the field editor in the data dictionary. Here is a validation expression in the field orderline.ordernum in the sports2000 database:

Code:
----------------------------------------------------------------------------
  Field-Name: Ordernum  Data-Type: integer
  Format: zzzzzzzzz9  Extent:
  Label: Order Num  Decimals: ?
Column-label: ?  Order: 10
  Initial: 0  Mandatory: no  (Not Null)
Component of-> View: no  Index: yes  Position: 2  Case-sensitive: no
Valexp: CAN-FIND(order OF orderline)

Valmsg: Order must exist
  Help: Please enter and Order Number for this order line.
  Desc:
 

KMoody

Member
Aha! I found that expression for item.prod-code:

can-find(PRODMSTR of ITEM)

Whoever set up the item table must have done that. Makes sense.

Is there some work around to this error? I think I'm getting it when I run ADD-LIKE-COLUMN.
 

Osborne

Active Member
I encountered this exact problem a while back and it was when ADD-LIKE-COLUMN was run. If you set the browse NO-VALIDATE = TRUE there should now be no errors.
 

KMoody

Member
Setting the browse's NO-VALIDATE value to TRUE fixed the problem. In my case, this is a safe maneuver because the user only selects from the browse list; my program does not allow the user to update entries within the browse widget.

(By default, the validation expression of a dynamic browse widget cannot contain CAN-FIND. That's why I was getting the error.)

Thanks, everyone!
 

GregTomkins

Active Member
If I may, I believe the correct quote is: " It makes a good demo. At least, it did in 1985." That's been stuck on my cube wall since you (TomB) posted it a few years back.

The biggest obvious flaw of validation expressions is that they are not applied to programmatic ASSIGN statements, only to user input (well not quite that simple but basically). Which makes them pretty useless IMO.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
It is also not ideal because it "hides" business logic in the database schema, whereas it should live in the application, either in the code or externally in a BRMS.

I think your experience sums it up: "Where the heck did this code snippet come from?"
 

TomBascom

Curmudgeon
Yes Greg, that would be the proper quote :)

The whole "define them in the dictionary" thing is bogus too.

These days this sort of stuff should almost all be the province of a rules engine. Like Coritcon.
 
Top