@Eduard Lebedyuk@Cristiano Silva Sorry if I was not clear I still need the whole XML Serial B and SerialC if populated and if I populate One segment I do not need the Other to appear.
@Eduard Lebedyuk I have classes with the similar structure in your test.Serial class I have Two properties Serial1 and Serial2 as test.Serial1 and 2 respectively and i would like to print out XML maybe populate Serial 1 and have Serial2 as an empty object and Leave it out when printing.How do I controll that ?,as it stands it prints out the empty elements even when ignore null is set.Please not all is the same as above so I am printing from a persistent Level.The difference being I have two serial objects properties In my test.Serial equavalent
This will do exactly what you want any problems give us shout
ClassMethod ImpCSV(fileName As %String = "C:\filepath where csv file is")
{
;;Refresh globals data at the begin of proecess
;;globals hold the file being written to data and the count of lines each file has
k ^ufile,^ufile2,^counter,^counter2
set Reader =##class(%Stream.FileCharacter).%New()
;;link to the file to read
set status=Reader.LinkToFile(fileName)
if $$$ISERR(status)
{
do $System.Status.DisplayError(status)
}
;;initialise the counter for the file lines to write to one file
set ^counter =0
set ^counter2 =0
set ^ufile=""
set ^ufile2=""
;;the count for the lines read in
set lineCount=0
;;start process the lines
while 'Reader.AtEnd
{
;;read the incoming file
set line=Reader.ReadLine()
;;increment the line count by one as you read the next line
set lineCount=lineCount+1
;;piece the column to check
;;one is for the first column and so on
;;string at after the equal sign is the value to check for
if ($piece(line,",",1)="Religion")
{
;;increment count for this file
set ^counter=^counter+1
;;the counter is at one to assign the file path to write to
if (^counter=1)
{
;;set the file name to write to the global
set ^ufile=..writeFileOut("fileone",".csv",line,,^counter)
}
else
{
;;check the count has no reached the limit for the number of lines to write to
if (^counter=51)
{
;;reset the count if limit reach
set ^counter=1
;;new file
set ^ufile =..writeFileOut("fileone",".csv",line,,^counter)
}
else
{
;;use the current file
do ..writeFileOut(,,line,,^counter,"REG")
}
}
}
;;second check for the next set of data if you have more than
;;two to check for copy the below and change accordingly to accommodate the next check
;;same as above
if ($piece(line,",",1)="description")
{
;;set attributes for the second file to write to
set ^counter2=^counter2+1
if (^counter2=1)
{
set ^ufile2=..writeFileOut("fileTwo",".csv",line,,^counter2)
}else
{
if (^counter2=51)
{
set ^counter2=1
;;new file
set ^ufile2= ..writeFileOut("fileTwo",".csv",line,,^counter2)
}else
{
do ..writeFileOut(,,line,,^counter2,"DESC")
}
}
}
}
kill ^ufile,^ufile2
}
ClassMethod writeFileOut(filename, fileext As %String, line As %String, directory = "C:\directory to store files", linecount As %Integer, FileToUse)
{
set oLF = ##class(%Library.File).%New()
if (linecount=1)
{
Set filenam=directory_filename_$i(^timmmy)_fileext
set oLF.Name=filenam
if (oLF.Open("wns"))
{
set linecount=linecount+1
do oLF.WriteLine(line)
do oLF.Close()
;;w oLF.Name
quit oLF.Name
}
}else
{
if (FileToUse="DESC")
{
if (^ufile2'="")
{
set oLF.Name=^ufile2
}
}elseif(FileToUse="REG")
{
if (^ufile'="")
{
set oLF.Name=^ufile
}
}
If (##class(%File).Exists(oLF.Name))
{
Do oLF.Open("EWA")
if (linecount'=51)
{
set linecount=linecount+1
do oLF.WriteLine(line)
do oLF.Close()
quit oLF.Name
}
}
}
}
Yes %Populate exists but that's not what I am referring to the above is the correct answer by Alexander Koblov. I was referring to this class %Library.CachePopulate not what you are pointing me to
@Tomas Vaverka Yes that right but I know that the question may be was not clear I have an object class which has two properties one a string and a stream and was trying to pass that object ,all I could do was pass a string and an empty stream but I have read around the stream and found out that I can pass a stream as a stream but not inside an object thanks again
@Hansel Gaete Was wondering did you get this problem solved I also have an object with a stream property that I am trying to return in a soap response and is blank but in the trace on the production is populated any help appreciated
go to post
@Eduard Lebedyuk @Cristiano Silva
Sorry if I was not clear I still need the whole XML Serial B and SerialC if populated and if I populate One segment I do not need the Other to appear.
go to post
@Eduard Lebedyuk
I have classes with the similar structure in your test.Serial class I have Two properties Serial1 and Serial2 as test.Serial1 and 2 respectively and i would like to print out XML maybe populate Serial 1 and have Serial2 as an empty object and Leave it out when printing.How do I controll that ?,as it stands it prints out the empty elements even when ignore null is set.Please not all is the same as above so I am printing from a persistent Level.The difference being I have two serial objects properties In my test.Serial equavalent
go to post
This will do exactly what you want any problems give us shout
go to post
Hi Jenna Poindexter
Yes %Populate exists but that's not what I am referring to the above is the correct answer by Alexander Koblov. I was referring to this class %Library.CachePopulate not what you are pointing me to
go to post
@Alexander Koblov thank you
go to post
does it work if you revert to the original state?
go to post
@Suman Samanta
Please have a look at this question I posted earlier if you still need more code let me know here
go to post
@Tomas Vaverka
Yes that right but I know that the question may be was not clear I have an object class which has two properties one a string and a stream and was trying to pass that object ,all I could do was pass a string and an empty stream but I have read around the stream and found out that I can pass a stream as a stream but not inside an object thanks again
go to post
@Hansel Gaete
I am trying to send a pdf document encoded to base64 which means the size could vary depending on the document
go to post
@Hansel Gaete
Was wondering did you get this problem solved I also have an object with a stream property that I am trying to return in a soap response and is blank but in the trace on the production is populated any help appreciated