What does the syntax ->* mean? - abap

I have read some documents about the syntax ->*, but i still don't get it. Can anyone explain what it means and in what scenarios I can use it?
I have that syntax in this example:
assign ovs_callback_object->query_parameters->* to <ls_query_params> CASTING.

refvar->* is used to de-reference an unstructured reference variable. For a structured reference, you would use structref->component to access a component of the referenced object (an attribute of an object or a component of a structure). If you have something like TYPE REF TO i, there's no inner structure, so you have to use the special syntax ->*. It's all in the documentation...

The ->* operator is the "Dereference" operator. It turns a TYPE REF TO something into a TYPE something.
In your example, ovs_callback_object->query_parameters is likely a reference, but you don't want to assign the reference to the field-symbol, you want to assign the actual field the reference points to.

Related

ASSIGN fails with variable from debugger path

I am trying to assign the value of this stucture path to a fieldsymbol, but this path does not work because it has a table in it's path.
But with in the debugger this value of this path is shown correctly.
Is there a way to dynamically assign a component of a table line to a fieldsymbol, by passing one path?
If not then I will just read the table line and then use the path to get the wanted value.
ls_struct (Struct)
- SUPPLYCHAINTRADETRANSACTION (Struct)
- INCL_SUPP_CHAIN_ITEM (Table)
- ASSOCIATEDDOCUMENTLINEDOCUMENT (Element)
i_component_path = |IG_DDIC-SUPPLYCHAINTRADETRANSACTION-INCL_SUPP_CHAIN_ITEM[1]-ASSOCIATEDDOCUMENTLINEDOCUMENT|.
ASSIGN (i_component_path) TO FIELD-SYMBOL(<lg_value>).
IF <lg_value> IS NOT ASSIGNED.
return.
ENDIF.
<lg_value> won't be assigned
Solution by Sandra Rossi
The debugger has its own syntax and own logic, it doesn't apply the ASSIGN algorithm at all. With ABAP source code, you have to use ASSIGN twice, the first one to reach the internal table, then you select the first line, and the second one to reach the component of the line.
The debugger works completely differently, the debugger code works only in debug mode, you can't call the code from the debugger (i.e. if you call it, the kernel code used by the debugger will fail). No, there's no "abappath". There are the XSL transformation objects (xpath), but it's slow for what you ask.
Thank you very much
This seems to be a rather unexpected limitation of the ASSIGN statement. Probably worth a ticket to SAP's ABAP language group to clarify whether it's even a bug.
While this works:
ASSIGN data-some_table[ 1 ]-some_field TO FIELD-SYMBOL(<lv_source>).
the same expressed as a string doesn't:
ASSIGN (`data-some_table[ 1 ]-some_field`) TO FIELD-SYMBOL(<lv_source>).
Alternative 1 for (name) of the ABAP keyword documentation for the ASSIGN statement says that "[t]he name in name is structured in the same way as if specified directly".
However, this declaration is immediately followed by "the content of name must be the name of a data object which may contain offsets and lengths, structure component selectors, and component selectors for assigning structured data objects and attributes in classes or objects", a list that does not include the table expressions we would need here.

abap reference variables and dynamic types

I'm fluent in ABAP and have a grasp on OO and light reference variables, but can't seem to get a deeper handle on reference variables and dynamic types etc. I've done a bit of reading, but can't seem to get the deep understanding I feel I need.
Does anyone know of some great tutorials or websites that might give clear and concise? Thanks!
First of all just google this post title and You're golden.
Second:
I'm not sure if I understand You correctly, do You want to know about such constructions as:
DATA lo_ref_var TYPE REF TO zcl_my_class.
And by dynamic types do You mean in ABAP 7.4/7.5 (ex. DATA(lv_var) = 123)?
If yes, I'll try to give You the general idea:
Reference variable is just a variable that's "ready to become" an object.
If You'll take this for example:
DATA lo_ref_var TYPE REF TO zcl_my_class.
CREATE OBJECT lo_ref_var.
Then assuming the constructor doesn't need any variables You'll get an instance of zcl_my_class Class with all it's attributes and methods. Also if You have an abstract class zcl_abs_class as a super-class and zcl_sub_class1 and zcl_sub_class2 as it's non-abstract subclass' than:
DATA:
lo_abs TYPE REF TO zcl_abs_class,
lo_sub1 TYPE REF TO zcl_sub_class1,
lo_sub2 TYPE REF TO zcl_sub_class2.
CREATE OBJECT: lo_sub1, lo_sub2.
lo_abs ?= lo_sub1.
lo_abs ?= lo_sub2.
What You can do (as seen above) is cast a subclass object to the super-class reference variable since the subclass' inherits from zcl_abs_class.
For more, do some digging.
Dynamic types:
This is in fact very simple, all You need to remember is that a variable has to have a type when being created dynamically. So for example:
DATA(lv_text) = text-000.
DATA(lv_int) = 1.
Line with lv_text will not work (will not compile) since text-000 does not have a precise type.
The second line on the other hand will take the type I.
If one would like to decide which type to choose You can do this by writing:
DATA(lv_bukrs) = CONV bukrs( '1234' ).
You can even use the type that an already existing variable has by writing:
DATA(lv_bukrs2) = CONV #( lv_bukrs ).
since the "#" means "use the type of variable inside brackets".
Hope this will help You start :)

Access FlowVar dynamically in DataWeave

I'm trying to access a FlowVar name dynamically in DataWeave.
For example:
I have a flowVars named taxInfo123. This is a linked list and my applicant.ApplicantID = 123
In my dataweave, I want to access this dynamically. Something like the following:
"TaxInfo": flowVars.'taxInfo'+applicant.ApplicantID map ((taxIdentificationDetail , indexOfTaxIdentificationDetail) -> {
This obviously doesn't work, and I'm hoping this is possible and I just need the correct syntax.
If you need to dynamically create the variable name, you can use the flowVars[key] syntax instead of the flowVars.key syntax. In your scenario:
"TaxInfo": flowVars[('taxInfo' ++ (flowVars.applicant.ApplicantID as :string))]
I assumed applicant was also a flowVar but you could just as easily use payload.applicant.ApplicantID or whatever your situation calls for. I also assumed it was a number so I had to cast it as a string.
When you use this syntax you want to make sure you wrap the key expression in parenthesis so it is evaluated first and then the flowVar is resolved.
So to summarize:
If you know the variable name is 'taxInfo123' -
flowVars.taxInfo123 or flowVars[taxInfo123] are both valid
If you need to create the variable name dynamically -
flowVars[(expression)]
Hope that helps!
Forming the variable name needs append operator like ++. Please go through the MuleSoft documentation for Dataweave operators to get better understanding of how much flexiblity is possible in Dataweave.
https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators

What is the point of CTypeDynamic?

I'm using reflection to serialize an object. Getting the values as objects is a real murder on performance due to late binding penalties. CType / DirectCast can get rid of most of it but I can't feed a type variable into it so currently I'm using a switch case block on the type variable to select the correct DirectCast.
It came to my attention that CTypeDynamic exists and takes type variables but the return type is Object so... it converts an object into an object, cool. That got me wondering, what is the purpose of this function?
The CTypeDynamic function looks for dynamic information and performs the cast/conversion appropriately. This is different from the CType operator which looks for static information at compile time or relies on the types being IConvertible.
This function examines the object at runtime including looking for Shared (aka static) custom operators. As always, if you know the type then use CType, but if you need dynamic casting then you need to use CTypeDynamic.
More information here: http://blogs.msmvps.com/bill/2010/01/24/ctypedynamic/

Common name for variable and constant

In programming (and math) there are variables and constants. Is there a name to describe both of them?
I was thinking value, but that's not it. A value is what variables/constants contain, not what they are.
I would call it a symbol. From google:
sym·bol/ˈsimbəl/Noun
1. A thing that represents or stands for something else,
esp. a material object representing something abstract.
...
From what I know Its called a field
How about:
maths and logic: term
programming: l-value and r-value.
There are a few different terms I use, depending on context. I'll give you a list of the terms I (might) use - sometimes I'll just default to calling everything 'variables'.
Field - a variable or constant that's declared as part of the class definition.
Parameter - one of the inputs specified when defining a method in a class.
Argument - the actual value that you provide for a parameter when calling a method.
Method variable - a variable declared inside a method.
Method constant - a constant declared inside a method.
In OOP, the attribute can be both a variable and a constant.
Identifiers
In computer languages, identifiers are tokens (also called symbols) which name language entities. Some of the kinds of entities an identifier might denote include variables, types, labels, subroutines, and packages.
Symbols are super set of Identifiers
https://en.wikipedia.org/wiki/Identifier#In_computer_languages
How about "data item"?
One definition: https://www.yourdictionary.com/data-item
Example showing it can be used for local variables/constants as well (unlike "field" or "attribute"): https://www.microfocus.com/documentation/visual-cobol/VC222/EclWin/GUID-A3B817EE-1D63-4F67-A62C-61DE681C6719.html