2022 Dec 01 11:47 AM
Hi I have two subroutines, one that converts the necessary PO currencies and one that displays it in ALV.
FORM convert_foreign_to_local.
DATA: lv_foreign_amt LIKE ekbe-wrbtr,
lv_inv_amt LIKE ekbe-wrbtr.
CALL FUNCTION 'CONVERT_AMOUNT_TO_CURRENCY'
EXPORTING
foreign_currency = ekbe-waers
foreign_amount = ekbe-wrbtr
local_currency = ekko-waers
IMPORTING
local_amount = lv_inv_amt
EXCEPTIONS
error = 1
others = 2.
IF sy-subrc = 0.
lv_foreign_amt = lv_inv_amt.
ENDIF.
ENDFORM.
FORM display_alv.
>>> I want to use the lv_foreign_amt here however, I can't get the LV_FOREIGN_AMT value here.
>>> g_test_variable = lv_foreign_amt.
ENDFORM.
2022 Dec 01 11:55 AM
2022 Dec 01 12:02 PM
Hi,
If they are belongs to the same program than you can use global variable (like using the TOP include).
If not than the easiest way to create a new calss, ot use an existing one and use a static attribute for this purpose. Class static attributes are available at all level in the call stack.
Br
Richard
2022 Dec 01 12:13 PM
2022 Dec 01 12:17 PM
rpalotaiebc global variable is bad, very very bad, you should have a look to the Clean Code ABAP
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md
2022 Dec 01 3:00 PM
Hi Frederic,
Pls. let me know which part of the clean code suggestion refersto the global variable usage recommendations?
I can't find that, many thanks.
You are right that a subroutine should always use only data that it recieves via its interface. This is the best way to keep the code easily understandable for others.
But there are many cases where you need to use tricks, specially if you are modifying standard code, the subroutines are in different programs and levels of the call stack...
Back to our current problem Anuja has provided the rigth solution if you are running the subroutines from the same program. First you have to define the lv_foreign_amt parameter in your main program and then pass this variable to the subroutines(of this program) as part of their interface.
Br
Richard
2022 Dec 01 3:17 PM
2022 Dec 01 12:39 PM
Hi,
While calling both subroutine need to pass parameters with same name.
Perform convert_foreign_to_local changing lv_foreign_amt.
Perform display_alv using lv_foreign_amt.
form convert_foreign_to_local changing lv_foreign_amt type ekbe-wrbtr.
.
.
endform.
form display_alv using lv_foreign_amt type ekbe-wrbtr .
endform.
2022 Dec 01 12:51 PM