go to post Vitaliy Serdtsev · Apr 6, 2018 My best result is 77 72 69 67 so far. Class ITPlanet.Task4 [ Abstract ] { ClassMethod main(s As %Integer = 10) { f x=1:1:s w ! f y=1:1:s w $c(y#s<2!$lf($lb(1,s,y,s-y+1),x)*3+32) } ClassMethod length( class = {$classname()}, method = "main") As %Integer [ CodeMode = expression ] { ##class(%Dictionary.MethodDefinition).IDKEYOpen(class, method).Implementation.Size } } USER>w ##class(ITPlanet.Task4).length() 67 USER>d ##class(ITPlanet.Task4).main(11) ########### ## ## # # # # # # # # # # # # # # # # # # # # # # # # # # # ## ## ###########
go to post Vitaliy Serdtsev · Mar 27, 2018 Make two changes to your code: /// return json Method infoJson() As %String [ WebMethod ] { set soapresponse=##class(webservice.SOAPResponse).%New() set soapresponse.CustomerID="1" set soapresponse.Name="2" set soapresponse.Street="3" set soapresponse.City="4" set soapresponse.State="5" set soapresponse.Zip="6" set stream=##class(%Stream.TmpBinary).%New() do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(stream,soapresponse,,,$$$YES,"s") quit stream.Read($$$MaxStringLength) } /// write ##class(PRD.Test).test1() ClassMethod test1() As %String { set soapresponse=##class(webservice.SOAPResponse).%New() set soapresponse.CustomerID="1" set soapresponse.Name="2" set soapresponse.Street="3" set soapresponse.City="4" set soapresponse.State="5" set soapresponse.Zip="6" set stream=##class(%Stream.TmpBinary).%New() do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(stream,soapresponse,,,$$$YES,"s") quit stream.Read($$$MaxStringLength) }
go to post Vitaliy Serdtsev · Mar 5, 2018 Fixed bugs/typos and added new types. #include %PVA types ; Show COS-Datatypes ; kav ; 2018-03-04 n array,i,bitstring s $bit(bitstring,1) = 1 w "№",?4,"VALUE",?30,"JSON",?45,"$LISTBUILD",!,$TR($J("",55)," ","-"),! s array=[ (bitstring), ($ZBITSET($ZBITSTR(4,1),2,0)), ($lb("")), null, true, false, (##class(%ZEN.proxyObject).%New()), [], {}, "abcd", ($wc(35222)), "2", 2, -2, 2.1, -2.1, ($double(2.1)) ] s array."18"=2 s array."19"=-2 f i=0:1:array.%Size() { w i,")",?4,array.%Get(i),?30,$$TypeOf1(.array,i),?45,$$TypeOf2(array.%Get(i)),! } // Return JSON datatype by the documented way // TypeOf1(&array,key) { s typ=array.%GetTypeCodeOf(key) q typ_" "_$case(typ, $$$PVVALUENULL:"null", $$$PVVALUETRUE:"boolTrue", $$$PVVALUEFALSE:"boolFalse", $$$PVVALUEINTEGERPOS:"+int", $$$PVVALUEINTEGERNEG:"-int", $$$PVVALUEUNUSED1:"unused", $$$PVVALUEARRAY:"array", $$$PVVALUEOBJECT:"object", $$$PVVALUETEXT:"text", $$$PVVALUENUMBER:"number", $$$PVVALUEOVERFLOW:"overflow", $$$PVVALUECACHENUMERIC:"cacheNumeric", $$$PVVALUEOREF:"oref", $$$PVVALUEUNASSIGNED:"unassigned", $$$PVVALUELONGPOS:"+long", $$$PVVALUELONGNEG:"-long", $$$PVVALUEBYTE:"byte[]", $$$PVVALUEDATETIME:"dateTime", $$$PVVALUEDOUBLE:"double", $$$PVVALUESINGLE:"single", $$$PVVALUEUTF8:"utf8", $$$PVVALUENESTED:"nested", $$$PVVALUEEOF:"eof", :"unknown") } // Return datatype by the undocumented $LB() way // TypeOf2(val) { i $l(val)>253 { s typ=$ziswide(val)+1 } else { s typ=$a($lb(val),2) } q typ_" "_$case(typ ,1:"8bitString" ,2:"16bitString" ,4:"nonNegativeInteger" ,5:"negativeInteger" ,6:"nonNegativeFloat" ,7:"negativeFloat" ,8:"double" , :"??? never seen before") }Result: USER>d ^types № VALUE JSON $LISTBUILD ------------------------------------------------------- 0) 8 text 1 8bitString 8 text 1 8bitString 2) 8 text 1 8bitString 3) 0 null 1 8bitString 4) 1 1 boolTrue 1 8bitString 5) 0 2 boolFalse 1 8bitString 6) 4@%ZEN.proxyObject 12 oref 1 8bitString 7) 2@%Library.DynamicArray 6 array 1 8bitString 8) 1@%Library.DynamicObject 7 object 1 8bitString 9) abcd 8 text 1 8bitString 10) 視 8 text 2 16bitString 11) 2 8 text 1 8bitString 12) 2 9 number 4 nonNegativeInteger 13) -2 9 number 5 negativeInteger 14) 2.1 9 number 6 nonNegativeFloat 15) -2.1 9 number 7 negativeFloat 16) 2.1000000000000000888 18 double 8 double 17) 13 unassigned 1 8bitString 18) 2 3 +int 4 nonNegativeInteger 19) -2 4 -int 5 negativeInteger 20) 31 eof 1 8bitString
go to post Vitaliy Serdtsev · Mar 3, 2018 On my desktop quite other results. n N,j,time s N=1e8 f j=1,2/*,3,4,5*/ { w j,") " s time=$zh d @("j"_j)(N) w $zh-time," s.",! } q j1(N) public { f i=1:1:N {s (a,b,c,d,e,f)=0} } j2(N) public { f i=1:1:N {s a=0,b=0,c=0,d=0,e=0,f=0} } j3(N) public { f i=1:1:N {s a=0,b=1,c=2,d=3,e=4,f=5} } j4(N) public { f i=1:1:N {s a=0 s b=1 s c=2 s d=3 s e=4 s f=5} } j5(N) public { f i=1:1:N {s $lb(a,b,c,d,e,f)=$lb(0,1,2,3,4,5)} }Results: USER>d ^perf 1) 11.814189 s. 2) 4.683832 s.As you can see the difference is almost 2.5 times.
go to post Vitaliy Serdtsev · Feb 2, 2018 I also want to note that s (a,b,c)=0 is slower than s a=0,b=0,c=0
go to post Vitaliy Serdtsev · Feb 2, 2018 Please note that the option with %INLIST does not yet use “collection” indexes, and will therefore be slower than the one provided above proof
go to post Vitaliy Serdtsev · Dec 29, 2017 Undefined variable and the variable contains "" (null) is two different situations, e.g. (see $DATA): kill myObj write $data(myObj),! ; -> 0 set myObj=$$$NULLOREF write $data(myObj),! ; -> 1In your case it would be better to use $IsObject: kill myObj write $IsObject(myObj),! ; -> 0 set d=$$$NULLOREF write $IsObject(myObj),! ; -> 0 set myObj={} write $IsObject(myObj),! ; -> 1Accordingly, should be do $$$AssertTrue('$IsObject(myObj), "myObj is null")
go to post Vitaliy Serdtsev · Dec 29, 2017 You are right, the macro $$$NULL present only in %sqlMigration.inc and this is not the file that developers often include to its project.I prefer to use the macro $$$NULLOREF/$$$NULLOID from %occExtent.inc, which is available by default in the class that inherits from %Library.Base, and for routines is enough to include %systemInclude.inc.
go to post Vitaliy Serdtsev · Dec 28, 2017 Why so difficult?This similarly following condition: WHERE ( year(current_date) - year(DOB) ) >= 13It Besides above was already indicated, why does not follow to use such a code, for example: select datediff(year, todate(to_char({d '1990-12-31'},'YYYY')||':1','YYYY:MM'), -- birthday todate(to_char({d '2003-01-01'},'YYYY')||':1','YYYY:MM') -- report date )This gives an incorrect result - 13, although it should be 12.
go to post Vitaliy Serdtsev · Dec 26, 2017 Here's another way (without PlaceAfter): Class Macro.Child Extends Macro.Parent { ClassMethod %inc() [ Internal, Private ] { #include Child } ClassMethod Test() { write "Class: " , $classname() , ! , "Value: " , $$$name } }
go to post Vitaliy Serdtsev · Dec 26, 2017 The key difference of $classmethod is runtime: $CLASSMETHOD permits a ObjectScript program to invoke an arbitrary class method in an arbitrary class. Both the class name and the method name may be computed at runtime or supplied as string constants.proof
go to post Vitaliy Serdtsev · Dec 26, 2017 Class include is not required (and does not seem to affect anything) and can be omitted Yeah, I just forgot to delete that line.
go to post Vitaliy Serdtsev · Dec 26, 2017 Then this: Include Child Class Macro.Child Extends Macro.Parent { ClassMethod first() { #include Child } ClassMethod Test() [ PlaceAfter = first ] { write "Class: " , $classname() , ! , "Value: " , $$$name } }or this: ClassMethod Test() { #include Child write "Class: " , $classname() , ! , "Value: " , $$$name }
go to post Vitaliy Serdtsev · Dec 26, 2017 Macro.Parent.cls: Include Parent Class Macro.Parent { ClassMethod Test() { write "Class: " , $classname() , ! , "Value: " , $$$name } }Macro.Child.cls: Include Child Class Macro.Child Extends Macro.Parent { ClassMethod Test() { write "Class: " , $classname() , ! , "Value: " , $$$name } }Parent.inc: #ifndef name #define name "Parent" #endif nameChild.inc: #define name "Child"Result: >do ##class(Macro.Parent).Test() Class: Macro.Parent Value: Parent >do ##class(Macro.Child).Test() Class: Macro.Child Value: Child
go to post Vitaliy Serdtsev · Dec 19, 2017 This data is saved in the registry. You can even save greater value than allowed by the program (see screenshot).Example of work with the registry directly from Caché Object Script can be found here.
go to post Vitaliy Serdtsev · Dec 16, 2017 For better performance you should make a few changes: add an index on DOB field rebuild the index and run TuneTable modify the query select DOB from HSAA.Patient where dob<=dateadd('yy',-13,current_date) or dob between todate((year(current_date)-13)||'0101','yyyymmdd') and todate((year(current_date)-13)||'1231','yyyymmdd') The result will pleasantly surprise you.
go to post Vitaliy Serdtsev · Dec 15, 2017 Hi Marco. CSVTOCLASS creates a new class if it doesn't already exist and then it calls the Import method. Since you already have created the class, it is not created, but there is no Import method, so nothing works. Solution: delete all previously created classes: ZenImport.Country, TestCsv.Csv, etc. run in terminal: USER>set rowtype = "Code VARCHAR(2),Name VARCHAR(9)" USER>set filename = "c:\temp\Country.csv" USER>do ##class(%SQL.Util.Procedures).CSVTOCLASS(2, .rowtype, filename,";",,,"Test.CSV") run in Portal: select * from Test.CSVopen and see the class "Test.CSV". Profit!!!
go to post Vitaliy Serdtsev · Dec 14, 2017 select DOB from sample.person -- or HSAA.Patient where (tochar(current_date,'YYYYMMDD')-tochar(DOB,'YYYYMMDD'))\10000>=13 or ((year(current_date)||'1231')-tochar(DOB,'YYYYMMDD'))\10000=13
go to post Vitaliy Serdtsev · Dec 14, 2017 Never use DATEDIFF for accurate calculation of the age since days and months here are not taken into account. See example