2020 Jan 22 6:51 AM
Hi
I am trying to do a simple code like this one
loop at my_lines
reference into data(o_line).
data(my_summ) = o_line->my_quantity + my_sum.
endloop.
(the objective is not to do a simple sum, this is just an example)
but, I have an error "my_sum is unknown"
is it a real limitation of the inline declaration ?
2020 Jan 22 7:46 AM
It looks like it is not possible, check the comment from horst.keller
https://blogs.sap.com/2013/05/23/abap-news-for-release-740-inline-declarations/#comment-349626
I couldn't understand the standard help terminology but I think they are talking about the same.
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abendata_inline.htm
Just like the statement DATA, an inline declaration does not open a local context for the current statement block. An inline declaration for a variable can only be made once within a context and the variable cannot yet be declared there using DATA.is this the same? that statement is super confusing for me 😄
Thanks,
Mahesh
Hi
I am trying to do a simple code like this one
loop at my_lines
reference into data(o_line).
data(my_summ) = o_line->my_quantity + my_sum.
endloop.
(the objective is not to do a simple sum, this is just an example)
but, I have an error "my_sum is unknown"
is it a real limitation of the inline declaration ?
2020 Jan 22 7:46 AM
It looks like it is not possible, check the comment from horst.keller
https://blogs.sap.com/2013/05/23/abap-news-for-release-740-inline-declarations/#comment-349626
I couldn't understand the standard help terminology but I think they are talking about the same.
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abendata_inline.htm
Just like the statement DATA, an inline declaration does not open a local context for the current statement block. An inline declaration for a variable can only be made once within a context and the variable cannot yet be declared there using DATA.is this the same? that statement is super confusing for me 😄
Thanks,
Mahesh
2020 Jan 22 8:37 AM
I think you have right with this sentence
Just like the statement DATA, an inline declaration does not open a local context for the current statement
even if when we used FOR ... IN ... the system do exactly the oposite
2020 Jan 22 9:18 AM
This sentence explains that DATA(xxx) is just like DATA, it's not a new notion of "local context for the current statement block" like in other programming languages (in a method the same variable can be different if declared in separate { ... } blocks), and consequently DATA(xxx) cannot be repeated in the same "context" (procedures, instances of classes, classes, and programs).
It's more this sentence:
The date type of the variable is determined by the operand typeThe compiler tries to determine the type of "my_sum" based on the types of the Right-Hand Side, but there is a kind of recursive determination because "my_sum" also appears in the RHS.
2020 Jan 23 11:00 AM
Thanks Sandra Rossi & frdric.girod for the explanation, even in other languages like javascript also this is not possible, as it makes sense that the LHS type is dependent on the RHS type, but it will be based on the total RHS value type, in this case it will be
data(dyn_variable) = (some value) + (dyn_variable(with undefined type)) => so an error.
2020 Jan 22 8:32 AM
Typo in your code (my_summ -> my_sum).
No other choice than doing it in two steps:
data(my_sum) = 0.
loop at my_lines
reference into data(o_line).
my_sum = o_line->my_quantity + my_sum.
endloop.
2020 Jan 22 8:39 AM
sandra.rossi , yes I exactly do that. But ... I don't know why, but I did not like to use the DATA ... anymore. I try to avoid it as much as possible.
2020 Jan 23 1:00 PM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |