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

Convert variable lenght field to fixed lenght


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Francisco javier Niño

New User


Joined: 28 Mar 2008
Posts: 7
Location: Chile

PostPosted: Wed Dec 10, 2008 9:45 pm
Reply with quote

I have the following input file layout :
Record format . . . : VB
Record length . . . : 79

VAR1 PIC X(20)
VAR2 PIC 9(04) BINARY. (This indicated the VAR3 field length)
VAR3 PIC X(**).
VAR4 PIC 9(08) BINARY.

I want to reformat as:
VAR1 PIC X(20)
VAR3 PIC X(33). (33 is the max length I expect the VAR3 to be)
VAR4 PIC 9(08) BINARY.

I searched over the forums and already went through the IBM DFSORT manuals but haven't found any example like this.
I have both Z/OS DFSORT V1R5 and SYNCSORT FOR Z/OS 1.2.3.1R installed
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 10:06 pm
Reply with quote

Francisco javier Niño,

Input field lengths sum up to only 59 though the LRECL is 79. Do you have any other fields in your input file? Also is your output file of FB/LRECL=57 ?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 10:09 pm
Reply with quote

Francisco javier Niño,

Adding to the above, Is the position of 'VAR4' field in your input subjected to change depending on the length of 'VAR3' ?
Back to top
View user's profile Send private message
Francisco javier Niño

New User


Joined: 28 Mar 2008
Posts: 7
Location: Chile

PostPosted: Wed Dec 10, 2008 10:29 pm
Reply with quote

Sorry Arcvns, You're right the correct RECL is 59 (20+2+33+4).
And Yes VAR4 position changes depending on the length of VAR3.
Thanks for your quick response.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 10:45 pm
Reply with quote

Francisco javier Niño,

I should have asked this in the previous post. Your input file should have a 4 byte RDW in addition to the fields you mentioned, since it's a VB file. Wont that make the LRECL=63
Back to top
View user's profile Send private message
Francisco javier Niño

New User


Joined: 28 Mar 2008
Posts: 7
Location: Chile

PostPosted: Wed Dec 10, 2008 10:56 pm
Reply with quote

The file layout adds up to 59, but yes ISPF shows LRECL=63.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Dec 10, 2008 11:13 pm
Reply with quote

Francisco javier Niño,

Use the following DFSORT control cards

Code:

//SYSIN    DD *                                             
  SORT FIELDS=COPY                                           
  INREC IFTHEN=(WHEN=(25,2,BI,EQ,01),BUILD=(1,27,32X,28,4)),
  IFTHEN=(WHEN=(25,2,BI,EQ,02),BUILD=(1,28,31X,29,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,03),BUILD=(1,29,30X,30,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,04),BUILD=(1,30,29X,31,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,05),BUILD=(1,31,28X,32,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,06),BUILD=(1,32,27X,33,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,07),BUILD=(1,33,26X,34,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,08),BUILD=(1,34,25X,35,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,09),BUILD=(1,35,24X,36,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,10),BUILD=(1,36,23X,37,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,11),BUILD=(1,37,22X,38,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,12),BUILD=(1,38,21X,39,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,13),BUILD=(1,39,20X,40,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,14),BUILD=(1,40,19X,41,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,15),BUILD=(1,41,18X,42,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,16),BUILD=(1,42,17X,43,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,17),BUILD=(1,43,16X,44,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,18),BUILD=(1,44,15X,45,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,19),BUILD=(1,45,14X,46,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,20),BUILD=(1,46,13X,47,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,21),BUILD=(1,47,12X,48,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,22),BUILD=(1,48,11X,49,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,23),BUILD=(1,49,10X,50,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,24),BUILD=(1,50,09X,51,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,25),BUILD=(1,51,08X,52,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,26),BUILD=(1,52,07X,53,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,27),BUILD=(1,53,06X,54,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,28),BUILD=(1,54,05X,55,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,29),BUILD=(1,55,04X,56,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,30),BUILD=(1,56,03X,57,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,31),BUILD=(1,57,02X,58,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,32),BUILD=(1,58,01X,59,4)),       
  IFTHEN=(WHEN=(25,2,BI,EQ,33),BUILD=(1,63))                 
/*
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 11:37 pm
Reply with quote

Francisco javier Niño,

I doubt whether the job given by Kolusu will work for you as your expected output file is of FB,LRECL=57. The below job does exactly what you want.
Code:

//STEP1    EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD DSN= Input  file --- VB,LRECL=63                   
//SORTOUT  DD DSN= Output file --- FB,LRECL=57                   
//SYSIN    DD *                                                 
 OPTION COPY                                                     
 INREC IFTHEN=(WHEN=(25,2,BI,EQ,01),BUILD=(1,24,27,01,32X,28,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,02),BUILD=(1,24,27,02,31X,29,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,03),BUILD=(1,24,27,03,30X,30,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,04),BUILD=(1,24,27,04,29X,31,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,05),BUILD=(1,24,27,05,28X,32,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,06),BUILD=(1,24,27,06,27X,33,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,07),BUILD=(1,24,27,07,26X,34,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,08),BUILD=(1,24,27,08,25X,35,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,09),BUILD=(1,24,27,09,24X,36,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,10),BUILD=(1,24,27,10,23X,37,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,11),BUILD=(1,24,27,11,22X,38,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,12),BUILD=(1,24,27,12,21X,39,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,13),BUILD=(1,24,27,13,20X,40,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,14),BUILD=(1,24,27,14,19X,41,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,15),BUILD=(1,24,27,15,18X,42,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,16),BUILD=(1,24,27,16,17X,43,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,17),BUILD=(1,24,27,17,16X,44,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,18),BUILD=(1,24,27,18,15X,45,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,19),BUILD=(1,24,27,19,14X,46,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,20),BUILD=(1,24,27,20,13X,47,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,21),BUILD=(1,24,27,21,12X,48,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,22),BUILD=(1,24,27,22,11X,49,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,23),BUILD=(1,24,27,23,10X,50,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,24),BUILD=(1,24,27,24,09X,51,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,25),BUILD=(1,24,27,25,08X,52,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,26),BUILD=(1,24,27,26,07X,53,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,27),BUILD=(1,24,27,27,06X,54,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,28),BUILD=(1,24,27,28,05X,55,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,29),BUILD=(1,24,27,29,04X,56,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,30),BUILD=(1,24,27,30,03X,57,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,31),BUILD=(1,24,27,31,02X,58,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,32),BUILD=(1,24,27,32,01X,59,4)),
       IFTHEN=(WHEN=(25,2,BI,EQ,33),BUILD=(1,24,27,33,60,4))     
 OUTFIL BUILD=(5,57),CONVERT
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Dec 11, 2008 12:00 am
Reply with quote

arcvns,

I am not sure if OP wanted a FB file. I just provided a sample for creating the fixed portion of var3 (33 bytes) keeping the input dataset attributes the same.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Dec 11, 2008 12:10 am
Reply with quote

Skolusu wrote:
I am not sure if OP wanted a FB file.
I guess the topic title explains it clearly.

Francisco javier Niño wrote:
I want to reformat as:
VAR1 PIC X(20)
VAR3 PIC X(33). (33 is the max length I expect the VAR3 to be)
VAR4 PIC 9(08) BINARY.
Also the OP wants to omit the 'VAR2' field while writing to output.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Dec 11, 2008 12:25 am
Reply with quote

Arcvns,

well OP can ignore my post . Thanks for clarifying it
Back to top
View user's profile Send private message
Francisco javier Niño

New User


Joined: 28 Mar 2008
Posts: 7
Location: Chile

PostPosted: Thu Dec 11, 2008 1:42 am
Reply with quote

Thanks arcvns, very bright solution, Just tested it and it worked fine.
On the other hand, this was the simplest of all my cases, I was expecting to extent this solution to my other cases. This solution is very case specific, I was thinking there maybe somehow to use the size field as parameter for the next field formatting.
I have another case where I have not one but two variable size fields, in that case I'll have to create the combination of all possible two fields size to obtain the same result.
E.G.
VAR1 PIC X(20)
VAR2 PIC 9(04) BINARY. (This indicated the VAR3 field length)
VAR3 PIC X(**).
VAR4 PIC 9(04) BINARY. (This indicated the VAR5 field length)
VAR5 PIC X(**).
VAR6 PIC 9(08) BINARY.

I want to reformat as:
VAR1 PIC X(20)
VAR3 PIC X(33). (33 is the max length I expect the VAR3 to be)
VAR5 PIC X(17). (17 is the max length I expect the VAR5 to be)
VAR6 PIC 9(08) BINARY.

I can have as much as 7 variable fields in a single record. Then this solution will be no longer easily extensible. Is there other general approach I could use? Or in this case it will be better just to write a program?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Sat Dec 13, 2008 12:41 pm
Reply with quote

Francisco javier Niño,

You're welcome. If you have multiple fields like this, it would be better to go ahead and do a bit of coding.
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 Store the data for fixed length COBOL Programming 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top