Parsing a "csv" file in QTP
Neil Harvey
neil@nha.co.za
Mon, 25 Sep 2000 07:26:23 +0200
Here is a snippet from a QTP I wrote. Target was HP3000 (initially 7.09).
This one handles 10 fields (max size 50 chars).
Wfile is defined the dictionary as a 1024byte file with one field called
w-rec.
You wil end up with a subfile with fields f01 to f10 holding the contents of
each comma delimited field.
You can extend it to handle your own requirements.
Hope it helps.
Regards
Neil
request csv2sub on calc errors report
access wfile
temp P00 int
temp P01 int
temp P02 int
temp P03 int
temp P04 int
temp P05 int
temp P06 int
temp P07 int
temp P08 int
temp P09 int
temp P10 int
temp P11 int
temp t-rec char*2050
item t-rec = trunc(W-REC) + ","
item P00 = 0
item P01 = P00 + index(t-rec[P00 + 1:1024],",")
item P02 = P01 + index(t-rec[P01 + 1:1024],",")
item P03 = P02 + index(t-rec[P02 + 1:1024],",")
item P04 = P03 + index(t-rec[P03 + 1:1024],",")
item P05 = P04 + index(t-rec[P04 + 1:1024],",")
item P06 = P05 + index(t-rec[P05 + 1:1024],",")
item P07 = P06 + index(t-rec[P06 + 1:1024],",")
item P08 = P07 + index(t-rec[P07 + 1:1024],",")
item P09 = P08 + index(t-rec[P08 + 1:1024],",")
item P10 = P09 + index(t-rec[P09 + 1:1024],",")
temp LL int
item LL = size(trunc(t-rec))
def F01 char*50 = t-rec[(P00 + 1):(P01 - P00 - 1)] if P00 = 0
def F02 char*50 = t-rec[(P01 + 1):(P02 - P01 - 1)] if P01 <> LL
def F03 char*50 = t-rec[(P02 + 1):(P03 - P02 - 1)] if P02 <> LL
def F04 char*50 = t-rec[(P03 + 1):(P04 - P03 - 1)] if P03 <> LL
def F05 char*50 = t-rec[(P04 + 1):(P05 - P04 - 1)] if P04 <> LL
def F06 char*50 = t-rec[(P05 + 1):(P06 - P05 - 1)] if P05 <> LL
def F07 char*50 = t-rec[(P06 + 1):(P07 - P06 - 1)] if P06 <> LL
def F08 char*50 = t-rec[(P07 + 1):(P08 - P07 - 1)] if P07 <> LL
def F09 char*50 = t-rec[(P08 + 1):(P09 - P08 - 1)] if P08 <> LL
def F10 char*50 = t-rec[(P09 + 1):(P10 - P09 - 1)] if P09 <> LL
:purge subf1
subfile subf1 keep include &
f01, &
f02, &
f03, &
f04, &
f05, &
f06, &
f07, &
f08, &
f09, &
f10
set pro lim 1000000
set lock update
go
-----Original Message-----
From: Latimer, Richard [mailto:richard.latimer@airways.co.nz]
Sent: Monday, September 25, 2000 1:33 AM
To: PowerHouse List (E-mail)
Subject: Parsing a "csv" file in QTP
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?
We are on 6.07E on AS/400
Richard Latimer
Wellington MIS Manager
Airways New Zealand
DDI + 64 4 471-4744
FAX + 64 4 471-0395
**********************************************************************
This electronic message together with any attachments is confidential. If
you receive it in error: (i) you must not use, disclose, copy or retain it;
(ii) please contact the sender immediately by reply email and then delete
the emails. Views expressed in this email may not be those of the Airways
Corporation of New Zealand Limited
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.