Documente Academic
Documente Profesional
Documente Cultură
********************************************************************
! PROGRAM NAME: hcsvread.sqr
! DESCRIPTION: Read csv file(column with embeded commas)
!********************************************************************
! AUTHOR:
Govinda Rao. Balikara
! DATE:
2012 Feb 03
!********************************************************************
!********************************************************************
! Procedure: main
! Description: main Process
!********************************************************************
begin-procedure main
do main
end-program
begin-procedure main
do get_file_path
do process_data_file
end-procedure !main
!**********************************************************************
! Procedure:
get_file_path
! Description: get_file_path
!**********************************************************************
begin-procedure get_file_path
let $INPUT_FILE = 'C:\Temp\test.csv'
#ifdef debugE
show ''
show 'Full Filename: ' $INPUT_FILE
show ''
#endif
end-procedure !get_file_path
!**********************************************************************
! Procedure:
process_data_file
! Description: process_data_file
!**********************************************************************
begin-procedure process_data_file
open $INPUT_FILE as 1 for-reading record = 1000:vary status=#FILE_STATUS
if #FILE_STATUS = 0
show 'File open successful: ' $INPUT_FILE
show ''
else
show 'Error in opening file: ' $INPUT_FILE
stop
end-if
while 1
read 1 into $INPUT_RECORD:1000
if #end-file
#ifdef debugE
show 'End of File Reached '
#endif
break
end-if
#ifdef debugE
show 'Input file: ' $INPUT_RECORD
#endif
let #COUNT = 0
let #QUOTES_EXISTS = 1
let #POSITION = 1
while #COUNT < #QUOTES_EXISTS
if instr($INPUT_RECORD, '"', #POSITION) <> 0
let #QUOTES_EXISTS = 1
let #START_POINT = INSTR($INPUT_RECORD, '"',#POSITION)
let #POSITION = #START_POINT
let #END_POINT = INSTR($INPUT_RECORD, '"', #POSITION +1)
let #DIFER = #END_POINT - #START_POINT
let $STRING1 = SUBSTR($INPUT_RECORD, #START_POINT, #DIFER+1)
let $STRING2 = replace($STRING1, ',', '~')
let $INPUT_RECORD = replace($INPUT_RECORD, $STRING1, $STRING2)
else
let #QUOTES_EXISTS = 0
end-if
let #POSITION = #END_POINT + 1
end-while
unstring $INPUT_RECORD by ',' into $FIELD1 $FIELD2 $FIELD3 $FIELD4 $FIELD5 $FIEL
D6 $FIELD7 $FIELD8 $FIELD9 $FIELD10
$FIELD11 $FIELD12 $FIELD13 $FIELD14 $FIELD15 $FIELD16 $FIELD17 $FIELD18 $FIELD
19 $FIELD20
$FIELD21 $FIELD22 $FIELD23 $FIELD24 $FIELD25 $FIELD26 $FIELD27 $FIELD28 $FIELD
29 $FIELD30
$FIELD31 $FIELD32 $FIELD33 $FIELD34 $FIELD35 $FIELD36 $FIELD37 $FIELD38 $FIELD
39 $FIELD40
$FIELD41 $FIELD42 $FIELD43 $FIELD44 $FIELD45 $FIELD46 $FIELD47 $FIELD48 $FIELD
49 $FIELD50
$FIELD51 $FIELD52 $FIELD53
let
let
let
let
let
let
let
let
$FIELD1
$FIELD2
$FIELD3
$FIELD4
$FIELD5
$FIELD6
$FIELD7
$FIELD8
=
=
=
=
=
=
=
=
ltrim(rtrim(replace(replace($FIELD1,
ltrim(rtrim(replace(replace($FIELD2,
ltrim(rtrim(replace(replace($FIELD3,
ltrim(rtrim(replace(replace($FIELD4,
ltrim(rtrim(replace(replace($FIELD5,
ltrim(rtrim(replace(replace($FIELD6,
ltrim(rtrim(replace(replace($FIELD7,
ltrim(rtrim(replace(replace($FIELD8,
'~',','),
'~',','),
'~',','),
'~',','),
'~',','),
'~',','),
'~',','),
'~',','),
'"',''),'
'"',''),'
'"',''),'
'"',''),'
'"',''),'
'"',''),'
'"',''),'
'"',''),'
'),
'),
'),
'),
'),
'),
'),
'),
'
'
'
'
'
'
'
'
')
')
')
')
')
')
')
')
let
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
let
)
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show
show '$FIELD31:
show '$FIELD32:
show '$FIELD33:
show '$FIELD34:
show '$FIELD35:
show '$FIELD36:
show '$FIELD37:
show '$FIELD38:
show '$FIELD39:
show '$FIELD40:
show '$FIELD41:
show '$FIELD42:
show '$FIELD43:
show '$FIELD44:
show '$FIELD45:
show '$FIELD46:
show '$FIELD47:
show '$FIELD48:
show '$FIELD49:
show '$FIELD50:
show '$FIELD51:
show '$FIELD52:
show '$FIELD53:
show ''
end-while
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
$FIELD31
$FIELD32
$FIELD33
$FIELD34
$FIELD35
$FIELD36
$FIELD37
$FIELD38
$FIELD39
$FIELD40
$FIELD41
$FIELD42
$FIELD43
$FIELD44
$FIELD45
$FIELD46
$FIELD47
$FIELD48
$FIELD49
$FIELD50
$FIELD51
$FIELD52
$FIELD53
close 1
end-procedure !process_data_file