Record Data Validation and Manipulation

Record Data Validation in Lycia LowCode

Example: AFTER INPUT in settings_actions_update_input_after.4gl

Record Data Validation in Lycia LowCode

In usual 4GL programming (classic and modern) we can validate / manipulate INPUT data in BEFORE / AFTER FIELD / INPUT statement blocks.

INPUT x,y WITHOUT DEFAULTS FROM field_x, field_y

AFTER INPUT

IF x < 0 THEN

LET x = 0

END IF

 

IF y IS NULL THEN

ERROR “Field y can not be empty”

NEXT FIELD field_Y

END IF

 

END INPUT

Code snippet 1: Data validation in INPUT block

In Lycia LowCode, data validation is there “out of the box“ so you didn’t have to add INPUT blocks manually. To access (read and write) these data, you should use accessor methods.

To set (LET) or get any data from your input variables which you need to initialize, validate, correct and update, use the following functions:

1. SetFieldValue() - sets a value of any field (input member variable write access);

2. GetFieldValue() - gets the value of any field (input member variable read access).

 

Return to top

Example: AFTER INPUT in settings_actions_update_input_after.4gl

Objective: Validate the field test05_int (ensure it’s not NULL and the value is in the range of -1000 to +1000). If the value is outside of the range, inform the operator in form of a message box and move the input back to the same field.

Step 1. Assign an event handler function to the event AFTER INPUT:

LET l_rec_settings.actions["UPDATE"]["AFTER INPUT" ] = FUNCTION actions_UPDATE_after_input

Code snippet 2: Assigning an event handler function

Just like in any other event handler function, it has no direct access to the INPUT program variables. In our case, the event handler function to process the AFTER INPUT event is actions_UPDATE_after_input().

Step 2. To change / access the data, we have to use the dialog functions SetFieldValue() or GetFieldValue():

LET l_rec_test05.test05_int = iform.GetFieldValue("test05.test05_int")

Code snippet 3: Accessing the INPUT program variables

Step 3. In case we change any data, we have to write the modified data back to the field:

CALL iform.SetFieldValue("test05.test05_int",l_rec_test05.test05_int)

Code snippet 4: Writing the modified data back to the field

Example:

########################################################################

FUNCTION settings_list()

DEFINE l_rec_settings InteractForm_Settings

 

LET l_rec_settings.form_file="../llc_settings/llc_settings_list"

LET l_rec_settings.actions["UPDATE"]["AFTER INPUT" ] = FUNCTION actions_UPDATE_after_input

 

CALL InteractForm(l_rec_settings)

END FUNCTION

########################################################################

# END FUNCTION db_cms_test05_list()

########################################################################

 

 

 

########################################################################

# FUNCTION actions_UPDATE_after_field_test05_int()RETURNS BOOL

#

#

########################################################################

FUNCTION actions_UPDATE_after_input(iform InteractForm INOUT) RETURNS BOOL

DEFINE dlg ui.Dialog

DEFINE l_rec_test05 RECORD LIKE test05.*

DEFINE l_msg STRING

 

CALL fgl_winmessage("actions_UPDATE_after_input","actions_UPDATE_after_input","info")

 

LET dlg = ui.Dialog.GetCurrent()

 

LET l_rec_test05.test05_primary_key = iform.GetFieldValue("test05.test05_primary_key")

LET l_rec_test05.test05_fk_char = iform.GetFieldValue("test05.test05_fk_char")

LET l_rec_test05.test05_varchar = iform.GetFieldValue("test05.test05_varchar")

LET l_rec_test05.test05_int = iform.GetFieldValue("test05.test05_int")

LET l_rec_test05.test05_date = iform.GetFieldValue("test05.test05_date")

 

#test05_primary_key

IF l_rec_test05.test05_primary_key IS NULL THEN

CALL fgl_winmessage("Field test05_primary_key can not be NULL","Field test05_primary_key can not be NULL","error")

CALL dlg.NextField("test05_primary_key")

CALL ui.Dialog.GetCurrent().Continue()

RETURN TRUE

END IF

 

#test05_fk_char

IF l_rec_test05.test05_fk_char IS NULL THEN

CALL fgl_winmessage("Field test05_fk_char can not be NULL","Field test05_fk_char can not be NULL","error")

CALL dlg.NextField("test05_fk_char")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

#test05_varchar

IF l_rec_test05.test05_varchar IS NULL THEN

CALL fgl_winmessage("Field test05_varchar can not be NULL","Field test05_varchar can not be NULL","error")

CALL dlg.NextField("test05_varchar")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

IF length(l_rec_test05.test05_varchar) < 10 AND length(l_rec_test05.test05_varchar) > 20 THEN

#IF l_rec_test05.test05_varchar.GetLength() < 10 AND l_rec_test05.test05_varchar.GetLength() > 20 THEN

CALL fgl_winmessage("Field test05_varchar lenght is out of range (10-20 Char)","Field test05_varchar lenght is out of range (10-20 Char)","error")

CALL dlg.NextField("test05_varchar")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

#test05_int

IF l_rec_test05.test05_int IS NULL THEN

CALL fgl_winmessage("Field test05_int can not be NULL","Field test05_int can not be NULL","error")

CALL dlg.NextField("test05_int")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

 

IF l_rec_test05.test05_int > 1000 AND l_rec_test05.test05_int < -1000 THEN

CALL fgl_winmessage("Field test05_date is out of range","Field test05_date is out of range","error")

CALL dlg.NextField("test05_int")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

#test05_date

IF l_rec_test05.test05_date IS NULL THEN

CALL fgl_winmessage("Field test05_date can not be NULL","Field test05_date can not be NULL","error")

CALL dlg.NextField("test05_date")

CALL ui.Dialog.GetCurrent().Continue()

 

RETURN TRUE

END IF

 

IF l_rec_test05.test05_date > TODAY() AND l_rec_test05.test05_date < "01/01/1900" THEN

CALL fgl_winmessage("Field test05_date is out of range","Field test05_date is out of range","error")

CALL dlg.NextField("test05_date")

 

CALL ui.Dialog.GetCurrent().Continue()

RETURN TRUE

END IF

 

RETURN FALSE # Means that built-in function should not be prevented

END FUNCTION

########################################################################

# END FUNCTION actions_UPDATE_after_field_test05_int()RETURNS BOOL

########################################################################

Code snippet 5: Data validation in settings_actions_update_input_after.4gl program

 

Return to top

 

See next: ComboBox List Population

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.