Page 1 of 2

Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 10:43 am
by danny_ce16
Hi,

i have a VB file of rec len 80 with the following recs.

C;0088999;TEST NAME NAME1 ;1485/1111111111111
D;1122333;TESTNAME NAME23 NAME7 ;2596/3333333333333
E;5555444;TESTTEST NAME NAME4 ;3912/5555555555555

i need to replace the first character with a number (C to 1, D to 2 E to 3) and remove the trailing spaces that appears after the name, giving the output as below

1;007788999;TEST NAME NAME1;14785/111111111111111
2;111222333;TESTNAME NAME23 NAME7;25896/333333333333333
3;321654987;TESTTEST NAME NAME4;36912/555555555555555

Thanks in advance.

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 10:59 am
by danny_ce16
for clear data, from

C;007788999;TEST NAME NAME1                          ;14785/111111111111111
D;111222333;TESTNAME NAME23 NAME7                    ;25896/333333333333333
E;321654987;TESTTEST NAME NAME4                      ;36912/555555555555555


to

1;007788999;TEST NAME NAME1;14785/111111111111111
2;111222333;TESTNAME NAME23 NAME7;25896/333333333333333
3;321654987;TESTTEST NAME NAME4;36912/555555555555555

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 1:13 pm
by BillyBoyo
Thanks for taking the time to improve the readability.

For the replacement, have you looked at IFTHEN with WHEN= and then an OVERLAY?

For removing the trailing blanks, have a look at SQZ.

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 5:52 pm
by danny_ce16
yes Bill, i first converted the file to FB and then tried to squeeze.

INREC OVERLAY=(1,80,SQZ=(SHIFT=LEFT,MID=C' '))

but im getting a single space at the end of name fields displayed.. the names shouldnt have any trailing spaces

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 6:05 pm
by BillyBoyo
Have a check in the DFSORT manual waht the MID=C' ' is doing. That is where your extra space is coming from.

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 6:25 pm
by danny_ce16
without MID=C' ', it would remove all the spaces including the one in between the first name,middle name and last name right?

Re: Remove trailing spaces and replace character

PostPosted: Tue Nov 15, 2011 8:53 pm
by BillyBoyo
But you are not doing it to a field, there is another field after it. It is treating your whole 80 characters and will put a blank everywhere between first and last non-blank when it removes the spaces.

So, yes, your MID is preserving spaces between name elements, but inserting a space after the last name element because it is followed by something else.

I guess you want a way around it as well?

Maybe if you BUILD the output record so that you just do the SQZ on any fields which need the spaces dropped? Keeping the MID as you have it, but at field level.

Re: Remove trailing spaces and replace character

PostPosted: Wed Nov 16, 2011 12:35 am
by Frank Yaeger
Danny,

Here's a DFSORT job that will do what you asked for:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (VB/80)
//SORTOUT DD DSN=...  output file (VB/80)
//SYSIN DD *
  OPTION COPY
  INREC IFOUTLEN=80,
   IFTHEN=(WHEN=INIT,
    BUILD=(1,4,5,1,CHANGE=(1,C'C',C'1',C'D',C'2',C'E',C'3'),
      6,11,17,41,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'";',LENGTH=44),
      59,22)),
   IFTHEN=(WHEN=INIT,
     BUILD=(1,4,5,80,SQZ=(SHIFT=LEFT,PAIR=QUOTE))),
   IFTHEN=(WHEN=INIT,FINDREP=(IN=C'"',OUT=C''))
/*

Re: Remove trailing spaces and replace character

PostPosted: Wed Nov 16, 2011 11:43 am
by danny_ce16
its failing for me

SYSIN :                                                             
    OPTION COPY                                                     
    INREC IFOUTLEN=80,                                             
     IFTHEN=(WHEN=INIT,                                             
      BUILD=(1,4,5,1,CHANGE=(1,C'P',C'1',C'B',C'2',C' ',C'3'),     
        6,11,17,41,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'";',LENGTH=44),
        59,22)),                                                   
     IFTHEN=(WHEN=INIT,                                             
       BUILD=(1,4,5,80,SQZ=(SHIFT=LEFT,PAIR=QUOTE))),               
     IFTHEN=(WHEN=INIT,FINDREP=(IN=C'"',OUT=C''))                   
                       *                                           
WER268A  INREC STATEMENT   : SYNTAX ERROR                           
WER211B  SYNCSMF  CALLED BY SYNCSORT; RC=0000


am i missing something here..?

Re: Remove trailing spaces and replace character

PostPosted: Wed Nov 16, 2011 11:58 am
by NicC
Yes - you are missing the fact that you are using SYNCSORT and that this is the DFSORT section of the forum - not the SYNCSORT section. As the 2 products are not the same (although similar) control cards for one will not necessarily work for the other.