View previous topic :: View next topic |
Author |
Message |
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Mon Aug 13, 2007 1:42 pm Post subject: PARSE / LOCATE a string |
|
|
I have this below requirement:
INPUT FILE
Code: |
-------ERROR: * Reason: XXXX * Message: Message1 AAAA.................
------------ERROR: * Reason: XXXX * Message: Message2 BBBB..........
------------------ERROR: * Reason: XXXX * Message: Message1 AAAA...
------ERROR: * Reason: XXXX * Message: Message2 BBBB..................
--ERROR: * Reason: XXXX * Message: Message3 CCCC......................
|
OUTPUT FIle:
Code: |
Message1 : AAAA 4
Message2 : BBBB 2
Message3: CCCC 1
|
Can we do this using Easytrieve?
(DFSORT PARSE is a better option to get the report. But i cant use DFSORT. One more option is coding a COBOL-DB2 program using combination of LOCATE and SUBSTRING fuction. But looking for help if we can impletement this using easytrieve)
Thanks!
Dip |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon Aug 13, 2007 1:55 pm Post subject: |
|
|
Easytrieve wouldn't be my first choice. REXX string handling is much more robust. COBOL's UNSTRING would be a decent choice too. Are there requirements that demand Easytrieve and not DFSORT? |
|
Back to top |
|
|
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Mon Aug 13, 2007 2:09 pm Post subject: |
|
|
We dont have DFSORT on the Mainframes..and i dont know REXX coding.. But if REXX is a better option i can learn and implement it...Can you give me some pointers or link to sample REXX code for STRING search?
Thanks!
Dip. |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon Aug 13, 2007 2:30 pm Post subject: |
|
|
There's a REXX User's Guide and also Reference manual at the 'Quick Manuals' link at the top of this page. You can also find them at:
http://www-03.ibm.com/servers/s390/os390/bkserv/r10pdf/tsoe.html
If you have time, I'd go through the examples and try to put together a REXX script. REXX is very powerful. However, file IO can be a little tricky.
It sounds like you know COBOL, if you need something right away, I'd go with the COBOL UNSTRING. That will give you what you need. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Aug 13, 2007 2:47 pm Post subject: |
|
|
Dip,
Try this. I assumed that your input is FB RECFM and 80 bytes LRECL. I also assumed that the message length is 13 bytes. Change the values according to your needs.
Code: |
//STEP0100 EXEC PGM=EZTPA00
//STEPLIB DD DSN=EASYTREV.PROD.LOADLIB,
// DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSSNAP DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//INFILE DD *
-------ERROR: * REASON: XXXX * MESSAGE: MESSAGE1 AAAA.................
------------ERROR: * REASON: XXXX * MESSAGE: MESSAGE2 BBBB..........
------------------ERROR: * REASON: XXXX * MESSAGE: MESSAGE1 AAAA...
------ERROR: * REASON: XXXX * MESSAGE: MESSAGE2 BBBB..................
--ERROR: * REASON: XXXX * MESSAGE: MESSAGE3 CCCC......................
//OUTRPT DD SYSOUT=*,RECFM=FB,LRECL=80
//SYSIN DD *
FILE INFILE
I-REC 01 001 A OCCURS 80 INDEX IDX
FILE OUTRPT PRINTER FB(0 0)
W-MESG-FOUND W 01 A
W-CHECK-STRING W 08 A
W-RPT-STRING W 13 A
*************************************************
* MAINLINE
*************************************************
JOB INPUT INFILE
IDX = 1
W-CHECK-STRING = ' '
W-MESG-FOUND = 'N'
W-RPT-STRING = ' '
DO UNTIL IDX GT 80 OR W-MESG-FOUND = 'Y'
IF I-REC (IDX) = 'M'
MOVE I-REC (IDX) 8 TO W-CHECK-STRING
IF W-CHECK-STRING = 'MESSAGE:'
W-MESG-FOUND = 'Y'
IDX = IDX + 9
MOVE I-REC (IDX) 13 TO W-RPT-STRING
PRINT RPT
END-IF
END-IF
IDX = IDX + 1
END-DO
REPORT RPT SUMMARY LINESIZE 79 PRINTER OUTRPT
SEQUENCE W-RPT-STRING
CONTROL W-RPT-STRING
TITLE 1 'TALLY OF ERROR MESSAGES BY MESSAGE CODE'
HEADING W-RPT-STRING ('MESSAGE')
LINE W-RPT-STRING TALLY
/* |
The output is
Code: |
TALLY OF ERROR MESSAGES BY MESSAGE CODE
MESSAGE TALLY
MESSAGE1 AAAA 2
MESSAGE2 BBBB 2
MESSAGE3 CCCC 1
5
|
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon Aug 13, 2007 3:09 pm Post subject: |
|
|
Here's a quick script to get you started with REXX. It reads records from an input file and writes them to an output file. I'll leave it to you to read about and experiment with the functions to get the output you want. Create a PDS and store the exec in the PDS.
Code: |
/* REXX - File IO example; REXX exec executed from batch job */
SAY "> TEMP2 exec starting at "TIME('C')
INFL_EOF='NO'
INFL_RECS_READ_CTR=0
OUTFL_RECS_WRITTEN_CTR=0
CALL READ_INFL_REC_RTN
/* Process input file */
DO WHILE INFL_EOF = 'NO'
DO
/* process records here *>
OUTFL_REC = INFL_REC
/* write a record *>
PUSH OUTFL_REC
"EXECIO 1 DISKW OUTFL "
OUTFL_RECS_WRITTEN_CTR = OUTFL_RECS_WRITTEN_CTR + 1
CALL READ_INFL_REC_RTN
END /* DO END */
END /* DO WHILE END */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SAY " "
SAY "> Input Records Read: " INFL_RECS_READ_CTR
SAY "> Output Records Written: " OUTFL_RECS_WRITTEN_CTR
SAY " "
SAY "> TEMP2 exec terminating at "TIME('C')
ADDRESS TSO "EXECIO 0 DISKR INFL (FINIS)"
ADDRESS TSO "FREE FILE(INFL)"
ADDRESS TSO "EXECIO 0 DISKR OUTFL (FINIS)"
ADDRESS TSO "FREE FILE(OUTFL)"
EXIT
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
READ_INFL_REC_RTN: PROCEDURE EXPOSE INFL_EOF,
INFL_REC,
INFL_RECS_READ_CTR
"EXECIO 1 DISKR INFL "
/* condition is true at end of file */
IF RC=2 THEN
DO
INFL_EOF='YES'
END
ELSE
DO
PARSE PULL INFL_REC
INFL_RECS_READ_CTR=INFL_RECS_READ_CTR+1
END
RETURN
|
Here's some JCL to get you started. You'll need to get the dataset names for the ISPF libraries to run the batch job. I've usually found them with high level qualifiers of SYS1 or TSO, but you'll have to hunt them down. You don't need all of them all the time, but I just leave them in the JCL once I find them. Check in 3;4 or some jobs in SDSF.
Code: |
//DELT10 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DELETE <tsoid>.TEMP.OUTFL
//*
//REXX20 EXEC PGM=IKJEFT01
//INFL DD *
Just a couple data records
Here's another one
and just one more
//OUTFL DD DSN=<tsoid>.TEMP.OUTFL,
// DISP=(,CATLG,DELETE),
// UNIT=DISK,SPACE=(TRK,1),
// RECFM=FB,LRECL=80,BLKSIZE=0
//* PANEL LIBRARIES
//ISPPLIB DD DSN=xxxx.ISPPLIB,DISP=SHR
//* MSG LIBRARIES
//ISPMLIB DD DSN=xxxx.ISPMLIB,DISP=SHR
//* SKELETON LIBRARIES
//ISPSLIB DD DSN=xxxx.ISPSLIB,DISP=SHRR
//* TABLE LIBRARIES
//ISPTLIB DD DSN=xxxx.ISPTLIB,DISP=SHR
//*** PDS WITH THE REXX EXEC
//SYSEXEC DD DSN=<tsoid>.TEST.REXX,DISP=SHR
//ISPPROF DD UNIT=DISK,SPACE=(6233,(100,1,10)),
// DCB=(LRECL=80,BLKSIZE=3120,RECFM=FB,DSORG=PO)
//SYSTSPRT DD SYSOUT=*
//*** EXECUTES the EXEC
//SYSTSIN DD *
%TEMP2
//SYSIN DD DUMMY
//* |
|
|
Back to top |
|
|
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Fri Aug 17, 2007 3:18 pm Post subject: |
|
|
Thanks so much Kolsu.. Using ur code as a base i have modified the code as per my requirement and its working!
Thanks jsharon1248... I didnt explore the rexx code.. but surely i will try it when i get some time..
Dip. |
|
Back to top |
|
|
|
|