Skip to content

Instantly share code, notes, and snippets.

@esjewett
Created March 2, 2011 14:26
Show Gist options
  • Save esjewett/851008 to your computer and use it in GitHub Desktop.
Save esjewett/851008 to your computer and use it in GitHub Desktop.
See if you can guess the output?
FUNCTION ZTEST12345.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(E_TEST) TYPE I
*"----------------------------------------------------------------------
e_test = e_test + 1.
ENDFUNCTION.
Example A:
FUNCTION ZEXAMPLEA.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(E_TEST) TYPE I
*"----------------------------------------------------------------------
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test.
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test.
ENDFUNCTION.
Example B:
FUNCTION ZEXAMPLEB.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(E_TEST) TYPE I
*"----------------------------------------------------------------------
CALL FUNCTION 'ZTEST12345'
* IMPORTING
* E_TEST = e_test
.
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test.
ENDFUNCTION.
Example C:
FUNCTION ZEXAMPLEC.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(E_TEST) TYPE I
*"----------------------------------------------------------------------
data e_test2 type i.
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test2.
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test.
ENDFUNCTION.
Example D:
FUNCTION ZEXAMPLED.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXPORTING
*" REFERENCE(E_TEST) TYPE I
*"----------------------------------------------------------------------
e_test = 1.
CALL FUNCTION 'ZTEST12345'
IMPORTING
E_TEST = e_test.
ENDFUNCTION.
Answer key (value of e_test):
A: 2
B: 1
C: 1
D: 2
Moral of the story: The way to approximate functional programming in ABAP is using class
methods and RETURNING parameters. But wait ... doesn't that just force pass-by-value,
which the documentation tells us is incredibly inefficient for complex data structures?
Yes, indeed it does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment