0
votes

I have a FM with structure in importing. When I try to change field value (wa_str-data = '31129999' for example), the change works, but when I get out of the FM, the field value is reset.

Is it possible to change the field value of a Function Module importing parameter which is of structured type?

Thanks to all.

1
Why don't you define your "importing" parameter as a "changing" parameter? (importing means it's just an input parameter, exporting means it's just an output parameter, and changing means it's both an input and output parameter) - Sandra Rossi
Hi,thanks for response. The function that I have to modify provides only internal changes to it. - Raffaele
So, you can't. Your only chance is to modify the calling program too and pass the value to be changed, the way you wish. Be careful of side effects, in that changing the official code of SAP software means in case of data integrity errors that SAP assistance is not included in SAP license. - Sandra Rossi
You call it like IMPORTING or defined in FM like importing? The former is output parameter, the latter is input - Suncatcher

1 Answers

0
votes

No, you can't change the value of an IMPORTING parameter (unless it happens to be a TYPE REF TO, in which case you can change the value of the referenced object/data). You can only change values of CHANGING parameters. However, there is a dirty trick you might be able to use here. If you want to access the variable foo in the calling program Z_BAR, then you can do this:

FIELD-SYMBOLS <foo>.
ASSIGN ('(Z_BAR)FOO-DATA') TO <foo>.
IF sy-subrc = 0.
    <foo> = newValue.
ENDIF.

(By the way, Z_BAR does not even need to be the direct caller of the function module. It just needs to be somewhere in the call stack.)

Why am I calling this a "dirty" trick?

  • It creates "spooky effects at a distance". Anyone examining Z_BAR would never expect a function module to change foo when it's not in its parameter list.
  • The variable name gets resolved at runtime, so there is no syntax check when you misspell it.
  • It breaks when the variable in the calling program gets renamed, and you won't know until it fails at runtime.
  • You need to know the name of the calling program in advance. When the function module gets called from another program, then it's not going to work anymore.

So I would only recommend this as a last resort measure.