Page 1 of 1

File - Remove Spaces

PostPosted: Mon Aug 31, 2009 6:15 pm
by mahesh100
Hi,

I need to remove the padded spaces from one of the field.

File layout
two-char x(2)
three-char (3)
name x(35)
indicator 9(1)
indicator 9(1)

Input file



HEADER
IN,IND,INDIA                      ,1,0
GB,GBP,GREAT BRITAIN POUND        ,1,O
TRAILOR


(Remove all the extra spaces in the name field)
Output file:

HEADER
IN,IND,INDIA,1,0
GB,GBP,GREAT BRITIAN POUND,1,0
TRAILOR


I was thinking with Program but if can be done using DFSORT then it will be great.
Please let me know of any thoughts.

Re: File - Remove Spaces

PostPosted: Mon Aug 31, 2009 9:38 pm
by Frank Yaeger
You description of the layout doesn't match your example. Your layout describes fixed fields, but your example has comma delimited fields. Which is it?

Also, what is the RECFM and LRECL of the input file?

Is the name field the only one that can have embedded blanks?

Re: File - Remove Spaces

PostPosted: Tue Sep 01, 2009 8:54 am
by mahesh100
Frank,

Input file :
File layout
two-char x(2)
Filler value comma
three-char (3)
filler value comma
name x(40)
filler value comma
indicator 9(1)
filler value comma
indicator 9(1)


1) The file is delimited by comma.
2) Input file is fixed length and LRECL=51
3) Yes only Name field will have embedded spaces.

Thanks,
Mahe

Re: File - Remove Spaces

PostPosted: Tue Sep 01, 2009 10:13 am
by dick scherrer
Hello,

Do not post the same question in multiple parts of the forum. . .
ibm-cobol/topic2319.html#p9079

But still i am thinking on it ,how to use that ...
If any help on that will be great...


What is not clear? The input is a "not quite usable" delimited string (because of embedded spaces). If the string is unstrung into several variables, the meaningful length of each component can be calculated (field length minus trailing spaces), and then the values can be strung back together using reference modification, eliminating the unwanted trailing spaces.

Re: File - Remove Spaces

PostPosted: Tue Sep 01, 2009 7:13 pm
by mahesh100
Dick,

I wanted to use the ICETOOL or sort instead of program.
I am not sure why they want using sort, I guess it performance issue.

Thanks,
Mahesh

Re: File - Remove Spaces

PostPosted: Tue Sep 01, 2009 10:35 pm
by Frank Yaeger
Here's a D[size=150][/size]FSORT job that will do what you asked for:

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=... input file (FB/51)
//SORTOUT DD DSN=... output file (FB/51)
//SYSIN    DD    *
  OPTION COPY
  INREC IFOUTLEN=51,
   IFTHEN=(WHEN=(3,1,CH,EQ,C','),
    BUILD=(1,7,8:8,40,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'"',LENGTH=42),
     50:48,4),HIT=NEXT),
   IFTHEN=(WHEN=(3,1,CH,EQ,C','),
     OVERLAY=(8:8,46,SQZ=(SHIFT=LEFT,PAIR=QUOTE)),HIT=NEXT),
   IFTHEN=(WHEN=(3,1,CH,EQ,C','),
     FINDREP=(IN=C'"',OUT=C''))
/*

Re: File - Remove Spaces

PostPosted: Wed Sep 02, 2009 9:01 am
by mahesh100
Thanks Frank.
I will try this code.

Re: File - Remove Spaces

PostPosted: Wed Sep 02, 2009 8:47 pm
by mahesh100
Thanks Frank... Its working Fine

But i did not get the logic of below line. Could you please let me know on this(What is the purpose of giving 50:48,4)

BUILD=(1,7,8:8,40,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'"',LENGTH=42),50:48,4),HIT=NEXT),

Thanks,
Mahesh

Re: File - Remove Spaces

PostPosted: Thu Sep 03, 2009 12:43 am
by Frank Yaeger
We are adding quotes around the name which increases its length by 2. We need to shift the indicators after the name before we squeeze them together.

For example:

GB,GBP,GREAT BRITAIN POUND        ,1,O


would be justified to:

GB,GBP,"GREAT BRITAIN POUND"        ,1,O


then squeezed to:

GB,GBP,"GREAT BRITAIN POUND",1,O


Finally, the quotes are removed and we get:

GB,GBP,GREAT BRITAIN POUND,1,O