Today I encountered a strange behaviour after I added a SWITCH statement in a VALUE assignment.
Let's assume there is a simple table with two columns ID and TXT:
TYPES: BEGIN OF _test, id TYPE char02, txt TYPE string, END OF _test, _test_t TYPE STANDARD TABLE OF _test WITH DEFAULT KEY.
Then there is a simple VALUE statement to fill the table:
DATA(test) = VALUE _test_t( ( id = 'AA' txt = 'AAA' ) ( id = 'bb' txt = 'bbb' ) ( txt = 'CCC' ) ).
Not a big deal and works as expected:
ID | TXT ---+----- AA | AAA bb | bbb | CCC
Then I added the SWITCH statement because line #2 should have a different value depending on a variable:
DATA(test) = VALUE _test_t( ( id = 'AA' txt = 'AAA' ) ( SWITCH #( sy-uname(1) WHEN 'E' THEN VALUE #( id = 'BB' txt = 'BBB' ) ELSE VALUE #( id = 'bb' txt = 'bbb' ) ) ) ( txt = 'CCC' ) ).
As my username starts with E the result looks - also expected - like this:
ID | TXT ---+----- AA | AAA BB | BBB | CCC
But then for any reason I didn't want to have the field ID filled in the first line and changed my code accordingly:
DATA(test) = VALUE _test_t( ( txt = 'AAA' ) "Value for ID deleted! ( SWITCH #( sy-uname(1) WHEN 'E' THEN VALUE #( id = 'BB' txt = 'BBB' ) ELSE VALUE #( id = 'bb' txt = 'bbb' ) ) ) ( txt = 'CCC' ) ).
The expected result would be, that line #2 is the only line where field ID is filled:
ID | TXT ---+----- | AAA BB | BBB | CCC
But the result is the following:
ID | TXT ---+----- | AAA BB | BBB BB | CCC
Line #3 is filled with ID = "BB" although I do not tell the system to do so...
I tested on two different SAP-Systems:
Can anyone proof this behavior or tell me what I am doing wrong?
Thanks in advance
~Enno