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 

Fixed length file to CSV file - using easytrieve

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


Joined: 24 Mar 2006
Posts: 27
Topics: 14

PostPosted: Wed Dec 12, 2007 5:53 pm    Post subject: Fixed length file to CSV file - using easytrieve Reply with quote

I need to convert a Fixed length file to CSV file programatically (Batch Job) using easytrieve or cobol or Syncsort ? Can someone help me with sample code if you already tried it before?

Code:


Input:

AA   BBB    CCC
XX   YYYY   ZZZZZ
XC   AX     A

The output:

AA,BBB,CCC
XX,YYYY,ZZZZZ
XC,AX,Z


Thanks!
Dip.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Dec 12, 2007 10:49 pm    Post subject: Reply with quote

Dip,


That is simple task in any programming language. read each record as a single byte array and check if it is a space. If you find a space move comma and scan until you find non-space character.

untested ezt code

Code:

  FILE INFILE                                                 
       IN-REC           01 001 A OCCURS 80 INDEX IDX           
                                                               
  FILE OUTPUT                                                 
       O-REC            01 080 A                               
       O-CHAR           01 001 A OCCURS 80 INDEX ODX           
                                                               
   S-PUT-COMMA   W 01 A

***********************************************************************
* MAINLINE                                                            *
***********************************************************************
                                                                       
 JOB INPUT INFILE                                                     
                                                                       
   IDX         = 1
   ODX         = 1                                                           
   O-REC       = ' '                                                         
   S-PUT-COMMA = 'N'
 
   DO UNTIL IDX > 80
      IF IN-REC(IDX)    NE ' '
         IF S-PUT-COMMA = 'Y'
            O-CHAR(ODX) = ','
            ODX         = ODX + 1
            S-PUT-COMMA = 'N'
         END-IF                                             

         O-CHAR(ODX)    = IN-REC(IDX)
         IDX            = IDX + 1
         ODX            = ODX + 1
      ELSE 
         S-PUT-COMMA    = 'Y'
         IDX            = IDX + 1
      END-IF                                                           
   END-DO   
                                                         
   PUT OUTPUT                                                         
/*       

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


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Thu Dec 13, 2007 12:23 am    Post subject: Reply with quote

Dip,

If u have DFSORT, following will do what u asked for:

Code:


//S1    EXEC  PGM=ICEMAN                           
//SYSOUT    DD  SYSOUT=*                           
//SORTIN DD *                                     
AA   BBB    CCC                                   
XX   YYYY   ZZZZZ                                 
XC   AX     A                                     
/*                                                 
//SORTOUT DD SYSOUT=*                             
//SYSIN    DD    *                                 
  OPTION COPY                                     
  INREC OVERLAY=(1,80,SQZ=(SHIFT=LEFT,MID=C','))   
/*                                                 

_________________
Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay)
Back to top
View user's profile Send private message
Dip
Beginner


Joined: 24 Mar 2006
Posts: 27
Topics: 14

PostPosted: Thu Dec 13, 2007 2:31 pm    Post subject: Reply with quote

Thanks Kolusu!

You make the logic so simple..yesterday i started with COBOL and made the logic very complex (String reverse/ calculate the length / put comma / trim the spaces...) and finally i gave up...

I tested your code and its working fine.

Thanks Vivek for your reply!

Regrads
Dip.
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 -> Application Programming 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