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:ย 

Convert perform subroutine into method using oops concepts in SAP ABAP.

its_mkz
Discoverer
0 Kudos

Greetings Abapers,

Need to translate-procedural subroutine call using internal table into method call using oops concepts.

Sample statement -

PERFORM f_test_subroutine TABLE lt_table .

------------------------------------------------------------------------

FORM f_test_subroutine TABLES tab1 like gt_test.

ENDFORM.

------------------------------------------------------------------------

Please provide definition and implementation of class as well.

Thanks in advance ๐Ÿ™‚

6 REPLIES 6

moshenaveh
Community Manager
Community Manager
0 Kudos

Welcome to the SAP Community! Thank you for visiting us to get answers to your questions.

Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.

First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Secondly, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will help you when submitting questions to the community.

Finally, I recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

Sandra_Rossi
Active Contributor

Seems quite basic, what is your problem rewriting form as method?

matt
Active Contributor

Chat gpt can answer this kind of question reasonably well.

its_mkz
Discoverer
0 Kudos

Usually methods don't support TABLES parameters.

So wanted to know how exactly we translate the same.

matt
Active Contributor
BEGIN OF TYPE: ty_record,
  field1 TYPE i,
  field2 type char20,
END OF TYPE ty_record.

TYPE ty_records TYPE STANDARD TABLE OF ty_record WITH DEFAULT KEY.

CLASS myclass DEFINITION.
  PUBLIC SECTION.
    METHODS my_method
      IMPORTING i_records TYPE ty_records.
...

Sandra_Rossi
Active Contributor

It's not "usually", "TABLES" parameter has been obsolete for a long time (at same time as subroutines I guess), and doesn't exist in methods. You pass internal tables by declaring a Table Type, and using it via IMPORTING, EXPORTING, CHANGING or RETURNING/RECEIVING.

TYPES your_type_name TYPE ... TABLE OF ... (could be also a range type or a DDIC Table Type instead of TABLE OF)

METHODS ...

parameter_name TYPE your_type_name

...