Comments (4)
I think this should be extended to exception classes and the use of IF_T100_DYN_MSG, encouraging the use of
RAISE EXCEPTION TYPE cx_fail
MESSAGE ID ...
...
Incidentally, this is an area that some additional clarification from SAP could be useful. When exception classes were first introduced, the documentation hinted that the T100 model was an endangered species and instead encouraged customers to use exception classes pretty much across the technical and application domains due to their much richer functionality and bells and whistles such as OTR texts, attributes and inheritance.
But the approach seems to have shifted back, nowadays the doco recommends to only use exception classes in technical contexts and use T100 as our primary error concept for application-level errors.
from styleguides.
A common pattern for this is the following:
MESSAGE e055(oo) WITH 'VAR' INTO DATA(lv_dummy) ##NEEDED.
li_logger->add_msg_from_sy( ).
(ADT code template MESSAGE ${msgtyno}(${msgid}) WITH ${msgv} INTO DATA(${lv_dummy}) ##NEEDED
).
With something like this:
METHODS:
add_msg_from_sy IMPORTING VALUE(iv_msgid) TYPE syst_msgid DEFAULT sy-msgid
VALUE(iv_msgno) TYPE syst_msgno DEFAULT sy-msgno
VALUE(iv_msgty) TYPE syst_msgty DEFAULT sy-msgty
VALUE(iv_msgv1) TYPE syst_msgv DEFAULT sy-msgv1
VALUE(iv_msgv2) TYPE syst_msgv DEFAULT sy-msgv2
VALUE(iv_msgv3) TYPE syst_msgv DEFAULT sy-msgv3
VALUE(iv_msgv4) TYPE syst_msgv DEFAULT sy-msgv4
It is very important to use pass by value here as these variables can otherwise change in the implementation of add_msg_from_sy
before they are read.
Unfortunately there is no MESSAGE ... TRANSPORTING NO FIELDS
, so once you have more message statements you need to move the dummy variable declaration. I also saw code where global variables of the runtime environment are used, like INTO %_PRINT
or INTO sy-some_hopefully_not_used_component
which does not seem ideal to me.
There is also this pattern which seems way worse than the dummy MESSAGE statement as it has dead code and duplication (maybe MESSAGE ... INTO
didn't exist yet?).
cl_feb_appl_log_handler=>add_message( i_msgid = 'FEB_BSIMP'
i_msgty = 'E'
i_msgno = '056'
i_msgv1 = lv_os_error_msg
i_detlevel = iv_detlevel ).
IF 1 = 2. MESSAGE e056(feb_bsimp). ENDIF. "#EC MG_PAR_CNT
Edit:
And by the way, keeping the static reference to the message class is not only important for the where used list but also for code inspector / syntax checks, like does the message even exist and is the correct number of variables supplied. And I guess "is the message class even accessable?" if you are using package interfaces.
from styleguides.
MESSAGE e055(oo) WITH 'VAR' INTO DATA(lv_dummy) ##NEEDED.
li_logger->add_msg_from_sy( ).
This is how I normally do it, but it is not perfect. If your logger is (for example) the BAL logger, you loose the reference to the message ID/Number. Any long-text is gone as well as the possibility to lok afterwards where this message was thrown.. you only have the text.
So it is a consideration if you prefer the user to have longtext or the developer to have a where-used-reference.
To "have both", you would have to somehow "do both" things (duplicate code).
from styleguides.
Was fixed in #88
from styleguides.
Related Issues (20)
- Strategy regarding translations HOT 2
- Strategy for handling dependencies to system releases HOT 4
- Text on logo not readable in dark mode (Code Review Guide) HOT 3
- [Exploit the test tools] Add CL_AUNIT_AUTHORITY_CHECK to the list? HOT 6
- [Consider decomposing complex conditions] bad use case example HOT 1
- German Translation: Typo HOT 1
- Use assert class instead of ASSERT HOT 12
- Are comments bad or not?
- [Use CHANGING sparingly, where suited] Is it ok to use IMPORTING REF instead of CHANGING? HOT 7
- New rule: prefer inferring types HOT 1
- Abap Exception categories HOT 3
- Use READ-ONLY sparingly - new abap command FINAL HOT 2
- How to add sample code to Clean ABAP? HOT 1
- Unclear explanation of [Use LOCAL FRIENDS to access the dependency-inverting constructor] HOT 5
- Follow rules when abbreviating HOT 1
- "Dead" link at section "split-method-instead-of-boolean-input-parameter" HOT 3
- Chapter "Avoid abbreviations" HOT 7
- [Prefer RAISE EXCEPTION NEW to RAISE EXCEPTION TYPE] In defense of RAISE EXCEPTION TYPE HOT 6
- Prefer ENUM to constants interfaces HOT 1
- [Use | to assemble text] Is a caveat needed in case of translatable texts? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from styleguides.