1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【COBOL】COBOLでSEARCH文 COBOLの配列検索

Last updated at Posted at 2022-06-13

研修時代、難しすぎてわからなかったけど今は一日で理解できた

入力

ccc

コード

IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN.
DATA DIVISION.
  WORKING-STORAGE SECTION.
     01 TEST-TXT PIC X(42).
     01 INP PIC X(3).
     01 BLKTBL.
       03 PIC X(6) VALUE "aaa".
       03 PIC X(6) VALUE "bbb".
       03 PIC X(6) VALUE "ccc".
       03 PIC X(6) VALUE "ddd".
       03 PIC X(6) VALUE "eee".
     01 BLKTBL-R REDEFINES BLKTBL.
       03 BLK-REC OCCURS 5 INDEXED BY IDX.
         05 VAL PIC X(03).
    PROCEDURE DIVISION.
        ACCEPT INP.
        SET IDX TO 1.
        SEARCH BLK-REC
          AT END
            DISPLAY "入力した値は存在しません"
        WHEN VAL(IDX) = INP
            STRING
               "入力した【" DELIMITED BY SIZE
                   VAL(IDX) DELIMITED BY SIZE
             "】はありました。" DELIMITED BY SIZE
              INTO TEST-TXT
            DISPLAY TEST-TXT
        END-SEARCH.
END PROGRAM MAIN.

結果

入力した【 ccc】はありました。

入力した値は存在しません

参考
http://source.ojaru.jp/COBOL/COBOL_SEARCH.html

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?