ACCEPT/REJECTs within IF blocks

Hello !
I have a doubt… I need to perform a search in a READ according to 2 entry values… these 2 values correspond to fields in adabas file, but are not descriptors… my question is: inside the READ, I can ACCEPT oi REJECT values depending on IF conditions (evaluating these 2 values? For example:*

READ FILE BY SUPER
IF VALUE-1 = 2
ACCEPT VALUE-1
END-IF
*
IF VALUE-2 = 0 AND VALUE-1 = 1
REJECT VALUE-2
END-IF

Does ACCEPT and REJECT will work fine within IF conditions?
Thanks in advance.

ACCEPT and REJECT could be considered types of IF statements. The syntax is
ACCEPT IF condition
REJECT IF condition
An alternative is to code your conditions in a WHERE clause of the READ.

READ file BY super
  WHERE value-1 = 2
    OR NOT (value-1 = 1 AND value-2 = 0)
1 Like

Better to do it this way:

READ FILE BY SUPER
ACCEPT IF VALUE-1 = 2
REJECT IF VALUE-2 = 0 AND VALUE-1 = 1

However Note that if Condition 1 is met Condition 2 is checked and if condition is not met Record is accepted.

I prefer to do it this way:

READ FILE BY SUPER
REJECT IF VALUE-1 NE 2 OR (VALUE-2 = 0 AND VALUE-1 = 1)

Note: the OR could be an AND depending on your desires.

Finally note that you can also use a WHERE clause, or IF… ESCAPE BOTTOM.

Eugene (Gene) Miklovich

ADABAS/NATURAL Systems Support and DBA

Cell: 916-202-7047

Normal Hours: 8am-4pm E.T.

Please call or text if assistance needed outside these hours.

Out of Office Thursday Mar 9th-Sat Mar 11th.

1 Like

I prefer to code conditions all in one statement as Ralph has demo’d. This can be a WHERE, IF … ESCAPE, or a single ACCEPT/REJECT statement.

The problem is that if you code multiple ACCEPT, REJECT statements as a series the logic gets complicated. The rule is that NATURAL checks each condition in sequence until one has been met and then ignores the rest. If it gets to last one and it isn’t met then it does the opposite of the last condition.

This can lead to accidental maintenance issues if someone were to insert a statement in the middle of the series. So I recommend always code a single statement even if it means coding a complex condition.

Eugene (Gene) Miklovich

ADABAS/NATURAL Systems Support and DBA

Cell: 916-202-7047

Normal Hours: 8am-4pm E.T.

Please call or text if assistance needed outside these hours.

Out of Office Thursday Mar 9th-Sat Mar 11th.

1 Like

When I teach Natural Programming, I mention that the ACCEPT/REJECT statements are retained in Natural for compatibility with early versions of Natural, but suggest that they be avoided due to the confusion Gene and Ralph refer to.

You can use an “IF THEN ESCAPE TOP” to mimic the REJECT logic and simply use a regular IF THEN…END-IF that performs the remaining logic in your program for the “ACCEPT” test (or a WHERE clause).

And consider using the DECIDE statements to help simplify complex conditionals and nested IF statements!

3 Likes

From an operational view you should be aware that there is a slight difference between using the WHERE clause and the IF… ESCAPE or ACCEPT/REJECT approach. The minor difference is the value of *COUNTER. Since WHERE clause rejects records before entering the loop the value will be the number of records that pass the condition(s). Whereas the other two approaches the value of *COUNTER is the total number of records considered (i.e. including rejected ones)…. :blush:

Eugene (Gene) Miklovich

ADABAS/NATURAL Systems Support and DBA

Cell: 916-202-7047

Normal Hours: 8am-4pm E.T.

Please call or text if assistance needed outside these hours.

Out of Office Thursday Mar 9th-Sat Mar 11th.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.