Page 1 of 1

Separate fields with ';' and get rid of spaces

PostPosted: Fri Feb 20, 2015 6:06 pm
by puffes
Hi,
I have a fixed blocked file with lrecl=10 that contains several records with 4 fixed fields.
The 4 fixed fields are in position 1-4,5-6,7,8-10.
I want to combine all the 4 fields and get rid of the spaces to the right of every field and separate them with ';'.
If a fixed field only contains of spaces it should also be separated with ';'.
How do I accomplish that?

Here is how my file with 3 records look like where b=spaces:
ABbCCDEFGb
AB1bCbbbbK
bbbbbbJbbb


So my output-file should consist of:
AB C;CD;F;G
AB1;C;;  K
;;J;


Hope You understand my problem and can help me.

Mikael

Code'd

Re: Separate fields with ';' and get rid of spaces

PostPosted: Fri Feb 20, 2015 7:36 pm
by NicC
PARSE your input into 4 variables and BUILD your output with your semi-colon between each parsed variable.

Re: Separate fields with ';' and get rid of spaces

PostPosted: Fri Feb 20, 2015 8:20 pm
by BillyBoyo
The problem is that you have a "mixture" of blanks. Leading and embedded blanks, which are significant, and trailing blanks which are not.

If we take just one column, this input:

AAAA
AAA
AA
A
   
 AAA
A AA


Needs to give you this output:

AAAA;
AAA;
AA;
A;
;   
 AAA;
A AA;


There's no short-cut to coding it.
  INREC IFTHEN=(WHEN=INIT,
                BUILD=(1,4,C';')),
              IFTHEN=(WHEN=(1,4,CH,EQ,C' '),
                BUILD=(5,1)),
              IFTHEN=(WHEN=(2,3,CH,EQ,C' '),
                BUILD=(1,1,5,1)),
              IFTHEN=(WHEN=(3,2,CH,EQ,C' '),
                BUILD=(1,2,5,1)),
              IFTHEN=(WHEN=(4,1,CH,EQ,C' '),
                BUILD=(1,3,5,1))


So:

  INREC IFTHEN=(WHEN=INIT,
                BUILD=(1,4,C';',5,2,C';',7,1,C';',8,3)),


Then, starting from the right, you need to apply the above to your data:

* Last field, starts at 11, length of three, not delimiter
              IFTHEN=(WHEN=(11,3,CH,EQ,C' '),
                BUILD=(1,10),HIT=NEXT),
              IFTHEN=(WHEN=(12,2,CH,EQ,C' '),
                BUILD=(1,10,11,1),HIT=NEXT),
              IFTHEN=(WHEN=(13,1,2,CH,EQ,C' '),
                BUILD=(1,10,11,2),HIT=NEXT),
* Third field, starts at nine, length of one, delimiter and required data follow
              IFTHEN=(WHEN=(9,1,CH,EQ,C' '),
                BUILD=(1,8,10,4),HIT=NEXT),
* Second field, starts at six, length of two, delimiter and required data follow
              IFTHEN=(WHEN=(6,2,CH,EQ,C' '),
                BUILD=(1,5,8,6),HIT=NEXT),
              IFTHEN=(WHEN=(7,1,CH,EQ,C' '),
                BUILD=(1,5,6,1,8,6),HIT=NEXT),
* First field, starts at one, length of four, delimiter and required data follow
              IFTHEN=(WHEN=(1,4,CH,EQ,C' '),
                BUILD=(5,9)),
              IFTHEN=(WHEN=(2,3,CH,EQ,C' '),
                BUILD=(1,1,5,9)),
              IFTHEN=(WHEN=(3,2,CH,EQ,C' '),
                BUILD=(1,2,5,9)),
              IFTHEN=(WHEN=(4,1,CH,EQ,C' '),
                BUILD=(1,3,5,9))


The HIT=NEXT is required when further IFTHEN=(WHEN=(logical expression tests are needed to be carried out on the same record.

That's untested, but should be close.