Page 1 of 1

Including delimiter in a PS file

PostPosted: Mon Oct 24, 2011 10:47 pm
by nm992
Hi..

I have a PS File.I need to include a delimiter between each field and generate an output..

For ex : My Inpput is:

Rachita       Bangalore          City
Mohan         Delhi              Capital


I want output as

Rachita/bangalore/Ciby
Mohan/Delhi/Capital

Re: Including delimiter in a PS file

PostPosted: Mon Oct 24, 2011 11:04 pm
by Frank Yaeger
nm992,

You can use a DFSORT job like the following to do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

//S1 EXEC PGM=SORT                                   
//SYSOUT DD SYSOUT=*                                 
//SORTIN DD *                                       
Rachita       Bangalore          City               
Mohan         Delhi              Capital             
//SORTOUT DD SYSOUT=*                               
//SYSIN DD *                                         
  OPTION COPY                                       
  INREC BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C'/'))       
/*

Re: Including delimiter in a PS file

PostPosted: Tue Oct 25, 2011 12:52 pm
by nm992
Hi Frank

Its not coming correct in fields where there is no space..

For exacmple if my Name is long

rachitadasguptabangalore
dennis delhi
ricksi chennai

/ is not coming in the first ro as this is continous and occupy full byte assigned to it.

Re: Including delimiter in a PS file

PostPosted: Tue Oct 25, 2011 1:46 pm
by BillyBoyo
Well, you should have provided this example in your sample input if you want anyone to know it is a possible situation. Without such an example, the natural assumption is that the fields are seperated by at least one blank. Have you tried the code with combinations of blank fields as well?

Re: Including delimiter in a PS file

PostPosted: Tue Oct 25, 2011 10:41 pm
by Frank Yaeger
Its not coming correct in fields where there is no space..

For exacmple if my Name is long

rachitadasguptabangalore
dennis delhi
ricksi chennai

/ is not coming in the first ro as this is continous and occupy full byte assigned to it.


Huh? In your first post, you said
I need to include a delimiter between each field


Why would you expect a delimiter for just one field? There's no "between" in that case.

I have no idea what output you're looking for with your new input example - what are you expecting for output? Where/why would you expect a / for that long field and what are the "rules" for that? I really can't read your mind. You need to show an example of input and expected output for all possible variations if you want me to show you how to handle all possible variations.

Re: Including delimiter in a PS file

PostPosted: Tue Oct 25, 2011 10:55 pm
by nm992
Hi,

My Input is as below

NAME(20 Bytes) CITY(15 BYTES) AGE(3 BYTES) A/C BANK(10 Bytes)

Rachita Bangalore 24 HDFC
Mohan Bangalore 23 ICICI
Mhandasgupta Delhi 23 HDFC
ParvRVenkateshwaraaaBangalore 56 SBI

I want ouptput as

rachita/bangalore/24/hdfc
mohan/bangalore/23/icici
mohandasgupta/delhi/23/hdfc
ParvRVenkateshwaraaa/bangalore/56/sbi

The above solution you posted is working fine but it is not working and not introducing / if any field value is occupying maximum bytes(i.e there is no space between consequent fields)

Re: Including delimiter in a PS file

PostPosted: Tue Oct 25, 2011 11:06 pm
by Frank Yaeger
Given those new rules, here's a DFSORT job that will do what you asked for:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (FB/48)
//SORTOUT DD DSN=...  output file (FB/48)
//SYSIN DD *
   OPTION COPY
   INREC IFOUTLEN=48,
    IFTHEN=(WHEN=INIT,
     BUILD=(1,20,C'/',21,15,C'/',36,3,C'/',39,10)),
    IFTHEN=(WHEN=INIT,BUILD=(1,51,SQZ=(SHIFT=LEFT)))
/*


Input:

Rachita             Bangalore      24 HDFC           
Mohan               Bangalore      23 ICICI         
Mhandasgupta        Delhi          23 HDFC           
ParvRVenkateshwaraaaBangalore      56 SBI           
ParvRVenkateshwaraaaBangalorexxxxxx561SBIxxxxxxx     


Output:

Rachita/Bangalore/24/HDFC                               
Mohan/Bangalore/23/ICICI                                 
Mhandasgupta/Delhi/23/HDFC                               
ParvRVenkateshwaraaa/Bangalore/56/SBI                   
ParvRVenkateshwaraaa/Bangalorexxxxxx/561/SBIxxxx         

Re: Including delimiter in a PS file

PostPosted: Fri Oct 28, 2011 6:21 pm
by nm992
What is the significance of 51in your data

Re: Including delimiter in a PS file

PostPosted: Fri Oct 28, 2011 8:39 pm
by enrico-sorichetti
why not show a bit of ingenuity and try to find out Yourself ...
anyway,

51 = length of first field + length of second field + length of third field + length of fourth field + 3 * length of separator

51 = 20 + 15 + 3 + 10 + 3