Question
· Sep 17, 2020

Bulk load csv into global

Is there a way to bulk load csv into a global? I have a csv with 283 lines in the following pattern

123, first text

234, second text

456, third text

I want to load them into a global ^loader(code, text). Is there a way to upload them using code?

Discussion (4)0
Log in or sign up to continue

You'll need to do the ReadLine() just once in each iteration of the loop so that you don't get the P1 from one line pairing with the P2 from the next line, something like this:

set file=##class(%Stream.FileCharacter).%New()

do file.LinkToFile("c:\location of csv")

for  quit:file.AtEnd  set line=file.ReadLine() set ^GLOBAL($piece(line,",",1),$piece(line,",",*))=""