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: 

ABAP 7.4 Loop Statement

former_member227911
Participant
0 Kudos
14,587

Hi,

I want to Loop the record and need to append in the new internal Table. As we are doing in the old abap statement

The below highlighted is an Deep Structure.

loop at output-ev_success-item into data(ls_success_output).

ls_success-status = ls_success_output-status.

append ls_success to lt_success.
clear ls_success.
endloop.

For the Above statement i need to write in ABAP 7.4 Syntax. I have tried in the below code.

TYPES : lt_succ TYPE TABLE OF zbi_success-EV_SUCCESS-item WITH EMPTY KEY.

DATA(lt_success) = VALUE lt_succ( FOR ls_succ IN output-ev_success-item ( ) ).

But am not getting the values in LT_SUCCESS.

Can you please help me on this.

Thanks,
Sadiq.

8 REPLIES 8

hegde_dhananjay
Explorer
9,858

Hi Sadiq,

Please check if this helps:

lt_success = VALUE #( FOR ls_succ IN output-ev_success-item ( status = ls_succ-status ) ). 

In your code, inner ( ) is empty.

Thank you,

Dhananjay

0 Kudos
9,858
Hi Dhananjay,

Thanks for your response. I tried with the below code as you suggested its giving the below error.

lt_success =VALUE#(FOR ls_succ IN output-ev_success-item (status= ls_succ-status )).

Error:

A table row specified in "( ... )" was expected.

0 Kudos
9,858

sadiq.k Be careful with the spaces. I guess it's copy/paste error due to SAP Community form.

Other possibility, the type of lt_success is incorrect, its lines don't contain the component status. What is the type of zbi_success-EV_SUCCESS-item? If it's a table type, you don't need to define lt_success as a "table of table".

0 Kudos
9,858

Hi Sandra,

Thanks for your response.

You are right its copy paste due to SAP form.

The type of zbi_success-EV_SUCCESS-item its an Deep Struture in the structure we have the Table Type.

As you said lt_sucess doesn't have the field called status its right but here the problem with the deep structure.

The below code i can get the data in output-ev_success-item but the problem when i specify the Status = ls_succ-status its gives me the error.

The Type for lt_success in the below Declaration.

DATA : lt_success TYPE TABLE OF zbi_bounce_back_email_response-ev_success_response-item
lt_success = VALUE #( FOR ls_succ IN output-ev_success-item ( ) ). 

Can you please help.

Regards,
Sadiq K

9,858

sadiq.k I don't think you use the right term.

You say "its an Deep Struture in the structure we have the Table Type", it can be a deep structure only if the table type is defined under a named component. Imagine that you have declared via an ABAP type "ty_email_response_item", it would look like this:

TYPES: BEGIN OF ty_email_response_item,
         status TYPE STANDARD TABLE OF string WITH EMPTY KEY,
       END OF ty_email_response_item.

See that there's a named component, so it's a structure, and because this component is a table, it's called a deep structure (a deep-structured type to be exact).

(note that the parts "STANDARD", "string" and "EMPTY KEY" could be anything else)

Instead, I think you this (in the DDic it's called a table type):

TYPES ty_email_response_item TYPE STANDARD TABLE OF string WITH EMPTY KEY.<br>

See that there's no component, consequently, it cannot be called a structure (and even less a a deep structure), it's just a Table Type (a DDIC table type in your case).

So, the line "DATA lt_success TYPE TABLE..." means that you declared lt_success like a table of table. Is it really what you want, why?

If I'm wrong, please indicate the exact source and target types (screenshots if you prefer) so that we can better understand what you want to achieve.

9,858

Hi Sandra,

Thanks a lot for your kind response. Now its working fine.

The problem not with lt_success but with lt_succ type was table type thats the reason it couldn't able to recognize the status field.

I have changed the type of lt_succ.

 TYPES : lt_succ TYPE STANDARD TABLE OF zbi_succ WITH EMPTY KEY.

The below code which i can able to get the records in lt_success


DATA(lt_success) = VALUE lt_succ( FOR ls_succ IN output-ev_success-item ( status = ls_succ-status ) ).

Thanks Sandra.

Regards,
Sadiq

Sandra_Rossi
Active Contributor
9,858

You may wish to edit your question to format your ABAP code with the CODE button, so that everyone can read it easily. Like that:

loop at output-ev_success-item into data(ls_success_output).
ls_success-status = ls_success_output-status.
append ls_success to lt_success.
clear ls_success.
endloop.

and that:

TYPES : lt_succ TYPE TABLE OF zbi_success-EV_SUCCESS-item WITH EMPTY KEY.
DATA(lt_success) = VALUE lt_succ( FOR ls_succ IN output-ev_success-item ( ) ).

Sandra_Rossi
Active Contributor
9,858

The issue with your code is that you just add empty lines by using empty parentheses ( ).

You must define inside the parentheses the contents of the line you want to store in lt_success. Its content is evaluated at each iteration of the table output-ev_success-item.