05-28-2018 12:59 PM
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
05-29-2018 7: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' ) ).
05-28-2018 6: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..
05-29-2018 6:47 AM
05-29-2018 7:09 AM
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...
05-29-2018 5:36 AM
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').
05-29-2018 6:48 AM
05-29-2018 7:00 AM
I remember when the documentation for UPDATE with SET gave an example using a colon. It caused much confusion. Long since fixed though.
05-29-2018 6:46 AM
Methods have keyword parameters for good reasons.
One reason not to use subroutines any more are their positional parameters.
05-29-2018 7:03 AM
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.
05-29-2018 7: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' ) ).