Parsing a "csv" file in QTP
Jeff Hoffman
JeffHoffman@goconnect.net
Sat, 30 Sep 2000 18:15:54 +1000
Richard
you wrote:
>Greetings listland . . .
>
>I have a pressing requirement to parse a comma separated file into it's
>component fields - preferably using QTP although Quick, Quiz and IBM's
>AS/400 Control Language are available. The input file is a known quantity
>and will always contain the same number of data items.
>
>Has anyone tried this before or got any suggestions on how to go about it
>efficiently?
Here is another solution
Create a file in FDL, I use 400 chars as I have several different files of
varying length. You will need to modify you file to the fixed length.
Then use QTP to load the data to the database or a subfile.
;****************
Element temprec char*400
File tempfile &
Organization direct &
Type MPE &
Description &
"File used as a generic intermediate file when transferring" &
"data from PC data being in tab delimited format"
Record tempfile
item temprec
;****************
REQUEST format_pc_data
acc tempfile
def file_len = 400 ; record length of tempfile
def delim char*1 = "," ; or anyother separating character(s).
temp col_a char*30
temp col_bc char*8
temp col_b num*8
temp col_c char*40
temp strt
temp endd
; Extract Data
; Col A
item strt = 1
item endd = index(temprec[strt:file_len -strt],delim)
item col_a = upshift(lj(temprec[strt:endd -1]))
; Col B
item strt = strt + endd
item endd = index(temprec[strt:file_len -strt],delim)
item col_bc = upshift(lj(temprec[strt:endd -1]))
item col_b = ncon(col_bc)