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

Help using FOR iteration statement 7.4 feature

jeff_broodwar
Active Participant
15,994

Hi Friends,

I came across the "for" statement, upon checking our system version shows we're using 740 sp-level 0017.

i_test = value #( for wa_bukrs in i_bukrs( wa_bukrs-bukrs ) ).
*Error the syntax for a method specification is "objref->method or...
*if i try the other form...
data(i_test2) = value ty_bukrs( for wa_bukrs in i_bukrs( wa_bukrs-bukrs ) ).
*Error No component exists with the name "FOR". "FOR".

I know its basic, but i've tried several ways and different forums, these all point to same syntax which doesn't work at all.. any inputs will be appreciated.

Thank you.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
7,760

DATA flights type table of sflight.
DATA carrids type table of sflight-carrid.
carrids = value #( for <flight> in flights ( <flight>-carrid ) ). " space before parenthesis

Beware the spaces in ABAP, they are very important ! (space before parenthesis)

18 REPLIES 18
Read only

0 Likes
7,760

Thanks Horst, is it possible to have the syntax checked and recommend possible solution? I can't make it work. thanks.

Read only

0 Likes
7,760

Aren't you able to compare it yourself with the syntax and the examples from the documentation?

You have to specify an internal table behind IN. But you use the syntax for a function call.

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_in_itab.ht...

Read only

matt
Active Contributor
0 Likes
7,760

Looks like an importing parameter rather than a function call.

Read only

0 Likes
7,760

Yeah, the name, but the parentheses behind i_bukrs are the syntax for a function(al method) call and that's also what the syntax check complains. It doesn't care for names. And i_ could also mean itab, who knows.

Read only

matt
Active Contributor
0 Likes
7,760

I didn't look to closely, but thought perhaps it's an attempt at some kind of Value expression!

Read only

matt
Active Contributor
0 Likes
7,760

i_ is an internal table in the OP's standards. How I hate typing prefixes!

Read only

DoanManhQuynh
Active Contributor
0 Likes
7,760

Hi jeff.

I guest what you want to do is fetch company code from i_burks to i_test.

if so, i think FOR GROUPS could be used:

i_test = VALUE #( FOR GROUPS burks OF <fs_burks> IN i_burks GROUP BY <fs_burks>-burks WITHOUT MEMBERS ( burks ) ).
Read only

0 Likes
7,760

Thanks quynh, will also try GROUPS as well.

Read only

Sandra_Rossi
Active Contributor
7,761

DATA flights type table of sflight.
DATA carrids type table of sflight-carrid.
carrids = value #( for <flight> in flights ( <flight>-carrid ) ). " space before parenthesis

Beware the spaces in ABAP, they are very important ! (space before parenthesis)

Read only

0 Likes
7,760

Thanks All, I removed the space before the parenthesis however, I still get an error:

TYPES: BEGIN OF ty_bukrs,
  bukrs TYPE bukrs,
  butxt TYPE butxt,
  ort01 TYPE ort01,
  land1 TYPE land1,
  waers TYPE waers,
  spras TYPE spras,
  ktopl TYPE ktopl.
TYPES: END OF ty_bukrs.

data(i_test2) = value ty_bukrs( for wa_bukrs in i_bukrs ( wa_bukrs-bukrs ) ). 
"Error no component exists with the name "FOR"."FOR".

any ideas? thank you.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
7,760

Ouch, Sandra you're simply the best. I didn't see it 😉

Read only

matt
Active Contributor
7,760

Maybe this will make it clear:

TYPES: BEGIN OF ty_bukrs,
         bukrs TYPE bukrs,
         butxt TYPE butxt,
         ort01 TYPE ort01,
         land1 TYPE land1,
         waers TYPE waers,
         spras TYPE spras,
         ktopl TYPE ktopl.
TYPES: END OF ty_bukrs.
DATA i_bukrs TYPE STANDARD TABLE OF ty_bukrs.
TYPES ty_company_codes TYPE STANDARD TABLE OF bukrs WITH DEFAULT KEY.

DATA(i_test2) = VALUE ty_company_codes( FOR wa_bukrs IN i_bukrs ( wa_bukrs-bukrs ) ).

Your FOR expression was not returning data of type ty_bukrs.

Read only

0 Likes
7,760

Thanks Matthew, working now. but can you also make the code below work (please include declarations similar to your previous answer). having trouble using "#" in this example:

i_test = value #( for wa_bukrs in i_bukrs ( wa_bukrs-bukrs ) ).

Thanks!

Read only

matt
Active Contributor
0 Likes
7,760

I respectfully decline.

Read only

0 Likes
7,760

anyway, thanks for your inputs appreciate it.

Read only

former_member670752
Discoverer
0 Likes
7,760

Hello Jeff,

I am getting the same error No component exists with name "FOR" . "FOR"

Could you please let me know how did you solve your issue.

Thanks in advance.

Best Regards,

Kavya

Read only

jeff_broodwar
Active Participant
0 Likes
7,760

Hi Kavya, Please see answer of Sandra Rossi. Normally space issue. thanks.