Calling Second Method inside the Main Method
Hy,
I have a question how to call another methode inside the main method ?
like
this_MainMethod
{
calling SecondMethod
}
Method SecondMethod
{
}
When I try to call the data without second method, it works, but when I try to call with SecondMethod, it show empty
Thank you for your help
Comments
..SecondMethod
I assume, we are talking about ObjectScript? Then you got in the main method a <SYNTAX> error because "calling" is not a command keyword. So what are you really doing? We don't need the whole main method, the line with the call would be enough. By the way, a method name like "this_method" is not a valid name except if you place it in (double)quotes. Something, which is formal correct, looks like this:
Method "this_MainMethod"()
{
do..SecondMethod()
}
Method SecondMethod()
{
// ...
}This, or if SecondMethod returns a value of some sort, you'd want to:
Method "this_MainMethod"()
{
set somevalue = ..SecondMethod()
}
Method SecondMethod()
{
// ...
}I've try but it doesn't work
maybe I do something wrong
I'm not using object, just an ordinary query
Dear Julius Kavay,
sorry I'm not using Object script
I'm still using Query in my script
I've no idea how to call this method
ClassMethod GetSphereJauh(Id As %String) As %String ----this is the second method
{
set Id=$zstrip(Id,"*C")
set (ID,OBSATParRef,OBSATValue,ATTRCode,ATTRDesc)=""
// Query Data Encounter
&sql(declare adm cursor for
select
OBS_ParRef,
OBSAT_ParRef,
OBSAT_Value,
OBSAT_ItemAttribute_DR ->ATTR_Code,
OBSAT_ItemAttribute_DR ->ATTR_DESC
into :ID,:OBSATParRef,:OBSATValue,:ATTRCode,:ATTRDesc
from SQLUser.MR_ObservationsAttribute
Join SQLUser.MR_Observations on OBS_RowId = OBSAT_ParRef
Join SQLUser.MRC_ObservationItemAttribute on ATTR_RowId = OBSAT_ItemAttribute_DR
where OBSAT_ParRef =:Id and ATTR_Code ='EKA.Sphere.OD' )&sql(open adm)
for {
&sql(fetch adm)
quit:SQLCODE'=0
set ind=ind+1
set ^||IRISTemp("TRAK",repid,ind)=$lb(ind,ID,OBSATParRef,OBSATValue,ATTRCode,ATTRDesc)
}&sql(close adm)
// Build QHandle (AtEnd,ReportID,Index)
set QHandle=$listbuild(0,repid,0)
set QHandle(1)=mon
quit $$$OK
}ClassMethod GetSphereJauh(Id As %String) As %String
{
set Id=$zstrip(Id,"*C")
set (ID,OBSATParRef,OBSATValue,ATTRCode,ATTRDesc)=""
// Query Data Encounter
&sql(declare adm cursor for
select
OBS_ParRef,
OBSAT_ParRef,
OBSAT_Value,
OBSAT_ItemAttribute_DR ->ATTR_Code,
OBSAT_ItemAttribute_DR ->ATTR_DESC
into :ID,:OBSATParRef,:OBSATValue,:ATTRCode,:ATTRDesc
from SQLUser.MR_ObservationsAttribute
Join SQLUser.MR_Observations on OBS_RowId = OBSAT_ParRef
Join SQLUser.MRC_ObservationItemAttribute on ATTR_RowId = OBSAT_ItemAttribute_DR
where OBSAT_ParRef =:Id and ATTR_Code ='EKA.Sphere.OD' )&sql(open adm)
for {
&sql(fetch adm)
quit:SQLCODE'=0
set ind=ind+1
set ^||IRISTemp("TRAK",repid,ind)=$lb(ind,ID,OBSATParRef,OBSATValue,ATTRCode,ATTRDesc)
}&sql(close adm)
// Build QHandle (AtEnd,ReportID,Index)
set QHandle=$listbuild(0,repid,0)
set QHandle(1)=mon
quit $$$OK
}
And I want to call this method Inside this main method
ClassMethod GetDataExecute(ByRef QHandle As %Library.Binary, Id As %String) As %Library.Status
{
//Start Monitor (if configured to capture stats)
set mon=..MonitorBegin()
// Get reportid i.e. use $INCREMENT to add another node to ^IRISTemp global.
// We use ^IRISTemp global because it will always use memory before disk
// Use $Increment to get the next node
set repid=$increment(^||IRISTemp("TRAK"))
if $data(^||IRISTemp("TRAK",repid)) {
kill ^||IRISTemp("TRAK",repid)
}
set ind=0
// Build data into ^IRISTemp("TRAK",ReportID)
set Id=$zstrip(Id,"*C")
//set EpisodeId=$zstrip(EpisodeId,"*C")
//set PatientId=$zstrip(PatientId,"*C")
set (ID,EpisodeID,PatientID,PAPMINAME2,PAPMINAME,Age,Address)="" // Query Data Encounter
&sql(declare adm cursor for
select
DISTINCT(OBS_ParRef),
MRADM_ADM_DR->PAADM_RowID EpisodeId,
PAADM_PAPMI_DR->PAPMI_RowId PatientId,
PAADM_PAPMI_DR->PAPMI_Name2,
PAADM_PAPMI_DR->PAPMI_Name,
PAADM_PAPMI_DR->PAPMI_PAPER_DR->PAPER_AgeYr Age,
PAADM_PAPMI_DR->PAPMI_PAPER_DR->PAPER_StName
into :ID,:PatientID,:PAPMIRowID,:PAPMINAME2,:PAPMINAME,:Age,:Address
from SQLUser.MR_Observations
join SQLUser.PA_PatMas on PAPMI_RowId=PAADM_PAPMI_DR
join SQLUser.PA_Person on PAPER_RowId=PAPMI_PAPER_DR
where OBS_ParRef =:Id)
&sql(open adm)
for {
&sql(fetch adm)
quit:SQLCODE'=0
set ind=ind+1
//set SphereJauh=..GetSphereJauh(ATTRDesc) ----Here I try to call this method
set ^||IRISTemp("TRAK",repid,ind)=$lb(ind,ID,PatientID,PAPMIRowID,PAPMINAME2,PAPMINAME,Age,Address,SphereJauh) }
&sql(close adm)
// Build QHandle (AtEnd,ReportID,Index)
set QHandle=$listbuild(0,repid,0)
set QHandle(1)=mon
quit $$$OK
}
It will give me an empty row, there's no data when I try to call the second method, but if I comment the calling for second method, it will display the data
yourClassMethod GetSphereJauh(Id..... is located in some Class
so just call it as any other class methodset SphereJauh=##class(classname).GetSphereJauh(ATTRDesc)
the fact that this is used as part of a custom class query is totally irrelevant in this context.
it is straightforward ObjectScript. nothing else
Dear Robert,
this is my classname
.png)
but it doesn't work when I try to put this, it display empty when I try to call it
.png)
BTW:
whatever your method does it always terminate with Quit $$$OK
so whatever happens it is equivalent to
set SphereJauh=1
I assume you look for a different return value ? Is it ?
yes, that right, I look for a different return
But I've no idea for that
You have 2 options to return a value from a Method, one is to send by reference an object and instantiate that object inside the method called:
ClassMethod MyMethod(myInput As String, Output myOutput As MyPackage.MyClass) As%Library.Status
{
set myOuput = ##class(MyPackage.MyClass).%New()
set myOutput.name = "This is a name"return$$$OK
}And invoke it like:
// Invoke method with .. if it belong to the same class or with ##class(classname).method if it doesn'tset tSC = ..MyMethod("One Input", .output)
// Now output has been created and output.name has the value "This is a name"write output.nameYou can see here in the documentation how to pass variables by reference:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
thanks for your help but not works, still I need some clue
You need to change your cursors names, use two different names in your declare statements, try it.
Some considerations about embedded SQL cursors:
1) I think using embedded SQL Cursors is a practice to be avoided in favor of %SQL.Statement class usage:
https://docs.intersystems.com/iris20232/csp/docbook/Doc.View.cls?KEY=GS…
2) Genarally is not a good idea to have the same name in embedded SQL cursors, even if they are in different Methods, this because of the behaviour of the Stack separations used by the embedded SQL cursors.
3) Use a close statement before every open statement of embedded SQL cursors, this prevent problems if your process crash and in the same context you re execute it.
Thanks you but nothing I can get here
no example or other way
The method GetSphereJauh work if called from terminal?
It's looks like there are some undefined variebles there , in main method from your comment of the Aug 4 the variable "ATTRDesc" seems to be undefined and in the called method I do not see any value for "repid" variable (but it depend if your class is procedureblock or not).
After reading through this thread, it seems like there are two questions:
- What is the correct syntax for calling a method? That question has been answered by several posts. It's either using ..method2() if method2() is in the same class as method1(), or ##class(package.class).method2() if method2() is in a different package.class. Use "do" to call the method, or "set retval = " to call the method and capture the returned value.
- Why when I run method1() I get data, but when I add a call to method2() from inside method1() I get no data? As Davide suggested, using "adm" as an embedded SQL cursor in the GetDataExecute() method and the GetSphereJauh() method is probably causing the problem, so try changing the cursor name to "juah" in the declare, open, fetch and close statements in GetSphereJauh(). If that doesn't help, you should probably contact TrakCare Support and get their help.
Hi,
the issue is with your 2nd method return values. You have defined the method to return %String which is fine.
But then at the end you quit $$$OK, which translates to a return value of 1.
You need to build your return string e.g.
set retVal="some string:"_variableExample
return retVal