Reputation: 1
I have requirement to search a table using certain Key fields. Now for set of records that match the key fields. I am able to retrieve data from data For the key fields that do not match How to retrieve data from table?
I used search logic in mainframe but am not able to get table records that does not match the key
Upvotes: 0
Views: 396
Reputation: 4407
You wrote: I used search logic in mainframe but am not able to get table records that does not match the key
While SEARCH
may be used, it is not necessary and may be complicated. That is because the matching condition must be negative as I show below in the code for selecting all records not matching "E".
It is much easier to use one of the conditional statements: IF
or EVALUATE
, which may be used for even complicated situations involving multiple key values or multiple fields.
For this example, I created a table with with values "A" through "I". I then used SEARCH
to allow the display of all records not matching a single key value. I also used EVALUATE
to allow the display of all records not matching three key values.
Code:
data division.
working-storage section.
01 s-key pic x value "E".
01 m-key-table value "CFI".
03 m-key pic x occurs 3.
01 s-table value "ABCDEFGHI".
03 s-entry pic x occurs 9 indexed idx.
procedure division.
display "Records not matching single key "
quote "E" quote
perform varying idx from 1 by 1
until idx > 9
search s-entry
at end
continue
when s-entry (idx) not = s-key
display s-entry (idx) *> or move
end-search
end-perform
display space
display "Records not matching multiple keys "
quote "C, F or I" quote
perform varying idx from 1 by 1
until idx > 9
evaluate s-entry (idx)
when m-key (1) *> ignore matching keys
when m-key (2)
when m-key (3)
continue
when other
display s-entry (idx) *> or move
end-evaluate
end-perform
goback
.
Output:
Records not matching single key "E"
A
B
C
D
F
G
H
I
Records not matching multiple keys "C, F or I"
A
B
D
E
G
H
Upvotes: 1