Monday, September 26, 2011

Easytrieve: SEARCH logic

For each record in the IN1 file, the below program carries out binary search in IN2 file. So, the IN2 file should not have any duplicates for the key field. The key field in the IN2 file should be defined as "ARG" and the second field should be defined as "DESC". The table file (IN2 file) can have other data along with ARG and DESC fields, but only ARG and DESC should be defined in the file section.  The "IF IN2" condition verifies if the search is successful.

//STEP0100 EXEC PGM=EZTPA00
//STEPLIB DD DSN=EASYTREV.LOADLIB,
// DISP=SHR
//EZTVFM DD UNIT=SYSDA,SPACE=(CYL,(50,50),RLSE)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSSNAP DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//IN1 DD *
1 AAA BBBBB CCCCC DDDDDD 100
2 AAA BBBBB CCCCC DDDDDD 11
3 AAA BBBBB CCCCC DDDDDD 10
4 AAA BBBBB CCCCC DDDDDD 111
5 AAA BBBBB CCCCC DDDDDD 100
6 AAA BBBBB CCCCC DDDDDD 111
//IN2 DD *
1 10  AUSTRALIA
2 11  AUSTRIA
3 33  CANADA
4 100 GERMANY
5 111 FINLAND
//OUTFILE DD DSN=YOUR OUTPUT FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(X,Y),RLSE),
// DCB=(LRECL=250,RECFM=FB,BLKSIZE=0)
//SYSIN DD *

FILE IN1
IN1-REC  001 229 A
IN1-CODE 230 003 A

FILE IN2 TABLE
ARG  003 003 A
DESC 007 020 A

FILE OUTFILE FB(0 0)
OUT-REC  001 229 A
OUT-CODE 230 020 A

W-SEARCH-CODE  W 03 A
W-COUNTRY-NAME W 20 A

**********************************************************************
* PROCESSES AREA
**********************************************************************

JOB INPUT IN1

W-SEARCH-CODE  = IN1-CODE
W-COUNTRY-NAME = ' '
SEARCH IN2 WITH W-SEARCH-CODE, GIVING W-COUNTRY-NAME

IF IN2
   OUT-REC  = IN1-REC
   OUT-CODE = W-COUNTRY-NAME
   PUT OUTFILE

END-IF

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.