Check target field of select
Hey SAP experts,
there is a quite common issue from our developers that target fields (structure/table type) do not match SELECT field list. Can you provide a check for that, please? 🙏
Example:
FORM cut.
DATA: ls_mara TYPE mara.
SELECT SINGLE mtart FROM mara
INTO ls_mara " MTART is not moved to ls_mara-mtart but into
" the first fields MANDT (3 characters) and MATNR (1 character)
" -> How to track this with SCI/ATC/SLIN, etc?
WHERE matnr = '...'.
ENDFORM.
While this is a very understandable request (and I'm a bit shocked there aren't any checks in the standard for this that I can find), this isn't really within the scope of CodePAL, which is intended to check adherence to Clean ABAP.
This problem isn't about coding style in the sense of Clean ABAP, it's just a footgun because ABAP type checks are weak. This kind of check would be more at home in the Extended Program Check (if provided by SAP) or stuff like the abapOpenChecks, which have a broader mission.
However, this problem (or at least many instances of it) would also be solved by a check implementing the general rule of preferring inline declarations - you can't get the type of the target wrong if you're declaring it right in the SELECT statement.