Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizing global variables

When using the Extended Program Check, I get the following warning:

Do not declare fields and field symbols (variable name) globally.

This is from declaring global data before the selection screen. The obvious solution is that they should be declared locally in a subroutine.

If I decide to do this, the data will now be out of scope for the other subroutines, so I would end up creating something to the effect of a main() function from C or Java. This sounds like a good idea - however, events such as INITIALIZATION are not allowed to be inside of subroutines, meaning that it forces a break in scope.

Observe the sample program below:

REPORT Z_EXAMPLE.
SELECTION-SCREEN BEGIN OF BLOCK upload WITH FRAME TITLE text-H01.
  PARAMETERS: p_infile TYPE rlgrap-filename LOWER CASE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK upload.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
  PERFORM main1 CHANGING p_infile.
INITIALIZATION.
  PERFORM main2.
TOP-OF-PAGE.
  PERFORM main3.
...

main1, main2, and main3 cannot to my knowledge pass any data to one another without global declaration. If the data is parsed from the uploaded file p_infile in main1, it cannot be accessed in main2 or main3. Aside from omitting events all together, is there any way to abide by the warning but let data be passed over events?

like image 429
gkubed Avatar asked Apr 08 '26 08:04

gkubed


1 Answers

There are a variety of techniques - I prefer to code almost everything except for the basic selection screen handling in a separate controller class. The report simply defers to that class and calls its methods. Other than that - it's just a warning that you can ignore if you know what you're doing. Writing a program without any global variable at all will certainly not be practical - however, you should think at least twice before using global variables or attributes in a place where a method parameter would be more appropriate.

like image 193
vwegert Avatar answered Apr 14 '26 10:04

vwegert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!