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

using substr() and instr() to identify patterns of fields



Please excuse this lengthy post --
 
I am trying to write the contents of one field in a csv file to a txt file ( I also need the other fields later on  in the SQR).
 
The problem:
On unstring, the SQR assigns the text only from the first line to $RESUME_TXT, and then everything following gets thrown off. If I comment out this field, then everything else runs fine.
 
In trying to address that problem,
I tried using substr() and instr() to identify patterns of the fields preceding and following the clunker resume field. The preceding field always starts with 4 zeroes and the field following is always a date field in the format DD/MM/YYYY.
 
Now, I have a second problem as well - I get an error that 'Specified file number not opened for writing."
 
Is my substr() and/or instr() syntax right?
 
Here is my code:
 
!*********************************************
Begin-Program
!*********************************************
  Let $Input_File = 'H:\EmpACT_Work_Area\Empact_out.csv'
  Show '$Input_File = ' $Input_File
 
  Open $Input_File as 1 For-Reading Record=1000 Status=#OpenStat
  If #OpenStat != 0
        Show 'Error Opening ' $Input_File
  Else
        Show  $Input_File ' has been opened for reading.'
  End-If
 
Do Read-Input-File
 
End-Program
!*********************************************
Begin-Procedure Read-Input-File
!*********************************************
Show 'Now reading ' $Input_File
 Move 0 To #Tot_Recs
 
 While Not #end-file
  Read 1 Into $Input:1000
  If #end-file
    Break
  End-If
 
  Unstring $Input By ',' Into
  $EMPLID
  $RESUME_TXT     !<----- this is the scanned resume field
  $MOD_DTTM
  $MOD_USER
  $BRANCH_ID
  $SSN
  $FIRST_NAME
  $MIDDLE_NAME
  $LAST_NAME
  $ADDRESS1
  $CITY
  $STATE
  $ZIP
  $COUNTY
 
  Add 1 to  #Tot_Recs
  Display 'Total records exported: ' Noline
  Display #Tot_Recs 999,999,999
 
  Let $RESUME_FILE_NAME = $EMPLID ||'.txt'
  Show '$RESUME_FILE_NAME = ' $RESUME_FILE_NAME
 
  Let $RESUME_TEXT_FILE = 'd:\temp\'||$RESUME_FILE_NAME      
  Show '$RESUME_TEXT_FILE = ' $RESUME_TEXT_FILE
 
  If substr($read,1,4) = '0000'
   Open $RESUME_TEXT_FILE as 2 For-Writing Record=1000 Status=#OpenStat
 
   If #OpenStat != 0
      Show 'Error opening ' $RESUME_TEXT_FILE
   Else
       Show $RESUME_TEXT_FILE ' has been opened for writing.'
   End-If
  End-if

  Write 2  from $read
 
  If instr($read, '/', 4) = 3
   and instr($read, '/', 4) = 6
  Close 2
  End-if
 
  End-While

 Display 'Total Records Inserted: ' Noline
 Display #Tot_Recs 999,999,999

End-Procedure
*****************************************************************************************
As always, thanks in advance!
Joe Johnson
PeopleSoft Systems Analyst
joejo@snellingcorp.com
972-776-1332