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

Calling a method multiple times with one call

kmoore007
Active Contributor
0 Likes
3,278

I am rather new to ABAP OO. I'm trying to re-write a traditional ABAP program using ABAP OO. I ran across a PERFORM routine which I'm not sure if I can duplicate how it works using something similar with a METHOD.

Here is the PERFORM routine which passes only one variable, but the routine is performed multiple times for each of the values after the 'USING' command:

PERFORM init_pids USING: 'PBR', 'PBS', 'PRG', 'PKR', 'KOS'.

The only way I know of how to achieve this same thing with ABAP OO is like this, which you can see takes more coding:

CALL METHOD lcl_zhr10014=>init_pids( 'PBR' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PBS' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PRG' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PKR' ).

CALL METHOD lcl_zhr10014=>init_pids( 'KOS' ).

Is there another more efficient way?

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,555

PERFORM init_pids USING: 'PBR', 'PBS', 'PRG', 'PKR', 'KOS'.

As you have chained the PERFORM statement, you can also chain this CALL METHOD statement.


CALL METHOD: 
  lcl_zhr10014=>init_pids( 'PBR' ),
  lcl_zhr10014=>init_pids( 'PBS' ),
  lcl_zhr10014=>init_pids( 'PRG' ),
  lcl_zhr10014=>init_pids( 'PKR' ),
  lcl_zhr10014=>init_pids( 'KOS' ).

You can also try to create MACRO and use it.

If you are using the Global class than create a macro in the MACRO section (button on the application toolbar) and use it here instead of calling the method.

Regards,

Naimesh Patel

I am rather new to ABAP OO. I'm trying to re-write a traditional ABAP program using ABAP OO. I ran across a PERFORM routine which I'm not sure if I can duplicate how it works using something similar with a METHOD.

Here is the PERFORM routine which passes only one variable, but the routine is performed multiple times for each of the values after the 'USING' command:

PERFORM init_pids USING: 'PBR', 'PBS', 'PRG', 'PKR', 'KOS'.

The only way I know of how to achieve this same thing with ABAP OO is like this, which you can see takes more coding:

CALL METHOD lcl_zhr10014=>init_pids( 'PBR' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PBS' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PRG' ).

CALL METHOD lcl_zhr10014=>init_pids( 'PKR' ).

CALL METHOD lcl_zhr10014=>init_pids( 'KOS' ).

Is there another more efficient way?

2 REPLIES 2
Read only

Former Member
0 Likes
1,555

Hi Kenneth,

Here is what i think:


PERFORM init_pids USING: 'PBR', 'PBS', 'PRG', 'PKR', 'KOS'.

*Technically it be will execute as, Its JUST more readable
PERFORM init_pids USING 'PBR'.
PERFORM init_pids USING 'PBS'.
PERFORM init_pids USING 'PRG'.
PERFORM init_pids USING 'PKR'.
PERFORM init_pids USING 'KOS'.


* As far as OO is concerned you have written as
CALL METHOD lcl_zhr10014=>init_pids( 'PBR' ).
CALL METHOD lcl_zhr10014=>init_pids( 'PBS' ).
CALL METHOD lcl_zhr10014=>init_pids( 'PRG' ).
CALL METHOD lcl_zhr10014=>init_pids( 'PKR' ).
CALL METHOD lcl_zhr10014=>init_pids( 'KOS' ).

So both ways I will say are same. In OO there is no other way to write it.

If at all you need to change it you can WRITE CALL METHOD in LOOP and change the parameter value runtime, but this doesn't add any value.

Regards

Shital

Read only

naimesh_patel
Active Contributor
0 Likes
1,556

PERFORM init_pids USING: 'PBR', 'PBS', 'PRG', 'PKR', 'KOS'.

As you have chained the PERFORM statement, you can also chain this CALL METHOD statement.


CALL METHOD: 
  lcl_zhr10014=>init_pids( 'PBR' ),
  lcl_zhr10014=>init_pids( 'PBS' ),
  lcl_zhr10014=>init_pids( 'PRG' ),
  lcl_zhr10014=>init_pids( 'PKR' ),
  lcl_zhr10014=>init_pids( 'KOS' ).

You can also try to create MACRO and use it.

If you are using the Global class than create a macro in the MACRO section (button on the application toolbar) and use it here instead of calling the method.

Regards,

Naimesh Patel