ObjectScript

Syndicate content 31 

Here's an easy one for you; before I spend another hour looking for the answer, how do you convert %ArrayOfDataTypes to an array (that could, say, fit into the %session.Data array, or maybe just some array named info()), and of course back again?

NS>s aodt=##class(%ArrayOfDataTypes).%New()
 
NS>w aodt.SetAt("lcavanaugh","username")
1
NS>w aodt.SetAt("organization","coolcompany")
1
NS>w ##class(%ArrayOfDataTypes).BuildValueArray(aodt,.array)
 
<LIST>zBuildValueArray+1^%Library.ArrayOfDataTypes.1

aodt must be serialzed.  What?

NS>zw array

NS>

Last answer 4 November 2016 Last comment 4 November 2016
0   0 1
381

views

0

rating

I try to run the cmd command in the studio terminal, but i am getting the <NOTOPEN> Error.

Even ZF(-1) also not working. Any help, Please!!!

 

Note: i restart the Cache instance service with full privilege

 

Code:

Set Path="mkdir E:\Sample\New"

Open Path:"QR":10

Error:<NOTOPEN>

 

This command working on my PC, but on server throws error.

 

Many Thanks

Last answer 4 November 2016 Last comment 4 November 2016
0   0 2
283

views

0

rating

Can somebody explain this behaviour of Cache (and many other calculating machine as well) :

WRITE 1/3*12

4

WRITE 1/3*5

1.666666666666666667

W 1/3*18

5.999999999999999999

W 1/3*21

6.999999999999999999

W 1/3*24

7.999999999999999999

How can we make more occurate caculations in Cache ?

Last answer 3 November 2016
+ 1   0 2
0

comments

435

views

+ 1

rating

There is an interesting discussion in the Russian forum going. 

What is the best solution for the function which returns the max for the set of parameters?

From the listed solutions I like this one:

ClassMethod max(args...) {
  for i=1:1:args {  max(+$g(args(i))) = }
  i=""max=$o(max(i),-1, iQ $lb(maxi)
}

Last answer 31 October 2016 Last comment 3 November 2016
+ 1   0 2
303

views

+ 1

rating

I was recently asked whether we have a function to convert LDAP date time stamps into $HOROLOG format or other formats and the answer is not at the moment, but there is a simple method to do the conversion.

Let us look at the facts and figures involved...

1) Active Directory's (AD) date 0 (zero) is 1601-01-01 00:00:00.000 or January 1st, 1601 at midnight (00:00:00)

2) AD timestamps are calculated as the number of 100 nanosecond intervals from date 0

3) 864000000000 is the number of 100 nanosecond intervals per day

4) The $HOROLOG format (Cache internal date) is a pair of numbers separated by a comma. The first number is the number of days since December 31st, 1840 and the second number is the number of seconds since midnight on the given day.

5) It is 87657 days from the 01/01/1601 to 01/01/1841, but not including the end date - so number of days pas

+ 5   0 2
0

comments

413

views

+ 5

rating

This post is the direct result of working with an InterSystems customer who came to me with the following problem:

SELECT COUNT(*) FROM MyCustomTable

Takes 0.005 seconds, total 2300 rows.  However:

SELECT * FROM MyCustomTable

Took minutes.  The reason for this is subtle and interesting enough for me to write a post about.  This post is lengthy, but if you scroll to the bottom I'll write a quick summary, so if you've gotten this far and think you've already read enough, scroll to the end to get the main point.  Check for the sentence in bold.


There is consideration to take when creating your classes when it comes to storage.  As many of you know, all data in Caché is stored in Globals.  

<Digression> 

If you don't know this then I think this post is going to be a bit much.  I recommend checking out this excellent tutorial in our docs

Last comment 1 November 2016
+ 10   0 11
966

views

+ 10

rating

Here you have an easy way to write and execute COS code from your unix scripts. This way one does not need to write routines or even open Studio or Atelier. It can be an option for simple and small actions for instance things like installation tasks or compiling.

See sample bash script (compile.sh) to compile classes:

#!/bin/bash
#####################################################################
# Script to compile classes
# $1 = NAMESPACE
# $2 = ClassName
#
# For example:
# ./compile.sh "SAMPLES" "Sample.Person" 
#####################################################################
echo -n "username:"
read username
echo -n "password:"
read pwd

csession HSINSTANCE -U "$1" <<EOFF
$username
$pwd
set status = \$SYSTEM.OBJ.Compile("$2")
h
EOFF

This is the output from the console

Last comment 14 October 2016
+ 4   0 3
472

views

+ 4

rating

With a routine like this one, you can quickly calculate how many lines of code you are working with. And it is not only for routines, it works for classes because remember that classes generate routines !

Here you have the routine source code:

LinesOfCode ;
    new SQLCODE,tRoutine
    set tTotalLOC = 0
    &sql(DECLARE ROUTINES CURSOR FOR
     SELECT NAME 
FROM %Library.RoutineIndex 
WHERE TYPE = 'MAC'
ORDER BY NAME)
    &sql(OPEN ROUTINES)
    &sql(FETCH ROUTINES INTO :tRoutine)
    while (SQLCODE=0)
    {
        write !,$j($i(tCount),5),": ",tRoutine
        set tLOC = $get(^rMAC(tRoutine,0,0))
        write "("_tLOC_")"
        set tTotalLOC = tTotalLOC + tLOC
        &sql(FETCH ROUTINES INTO :tRoutine)
    }
    &sql(CLOSE ROUTINES)
    write !!,"Total lines of code = "_tTotalLOC

This is the output in a terminal

Last comment 13 October 2016
+ 5   0 6
431

views

+ 5

rating

Now, let’s say you can’t access the terminal or simply you just rather execute it from a web interface. In this article, I will show you how to execute terminal commands from a simple web page.

For example, in the image below you see how we execute $zv on a webpage:

This is mostly possible due to the XECUTE command in Caché ObjectSCript. This command takes a string as a parameter and tries to execute it. This is the command used from the webpage, to execute what is being passed from the left navigation menu.

This article contains three snippets of code. Each of which corresponds with a separate file. In total, there are three files:

1. Index.csp  (A sample page with two frames)

Last comment 13 October 2016
+ 2   0 0
5322

views

+ 2

rating

The topic of for/while loop performance in Caché ObjectScript came up in discussion recently, and I'd like to share some thoughts/best practices with the rest of the community. While this is a basic topic in itself, it's easy to overlook the performance implications of otherwise-reasonable approaches. In short, loops iterating over $ListBuild lists with $ListNext or over a local array with $Order are the fastest options.

As a motivating example, we will consider looping over the pieces of a comma-delimited string.

A natural way to write such a loop, in minimal code, is

Last comment 3 October 2016
+ 18   0 12
4373

views

+ 18

rating

Hello, guys. 

I found one interesting moment in Cache Object Script. It doesn't have(or at least I didn't find) trimming function. By trimming I mean if a string has some whitespaces/tabs/carriage returns from very beginning or/and from very right, this function removes them. 

  I have found several workaround ways. 

1. Using Cache Basic

ClassMethod TrimCacheBasic(str As %String) As %String [ Language = basic ]
{
Return Trim(str)
}

2. Using SQ

Last answer 9 September 2016 Last comment 30 September 2016
+ 1   0 1
588

views

+ 1

rating

Hello,

we build a COS-application which includes classmethods for running a simulation calculation (differential equations by Runge Kutta procedure) which runs well but needs too much time.  This is embeded in Cache Server Pages and we tried already to start the simulation as a JOB to avoid the CSP-timeout. However the Job needs of course also too much time. May be this could be solved by a different strategy to run the simulation calculation by an external Windows -Programm (developed with Delphi). Original the application for simulation was developed in Delphi, where it needs a significant shorter time than in the COS-application.

Our question is how can we start and execute the windows-programm from a Cache Server Page?

Any hint is welcome?

Lutz.

Last answer 4 August 2016 Last comment 21 September 2016
0   0 2
801

views

0

rating

Wir suchen für ein Unternehmen unserer Firmengruppe

eine/n ERP System Developer / Programmierer/ Software Entwickler

Unser Partnerunternehmen ist ein international agierendes Handelsunternehmen mit Sitz in der Nähe von Wien.

Der zukunftsorientierte IT Bereich entwickelt intelligente innovative Lösungen für die Vielfalt der Herausforderungen, die sich täglich stellen. Die Fülle der abwechslungsreichen Aufgaben und Projekte, sowie die Art und Weise wie zusammengearbeitet wird, bietet hervorragende Wachstums- und Entwicklungschancen.

Für die Entwicklung und ständige Weiterentwicklung der Softwarelösungen innerhalb des eigenentwickelten ERP-Systems wird derzeit Teamverstärkung gesucht.

Die Herausforderung:

+ 1   0 1
0

comments

216

views

+ 1

rating

Hello community!

Is there any method/property/way in Caché to obtain something like unique identifier for installed Caché system? The idea is to get the identifier that will differ on any other installation/machine/etc, but will forever remain the same for the current installation, even if $zv changes (in case of update) or any data is removed from the database.

Last answer 24 August 2016 Last comment 24 August 2016
0   0 1
216

views

0

rating

Hi -

I have 3 classes: "Class A" has a property X, "Class B" has a property which is a Class A, and I have a "Class C" which has a property of a Class B.

Class A definition

Class USER.ClassA Extends %Persistent

{

Property Propx as %String;

}

Class B definition

Class USER.ClassB Extends %Persistent

{

Property Record as USER.ClassA;

}

Class C defintion (which is where I'm having my problem)

Class USER.ClassC Extends %Persistent

{

Property BRecord As USER.ClassB;

Property ARecord As USER.ClassA [ Calculated, SqlComputeCode = { ????? }, SqlComputed ];

Last answer 29 June 2016 Last comment 24 August 2016
0   0 2
197

views

0

rating

In this article we are going to compare $Increment and $Sequence functions.

First of all, a note for readers who have never heard of $Increment. $Increment is a Caché ObjectScript function which performs an atomic operation to increment its argument by 1 and return the resulting value. You can only pass a global or local variable node as a parameter to $Increment, not an arbitrary expression. $Increment is heavily used when assigning sequential IDs. In such cases parameter of $Increment is usually a global node. $Increment guarantees that each process using it gets a unique ID

Last comment 19 August 2016
+ 14   0 8
750

views

+ 14

rating

Process-private Globals  can be used as a data global in storage definition. That way, each process can have its own objects for the class with ppg storage. For example lets define a pool, which can:

  • add elements to a pool (ignoring duplicates)
  • check if an element exists in the pool

Here's the class

Last comment 16 August 2016
+ 4   0 3
397

views

+ 4

rating