Skip to content
IT Canvass
SAP ABAP development · Lesson

Methods

Quick answer

Keep methods small and single-purpose, prefer RETURNING for a single result (enabling clean inline calls), name them for what they do, and handle errors via class-based exceptions (RAISING).

Key takeaways

  • A method is a named block of code inside a class that performs a task, optionally taking input and returning output.
  • IMPORTING: inputs passed in.
  • EXPORTING: outputs passed back.
  • Watch out: Giant do-everything methods.

What a method is

A method is a named block of code inside a class that performs a task, optionally taking input and returning output. Methods encapsulate logic so it can be called, reused and tested. They replace the older FORM subroutines and are the building blocks of OO ABAP.

Parameter kinds

  • IMPORTING: inputs passed in.
  • EXPORTING: outputs passed back.
  • CHANGING: in-out parameters.
  • RETURNING: a single return value (enables functional-style calls).
  • RAISING: exceptions the method may raise.

A functional method call

METHODS get_discount IMPORTING iv_amount TYPE p
                     RETURNING VALUE(rv_disc) TYPE p
                     RAISING cx_invalid_input.

" call it inline
DATA(lv_d) = lo_pricing->get_discount( iv_amount = 1000 ).

Good method design

Keep methods small and single-purpose, prefer RETURNING for a single result (enabling clean inline calls), name them for what they do, and handle errors via class-based exceptions (RAISING). Small, well-named methods make code readable and testable.

Common pitfalls

  • Giant do-everything methods.
  • Overusing EXPORTING where RETURNING is cleaner.
  • Ignoring exceptions instead of raising/handling them.

Want to learn this properly?

Our live, instructor-led SAP Training covers this hands-on, with real projects and a certification path.

Check your understanding

  1. Which statement is true of Methods?

    • A. An RFC destination defines how SAP connects to another system for remote calls.
    • B. Methods encapsulate logic so it can be called, reused and tested.
    • C. SAP’s architecture overview ties together the pieces that make an SAP system work: the three-tier…
    Show answer

    B. Methods encapsulate logic so it can be called, reused and tested.

    Covered in the “What a method is” section of this lesson.

  2. Which of these also applies to Methods?

    • A. Wrong tool for the integration style.
    • B. Assuming one is universally better, fit depends on your needs.
    • C. They replace the older FORM subroutines and are the building blocks of OO ABAP.
    Show answer

    C. They replace the older FORM subroutines and are the building blocks of OO ABAP.

    Covered in the “What a method is” section of this lesson.

  3. Which part of the Learn SAP curriculum covers Methods?

    • A. SAP HANA
    • B. SAP FI
    • C. SAP ABAP development
    Show answer

    C. SAP ABAP development

    This lesson sits in the SAP ABAP development section of the Learn SAP course.

Frequently asked questions

What does the term Methods refer to in SAP?

Methods are the functions of ABAP classes, the units of behaviour that do the work. Writing well-designed methods with clear parameters is core to clean object-oriented ABAP.

What is the practical takeaway on Methods?

Keep methods small and single-purpose, prefer RETURNING for a single result (enabling clean inline calls), name them for what they do, and handle errors via class-based exceptions (RAISING).

What is worth remembering about Methods in practice?

A method is a named block of code inside a class that performs a task, optionally taking input and returning output.

What tends to go wrong with Methods?

Giant do-everything methods. Overusing EXPORTING where RETURNING is cleaner. Ignoring exceptions instead of raising/handling them.
CallWhatsAppEnquire