Separate fields with ';' and get rid of spaces



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Separate fields with ';' and get rid of spaces

Postby puffes » Fri Feb 20, 2015 6:06 pm

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
puffes
 
Posts: 5
Joined: Wed Mar 12, 2014 12:46 am
Has thanked: 0 time
Been thanked: 0 time

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

Postby NicC » Fri Feb 20, 2015 7:36 pm

PARSE your input into 4 variables and BUILD your output with your semi-colon between each parsed variable.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby BillyBoyo » Fri Feb 20, 2015 8:20 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post