Page 1 of 2

Count of bytes between strings

PostPosted: Tue Oct 26, 2010 10:50 pm
by jnkarthik
Hello All,

I have a large Variable length record file.
My requirement is to count the bytes between particular strings i.e.,If I have a file something like below. I need to count the bytes from xyz to next xyz. In case of last set till the end of file. Can some one could advise whether it is achievable through DFSORT utilities? If not which will be better option - REXX, Easytrieve or Only Cobol?
xyz
abcdedfgggggggggg
abccccccddddddddddddddddef
aaaaaaaaaaaaaaaaaaaaa

xyz
bbbbbbbbb
bcvcfdggggggggggggggggggggg
ddddddddddddd
vdffdfvb

xyz
ccccccccccccccddddddddddddddd
eeeeffffggggggggg
eeeeeeeefffff

Re: Count of bytes between strings

PostPosted: Tue Oct 26, 2010 11:30 pm
by skolusu
Jnkarthik,

You haven't shown the desired output. Assuming that you want to count the bytes between the groups, the following DFSORT JCL will give you the desired results


//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD DSN=Your input VB file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                   
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,1,2,BI,SUB,+4,BI,LENGTH=2,5,3)),
  IFTHEN=(WHEN=GROUP,BEGIN=(7,3,CH,EQ,C'XYZ'),PUSH=(10:ID=8))       
  OUTFIL REMOVECC,NODETAIL,VTOF,BUILD=(80X),                         
  SECTIONS=(10,8,                                                   
  TRAILER3=('TOTAL BYTES FOR GROUP XYZ ',10,8,X,                     
             TOT=(5,2,BI,M10,LENGTH=8)))                             
//*


The output from the above is
TOTAL BYTES FOR GROUP XYZ 00000001       67
TOTAL BYTES FOR GROUP XYZ 00000002       60
TOTAL BYTES FOR GROUP XYZ 00000003       62


if that is not what you want , then you need to do a better job of describing your requirements.

Re: Count of bytes between strings

PostPosted: Wed Oct 27, 2010 3:24 pm
by jnkarthik
Thanks Mr.Kolusu,

It looks like it will help for my requirement. Sorry I have not detailed you clearly on my requirement in my first instance (Which I struggle always :-) )

Could you please brief how this works... Very simple steps but doing complex things over here.
Below is how my input file will look like which will repeats with hexa decimal x'5044462D312E330A' (i.e., my xyz) and need to identify the count of bytes between this. I will try to change the code based on your guidence. If you could brief how it work it might ease it.

&àã.....
...?¦.....äÊÁ/È?Ê..áÌËÈÊÁ/_.àÑ/%?ÅÍÁ.îÁÊËÑ?>..........
äÊÁ/ÈÑ?>à/ÈÁ......................
ÍÈÇ?Ê..êÁÅÑËÈÁÊÁÀ.È?..+|êïñäç...
èÑÈ%Á..ç..¬ øø%ÑÄ/ÈÑ?>¬.&¬<<íè¬î.....øÇ/ËÁ....
..Á>À?¦.
&àã.ã?>È..ã.....
.......?¦.
..
è`øÁ..ã?>È.
ëÍÂÈ`øÁ..è`øÁ..
á>Ä?ÀÑ>Å..............ê.
â/ËÁã?>È..çÁ%ÎÁÈÑÄ/.
..Á>À?¦..
&àã.ã?>È..ã.....
.......?¦.
..



Thanks a lot for your response.

Re: Count of bytes between strings

PostPosted: Wed Oct 27, 2010 3:50 pm
by jnkarthik
Hello Again, Sorry is it possible to get the byte count in hexa decimal format?

Re: Count of bytes between strings

PostPosted: Wed Oct 27, 2010 6:55 pm
by NicC
hexa decimal format

Do you mean that if the count is 16 decimal you want it reported as 10 hexadecimal?

Re: Count of bytes between strings

PostPosted: Wed Oct 27, 2010 9:24 pm
by jnkarthik
Hello NicC,

Thanks for the response. Yes you are correct. Is it possible to achieve?

Re: Count of bytes between strings

PostPosted: Thu Oct 28, 2010 2:02 pm
by jnkarthik
Could some one able to respond on my query please?

Re: Count of bytes between strings

PostPosted: Thu Oct 28, 2010 9:44 pm
by jnkarthik
Hello All,
To be more clear on my requriement,
I have binary file something as below and I need to find the byte count between &àã..... which is hexa decimal x'5044462D312E330A'. Can that be achieved via sort?
&àã.....
...?¦.....äÊÁ/È?Ê..áÌËÈÊÁ/_.àÑ/%?ÅÍÁ.îÁÊËÑ?>..........
äÊÁ/ÈÑ?>à/ÈÁ......................
 ÍÈÇ?Ê..êÁÅÑËÈÁÊÁÀ.È?..+|êïñäç...
èÑÈ%Á..ç..¬ øø%ÑÄ/ÈÑ?>¬.&¬<<íè¬î.....øÇ/ËÁ....
..Á>À?¦.
&àã.ã?>È..ã.....
.......?¦.
..
è`øÁ..ã?>È.
ëÍÂÈ`øÁ..è`øÁ..
á>Ä?ÀÑ>Å..............ê.
â/ËÁã?>È..çÁ%ÎÁÈÑÄ/.
..Á>À?¦..
&àã.ã?>È..ã.....
.......?¦.
..
...?¦.....è`øÁ..á>Ä?ÀÑ>Å..â/ËÁá>Ä?ÀÑ>Å..ïÑ> >ËÑá>Ä?ÀÑ>Å..àÑÃÃÁÊÁ>ÄÁË.£.
...Ëø/ÄÁ..ÁÌÄ%/_..ÉÍ?ÈÁÀÂ%..>Í_ÂÁÊËÑÅ>..À?%%/Ê..øÁÊÄÁ>È../_øÁÊË/>À..ÉÍ?ÈÁÊÑÅÇÈ..
øÁÊÑ?À..Ë%/ËÇ..:ÁÊ?..?>Á..ÈÏ?..ÈÇÊÁÁ..Ã?ÍÊ..ÃÑÎÁ..ËÑÌ..ËÁÎÁ>..ÁÑÅÇÈ..>Ñ>Á..Ä?%?>
 ..â..ä..à..á..ã..å..ç..ñ..$.....<..(..+..|..&..é..ê..ë..è..í..î..ï..ì..ß..!..ÂÊ
Í>ÀÁÊËÄ?ÊÁ..ÅÊ/ÎÁ../..Â..Ä..À..Á..Ã..Å..Ç..Ñ..¦..,..%.._..>..?..ø..É..Ê..Ë..È..Í
.>?ÈÀÁÃ..áÍÊ?...>?ÈÀÁÃ..ÉÍ?ÈÁËÑ>Å%Â/ËÁ..Ã%?ÊÑ>..ÉÍ?ÈÁÀÂ%Â/ËÁ..Á%%ÑøËÑË..À/ÅÅÁÊ..
|á...>?ÈÀÁÃ..!Ä/Ê?>...>?ÈÀÁÃ...>?ÈÀÁÃ..ÉÍ?ÈÁ%ÁÃÈ..ÉÍ?ÈÁÊÑÅÇÈ..ÉÍ?ÈÁÀÂ%%ÁÃÈ..ÉÍ?È
&àã.....
...?¦.....äÊÁ/È?Ê..áÌËÈÊÁ/_.àÑ/%?ÅÍÁ.îÁÊËÑ?>..........
äÊÁ/ÈÑ?>à/ÈÁ......................
 ÍÈÇ?Ê..êÁÅÑËÈÁÊÁÀ.È?..+|êïñäç...
èÑÈ%Á..ç..¬ øø%ÑÄ/ÈÑ?>¬.&¬<<íè¬î.....øÇ/ËÁ....
..Á>À?¦.
&àã.ã?>È..ã.....
.......?¦.

Re: Count of bytes between strings

PostPosted: Thu Oct 28, 2010 10:10 pm
by skolusu
Jnkarthik,

I still don't understand what the final output is. You keep changing your version from displayable data to hex data.

If all you want is to validate hex data of X'5044462D312E330A' at position 5 (since your input is VB) then it is very simple. Use the following DFSORT JCL

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD DSN=Your input VB file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                   
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,1,2,BI,SUB,+4,BI,LENGTH=2,5,8)),
  IFTHEN=(WHEN=GROUP,BEGIN=(7,8,CH,EQ,X'5044462D312E330A'),         
  PUSH=(15:ID=8))                                                   
  OUTFIL REMOVECC,NODETAIL,VTOF,BUILD=(80X),                         
  SECTIONS=(15,8,                                                   
  TRAILER3=('TOTAL BYTES FOR GROUP ',15,8,X,                         
             TOT=(5,2,BI,M10,LENGTH=8)))                             
//*


This will produce a report like this

TOTAL BYTES FOR GROUP 00000001       72
TOTAL BYTES FOR GROUP 00000002       65
TOTAL BYTES FOR GROUP 00000003       67


Do you need the byte count in hex ? like this ?

TOTAL BYTES FOR GROUP 00000001 404040404040F7F2
TOTAL BYTES FOR GROUP 00000002 404040404040F6F5
TOTAL BYTES FOR GROUP 00000003 404040404040F6F7

Re: Count of bytes between strings

PostPosted: Fri Oct 29, 2010 12:31 am
by jnkarthik
Thanks Mr. Kolusu,
The output what you are producing is what I required exactly.
I tried your sample and it is working but I have 29 groups in my input file but the output produced only for one group. May be it has not found the searching criteria properly not sure why it is? Since it has taken the complete file, It produced me the complete file byte count instead of the group. Could you tell why this is so?