When we declare a variable normally we specify its type.
What happens to the type of an inline declaration variable if we don't specify it? Is it assigned according to the value it receives?
For example:
Ex.1 Here we get the string type by the value we pass in?
DATA(lv_name) = 'Testing Value'.
Ex.2 Here we get lt_mara as TYPE TABLE OF mara?
SELECT * FROM mara
INTO TABLE @DATA(lt_mara) UP TO 10 ROWS.
Do I understand this issue correctly?
Yes, the type gets derived automatically at activation depending on the type of what you assign.
DATA(lv_name) = 'Testing Value'will result in aTYPE c LENGTH 13, because that's the length of the character literal you assign. If you want aTYPE string, assign it with the string template syntax:DATA(lv_name) = |Testing Value|.If you want to force a specific type, then you can combine it with the
CONVoperator. This is most useful with numeric types, because there are no dedicated literals for any of them except forTYPE i. For example:This will result in a
TYPE decfloat16variable with the value of12.5.There is a slight peculiarity with
TYPE p LENGTH x DECIMALS ytypes. For example, this does not work:But you can use the
CONV-operator withTYPE pif you define a named type beforehand:(This does of course work just as well with dictionary types).
When you use an inline declaration in a
SELECT * FROM mara, then the resulting structure won't technically be the dictionary-type MARA, but a type which has the exact same columns as MARA. So it is identical for most intents and purposes. Inline declarations withSELECTare most useful when you do not do just aSELECT *but when you specify a list of fields you want. Using an inline declaration means that you do not need to define a custom data-structure which you would then need to manually keep in sync whenever you change the column list of yourSELECT.