IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

I need a 4 lines block where substring can be found anywhere


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
aarnold#mvs

New User


Joined: 04 Dec 2022
Posts: 8
Location: Hungary

PostPosted: Sun Dec 04, 2022 3:26 am
Reply with quote

Hello

input file: FB, LRECL=30
Code:
-----------------------------
DDD   BBB CCC                 
GGG TTT                     
DDD SSS                     
-----------------------------
DDD         AAA   CCC                 
GGG TTT                     
DDD            SSS
-----------------------------
DDD    BBB       AAAA                 
GGG     TTT                     
DDD SSS                     
-----------------------------
DDD   BBB     CCC                 
GGG   TTT                     
DDD   SSS                     
-----------------------------
DDD  BBB    CCC                 
GGG    TTT                     
AAAAA SSS                   


I need the full blocks (4 lines blocks) starting with line: "-----------------------------" where substring "AAA" can be found anywhere.
I have used this code
Code:
  OPTION COPY                                               
  INREC  IFTHEN=(WHEN=GROUP,RECORDS=4,BEGIN=(1,1,CH,EQ,C'-'),
                        PUSH=(31:ID=1))                     
  OUTFIL INCLUDE=(1,30,SS,EQ,C'AAA'),BUILD=(1,30)           


I got only only the lines with "AAA"
Code:
DDD         AAA   CCC         
DDD    BBB       AAAA         
AAAAA SSS                     


but in this example, I need these "blocks":
Code:
-----------------------------
DDD         AAA   CCC                 
GGG TTT                     
DDD            SSS
-----------------------------
DDD    BBB       AAAA                 
GGG     TTT                     
DDD SSS                     
-----------------------------
DDD  BBB    CCC                 
GGG    TTT                     
AAAAA SSS                   



Could you please help me?
Many thanks
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1308
Location: Bamberg, Germany

PostPosted: Sun Dec 04, 2022 1:13 pm
Reply with quote

Code:
//WHATEVER EXEC PGM=ICEMAN                                 
//F1       DD *                                           
-----------------------------                             
DDD   BBB CCC                                             
GGG TTT                                                   
DDD SSS                                                   
-----------------------------                             
DDD         AAA   CCC                                     
GGG TTT                                                   
DDD            SSS                                         
-----------------------------                             
DDD    BBB       AAAA                                     
GGG     TTT                                               
DDD SSS                                                   
-----------------------------                             
DDD   BBB     CCC                                         
GGG   TTT                                                 
DDD   SSS                                                 
-----------------------------                             
DDD  BBB    CCC                                           
GGG    TTT                                                 
AAAAA SSS                                                 
/*                                                         
//F2       DD .. same as F1                               
//SYSOUT   DD SYSOUT=*                                     
//SORTOUT  DD SYSOUT=*                                     
//SYSIN    DD *                                           
  OPTION COPY                                             
  JOINKEYS F1=F1,FIELDS=(31,4,A)                           
  JOINKEYS F2=F2,FIELDS=(31,4,A)                           
  REFORMAT FIELDS=(F1:1,30,F2:35,2)                       
  OUTFIL FNAMES=(SORTOUT),                                 
    INCLUDE=(31,2,CH,EQ,C'XX'),                           
    BUILD=(1,30)                                           
  END   
/*                                                   
//JNF1CNTL DD *                                                 
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'-'),PUSH=(31:ID=4))
  END                                                           
/*                                                               
//JNF2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(35:2Z)),                     
    IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'-'),PUSH=(31:ID=4)),   
    IFTHEN=(WHEN=(1,30,SS,EQ,C'AAA'),OVERLAY=(35:C'XX'))         
    SUM FIELDS=(35,2,BI)                                         
  END                                                           
/*
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2120
Location: USA

PostPosted: Mon Dec 05, 2022 7:26 pm
Reply with quote

Joerg.Findeisen wrote:
Code:
. . . . . . . .                                                       
//JNF2CNTL DD *                                                 
 INREC IFTHEN=(WHEN=INIT,OVERLAY=(35:2Z)),                     
    IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'-'),PUSH=(31:ID=4)),   
    IFTHEN=(WHEN=(1,30,SS,EQ,C'AAA'),OVERLAY=(35:C'XX'))         
 SUM FIELDS=(35,2,BI)                                         
 END                                                           
/*


In case there are more than 1 line with 'AAA' in a group, the SUM FIELDS=(35,2,BI) should calculate C'XX' + C'XX', and produce unpredictable value, not detected in the main SORT processing...

It may be better to use OVERLAY=(35:X'0001'), and check for INCLUDE=(31,2,BI,GT,X'0000')
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1308
Location: Bamberg, Germany

PostPosted: Tue Dec 06, 2022 1:48 pm
Reply with quote

True, thanks for the update. icon_wink.gif
Back to top
View user's profile Send private message
aarnold#mvs

New User


Joined: 04 Dec 2022
Posts: 8
Location: Hungary

PostPosted: Wed Dec 07, 2022 8:20 pm
Reply with quote

Hello
Thank you for the codes.
Is there any way, if we have more input Datasets?
I mean, I want to do the search in the last 10 or more Generations (in case of GDG Datases).
Many thanks for the answer.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2120
Location: USA

PostPosted: Wed Dec 07, 2022 9:21 pm
Reply with quote

aarnold#mvs wrote:
Hello
Thank you for the codes.
Is there any way, if we have more input Datasets?
I mean, I want to do the search in the last 10 or more Generations (in case of GDG Datases).
Many thanks for the answer.


There are 2 options:

1) if record format (and layout) for all input datasets is the same (as it is for GDG datasets), you can concatenate any number of them under //SORTIN DD

2) in all other circumstances you can use PARM=MULTIIN option (maybe, only for SYNCSORT? I don't recall now, lazy to RTFM again). In that case each (different) input dataset is defined under its own //SORTINnn DD, where nn=00-99
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1308
Location: Bamberg, Germany

PostPosted: Thu Dec 08, 2022 10:36 am
Reply with quote

PARM=MULTIIN seems a SYNCSORT exclusive. Specify your GDS/GDG as suggested via DD:SORTIN/F1/F2.
Back to top
View user's profile Send private message
aarnold#mvs

New User


Joined: 04 Dec 2022
Posts: 8
Location: Hungary

PostPosted: Fri Dec 09, 2022 4:05 pm
Reply with quote

Hello

As I am a DFSORT beginner, during the code conversation to my real situation, I realized, that my first logic was not correct (sorry for that).
So here I am doing a better description which fit for my real situation:
Record format . . . : FB
Record length . . . : 133

the GROUP should start with DSNAME= and ended with - (group can contain different number of lines)

Dataset I am loking for is: AAA.BBB.CCC

Input (FB/133)
Code:
---
DSNAME=AAA.BBB.CCC     OTHER DETAILS
DSNEW=XAG.WOW.LOL.YES   OTHER DETAILS
DATE TIME
OTHER DETAILS
---
DSNAME=CCC.BBB.CCC
DSNEW=XAG.AAA.BBB.DDD
DATE TIME
OTHER DETAILS
---
DSNAME=KKK.BBB.CCC   OTHER DETAILS
DSNEW=XAG.OOO.TTT.CCC    OTHER DETAILS
DATE TIME
OTHER DETAILS
OTHER DETAILS
OTHER DETAILS
---
DSNAME=XAG.YES.EGG.FINE     OTHER DETAILS
DSNEW=AAA.BBB.CCC     OTHER DETAILS
DATE TIME
OTHER DETAILS
OTHER DETAILS
---

here is my working code where I add the required DS as variable, but maybe some step can be merged as there are some unnecessary ones in my logic:

Code:
//EXP1 EXPORT SYMLIST=(DSN01)         
//SET1 SET DSN01=AAA.BBB.CCC    <=== CODE THE DS AS VARIABLE
//*                                   
//SSP000A0 EXEC PGM=ICETOOL                                     
//TOOLMSG  DD SYSOUT=*                                         
//DFSMSG   DD SYSOUT=*                                         
//IN1      DD DISP=SHR,DSN=USERID.INPUTDS1 (FB/133)
//         DD DISP=SHR,DSN=USERID.INPUTDS2 (FB/133)
//         DD DISP=SHR,DSN=USERID.INPUTDS3 (FB/133)
//TMP1     DD DISP=OLD,DSN=USERID.TEST1    (FB/140)
//TMP2     DD DISP=OLD,DSN=USERID.TEST2    (FB/140)
//OUT1     DD DISP=OLD,DSN=USERID.OUTDS    (FB/140)
//TOOLIN   DD *                                                 
  COPY FROM(IN1) TO(TMP1) USING(CTL1)                           
  COPY FROM(TMP1) TO(TMP2) USING(CTL2)                         
  COPY FROM(TMP2) TO(OUT1) USING(CTL3)                         
//CTL1CNTL DD *                                                 
  OUTFIL IFTHEN=(WHEN=GROUP,BEGIN=(1,7,SS,EQ,C'DSNAME='),       
  END=(1,1,SS,EQ,C'-'),PUSH=(134:ID=7))                         
//CTL2CNTL DD *,SYMBOLS=JCLONLY                                 
  INCLUDE COND=(1,133,SS,EQ,C'&DSN01. ')             
//CTL3CNTL DD *                                                 
  JOINKEYS F1=TMP1,FIELDS=(134,7,A)                             
  JOINKEYS F2=TMP2,FIELDS=(134,7,A)                             
  REFORMAT FIELDS=(F1:1,140)                                   
  SORT FIELDS=COPY                                             
//*                                                           



result is fine (there is the GROUP identifier at the end of every lines what I am not describing here):
Code:
DSNAME=AAA.BBB.CCC     OTHER DETAILS
DSNEW=XAG.WOW.LOL.YES   OTHER DETAILS
DATE TIME
OTHER DETAILS
---
DSNAME=XAG.YES.EGG.FINE     OTHER DETAILS
DSNEW=AAA.BBB.CCC     OTHER DETAILS
DATE TIME
OTHER DETAILS
OTHER DETAILS
---

I understand now my code, but my question, there any way to create the same result with less code?

Many thanks
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2120
Location: USA

PostPosted: Sat Dec 10, 2022 12:27 am
Reply with quote

Why did you replace the code kindly provided to you by Joerg.Findeisen? icon_rolleyes.gif

There is no change in the general logic, even with your updated "requirements". Only minor cosmetic changes are required.

Joerg has done 99.99% of your own job, but you decided to throw it away, to spoil his code by your own hands, and then asking for help again??!! icon_axe.gif
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1308
Location: Bamberg, Germany

PostPosted: Sat Dec 10, 2022 2:41 pm
Reply with quote

The &DSN01 variable should be coded with a starting equal sign in your sample, otherwise you will have false positives. With your recent updates you have ended up with three ICETOOL steps where only one SORT step is actually required, see below:

Code:
//WHATEVER EXEC PGM=ICEMAN   
//F1       DD ..             
//F2       DD .. same as F1 
//SYSOUT   DD SYSOUT=*       
//SORTOUT  DD SYSOUT=*       
//SYSIN    DD *                                                 
  OPTION COPY                                                   
  JOINKEYS F1=F1,FIELDS=(136,8,A)                               
  JOINKEYS F2=F2,FIELDS=(136,8,A)                               
  REFORMAT FIELDS=(F1:1,133,F2:134,10)                           
  OUTFIL FNAMES=(SORTOUT),                                       
    OMIT=(134,2,BI,EQ,+0),                                       
    BUILD=(1,133)                                               
  END                                                           
/*                                                               
//JNF1CNTL DD *                                                 
  INREC IFTHEN=(WHEN=GROUP,END=(1,1,CH,EQ,C'-'),PUSH=(136:ID=8))
  END                                                           
/*                                                               
//JNF2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(134:2Z)),                     
    IFTHEN=(WHEN=GROUP,END=(1,1,CH,EQ,C'-'),PUSH=(136:ID=8)),   
    IFTHEN=(WHEN=(1,133,SS,EQ,C'=AAA.BBB.CCC '),                 
      OVERLAY=(134:+1,BI,LENGTH=2))                             
    SUM FIELDS=(134,2,BI)                                       
  END                                                           
/*


Btw, using SubString with fixed positions, or only one choice, makes no sense. Use other comparison methods instead.
Back to top
View user's profile Send private message
aarnold#mvs

New User


Joined: 04 Dec 2022
Posts: 8
Location: Hungary

PostPosted: Sun Dec 11, 2022 2:50 am
Reply with quote

Hello All,
First of all I would like to say sorry if I did something insulting somebody.
The reason why I also working on the proper code on my way that we are working on the rebuild of a lot of Checker Jobs on our systems, and I want to use codes what I understand.
That's why I asked again for help after my code.
I got the JOINKEYS idea from Joerg, and I found a very good documentation then I was able to understand it's working method and the logic here - but for the SUM, FNAMES and the OVERLAY not yet.
As I we want to use DFSORT instead of REXX in many cases (because of the performance), then I need to understand the whole code.
I am still thinking about the suggested code how it work.
Also I would like to tell you that this is my second DFSORT code and still a "bit" hard task to understand the working method.

Many thanks for your help and for your understanding for both of you.

Regards,
Arnold
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1308
Location: Bamberg, Germany

PostPosted: Sun Dec 11, 2022 11:32 am
Reply with quote

First of all, see https://www.ibm.com/docs/en/zos/2.1.0?topic=overview-joinkeys-application-processing to understand the execution sequence.

1) Processing of JNF1CNTL and JNF2CNTL
1a) INREC assigns a unique ID to each of your blocks, and adds a counter of all found matches. The counter is initialized with HEXZEROS, but updated on a match.
2) JOINKEYS Processing (basically a SORT/MERGE)
3) SUMming up the counter introduced in 1a)
4) JOIN/REFORMAT based on the unique ID, that is
4a) Original record plus ID and counter of matches per block
5) OUTFIL processing is the report part, FNAMES tells what DD to write the OUTPUT to
5a) OMIT all blocks with no matches and reBUILD the original RECORD (length 133)

That's it.
Back to top
View user's profile Send private message
aarnold#mvs

New User


Joined: 04 Dec 2022
Posts: 8
Location: Hungary

PostPosted: Thu Dec 29, 2022 3:17 am
Reply with quote

Thank you for the detailed description.
I almost understand all steps, and if I will have queston, I will ask you again.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Mark Previous & next lines when a... DFSORT/ICETOOL 9
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts How I Found a Bug in a FORTRAN Compiler All Other Mainframe Topics 4
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts A directory in the pathname was not f... ABENDS & Debugging 0
Search our Forums:

Back to Top