2022 Jul 25 10:51 AM
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 🙂
2022 Jul 25 11:07 AM
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
2022 Jul 25 10:53 AM
Strange to request to use new ABAP syntax with an old concept like the FM.
2022 Jul 25 11:07 AM
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
2022 Jul 25 11:30 AM
Thanks. I will wrap the FMs functionality in a method and call it using LET.
2022 Jul 25 11:28 AM
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.