on ‎2021 Oct 13 12:48 PM
Hello, i am facing an interesing issue.
In this piece of code everything works fine.
READ TABLE lt_charge ASSIGNING <ls_charge> WITH KEY key = ls_data-key.
IF sy-subrc IS INITIAL.
<ls_output_data>-costs = <ls_output_data>-costs + ( <ls_charge>-amount * 10000 ).
ENDIF.
But when i change to this version, it always refreshes <ls_output_data>-costs. What is the difference between these 2 versions?
READ TABLE lt_charge ASSIGNING <ls_charge> WITH KEY key = ls_data-key.
<ls_output_data>-costs = COND #( WHEN sy-subrc IS INITIAL THEN <ls_output_data>-costs + ( <ls_charge>-amount * 10000 ) ).
Request clarification before answering.
Hi Mustafa,
In your second snippet it always refreshes <ls_output_data>-costs because you're missing the ELSE part of the COND statement.
To quote the documentation:
"If none of the logical expressions are true, the result specified after ELSE is selected. If ELSE is not specified, the result is the initial value of the data type."
Try this instead:
<ls_output_data>-costs = COND #(
WHEN sy-subrc IS INITIAL
THEN <ls_output_data>-costs + ( <ls_charge>-amount * 10000 )
ELSE <ls_output_data>-costs ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For better legibility, I prefer the original writing 😄
READ TABLE lt_charge ASSIGNING <ls_charge> WITH KEY key = ls_data-key.
IF sy-subrc IS INITIAL.
<ls_output_data>-costs = <ls_output_data>-costs + ( <ls_charge>-amount * 10000 ).
ENDIF.
I agree and prefer IF-ELSE here too.
| User | Count |
|---|---|
| 14 | |
| 9 | |
| 8 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.