Why we use type casting ' ?='
Hii Team
sample code for fetching the input value from search view which is connected to btq1order contextnode
DATA : lr_qs TYPE REF TO cl_crm_bol_dquery_service,
lr_qr TYPE REF TO if_bol_bo_col,
lr_qs ?= me->typed_context->btq1order->collection_wrapper->get_current( ).
lr_qr = lr_qs->get_query_result( ).
I am new to SAP CRM .while understanding the code i got stuck in one problem that ,
1.what is the main purpose behind
TYPE CASTING ie; '?='
2.what happens if we write ?= becoz if we write '=' instead of '?=' the system thows an error.
3.when to use this operator ?= and when we cannot use ?
It is used almost every where in BOL coding .please help me by giving complete explaination with an example if possible.
Thanks in Advance
Hi Abhishek,
Please check returning parameter type for get_current_dquery() method. In case returning type is mutually convertible then you don't have to use type casting.
But in case where you are taking results in some other type where results are compatible but with different structure then you use type casting.
best example would be cl_crm_bol_entity and if_bol_bo_property_access. Here property access is an interface to class and hence we use type casting.
Please refer to:
type casting
You can find more documentation on internet if you search for type casting.
Regards,
BJ
Similar Messages
-
How to use Type Casting in JSF Expression Language
I have an attribute CategoryId in my VO of type oracle.jbo.domain.Number. I am trying to use the expression of Boolean item in JSF as #{row.CategoryId != 4}
Here is the JSF code:
<af:column id="s141NewItem3Col" noWrap="true" width="100"
rowHeader="false">
<f:facet name="header">
<af:outputLabel value="CAtIDDeq4" showRequired="false"
id="ol18"/>
</f:facet>
<af:inputText id="s141NewItem3"
value="#{row.CategoryId != 4}"
label="CAtIDDeq4" required="false"
readOnly="#{((pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn']))) or ((!pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn'])))}"></af:inputText>
</af:column>I am getting the run time exception as "Can not convert 4 of type class oracle.jbo.domain.Number to class java.lang.Long".
I am wondering how the row.CategoryId is treated as Long?. PLease advise. Also, will I be able to use type casting expressions in JSF Expression Language?
Thanks, Pradeepuse attributeValue
Try *#{row.bindings.CategoryId.attributeValue != 4}* ?
Check this thread for details which discusses about the same:
El expression to disable or enable
Thanks,
Navaneeth -
How to use type cast change string to number(dbl)?can it work?
how to use type cast change string to number(dbl)?can it work?
Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
2 simple examples:
"1" cast as I8 = 49 or 31 hex.
"1" converted to decimal = 1.
"20" cast as I16 = 12848 or 3230 hex.
"20" converted to decimal = 20.
Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
See tha attached LabView 6.1 example.
Attachments:
TypeCastAndConvert.vi 34 KB -
J2SE 6 warning message when using type casting
With Java SE 5 and 6 version, there's always an annoying warning message when I write the following code:
LinkedList<MyBean> cart0 = (LinkedList<MyBean>) session.getAttribute("cart");The warning message is because I use the type casting with the getAttribute method and thus this is not type-safe. So how do I get around the warning message and write standard code that sticks to the J2SE 6 standards? Thank you.Add a @SuppressWarnings annotation to the method. A bit intelligent IDE will provide you a quickfix option for it.
Keep in mind: it's a warning, not an error. The sessionMap is cannot be specifically parameterized and will never be, it should be able to store any object to your taste. Further on this has not much to do with JSF at itself. -
Hi, I'm new to Java and I'm trying to understand a certain convention that i've noticed in reading source code posted by "official" or "knowledgeable" sources. I'll try my best to explain what I mean.
Often in source code, I'll see that the author has called a constructor but is casting the reference to that constructor differently than what you would expect from the constructor itself. Take, for instance the following code (taken from the 2002/09/10 issue of Core Java Technologies Tech Tips email I get):
public class ZeroDemo2 {
public static void main(String args[]) {
// set up ArrayList and add strings to it
List stringlist = new ArrayList();
stringlist.add("string 1");
stringlist.add("string 2");
... etc ...My question pertains specifically to the line where the ArrayList() constructor is called but the reference "stringlist" is a List object, not an ArrayList object.
I have seen this in a lot of Java code -- the constructor is one thing, but the object that the constructor instantiates is not of the same type as the constructor! Why do we do this?
I can try to be more specific if I'm not making sense.Imagine a school directory. Some people are going to
be students, some are faculty, others administrators,
etc etc. All of these groups are different, and have
to have their own methods (addClass() for students,
for example) but they all have things in common (like
a university ID)Right, I can see where it is helpful to have a more general handle on an object (especially for reasons of polymorphism, since that way you can just call a method and know that one of the various subclasses is going to have extended that method and it will work). But for such a short example as the one in the Tech Tips newsletter -- it seems like there was no point in referring to this object as a List and not as the more specific ArrayList. Here is the full code, reprinted below:
import java.util.*;
public class ZeroDemo2 {
public static void main(String args[]) {
// set up ArrayList and add strings to it
List stringlist = new ArrayList();
stringlist.add("string 1");
stringlist.add("string 2");
stringlist.add("string 3");
// convert to String array
String out[] = (String[])stringlist.toArray(
new String[0]);
for (int i = 0; i < out.length; i++) {
System.out.println(out);
See what I mean? It's almost like it's convention to refer to an object by one of its ancestor types rather than just call it for what it is. (That is, to refer to the object as a List rather than an ArrayList I wonder why. -
Type Casting? When to use this concept?
There is one question bothering me very very much.
When should I use type casting?
For example
ClassNameQ c = (ClassNameQ) ......displayable
How do I know which 'cast type' to use? Is there a suitable pattern
we need to follow so that we can know 'Ah this is the cast
we need to use'
Please can any one point out which 'Cast type' points needs to be
followed?
RegardsYou can Cast an object from any subclass to its superclass,
or from a superclass to the sublass, if the object is already
an object of the subclass.
I have a class named Name:
public class Name {
I have a subclass named LastName:
public class LastName extends Name { [/b]
And another named FirstName:
[b]public class FirstName extends Name { [/b]
I create an object like this:
[b]LastName ln = new LastName("Johnson");
Then pass it to a method that can work on all names:
capitalFirstLetter(ln);
capitalFirstLetter(Name n) {
Now n in CapitalFirstLetter can be used only as a Name
object. Anything specific to the LastName object can't be used.
So if I need to use things specific to LastName I have to cast
the object to LastName. There is a problem, however, since this
method can work on all Names, so I don't know if the Name is
a LastName or not. The object itself DOES know, however, and
we can test, so we would cast to a subclass as follows:
if (n instanceof LastName) {
LastName ln = (LastName)n;
ln.addToGeneology();
} else of (n instanceof FirstName) {
FirstName fn = (FirstName)n;
fn.addOccurance();
Steve -
I have an attribute CategoryId in my VO of type oracle.jbo.domain.Number. I am trying to use the expression of Boolean item in JHS as #{row.CategoryId != 4}
Here is the generated JSF code:
<af:column id="s141NewItem3Col" noWrap="true" width="100"
rowHeader="false">
<f:facet name="header">
<af:outputLabel value="CAtIDDeq4" showRequired="false"
id="ol18"/>
</f:facet>
<af:inputText id="s141NewItem3"
value="#{row.CategoryId != 4}"
label="CAtIDDeq4" required="false"
readOnly="#{((pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn']))) or ((!pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn'])))}"></af:inputText>
</af:column>I am getting the run time exception as "Can not convert 4 of type class oracle.jbo.domain.Number to class java.lang.Long"
I am wondering how the row.CategoryId is treated as Long?. PLease advise. Also, will I be able to use type casting expressions in J Headstart/JSF Expression Language?
Thanks, PradeepI am trying to set disabled property of an item SubCategory dynamically based on CategoryId value. I guess the transient attribute will not work for newly created records as the transient attribute will be null for newly created records before save is performed. However, the expression #{row.bindings.CategoryId.attributeValue.value== 4 ? false : true} is working fine. row.bindings.CategoryId.attributeValue seem to be returning Long and, row.bindings.CategoryId.attributeValue.value might be returning a Number.
-
I need To Understand the "Type Cast Function"
Dears,
I need To Understand How the "Type Cast Function" Work, and if you can Give me an Example it will be Apperciated
BR
AhmedIn its simplest explanation Type Cast allows you to reinterpret a series of bytes. The numeric conversion functions convert from one data type to another and essentially do the same thing that Type Cast does, albeit with just numbers. Type Cast allows you to extend this to convert one data type to another, beyond just numbers. Thus, you could convert an array of 2 U8 values into a single U16 number by using Type Cast like this:
or you could reinterpret an array of lots of U8 values into an array of U16 values like this:
How you use it is entirely up to you, but it is an extremely powerful function. What are you trying to do?
Attachments:
Example_VI.png 6 KB
Example2_VI.png 11 KB -
Good
morning,
I am using
the “type cast” function and the “visa write” subvi to control a DO channel of
Arduino (RS232 communication), please see image attached. Can somebody advise how
should I program in LabVIEW in order to control more DO channels? Furthermore,
when I tried to read the output of “type cast function” during the run of vi I
saw a square symbol. Is there any way to decode this symbol ? I tried to use a
“decimal string to number” suvi but it didn’t work.
Thank you
in advance
Attachments:
samplevi.jpg 27 KBdan_u,
Thank you for your reply. It's the first time I am using RS232 communication and also other harware than that of NI and I am little bit confused. With the configuration shown on my vi everything seems to work fine. This means that I can enable and disable a DO channel of arduino, thus the format comes from the "type cast" function seems ok. A previous effort, when I tried to send a string (also by using the "write to visa") of "0" or "1" to disable and enable the same DO channel wasn't successful. This is the reason why I thought that using the "type cast" function is the correct way to write to visa. Now, what I want to do is using e.g three boolean to control three different DO channels. Could you please advise?
Thank you in advance
Attachments:
myvi.jpg 99 KB -
USE OF Type cast function ?
can any one explain the use of type cast function with help of example please i am not able to understand the explaination given in ni.com site
LabVIEW provides a function called Type Cast, which allows data to pass through it unchanged while the type of the wire changes. Please refer to the given link which elaborates on the type cast function with required instances.
http://zone.ni.com/reference/en-XX/help/371361H-01/glang/type_cast/
In case of any clarifications needed, do revert.
Regards,
Sahil Singla
Applications Engineer | National Instruments
(Give Kudos to good Answers and Mark it as a Solution if your problem is Solved) -
Why do we require Type Casting?
Hi,
In short can you guys share your experience and expalin me why and when do we require type casting of objetcs.I would appericiate if i get a simple application as an example.
regards
VickyHi,
In short can you guys share your experience and
nd expalin me why and when do we require type casting
of objetcs.I would appericiate if i get a simple
application as an example.
regards
VickyWhy do you need this again?
Well, really you need type casting because you want to be able to check for errors at compile time. You actually don't need any type casting if you just wait to link all your code at runtime.
Normally your function calls are checked vs the real 'type' at compile time to see if you are calling the function with the proper types and number of arguments. same with returning. However, you don't have to do this, just look at any scripting language. All that is checked at runtime.
Problems with not checking at compile time are mostly speed and corectness errors. The runtime might decide to call a different function then the one you wanted because at runtime a 'better' one was found. Of course now you would get a link error at runtime and the code would just not execute. There would be problems with overriding and hiding of functions, etc.
Also, since you can't link ahead of time it takes longer to execute functions since you have to find them everytime they are called.
The advantage is that you can be lazy about typing.
Typecasting primitaves are a whole other problem. I'm not even going to go into that, but check out scripting languages for examples of autocasting primitives. -
Why should useful life be given in case of PRC depr type?
Hi Experts,
I have no answer for that quation that if i have a depreciation type which is straight line but under calculation tab the type is PRC, then in asset master data why do i have to give a useful life for this asset.
I cannot add a new asset belonging such an asset class where this type of depreciation is linked, so if the useful life is 0, than the system doesnt let me add the asset!
Im using SAP 2007A SP01 PL9.
I thought that when PRC is used then example:Percentage is 14.5%
Asset acquisition value is 1000.
Deprecation value/year is 1000*14.5=145. Monthly->145/12 is the deprection val. But then why is useful life asked??
Is it new sap logic or bug or incorrect setting for my DB?
Any idea would be appreciated.The Fixed assets system will automatically write the balance of the asset off at the end of the useful life, so this feild is required for all calculations.
If you want to maintain assets then put a useful life of 999 periods as a workaround -
Reading a binary file using the type cast function is not working
Hello
I am trying to read a binary file. Using the Read from binary file and type cast functions I can actually get the information from the file.
I set an indicator in the “Normal” option in Properties. I can read the header and footer but not the body of the file; For the body of the file all I can see is characters of the type
“C¾ Ü Qþ X@ “. One of the other options, Password, seems to provide an output of just the characters that were originally written, but then again, I can not read the characters because it is only asterisks and I can not copy them onto a word processor either.
I tried setting the indicator in Hexadecimal mode, then creating a local variable that acts as a control and use the type cast function again to see if could convert the Hexadecimal string to readable ASCII characters; unfortunately, this did not work either.
I don’t know what else I should try or if there is something that I may not be doing right and for that reason I am not getting the desired results. I hope someone has an idea about this issue.
Regards,
RobertoThank you for your reply,
Well, actually I don’t have any information about this file. I will try to obtain information about it though.
This is a file that contains velocity information; there are 65 channels that form a velocity profile in a pipe. Also, there are 4096 velocity profiles. I don’t know what is the format of these values.
The software that creates the file provides a text file. Using this text file the velocity information can be processed and then plotted.
I want to avoid all these intermediate steps and read, process and plot everything using only LabView. BTW, I am using LabView 8.2
Roberto -
In my program i get a double array from a function call, i want to convert this into an int array, but when i try to type cast it the compiler tells me they are inconvertible types. ie.
int[][] mat = (int[][])mateng.getArray("arraySig");
where the getArray function returns a double array.
Is there any way around this? I have tried to cast the double[][] into an Object[][] array and then back to an int[][], but the compiler wouldnt let me do this either.
Thanks
AlexOne might ask why you're returning a double[][] if you
actually want a int[][]The method returns a double[][] because its a generic method that will also be used to get double[][]s. In those cases it wont do to lose the information that only returning an int[][] would lose.
I wanted to be able to cast the double[][] to an int[][] when i return a specific matrix (ie a ones matrix or a logical matrix).
Alex -
Is there any way to avoid casting in following code using generics.
public Interface SomeInterface
public class SomeClass implements SomeInterface
public class SomeClass1
public void meth(SomeInterface obj)
SomeClass cls = (SomeClass) obj;
}why would you want to cast the interface to the concrete class? if SomeClass implements SomeInterface, presumably it's because what your client code is interested in is SomeInterface, that's why we use interfaces. you can't be sure that obj is always going to be an instance of SomeClass, only that it's an instance of SomeInterface. If you could be sure, there'd be no point having the two types
generics are a non-issue here
Maybe you are looking for
-
Hi, Do you know a report where I can see a list of purchase order together with the payment terms? Thanks! Sofia
-
AS2 sender adapter 403 forbidden error
Hi Experts, I have a scenario which is connecting with third party using sender AS2 adapter. while third party sending message to PI they are getting 403 forbidden error. sender agreements are created one for MDN reports and another particular interf
-
My external iSight camera shuts itself off within 30 seconds of firewire plug-in. The green light goes out as a faint chirp sound is heard. I have tried it on numerous Macs and software apps. Any suggestions? I can handle small repairs short of board
-
Background colours disappear when question slide added in C4
I recently updgraded to Captivate 4. Since the upgrade I have encountered this problem. I am importing slides from power point. Some of the slides have a blue background. When I add a question slide in C4, the blue background does not show up when I
-
After the upgrade of mavericks..i get the idea, that bridge lost his cache.. very very slow...i did several things, restarting, upgrading the cache...given it more memory...etc.. But still very slow, every folder must build from zero... Someone else