04-15-2020 9:31 PM
Hi experts,
As in below there are two similar statements behaving differently.
Requesting to point out the mistake i’m making.
DATA: ls_ret TYPE bapiret2,
ls TYPE atpmsg,
lt TYPE tbl_atpmsg,
lt1 TYPE tbl_atpmsg.
ls_ret-message = 'test'.
APPEND INITIAL LINE TO lt1.
"*Statement1 - ****NOT WORKING****
lt = VALUE #( FOR ls1 IN lt1 ( VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls1 ) type = 'E' ) ) ).
"*Statement2 - ****WORKING**** ls = VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls ) type = lv_sflag ).
04-16-2020 8:54 AM
Could you describe the symptom instead of just saying "not working" please?
04-16-2020 9:04 AM
sandra.rossi
I kinda figured out what he was trying to say (hopefully that was his issue).In lt table, this value <ls_ret-message = 'test'> is not populated.but in ls, the value "test" is populated.I tried it in a differnet way like below and found the below odd behavior (couldn't figure out why 😞 )
" Used Let and can comparable to the for loop?
ls = VALUE #( LET a = ls IN BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls ) type = 'E' ).
cl_demo_output=>display( ls ). " This will not have "test" defaulted from ls_ret
clear ls.
" Same like op scenario
ls = VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls ) type = 'E' ).
cl_demo_output=>display( ls ). " This will have "test" defaulted from ls_ret<br>
How can the initialization of ls to a, impact the corresponding?
Hope you can shed some light.
04-16-2020 3:11 PM
The first statement is trying to fill a table based on lt1... is there any other code to fill lt1 besides the APPEND INITIAL LINE TO lt1? - I guess that after that lt1 has only an empty line, so in the statement ls1 is empty..
In statement2, is filling the work area, so no problem with the line there all fields are filled.
But would be ussefull if you tell wat are you trying to acomplish and what do you expect from both statements.
Regards,
Adolfo
04-18-2020 7:17 AM
Hi
* the target fields are overwritten by empty ls1 fields and type is set to 'E'
lt = VALUE #( FOR ls1 IN lt1 ( VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls1 ) type = 'E' ) ) ).
* Same behaviour for new structure (no table)
data(error_info) = VALUE atpmsg( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls ) type = 'E' ).
* here ls (as the target data object) is already filled because of BASE before the
* inner CORRESPONDING is executed...
ls = VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls ) type = 'E' ).
*********************************************************
* you can use EXCEPT * to get your expected result
data(error_info) = VALUE atpmsg( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls EXCEPT * ) type = 'E' ).
lt = VALUE #( FOR ls1 IN lt1 ( VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls1 EXCEPT * ) type = 'E' ) ) ).
regards Domi
04-18-2020 9:03 AM
Thanks for the explanation. For information, to better understand/explain the behavior, I simplified the minimal code to reproduce (see my comment below OP question), provided that ls and ls_ret have the same structures:
ls = CORRESPONDING #( BASE ( ls_ret ) ls ).
04-20-2020 9:00 AM
dominik.bigl2
Thanks for your comment.
‘ATPMSG’ structure have ‘BAPIRET2’ structure included with other fields.
I want the data in the other fields persisted and fields of BAPIRET2 structure be overwritten making type as ‘E’.
While using EXCEPT *, existing data is getting cleared.
PS: append initial line is not actually my case but will have some data populated in fields (other than of structure BAPIRET2)
Thanks
Ajay
04-20-2020 10:58 AM
dominik.bigl2
Thanks for your comment.
"ATPMSG" has a structure "BAPIRET2" along with some other fields.
On using EXCEPT *, it is not persisting the values (other than BAPIRET2 fields) that are already there.
PS: Append initial line in the question is just to give an idea that there is some data in lt1
Thanks
Ajay
04-20-2020 11:58 AM
04-25-2020 6:57 AM
Hi Former Member
Then just exclude the BAPIRET2 fields from overwriting...
lt = VALUE #( FOR ls1 IN lt1 ( VALUE #( BASE CORRESPONDING #( BASE ( CORRESPONDING #( ls_ret ) ) ls1
EXCEPT TYPE
ID
NUMBER
MESSAGE
LOG_NO
LOG_MSG_NO
MESSAGE_V1
MESSAGE_V2
MESSAGE_V3
MESSAGE_V4
PARAMETER
ROW
FIELD
SYSTEM ) type = 'E' ) ) ).
04-18-2020 7:42 AM
@ maheshkumar.palavalli
Due to the LET a different memory handling is used (necessary?) and LS is not filled by the BASE => see answer below
regards
Domi
04-18-2020 8:58 AM
I simplified the OP code to be minimal so that to better analyze what's going on.
If I understand well, the OP question is: why ls value contains "test"?
TYPES: BEGIN OF ty_atpmsg,
message TYPE string,
END OF ty_atpmsg.
DATA: ls TYPE ty_atpmsg,
ls1 TYPE ty_atpmsg,
ls_base TYPE ty_atpmsg.
ls_base-message = 'test'.
ls1 = CORRESPONDING #( BASE ( ls_base ) ls ).
ASSERT ls1 = VALUE ty_atpmsg( message = '' ). " CASE 1 : '' IS EXPECTED
ls = CORRESPONDING #( BASE ( ls_base ) ls ).
ASSERT ls = VALUE ty_atpmsg( message = 'test' ). " CASE 2 : 'test' IS NOT EXPECTED
What I understand: for each case, the construction occurs in two steps:
So, the result looks weird at first sight but now I understand the ABAP logic.
04-18-2020 9:05 AM
Mahesh Kumar Palavalli Your case (LET) would deserve a distinct question!
04-20-2020 9:00 AM
@Sandra Rossi, @Mahesh Kumar, @Adolfo Lopez
Thanks for your replies..
I’m sorry that i was not so clear with the question at first place.
But, Mahesh’s understanding is absolutely correct.
In statement 2, ‘test’ is populated in result but in statement 1, ‘test’ is not populated.
04-20-2020 9:21 AM
Former Member If you do a comment under a question/answer and you want to target someone else than the question/answer' author, the only solution is to copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work)
04-22-2020 8:57 AM
04-22-2020 8:58 AM