Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP 7.40 Syntax

Former Member
5,783

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 ).

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 ).

16 REPLIES 16
Read only

Sandra_Rossi
Active Contributor
5,111

Could you describe the symptom instead of just saying "not working" please?

Read only

maheshpalavalli
Active Contributor
5,111

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.

Read only

alopezv74
Participant
0 Likes
5,111

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

Read only

Domi
Active Contributor
5,111

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

Read only

Sandra_Rossi
Active Contributor
0 Likes
5,111

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 ).
Read only

Former Member
0 Likes
5,111

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

Read only

Former Member
0 Likes
5,111

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

Read only

Sandra_Rossi
Active Contributor
5,111

It's Domi, not Dorni 🙂

Read only

Domi
Active Contributor
0 Likes
5,111

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' ) ) ).
Read only

Domi
Active Contributor
0 Likes
5,111

@ 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

Read only

Sandra_Rossi
Active Contributor
5,111

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:

  • BASE ( ls_base ) moves ls_base to the target data object, respectively ls1 and ls for cases 1 and 2.
  • Then ls (which has been changed to 'test' in the first step of case 2) is transferred to the target data object.

So, the result looks weird at first sight but now I understand the ABAP logic.

Read only

Sandra_Rossi
Active Contributor
5,111

Mahesh Kumar Palavalli Your case (LET) would deserve a distinct question!

Read only

Former Member
0 Likes
5,111

@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.

Read only

Sandra_Rossi
Active Contributor
5,111

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)

Read only

Former Member
0 Likes
5,111

sandra.rossi

Apologies..

I’m very new to this site..

Read only

Sandra_Rossi
Active Contributor
0 Likes
5,111

No problem. That works, thanks 😉