‎2021 Jun 14 10:45 AM
Hello, I have the below code in a constructor to a class. I know that this is not a good one but I am going to re-construct this class later. The code is:
method constructor.
clear( ).
define log_mess.
CLEAR gs_log_message.
gs_log_message-msgty = &1.
gs_log_message-msgid = &2.
gs_log_message-msgno = &3.
gs_log_message-msgv1 = &4.
gs_log_message-msgv2 = &5.
gs_log_message-msgv3 = &6.
gs_log_message-msgv4 = &7.
zcl_slg1_log=>add_log( gs_log_message ). "SLG1
IF &1 EQ 'E'.
gv_error = abap_true.
ENDIF.
end-of-definition.
endmethod.
This give the below error in eclipse "The statement "LOG_MESS" is invalid. Check the spelling. spelling." but with F3 does to the macro and when you activate the class all are ok and the error disappeared.
Does anyone knows how to eliminate the error during the CHECK (Ctrl+F2).
Thnaks Elias
‎2021 Jun 14 12:16 PM
I found what was wrong. For some reason the constructor went below the methods that call the macros that's why I have this error, but the program was OK. Now I move the Constructor to the begining of the class implementation and the errors from the checking disappeared.
Thanks
Elias
‎2021 Jun 14 11:47 AM
I cannot see anything wrong in your code (from the syntax point of view).
About logging... if you are able to import programs to your system (your boss allows you, I mean), I recommend you to take a look at Git ABAP logger
I found it through a book of Paul Hardy, and they're awesome (the class...but the book and its author are awesome too)
‎2021 Jun 14 12:16 PM
I found what was wrong. For some reason the constructor went below the methods that call the macros that's why I have this error, but the program was OK. Now I move the Constructor to the begining of the class implementation and the errors from the checking disappeared.
Thanks
Elias
‎2021 Jun 14 1:15 PM
This demonstrates that there's a problem with your code. There's no way the syntax of a class should be wrong if a method implementation comes before another one. This is a code smell, and a problem waiting to bite again. If someone sorts the methods of the class, for example, it'll be syntactically incorrect again. And any new methods will have to have their implementation after the constructor.
Of course, the problem is the macro. There are two issues:
1) You've defined it in the wrong place. It should be defined in the Macro section.
2) Macros are obsolete and should not be used. Define your own logging class, or use the logger Vic recommended. Or replace the macro with a method.
‎2021 Jun 14 2:48 PM
Matthew you are right about the 2nd issue, that's why I said that I need an answer for now because I am going to re-engineer it. For the 1st issue I didn't know that there is a specific place for macros in a class. I will try to find it where.
As far as concern the code smell, I will check it and come back late in the evening.
Thanks
Elias
‎2021 Jun 14 12:19 PM
Not a single message in my Eclipse ADT 2020-09 (I know, I'm late) for this code (local class inside executable program) - I also tested in a global class, no message either:
REPORT zreport.
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS constructor.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
method constructor.
define log_mess.
assert 1 = 1.
end-of-definition.
ENDMETHOD.
ENDCLASS.
‎2021 Jun 14 12:27 PM
‎2021 Jun 14 2:56 PM
defining a macro to populate a method of another class & populate a global variable for the result.
This is terrible, could you post your code here :
https://answers.sap.com/articles/12984186/share-your-abap-gore-part-2.html