COBOL: SEARCH Vs PERFORM Which is Better

Search Table using PERFORM

PERFORM statement you can use when you defined an array with a subscript.

Method-1

PERFORM P200-READ-SALES-FILE.
MOVE '*** NO PART DESCRIPTION' TO RPT-DTL-PART-DESC.
PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL (WS-SUB > WS-TBL-MAX)
OR (IN-PRT-NBR = PART-NBR (WS-SUB))
IF IN-PRT-NBR = PART-NBR (WS-SUB)
MOVE PART-DESC TO RPT-DTL-PART-DESC
END-IF
END-PERFORM.

Search Table using SEARCH statement

Method-2

You can use SEARCH logic when your Table defined with an index.

PERFORM P200-READ-SALES-FILE.
SET WS-INDX TO 1.
SEARCH PART-TABLE
AT END MOVE '*** NO PART DESCRIPTION' TO RPT-DTL-PART-DESC
WHEN IN-PRT-NBR = PART-NBR (WS-INDX)
MOVE PART-DESC TO RPT-DTL-PART-DESC END-SEARCH.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.