Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to correct Message Code HEL 0510 ?

jimmy_guzman
Explorer
0 Kudos

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.

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

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( ).
13 REPLIES 13

p190355
Active Contributor
0 Kudos

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.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

"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.

0 Kudos

perhaps the key question is what is the alternative to avoid the use global variables in ECC Ehp 8 ?

p190355
Active Contributor

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"

Jelena
Active Contributor
0 Kudos

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.

0 Kudos

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 ?

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

"There is no HEL message class in EHP6."

This message rather comes from TRMSG or so.

Jelena
Active Contributor

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.

Jelena
Active Contributor
0 Kudos

Thanks for clarification! I guess I should've actually asked about ABAP version.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Does the warning appear in normal syntax check or in extended syntax check SLIN? What are the settings in the latter?

jimmy_guzman
Explorer
0 Kudos

The warning appears in transaction code SLIN and SCII ( code inspector )

The setting in transaction code SLIN is only one option --> "Programming Guidelines"

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

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( ).

0 Kudos

thanks Horst Keller