IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How do I replace spaces with value from prev record?


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
timburkart

New User


Joined: 17 Mar 2007
Posts: 29
Location: USA

PostPosted: Thu Apr 26, 2007 1:23 am
Reply with quote

I am reformatting a utility report into a CSV file for loading into a database. After stripping out the non-essential information and inserting delimiting commas (using DFSORT) I have a file that looks like this.

Code:

HWA,04/19/07,      47.88
   ,04/20/07,    1:30.32
   ,04/21/07,       0.17
   ,04/22/07,       0.18
   ,04/23/07,    1:32.02
   ,04/24/07,    1:44.60
   ,04/25/07,      12.28
HWB,04/24/07,       4.60
HWC,04/19/07,      10.41
   ,04/20/07,      55.55
   ,04/23/07,    1:22.26
   ,04/24/07,    1:16.14
HWE,04/19/07,       0.56


The utility report writer does not repeat values in subsequent records hence the spaces in locations 1-3. How can I carry over the non-blank value into subsequent records during the same process? I want my output file to look like this.

Code:

HWA,04/19/07,      47.88
HWA,04/20/07,    1:30.32
HWA,04/21/07,       0.17
HWA,04/22/07,       0.18
HWA,04/23/07,    1:32.02
HWA,04/24/07,    1:44.60
HWA,04/25/07,      12.28
HWB,04/24/07,       4.60
HWC,04/19/07,      10.41
HWC,04/20/07,      55.55
HWC,04/23/07,    1:22.26
HWC,04/24/07,    1:16.14
HWE,04/19/07,       0.56


I think I should use IFTHEN and INREC but don't know how all of the pieces fit together.

Code:

  INREC  IFTHEN=(WHEN=(2,3,CH,NE,C'   '),                       
               BUILD=(1:2,3,4:C',',5:44,8,13:C',',14:57,11,25:2,3)),
???         IFTHEN=(WHEN=(2,3,CH,EQ,C'   '),                       
              BUILD=(1:25,3,4:C',',5:44,8,13:C',',14:57,11))       
  OUTFIL OUTREC=(1:1,24) 


Thank you!!


tim
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Apr 26, 2007 1:56 am
Reply with quote

You need to use the IFTHEN group technique. Here's a DFSORT/ICETOOL job that will 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. You'll need z/OS DFSORT V1R5 PTF UK90007 or DFSORT R14 PTF UK90006 (April, 2006) in order to use INREC with SPLICE. If you don't have the April, 2006 PTF, you won't get the correct output, so ask your System Programmer to install the PTF (it's free). For complete details on all of the new DFSORT and ICETOOL functions available with the April, 2006 PTF, see:

Use [URL] BBCode for External Links

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input file (FB/80)
//OUT DD DSN=...  output file (FB/80)
//TOOLIN   DD    *
SPLICE FROM(IN) TO(OUT) ON(81,8,ZD) KEEPNODUPS -
  WITHALL WITH(4,77) USING(CTL1)
/*
//CTL1CNTL DD *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(1,3,CH,NE,C' '),
                OVERLAY=(81:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=NONE,
                OVERLAY=(89:SEQNUM,8,ZD,
                         81:81,8,ZD,SUB,89,8,ZD,M11,LENGTH=8))
  OUTFIL FNAMES=OUT,BUILD=(1,80)
/*
Back to top
View user's profile Send private message
timburkart

New User


Joined: 17 Mar 2007
Posts: 29
Location: USA

PostPosted: Thu Apr 26, 2007 3:14 am
Reply with quote

I always appreciate your help, Frank!! With minor adjustments it works like a charm.

Thank you very much!

regards,

tim
Back to top
View user's profile Send private message
mcollins

New User


Joined: 28 Apr 2007
Posts: 2
Location: England

PostPosted: Thu May 03, 2007 11:59 pm
Reply with quote

Could you tell me what adjustments you made? I tried the solution but the unique non-blank records i.e
HWA,04/19/07, 47.88
HWC,04/19/07, 10.41
were missing from the output.
I've ended up extracting the non blanks to another outfile and then merging it back into OUT and deduplicating, but I think I've gone a long way for a short cut.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri May 04, 2007 12:32 am
Reply with quote

mcollins,

Oops. Somehow I missed that when I looked at the output from my testing. To get the missing records, just add KEEPBASE to the SPLICE operator:

Code:

SPLICE FROM(IN) TO(OUT) ON(81,8,ZD) KEEPNODUPS KEEPBASE -
  WITHALL WITH(4,77) USING(CTL1)
Back to top
View user's profile Send private message
mcollins

New User


Joined: 28 Apr 2007
Posts: 2
Location: England

PostPosted: Fri May 04, 2007 2:45 pm
Reply with quote

Thanks for that - actually omitting the keepbase will come in useful in future
Back to top
View user's profile Send private message
timburkart

New User


Joined: 17 Mar 2007
Posts: 29
Location: USA

PostPosted: Fri May 04, 2007 7:50 pm
Reply with quote

Oh my! I did not check for any missing records. Thank you for catching this. I made three changes.

1-the sample data I provided had the desired data starting in column one however it actually began in column two
2-Frank's solution assumed an 80 byte output record, mine is 25
3-added SQZ=(SHIFT=LEFT)) to left justify the 3rd column of data

Code:

//TOOLIN   DD    *                                         
  SPLICE FROM(IN) TO(OUT) ON(81,8,ZD) KEEPNODUPS KEEPBASE -
    WITHALL WITH(5,77) USING(CTL1)                         
/*                       
                                 
//CTL1CNTL DD *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),         
      IFTHEN=(WHEN=(2,3,CH,NE,C' '),                       
              OVERLAY=(81:SEQNUM,8,ZD)),                   
      IFTHEN=(WHEN=NONE,                                   
              OVERLAY=(89:SEQNUM,8,ZD,                     
                       81:81,8,ZD,SUB,89,8,ZD,M11,LENGTH=8))
  OUTFIL FNAMES=OUT,                                         
       BUILD=(1:2,3,4:2C',',6:44,8,14:C',',                 
              15:57,11,SQZ=(SHIFT=LEFT))       
/*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top