SAP ABAP: referencing caller program’s variables within a CALL’ed FM

When executing a CALL command there is a way to access the variables of a caller program – see sample code below.

REPORT zcustom_caller.

DATA: gv_a TYPE i,
      gv_b TYPE i,
      gv_c TYPE i.

gv_a = 1.
gv_b = 2.
gv_c = 3.

CALL FUNCTION 'z_custom_called'
  EXPORTING
    i_a = gv_a
  IMPORTING
    e_c = gv_c.

WRITE: /
       'gv_a =', gv_a, /,
       'gv_b =', gv_b, /,
       'gv_c =', gv_c.

And here is the function module

FUNCTION z_custom_called.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_A) TYPE  I
*"  EXPORTING
*"     REFERENCE(E_C) TYPE  I
*"----------------------------------------------------------------------

  DATA: gv_b type i.
  FIELD-SYMBOLS:  TYPE i.
  e_c = i_a.

  ASSIGN ('(ZCUSTOM_CALLER)gv_b') to .
  check sy-subrc eq 0.
  gv_b    = .
  gv_b    = 1055.
    = gv_b.

ENDFUNCTION.

Leave a Reply

*

captcha *