parametersabapfunction-module

Do we need to clear an export parameter at FM start?


I found this code:

FUNCTION /FOO/BAR.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(IV_XYZ) TYPE  STRING
*"  EXPORTING
*"     VALUE(EV_RESULT_JSON) TYPE  STRING
*"----------------------------------------------------------------------



*-- Initialization
  clear ev_result_json.

Is clear ev_result_json needed?


Solution

  • Yes or No.

    No because it's a parameter passed by value (VALUE(EV_RESULT_JSON)) so its start value is always initial.

    If it was passed by reference then the answer might be yes because its start value is the value of the argument passed, so it depends on the algorithm of the function module.

    PS: personally, in the case of a parameter passed by value, I sometimes prefer to add a CLEAR at the start of the processing to facilitate the debug with the "jump" button to restart the processing; in the case of a parameter passed by reference, I sometimes add a CLEAR to "document" the fact that the input value is not used.

    Addendum 1 hr later: because the logic of the EXPORTING parameter is not so obvious, and because ABAP Objects is recommended (as far as possible), it is preferable to turn the function module into a functional method with the RETURNING parameter which is always passed by value and so there can't be any confusion.