2

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?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
guettli
  • 25,042
  • 81
  • 346
  • 663

2 Answers2

5

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    Correct. One amendment: clearing can be omitted if the exporting parameter is assigned a definite value in all execution branches, for example as ev_result_json = ‚something‘. This is quite often the case. Functions that do not do that, or not in all branches, should definitely add the CLEAR. Code Inspector should find these occurrences and throw a corresponding warning. – Florian Oct 26 '18 at 06:29
0

No because they will be cleared after you exit the FM.

Sorry didn't read properly. The answer is still NO. Because there is nothing in the Export Value right after you enter the FM.

Binh
  • 241
  • 1
  • 15