Created
March 2, 2011 14:26
-
-
Save esjewett/851008 to your computer and use it in GitHub Desktop.
See if you can guess the output?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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