[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

RE: [sqr-users] Reading from a tab delimited file



1-First open the file:

!----------------------------------------------------------------------!
! Procedure: Open-Flat-File                                            !
! Desc:      This procedure opens the file that will be read from.     !
!----------------------------------------------------------------------!
begin-procedure Open-Flat-File

  DISPLAY ' Open-Flat-File '
        
  let $newfile = 'folder_path\file.txt'
  open $newfile as 1 for-reading record=700:vary status=#secondfile

  if #secondfile != 0
     let $error_lit = 'error opening file'
     display $error_lit (0,+2)
     display $file ()
  else
     let $file_open = 'Y'
     display 'successful opening file'
  end-if     

END-PROCEDURE  

2- Extract the data:

!----------------------------------------------------------------------!
! Procedure: Extract-Row                                               !
! Desc:      This procedure reads the data from the flat file.         !
!----------------------------------------------------------------------!
begin-procedure Extract-Row
  
  DISPLAY ' Extract-Row '

  while not #end-file

    let $RecordData = ' '
    read 1 into $RecordData:500

    Let $RecordData = ltrim(rtrim($RecordData,' '),' ')
    let #space = instr($RecordData,' ',1)    

    extract $var1      from $RecordData 0 5 (position and char. Length)
    extract $var2        from $RecordData 11 6
    extract $var3       from $RecordData 20 5   
    

    Let $var1 = ltrim(rtrim($var1,' '),' ')
    Let $var2 = ltrim(rtrim($2,' '),' ')
    Let $var3 = ltrim(rtrim($var3,' '),' ')......and so on.
DISPLAY ' END-Extract-Row '

end-procedure


Good luck,

José A. Aguirre

-----Original Message-----
From: sqr-users-bounces+jaguir=lsuhsc.edu@sqrug.org 
[mailto:sqr-users-bounces+jaguir=lsuhsc.edu@sqrug.org] On Behalf Of Ryan, David
Sent: Wednesday, October 04, 2006 1:48 PM
To: sqr-users@sqrug.org
Subject: [sqr-users] Reading from a tab delimited file

Hello,
 
I'm trying to read from a tab delimited .txt file and insert values into 
variables.
I do not now know what the length of each field within the file is.
Could someone provide an example that would allow me to start at the beginning 
of a line, read from the beginning to the first tab, insert into a variable; 
read from the first tab to second tab, insert into a variable.....and so on...
 
thanks
 
 


The information contained in this email is strictly confidential and subject to 
the Confidentiality Notice at http://www.stratosglobal.com/email-privacy.html



_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users

_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users