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: 

Calling a method with implicitly giving formal parameter names in OOABAP ?

former_member197696
Participant
0 Kudos

My Method Declaration

fill_finaltab

importing

VALUE(im_toc) TYPE char30

VALUE(im_check) TYPE char50

Implementation of the method mentioned above.

METHOD fill_finaltab.
  DATA: lwa_final TYPE gty_final.
  lwa_final-toc = im_toc.
  lwa_final-check = im_check.
  APPEND lwa_final TO gt_final.
  CLEAR lwa_final.
ENDMETHOD.

CALLING THE METHOD.

fill_finaltab( im_toc = 'text1' im_check = 'text2' ).

The way I want to call the method.

fill_finaltab( text1 text2 text3 text4 text5 ).

Yes, I want to Omit the formal parameter names just for convenience sake as I would use it many times in a program.

I have tried making my import parameters optional, declared via reference and value, used preferred parameter option and so on.

Basically, I tried all the permutation and combinations while declaring the method signature.

The code works fine but I want to learn why cannot I send parameters just as I send them in a perform(old school)? perform f_data: PARAM1 PARAM2 PARAM3 ETC.

NOTE: this is not my assignment nor office work but just my personal research.

regards,

kk

1 ACCEPTED SOLUTION

matt
Active Contributor

You cannot do what you want because ABAP hasn't been designed that way. Parameters are named - the only exception is single parameters or a single preferred parameter.

Once you get to a 7.40 you can insert the values directly.

INSERT VALUE #( im_toc = 'text1' im_check = 'text2' ) INTO TABLE gt_final.

or even

gt_final = value #( ( 'text1' im_check = 'text2' )
                    ( 'text3' im_check = 'text4' ) ). 

9 REPLIES 9

nomssi
Active Contributor

I would use macros, e.g.

DEFINE m_fill.
  fill_finaltab( im_toc = &1
                 im_check = &2 ).
END-OF-DEFINITION.

m_fill: 'text1' 'text2',
        'text3' 'text4',
        'text5' 'text6'.

but beware syntactic sugar..

matt
Active Contributor
0 Kudos

To be fair, if you've ever tried writing a test class in < 7.4, setting up a table of test data is a pain. Macros are tempting...

former_member210008
Active Participant
0 Kudos

You can omit only preferred parameter name. But you still can use : while calling method.

CLASS lcl_class DEFINITION.
  PUBLIC SECTION.
    METHODS m1 IMPORTING p1 TYPE char30 PREFERRED PARAMETER p1.
ENDCLASS.

CLASS lcl_class IMPLEMENTATION.
  METHOD m1.

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(obj) = new lcl_class( ).
  obj->m1(: 'Text1'),'Text2'),'Text3').

0 Kudos

I remember when the documentation for UPDATE with SET gave an example using a colon. It caused much confusion. Long since fixed though.

horst_keller
Product and Topic Expert
Product and Topic Expert

Methods have keyword parameters for good reasons.

One reason not to use subroutines any more are their positional parameters.

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

matt
Active Contributor
0 Kudos

Please in future use the "code" button in the editor to correctly format any code you post. I've done it for you this time.

matt
Active Contributor

You cannot do what you want because ABAP hasn't been designed that way. Parameters are named - the only exception is single parameters or a single preferred parameter.

Once you get to a 7.40 you can insert the values directly.

INSERT VALUE #( im_toc = 'text1' im_check = 'text2' ) INTO TABLE gt_final.

or even

gt_final = value #( ( 'text1' im_check = 'text2' )
                    ( 'text3' im_check = 'text4' ) ).