Conditional database reading

Hi, I’m really new to natural and I’m having trouble doing a database read the depends on 3 fields.

I have 3 parameters that the user puts in, only one of them is required, the others may be blank (may come blank from the map and may be blank in the db).

it’s kind like this:
read view with param1 = #field1
now, if #field2 is not empty, then there should be an where param2 = #field2 and same for #field3.

I’ve tried something like
if #field1 and #field2
if #field1

etc… but as I suspected, it didn’t work…

Other thing I’m having trouble is to check if a field (from map or from db) is empty… I’m using a control variable for maps, but I’m guessing there’s a better way.

Thanks in advance,

Hi Gabriel;

Let’s start with the easy stuff:

IF #FIELD = ’ ’ will suffice to test if an alpha field is blank.

Next; are all three parameters descriptors?

If the user puts in one parameter, but not the other two, do you retrieve all records for which the first parameter is matched, or only the ones where the other two fields are blank?


Hi, sorry for the delay.

The if #field = ’ ’ worked, thanks.
It’s just that I’m used to other programming languages :roll:

About the query, if the other two fields are left blank, then all the matches to the first one will be retrieved. Same thing if two fields are filled, then all registers matching them will be retrieved, regardless of the #field3 value in the db.
And, for the record,
#field1 is a date
#field2 and #field3 are alphanumerics.

Okay, I understand the requirements. There is more info needed however:

which field(s) are descriptors.

which is the required field?

on average (if that is meaningful), how many records will satisfy the required value?

if a second or third value is not null, how many records would satisfy the resultant two or three values?


It’s a descriptor date field (required on the map) and 2 alph field, not descriptors (not required)
The query must retrieve all registers with a date minor or equal to the one the user puts in, regardless of the other two values, empty or not (on the db).

If one of the other fields are filled, than it should retrieve all the registers until the set date that also matches the field, or fields, the user typed in.

Hi Gabe;

Okay, you probably want something like the following (i am making an assumption discussed below)

                          INPUT to get values for #field1, #field2, #field3
                          if #field1 not a valid date, reinput 'error'
                          if #field2 = ' ' and #field3 = ' '
                             move 1 to #flag
                             if #field2 ne ' ' and #field3 ne ' '
                             move 2 to #flag
                             if #field2 ne ' ' and #field3 eq ' '
                             move 3 to #flag
                             else move 4 to #flag
                            * #flag now tells us which condition we have
                            read file by field1 starting from #field1 to #field1
                            decide on first value of #flag
                            value 1 perform process-record    /* any record okay
                            value 2
                            if field1 = #field1 and field2 = #field2
                               perform process record
                               escape bottom immediate (?)
                             etc for value 3 and 4

Are you sure you want to process ALL records with date less than or equal to what the user enters? this could be most of a file (how big is the file?)

not sure about the escape bottom immediate. where i put it, after you find a match for the extra parameters, you will process one record, then “end”.