Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

count the occurence of a string within a record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
pawan_kch

New User


Joined: 05 Apr 2006
Posts: 11
Location: Bangalore

PostPosted: Wed Feb 15, 2012 10:02 pm    Post subject: count the occurence of a string within a record
Reply with quote

Hi,

I have a comma delimted file which is copied to the mainframe flat file through other system,
lets says my input file is of LRECL 20 fixed length,
Code:
----+----1----+----2
********************
A,B,C,D,,E,F,G,H
A,B,C,D,E
A,B,C,D,E,F,G,H,I,J


I want to count the number of commas within a record and place the count towards the end of the file,
Output should be,
Code:
----+----1----+----2--
**********************
A,B,C,D,,E,F,G,H    08
A,B,C,D,E           04
A,B,C,D,E,F,G,H,I,J 09


For some reasons i want to omit the invalid records based on the delimter(,) count.

Lets say, the count of the comma within a record should be 8 for a valid record, here my first record is the valid one.
The other 2 records with comma count of 04 and 09 should fall into the invalid record file.

Can this be done using a SORT. Any ideas/code, please help me.
Back to top
View user's profile Send private message

Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Feb 15, 2012 11:13 pm    Post subject: Reply to: count the occurence of a string within a record
Reply with quote

pawan_kch,

DFSORT does NOT have any built in features to count the characters. If your lrecl is 20 as you say ( it may be different in real), you can use a bunch of IFTHEN statements to validate each byte and then count the number of comma's. A Cobol E15/E35 is the right way to do it

What is the LRECL and RECFM of the input file ? Do you have any packed/binary fields in the input file or is the entire file a plain text file with characters A - Z and 0-9?
Back to top
View user's profile Send private message
pawan_kch

New User


Joined: 05 Apr 2006
Posts: 11
Location: Bangalore

PostPosted: Thu Feb 16, 2012 12:17 am    Post subject: Reply to: count the occurence of a string within a record
Reply with quote

Hi, My input record length is 340, and the number of columns within a record is 29. Hence the count of commas should be 28 for the record to be valid.

No, my input file doesnt contain any packed/binary data.

do you have any pseudo code to present here? Thank You.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Feb 16, 2012 12:52 am    Post subject: Re: Reply to: count the occurence of a string within a recor
Reply with quote

pawan_kch wrote:
Hi, My input record length is 340, and the number of columns within a record is 29. Hence the count of commas should be 28 for the record to be valid.


pawan_kch,

Since the comma's are less than 100, we can use parse feature to grab the comma's and count them. Use the following DFSORT JCL which will give you the desired results. I assumed a max of 30 comma's

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD DSN=Your input FB 340 byte file,DISP=SHR
//VALID    DD SYSOUT=*         
//INVALID  DD SYSOUT=*                                     
//SYSIN    DD *                                             
  OPTION COPY                                               
  INREC IFOUTLEN=342,IFTHEN=(WHEN=INIT,OVERLAY=(341:30X)), 
  IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C',,',C', ,'))),       
  IFTHEN=(WHEN=INIT,                                       
  PARSE=(%01=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %02=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %03=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %04=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %05=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %06=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %07=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %08=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %09=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %10=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %11=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %12=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %13=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %14=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %15=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %16=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %17=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %18=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %19=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %20=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %21=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %22=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %23=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %24=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %25=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %26=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %27=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %28=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %29=(ENDAT=C',',ADDPOS=1,FIXLEN=1),               
         %30=(ENDAT=C',',ADDPOS=1,FIXLEN=1)), 
  OVERLAY=(371:%01,%02,%03,%04,%05,%06,%07,%08,%09,%10,               
               %11,%12,%13,%14,%15,%16,%17,%18,%19,%20,               
               %21,%22,%23,%24,%25,%26,%27,%28,%29,%30)),             
  IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=371,INOUT=(C',',C'1'))),       
  IFTHEN=(WHEN=INIT,                                                 
  OVERLAY=(341:(371,1,ZD,ADD,372,1,ZD,ADD,373,1,ZD,ADD,374,1,ZD,ADD, 
                375,1,ZD,ADD,376,1,ZD,ADD,377,1,ZD,ADD,378,1,ZD,ADD, 
                379,1,ZD,ADD,380,1,ZD,ADD,381,1,ZD,ADD,382,1,ZD,ADD, 
                383,1,ZD,ADD,384,1,ZD,ADD,385,1,ZD,ADD,386,1,ZD,ADD, 
                387,1,ZD,ADD,388,1,ZD,ADD,389,1,ZD,ADD,390,1,ZD,ADD, 
                391,1,ZD,ADD,392,1,ZD,ADD,393,1,ZD,ADD,394,1,ZD,ADD, 
                395,1,ZD,ADD,396,1,ZD,ADD,397,1,ZD,ADD,398,1,ZD,ADD, 
                399,1,ZD,ADD,400,1,ZD),EDIT=(TT)))
                                                     
  OUTFIL FNAMES=VALID,INCLUDE=(341,2,ZD,EQ,28)       
  OUTFIL FNAMES=INVALID,SAVE                         

//*
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Thu Feb 16, 2012 12:56 am    Post subject:
Reply with quote

If you want to put the records that have 28 commas in output file1 and the records that don't have 28 commas in output file2, you can use a DFSORT job like the following (there's no need to actually record the count in the record in order to create the two output files):

Code:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file1 (FB/340)
//GOOD DD DSN=...    output file1 (FB/340)
//BAD DD DSN=...     output file2 (FB/340)
//SYSIN DD *
  OPTION COPY
 INREC PARSE=(%=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %=(STARTAT=C','),%=(STARTAT=C','),%=(STARTAT=C','),
              %28=(STARTAT=C',',FIXLEN=1),
              %29=(STARTAT=C',',FIXLEN=1)),
       OVERLAY=(341:%28,%29)
 OUTFIL FNAMES=GOOD,INCLUDE=(341,1,CH,EQ,C',',AND,342,1,CH,EQ,C' '),
   BUILD=(1,340)
 OUTFIL FNAMES=BAD,SAVE,BUILD=(1,340)
/*


For my testing I used this input:

Code:

,,,,,,,,,,,,,,,,,,,,,,,,,,,,                               GOOD1   
,,,,,,,,,,,,,,,,,,,,,,,,,,,                                BAD1     
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,                              BAD2     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9  GOOD2   
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9, BAD3     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8    BAD4     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5          BAD5     
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,,                     GOOD3   
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,,,                    BAD6     
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,                      BAD7     
1,2,3,4                                                    BAD8     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,,BAD9     


and got this output:

GOOD:

Code:

,,,,,,,,,,,,,,,,,,,,,,,,,,,,                               GOOD1         
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9  GOOD2         
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,,                     GOOD3         


BAD

Code:

,,,,,,,,,,,,,,,,,,,,,,,,,,,                                BAD1     
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,                              BAD2     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9, BAD3     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8    BAD4     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5          BAD5     
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,,,                    BAD6     
,,,,,,,ABCDEFG,,,,,,,,,,XYZ,,,,,,,,,,                      BAD7     
1,2,3,4                                                    BAD8     
1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,,BAD9     
Back to top
View user's profile Send private message
pawan_kch

New User


Joined: 05 Apr 2006
Posts: 11
Location: Bangalore

PostPosted: Thu Feb 16, 2012 11:47 am    Post subject: Reply to: count the occurence of a string within a record
Reply with quote

Skolusu & Frank, Thanks very much for your ideas. very helpful.

Frank, This worked perfecly for me without actually counting the occurence of a string. This is great. Thanks much.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us