【问题标题】:COBOL search logicCOBOL search logic
【发布时间】:2022-12-02 10:32:35
【问题描述】:

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 yhat do not match How to retireve data from table?

I used search logic in mainframe but am not able to get table records that does not match the key

【问题讨论】:

  • Hi @rahshree-m and welcome to stackoverflow, please take the tour to see how this site works and how you can improve your question to get useful answers. One of the things: what have you tried (code), where is the problem...
  • How many entries are in the table? How many key values? Please edit your post to include that information along with the code you tried.

标签: search cobol mainframe


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多