IT CanvassTalk to an advisor
SAP ABAP development · LessonBy , SAP Trainer, 13 yrs · Published · SAP S/4HANA 2023 · all levels

Methods

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.

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.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
Which statement is true of Methods?

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.
Already working on SAP and stuck on a live ticket?Get an expert SAP developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support