MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Converting a Fixed lenth file to TAB delimited file

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
shiv_swami
Beginner


Joined: 29 Nov 2003
Posts: 68
Topics: 14

PostPosted: Fri Feb 06, 2004 1:04 pm    Post subject: Converting a Fixed lenth file to TAB delimited file Reply with quote

Hi ,

We have this strange requirement over here.We have created the file with following layout

Code:
01  WS1-CONTRACT-FMT-RECORD.                                     
    05 WS1-CONTRACT-NBR           PIC X(20)     VALUE SPACES.   
    05 FILLER                     PIC X          VALUE ' '.     
    05 WS1-OWNED-BY               PIC X(20)     VALUE SPACES.   
    05 FILLER                     PIC X          VALUE ' '.     
    05 WS1-PHASE                  PIC X(1)       VALUE SPACES.   
    05 FILLER                     PIC X          VALUE ' '.     
    05 WS1-FINANCIAL-PRODUCT      PIC X(20)     VALUE SPACES.   
    05 FILLER                     PIC X          VALUE ' '.     
    05 WS1-CONTRACT-TERM          PIC 9(3)       VALUE ZEROES.   
    05 FILLER                     PIC X          VALUE ' '.     
    05 WS1-LENGTH-PAY-PERIOD      PIC 9(2)       VALUE ZEROES.   
    05 FILLER                     PIC X          VALUE ' '.     


The receiving team of the file now wants to File to be TAB (X'05'?)
delimited .
We also need to remove the trailing spaces from all the character fileds and leading zeroes of numeric fields.
The strings can have embedded spaces & we need to take off the Trailing spacess from all the fields.
Can this be done by some utility ? We are looking for a quick fix as programs have already been developed.

Code:
Input

----+----1----+----2----+----3----+----4----+----5----+----6----
1234512345           ANDERSON             SGLINV               

Output
----+----1----+----2----+----3----+----4----+----5----+----6----
1234512345(TAB)ANDERSON(TAB)SGLINV(TAB)

It;s kind of urgent but forum guidelines say do not use words like so I have not used URGENT.But it truely is..
_________________
Regards,
Shivprakash
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Feb 06, 2004 2:25 pm    Post subject: Reply with quote

Shiv,

Tab delimiting the file is very easy. But the trimming of trailing spaces and leading zeroes is not that easy. Do you have easytrieve at your shop?

For tab delimiting run the following JCL
Code:

//STEP0100  EXEC  PGM=SORT                                             
//SYSOUT    DD SYSOUT=*                                               
//SORTIN    DD *                                                       
1234512345           ANDERSON             SGLINV                       
//SORTOUT   DD DSN=YOUR OUTPUT DSN,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(CYL,(X,Y),RLSE)
//SYSIN     DD *                                                     
  SORT FIELDS=COPY                                                     
  OUTREC FIELDS=(1,20,      $ WS1-CONTRACT-NBR                         
                 X'05',     $ TAB DELMITER                             
                22,20,      $ WS1-OWNED-BY                             
                 X'05',     $ TAB DELMITER                             
                43,01,      $ WS1-PHASE                                 
                 X'05',     $ TAB DELMITER                             
                45,20,      $ WS1-FINANCIAL-PRODUCT                     
                 X'05',     $ TAB DELMITER                             
                66,03,      $ WS1-CONTRACT-TERM                         
                 X'05',     $ TAB DELMITER                             
                70,02,      $ WS1-LENGTH-PAY-PERIOD                     
                 X'05')     $ TAB DELMITER                             
/*



Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
superk
Advanced


Joined: 19 Dec 2002
Posts: 684
Topics: 5

PostPosted: Fri Feb 06, 2004 2:28 pm    Post subject: Reply with quote

The two solutions that come immediately to mind are SAS (using the ODS utility for generating CSV output) or REXX.
Back to top
View user's profile Send private message
shiv_swami
Beginner


Joined: 29 Nov 2003
Posts: 68
Topics: 14

PostPosted: Fri Feb 06, 2004 3:21 pm    Post subject: Reply with quote

Thanks Kolusu,

I do have easytrieve at our shop.Also we need not bother about leading spaces on numbers.But trailing spacess removal from Alphanumeric fields is absolutely required.
_________________
Regards,
Shivprakash
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Feb 09, 2004 10:12 am    Post subject: Reply with quote

Shiv,

The following easytrieve will give you the desired results. I wrote this code on the fly and may not be the optimal one but will give you the desired results.


Code:
                                                                     
  FILE FILEIN                                                           
       WS1-CONTRACT-NBR              1   20  A                         
       WS1-OWNED-BY                 22   20  A                         
       WS1-PHASE                    43   01  A                         
       WS1-FINANCIAL-PRODUCT        45   20  A                         
       WS1-CONTRACT-TERM            66   03  A                         
       WS1-LENGTH-PAY-PERIOD        70   02  A                         
                                                                       
  W-STRING  W 20 A                                                     
    W-STR  W-STRING 01 A OCCURS 20                                     
                                                                       
  W-SUB              W  02  N 0                                         
  W-START-POS        W  02  N 0 VALUE 1                                 
  W-END-POS          W  02  N 0                                         
  W-DLM              W  01  A VALUE X'05'                               
  W-STR-FOUND        W  01  A VALUE 'N'                                 
                                                                       
  FILE FILEOUT FB(0 0)                                                 
       O-REC         01 80 A                                           
       OUT-REC       01 01 A OCCURS 72                                 
                                                                       
  JOB INPUT(FILEIN)                                                     
                                                                       
    O-REC          = ' '                                               
    W-STRING       = WS1-CONTRACT-NBR                                   
    PERFORM TRIM-SPACE                                                 
                                                                       
    W-STRING       = ' '                                               
    W-STRING       = WS1-OWNED-BY                                       
    W-START-POS    = W-START-POS  +  1                                 
    PERFORM TRIM-SPACE                                                 
                                                                       
    W-START-POS    = W-START-POS  +  1                                 
    MOVE WS1-PHASE TO OUT-REC (W-START-POS) (1)                         
                                                                       
    W-START-POS    = W-START-POS  +  1                                 
    MOVE W-DLM     TO OUT-REC (W-START-POS) (1)                         

                                                       
   W-STRING       = ' '                               
   W-START-POS    = W-START-POS  +  1                 
   W-STRING       = WS1-FINANCIAL-PRODUCT             
   PERFORM TRIM-SPACE                                 
                                                       
   W-STRING       = ' '                               
   W-START-POS    = W-START-POS  +  1                 
   W-STRING       = WS1-CONTRACT-TERM                 
   PERFORM TRIM-ZERO1                                 
                                                       
   W-STRING       = ' '                               
   W-START-POS    = W-START-POS  +  1                 
   W-STRING       = WS1-LENGTH-PAY-PERIOD             
   PERFORM TRIM-ZERO2                                 
   PUT FILEOUT                                         
                                                       
TRIM-SPACE. PROC                                       
                                                       
  W-SUB        = 20                                   
  W-STR-FOUND  = 'N'                                   
                                                       
  DO UNTIL W-SUB LE 1  OR W-STR-FOUND = 'Y'           
     IF W-STR (W-SUB) = ' '                           
        W-SUB         = W-SUB  - 1                     
     ELSE                                             
        W-STR-FOUND   = 'Y'                           
        MOVE W-STR (1) (W-SUB)   +                     
             TO OUT-REC (W-START-POS) (W-SUB)         
        W-START-POS   = W-START-POS + W-SUB           
        MOVE W-DLM TO OUT-REC (W-START-POS) (1)       
   END-IF                                             
  END-DO                                               
                                                       
END-PROC                                               
                                                       
                                                         
 TRIM-ZERO1. PROC                                         
                                                         
   W-SUB        = 1                                       
   W-STR-FOUND  = 'N'                                     
   DO UNTIL W-SUB GT 3 OR W-STR-FOUND = 'Y'               
      IF W-STR (W-SUB) = '0'                             
         W-SUB         = W-SUB  + 1                       
      ELSE                                               
         W-STR-FOUND   = 'Y'                             
         W-END-POS     = 4 -  W-SUB                       
         MOVE W-STR (W-SUB)  (W-END-POS)  +               
              TO OUT-REC (W-START-POS) (W-END-POS)       
         W-START-POS   = W-START-POS + W-SUB             
         MOVE W-DLM TO OUT-REC (W-START-POS) (1)         
    END-IF                                               
   END-DO                                                 
                                                         
 END-PROC                                                 
                                                         
 TRIM-ZERO2. PROC                                         
                                                         
   W-SUB        = 1                                       
   W-STR-FOUND  = 'N'                                     
                                                         
   DO UNTIL W-SUB GT 2 OR W-STR-FOUND = 'Y'               
      IF W-STR (W-SUB) = '0'                             
         W-SUB         = W-SUB  + 1                       
      ELSE                                               
         W-STR-FOUND   = 'Y'                             
         W-END-POS     = 3 -  W-SUB                       
         MOVE W-STR (W-SUB) (W-END-POS)  +               
              TO OUT-REC (W-START-POS) (W-END-POS)       
         W-START-POS   = W-START-POS + 1                 
         MOVE W-DLM TO OUT-REC (W-START-POS) (1)         
    END-IF                                               
   END-DO                                                 
                                                         
 END-PROC                                                 


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shiv_swami
Beginner


Joined: 29 Nov 2003
Posts: 68
Topics: 14

PostPosted: Thu Feb 12, 2004 3:36 am    Post subject: Reply with quote

Thanks Kolusu,

The requirement was changed & my team was not sure what to do in that case.So we could not test your solution.I will do it rightaway and let you know..
Meantime I started developing my own utility to do it generic ....I have written a cobol program which would take input file layout & load into a table and then use reference modification to INSPECT & STRING the contents of fields.The delimiter would be passed thru Linkage section.I will work on the remaining routines when time permits and post the solution over here.

Apologies for not giving feedback to your solution quickly enough.
_________________
Regards,
Shivprakash
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group