ERPClimb logoERPClimb
Modularization
ABAP Developmentintermediate 8 min read

Modularization Part 8: Parameter Passing — IMPORTING, EXPORTING, CHANGING and RETURNING

Preview · a free account unlocks the full lesson

Key takeaway

Design method interfaces correctly: parameter kinds, pass by reference vs VALUE( ), OPTIONAL and DEFAULT, IS SUPPLIED, typing (generic vs concrete), and when RETURNING makes code clearer.

In this lessonShow sections

Visual overview

Modularization Part 8: Parameter Passing — IMPORTING, EXPORTING, CHANGING and RETURNING — learning sheetIn one line: Design method interfaces correctly: parameter kinds, pass by reference vs VALUE( ), OPTIONAL and DEFAULT, IS SUPPLIED, typing (generic vs concrete), and when RETURNING makes code clearer.ERPClimb.com / ABAP / LESSON 8/10 / LEARNING SHEETModularization Part 8: Parameter Passing — IMPORTING,EXPORTING, CHANGING and RETURNING1 · IN ONE LINEDesign method interfaces correctly: parameter kinds, pass by reference vs VALUE( ), OPTIONALand DEFAULT, IS SUPPLIED, typing (generic vs concrete), and when RETURNING makes codeclearer.2 · KEY IDEAS EXPLAINEDParameter KindsIMPORTING iv_carrid TYPE s_carr_id — input; cannotbe changed inside the method (by reference).EXPORTING et_flights TYPE ty_flights — output.By Reference vs By ValueReference (default): no copy — efficient for largetables. IMPORTING by reference is protectedagainst change.VALUE( ): copy — safe but costs time for largedata; required for RETURNING and RFC/update FMs.Optional, Default, Is SuppliedMETHODS get_flights IMPORTING iv_carrid TYPEs_carr_id iv_max_rows TYPE i DEFAULT 100 iv_dateTYPE s_date OPTIONAL.TypingConcrete (TYPE s_carr_id, TYPE ty_flights) —syntax check catches mismatches; preferred.Generic (TYPE any, TYPE ANY TABLE, TYPE data) —for truly generic utilities; needs fieldsymbols/RTTI inside.3 · DO · AVOIDBest practice!Common mistakeRETURNING for single results.Concrete, dictionary-based typing.Initialize outputs at the start of the method.✕Not clearing EXPORTING parameters.✕Many OPTIONAL parameters instead of separatemethods.✕Using CHANGING for pure outputs.4 · IN A REAL PROJECTA validation method had an EXPORTING table of error messages and didn't clear it. When called in a loop,errors from the previous document remained in the table, so valid documents were rejected with the previousdocument's errors. Adding CLEAR at the beginning — and later changing the method to RETURNING a message table…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 6 and 7 of this series created classes; a good method interface is what makes a method easy to call correctly and hard to misuse. There are four kinds of method parameters. IMPORTING, for example iv_carrid TYPE s_carr_id, is input and cannot be changed inside the method when passed by reference. EXPORTING, for example et_flights TYPE ty_flights, is output.

CHANGING, for example ct_flights TYPE ty_flights, is both in and out. RETURNING, for example VALUE(rv_count) TYPE i, gives exactly one result, is always passed by value, and is what enables functional-style calls such as IF lo->count( ) > 0.

RAISING, for example zcx_flight_error, declares the exceptions a method can raise — not technically a parameter, but still part of its interface.

On passing mechanics: by reference, the default, makes no copy and is efficient for large tables, and an IMPORTING parameter passed by reference is protected against being changed inside the method. VALUE( ) makes a copy, which is safe but costs time for large data, and is required both for RETURNING and for RFC or update function modules.

One trap to watch for: an EXPORTING parameter passed by reference keeps whatever content it already had until you explicitly overwrite it, so you need to CLEAR your output parameters at the start of the method — or use VALUE( ), which always starts out initial.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.