2017 Nov 07 4:31 PM
how can I correct this warning ?
Programa: YY_TEST Línea: 8 [Prio 3]
Do not declare fields and field symbols (GLB_TXT) globally.
Deactivatable using pragma ##NEEDED. Message Code HEL 0510
this is the ABAP code -->
REPORT yy_test.
DATA glb_txt TYPE string.
START-OF-SELECTION.
glb_txt = 'HELLO WORLD !'.
END-OF-SELECTION.
WRITE / glb_txt.
2017 Nov 09 7:32 AM
The message is a warning from extended program check (SLIN) that occurrs only, if in SLIN the checks for Programming Guidelines are switched on.

Of course it is recommended to check this, but you don't have to.
In order to circumvent the message, you have to program according to the programming guidelines
Do not declare global variables
and avoid global data by implementing your code in (local) classes.
CLASS cls DEFINITION.
PUBLIC SECTION.
CLASS-DATA var TYPE i.
CLASS-METHODS main.
ENDCLASS.
CLASS cls IMPLEMENTATION.
METHOD main.
cl_demo_output=>display( var ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
cls=>main( ).
2017 Nov 07 5:58 PM
1) You can move the Data declaration to be within the START-OF-SELECTION
=or=
2) Suppress the message by suffixing for your declaration :
DATA glb_txt TYPE string. ##NEEDED
Hope this helps.
2017 Nov 07 6:43 PM
"You can move the Data declaration to be within the START-OF-SELECTION"
This doesn't change anything, because START-OF-SELECTION does not have a local data area.
2017 Nov 08 3:51 PM
perhaps the key question is what is the alternative to avoid the use global variables in ECC Ehp 8 ?
2017 Nov 10 10:51 PM
1). "Oops". for this specfic report, the declaration should move with a form routine
2) (Based on the approach you have given) :
Some project quality deliverables, recommend, the Extended check to be free of errors/warnings, with no changes in SLIN parameters. These QA document other wise known as "Code review checklist".
Here, ECCheck is run, downloaded and attached to the document
In such cases use of Pragmas "##" can not be avoided.
Good, that this a "Hello world" program, the warning can be avoided with Object Oriented approach.
In real time scenario, if its 2000 lines of procedural code, this approach is close to impossible. The change request on the development, will have the whole program re-written just to avoid a warning in ECCheck 😄
Take the case, the usage of a SELECT-OPTIONS parameters. These are inevitable global variables, that has to pass through ECCheck. (if there is no choice of keeping the warning)
The suggestive approach is to use Pragmas - "##", telling the system : "Hey !! there is nothing i can do about this warning, but to bypass it"
2017 Nov 07 5:58 PM
Which release are you on? There is no HEL message class in EHP6.
The message is quite self-explanatory though. In a nutshell, it doesn't like that you're declaring the variable at the top (=global) and then just using it everywhere. In case of a "hello world" program it's not really a problem IMHO (although some folks here might disagree 🙂 ). But how to change this is up to you. I suspect it'll become apparent when you move on to learning about modularization.
2017 Nov 08 3:54 PM
ECC Ehp 8
in previous releases the use of global variables was ok, but in this release it seem that this is not a best practice anymore ?
2017 Nov 08 5:39 PM
"There is no HEL message class in EHP6."
This message rather comes from TRMSG or so.
2017 Nov 08 6:01 PM
I believe it has not been "best practice" for quite sometime (if ever). It was just something available and used rather widely. But you'll find many mentions on SCN that global variables need to be avoided and it's like the root cause of all evil.
But, as I noted, in particular case of such a small program I honestly don't see a problem with it. I'd just ignore the warning for now.
Searched in Google for "global variables ABAP" but didn't find what I expected. I'd refer to the ABAP documentation for your ABAP version for more information on the variable scope.
2017 Nov 08 6:02 PM
Thanks for clarification! I guess I should've actually asked about ABAP version.
2017 Nov 08 5:41 PM
Does the warning appear in normal syntax check or in extended syntax check SLIN? What are the settings in the latter?
2017 Nov 08 7:50 PM
The warning appears in transaction code SLIN and SCII ( code inspector )
The setting in transaction code SLIN is only one option --> "Programming Guidelines"
2017 Nov 09 7:32 AM
The message is a warning from extended program check (SLIN) that occurrs only, if in SLIN the checks for Programming Guidelines are switched on.

Of course it is recommended to check this, but you don't have to.
In order to circumvent the message, you have to program according to the programming guidelines
Do not declare global variables
and avoid global data by implementing your code in (local) classes.
CLASS cls DEFINITION.
PUBLIC SECTION.
CLASS-DATA var TYPE i.
CLASS-METHODS main.
ENDCLASS.
CLASS cls IMPLEMENTATION.
METHOD main.
cl_demo_output=>display( var ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
cls=>main( ).
2017 Nov 10 3:04 PM