Skip to Content
-2

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

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Posted on May 29, 2018 at 06:07 AM

    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' ) ). 

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2018 at 05:46 AM

    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_subroutines.htm

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on May 28, 2018 at 05:08 PM

    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..

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2018 at 04:36 AM
    -2

    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').
    
    Add comment
    10|10000 characters needed characters exceeded