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: 

How to call a FM inside FOR loop with new ABAP syntax?

Nitish2027
Participant

Hi experts,

I have a requirement to call a FM inside the FOR Loop with the ABAP 750 syntax.

Basically what I want to know is how do I code the below requirement using a FOR Loop, if it is possible.

LOOP AT itab INTO wa.
CALL FUNCTION 'X'
EXPORTING
e_param = wa-field
IMPORTING
i_param = wa-field.
wa_range-sign = 'I'.
wa_range-option = 'EQ'.
wa_range-option-low = wa-field.
APPEND wa_range TO lr_range.
ENDLOOP.

I'm trying to do something like the below code. But, I want to pass wa-field to a conversion FM before creating the range table.

DATA(lr_range) = VALUE lr_range(
FOR wa IN it_tab (
sign = 'I'
option = 'EQ'
low = wa-field
)
).

How do I achieve this inside the FOR Loop?

Please advise. Thanks 🙂

1 ACCEPTED SOLUTION

DominikTylczyn
Active Contributor

Hello nitish2027

As frdric.girod FM is an old concept, that doesn't mix and match nicely with new ABAP syntax. However you can call methods from LET expression - see SAP Help let_exp - LET ... IN, example of alternative 1:

TYPES:
BEGIN OF struc,
col1 TYPE i,
col2 TYPE i,
END OF struc.

DATA(rnd) = cl_abap_random_int=>create(
seed = CONV i( sy-uzeit ) min = 1 max = 10 ).

DO 5 TIMES.
DATA(struc) = VALUE struc(
LET x = rnd->get_next( )
y = x * x
z = sy-index * 1000 IN col1 = x + z
col2 = y + z ).
cl_demo_output=>write( struc ).
ENDDO.
cl_demo_output=>display( ).

So, you could wrap the FM up in a method and call the method from FOR loop.

Best regards

Dominik Tylczynski

4 REPLIES 4

FredericGirod
Active Contributor

Strange to request to use new ABAP syntax with an old concept like the FM.

DominikTylczyn
Active Contributor

Hello nitish2027

As frdric.girod FM is an old concept, that doesn't mix and match nicely with new ABAP syntax. However you can call methods from LET expression - see SAP Help let_exp - LET ... IN, example of alternative 1:

TYPES:
BEGIN OF struc,
col1 TYPE i,
col2 TYPE i,
END OF struc.

DATA(rnd) = cl_abap_random_int=>create(
seed = CONV i( sy-uzeit ) min = 1 max = 10 ).

DO 5 TIMES.
DATA(struc) = VALUE struc(
LET x = rnd->get_next( )
y = x * x
z = sy-index * 1000 IN col1 = x + z
col2 = y + z ).
cl_demo_output=>write( struc ).
ENDDO.
cl_demo_output=>display( ).

So, you could wrap the FM up in a method and call the method from FOR loop.

Best regards

Dominik Tylczynski

Thanks. I will wrap the FMs functionality in a method and call it using LET.

Nitish2027
Participant
0 Kudos

That's what I wanted to know if it is possible to do if the requirement is like this.

Now I understand that requirements with FMs involved should be done with Loop Endloop.