Application Development 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: 

ABAP 7.40 Syntax

Former Member

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

Sandra_Rossi
Active Contributor

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

maheshpalavalli
Active Contributor

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.

alopezv74
Participant
0 Kudos

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

Domi
Contributor

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

Sandra_Rossi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Sandra_Rossi
Active Contributor

It's Domi, not Dorni 🙂

0 Kudos

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

Domi
Contributor
0 Kudos

@ 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

Sandra_Rossi
Active Contributor

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.

Sandra_Rossi
Active Contributor

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

Former Member
0 Kudos

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

Sandra_Rossi
Active Contributor

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)

Former Member
0 Kudos

sandra.rossi

Apologies..

I’m very new to this site..

Sandra_Rossi
Active Contributor
0 Kudos

No problem. That works, thanks 😉