Question
Ponnumani Gurusamy · Sep 21, 2016

Cache class Program

I get a input from user.How to I retrieve the data from these input. I enter the program but its occurred Some error .So give an idea of how to retrieve the data from properties.

ClassMethod Getvalue()
{
Details = ##class(Sample.Employeedetails).%New()
"Enter Your Name:" , Name1
Details.Name = Name1
"Enter Your Address :", Address1
Details.Address = Address1
"Enter your Phone Number:",Phonenumber1
Details.Phonenumber = Phonenumber1
"Enter your Blood Group:", Bloodgroup1
Details.Bloodgroup = Bloodgroup1
"Enter Your Desination:",Desiation1
Details.Desination = Desiation1
"Enter your Domain :",Domain1
Details.Domain = Domain1
status = Details.%Save()
}

ClassMethod PrintDetails()
{
##class(Sample.Employeedetails).#Name
}
 

0
0 256
Discussion (7)1
Log in or sign up to continue

You should actually read this tutorial.

Every class, has some types of elements, and some of them like Property and Parameter may contains some data.

Property stores data for every objects in this class, Parameter, for class itself.

In your example, saving data to properties of object was right. But in method PrintDetails, you try to read data from Parameter, not from property. To read data from property you should open this object before, but you also need to know an ID for such object.

#; open object by known ID
set obj=##class(Sample.Employeedetails).%OpenId(1)
#; if obj is empty, so this object could't be found, and open

#; ouptut property Name for this object
​Write !,obj.Name

Thanks. We retrieved individual data in a property. Is not possible to retrieve the whole data in a property?

What does you mean ? In this case we get all data in property Name, if you need data from other property just use it.

Write !,obj.Address

set obj.name = name1,name2,name3

Is possible I retrieve the all data in same properties without Id?

in your code,

obj - it is some object, it may have some ID or not, if it just created

name1 - it is a value for property name in that object

but I completely don't understand why is here name2 and name3, and what do you suppose should be happens after this line ?

and how it should save data in other objects which we even don't know which ?

you should know somehow which objects you want to update. If you know only some other properties, you can use SQL command UPDATE 

If you want to pull data out of multiple instances of the same class that have been previously stored, you will need to either get them 1 by 1 using object ids or you will need to do some sort of SQL query or result set type routine.

%SQL.Statement documentation may be helpful for you if you need to dynamically generate queries.