abapOpenChecks
abapOpenChecks copied to clipboard
Check 46: Shadowed variable bug
AOC Shadowed variables detect no shadowing inside a method
can you help adding an example?
Hi,
for example
&--------------------------------------------------------------------- *& Report z_shadowed variable &--------------------------------------------------------------------- *& &--------------------------------------------------------------------- REPORT z_shadowed variable.
CLASS lcl_class DEFINITION. PUBLIC SECTION. CLASS-METHODS get_mara IMPORTING iv_matnr TYPE matnr RETURNING VALUE(rs_mara) TYPE mara. class-methods get_mara_complete. ENDCLASS.
FORM change_mara2 USING iv_mara. DATA ls_mara TYPE mara.
SELECT SINGLE matnr FROM mara INTO CORRESPONDING FIELDS OF ls_mara WHERE matnr = iv_mara. ENDFORM.
DATA ls_mara TYPE mara.
START-OF-SELECTION.
SELECT SINGLE matnr FROM mara INTO CORRESPONDING FIELDS OF ls_mara WHERE matnr = '007'. WRITE: / ls_mara-matnr. PERFORM change_mara USING '008'. WRITE: / ls_mara-matnr. PERFORM change_mara_complete. WRITE: / ls_mara-mtart.
DATA(ls_mara2) = lcl_class=>get_mara( iv_matnr = '009' ).
WRITE: / ls_mara-matnr.
lcl_class=>get_mara_complete( ).
WRITE: / ls_mara-matnr.
PERFORM change_mara2 USING '001'. WRITE: / ls_mara-matnr.
END-OF-SELECTION.
FORM change_mara USING iv_matnr. DATA ls_mara TYPE mara.
SELECT SINGLE matnr FROM mara INTO CORRESPONDING FIELDS OF ls_mara WHERE matnr = iv_matnr. ENDFORM.
FORM change_mara_complete.
DATA ls_mara TYPE mara.
SELECT SINGLE * FROM mara INTO @DATA(ls_something) WHERE matnr = @ls_mara-matnr.
ENDFORM.
CLASS lcl_class IMPLEMENTATION. METHOD get_mara. DATA ls_mara TYPE mara.
SELECT SINGLE matnr FROM mara INTO CORRESPONDING FIELDS OF ls_mara
WHERE matnr = iv_matnr.
rs_mara = ls_mara.
ENDMETHOD.
METHOD get_mara_complete. DATA ls_mara TYPE mara.
SELECT SINGLE * FROM mara INTO @DATA(ls_something)
WHERE matnr = @ls_mara-matnr.
ENDMETHOD.
ENDCLASS.
Best regards
Stefan Riedel-Seifert
Expert ABAP Development Technology | Appl. Techn. Prod. and Logistics Endress+Hauser InfoServe GmbH+Co. KG | Heinrich-von-Stephan-Str. 8 | 79100 Freiburg | Germany Phone: +49 761 7059 115 | Mobile: +49 160 3637882 | Fax: +49 761 7059 5 115 [email protected] | www.infoserve.endress.com
Endress+Hauser InfoServe GmbH+Co. KG Location: Weil am Rhein Registered: Amtsgericht Freiburg i. Br. HRA 411272 Individual liable partner: Endress+Hauser InfoServe Verwaltungs-GmbH, Weil am Rhein Registered: Amtsgericht Freiburg i.Br. HRB 412621 Managing director: Pieter de Koning
According to the General Data Protection Regulation, we are obliged to inform you when collecting your personal data.
We comply with this information duty with the following Data Protection Statementhttps://www.de.endress.com/de/cookies-endress+hauser-website.
Disclaimer:
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer. This e-mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer unless explicitly and conspicuously designated or stated as such.
Von: Lars Hvam [mailto:[email protected]] Gesendet: Donnerstag, 21. Juni 2018 12:01 An: larshp/abapOpenChecks [email protected] Cc: Stefan Riedel-Seifert [email protected]; Author [email protected] Betreff: Re: [larshp/abapOpenChecks] Shadowed variable (#554)
can you help adding an example?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flarshp%2FabapOpenChecks%2Fissues%2F554%23issuecomment-399047426&data=02%7C01%7Cstefan.riedel-seifert%40infoserve.endress.com%7Cc9000db59f3344a1bc5d08d5d75df5d4%7C52daf2a93b734da4ac6a3f81adc92b7e%7C1%7C0%7C636651720924681688&sdata=OoH0kwGIpQ0NdYaM5MC7dBQs940ZDGoN574nNv4Muo4%3D&reserved=0, or mute the threadhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMbiuEAopjExDWTGaNWOMr4Gc_UwNujIks5t-274gaJpZM4UxwGp&data=02%7C01%7Cstefan.riedel-seifert%40infoserve.endress.com%7Cc9000db59f3344a1bc5d08d5d75df5d4%7C52daf2a93b734da4ac6a3f81adc92b7e%7C1%7C0%7C636651720924681688&sdata=m3fN8E2A6AS7bjxiSihVJC2HtXq%2B6MYiWpo9gJAdHTY%3D&reserved=0.
example reduced to
REPORT z_shadowedvariable.
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS get_usr02_complete.
ENDCLASS.
DATA ls_usr02 TYPE usr02.
START-OF-SELECTION.
lcl_class=>get_usr02_complete( ).
CLASS lcl_class IMPLEMENTATION.
METHOD get_usr02_complete.
DATA ls_usr02 TYPE usr02.
SELECT SINGLE * FROM usr02 INTO @DATA(ls_something).
ENDMETHOD.
ENDCLASS.
Guess there are the following scenarios:
- FORM local var shadows global var
- FORM parameter shadows global var
- Local class local var shadows global var
- Local class local var shadows class attribute
- Local class method parameter shadows class attribute
- Local class method parameter shadows global var
- Global class local var shadows class attribute
- Global class method parameter shadows class var
- Function modules?
Check this in addition 😊
[cid:[email protected]]
Best regards
Stefan Riedel-Seifert
Expert ABAP Development Technology | Appl. Techn. Prod. and Logistics Endress+Hauser InfoServe GmbH+Co. KG | Heinrich-von-Stephan-Str. 8 | 79100 Freiburg | Germany Phone: +49 761 7059 115 | Mobile: +49 160 3637882 | Fax: +49 761 7059 5 115 [email protected] | www.infoserve.endress.com
Endress+Hauser InfoServe GmbH+Co. KG Location: Weil am Rhein Registered: Amtsgericht Freiburg i. Br. HRA 411272 Individual liable partner: Endress+Hauser InfoServe Verwaltungs-GmbH, Weil am Rhein Registered: Amtsgericht Freiburg i.Br. HRB 412621 Managing director: Pieter de Koning
According to the General Data Protection Regulation, we are obliged to inform you when collecting your personal data.
We comply with this information duty with the following Data Protection Statementhttps://www.de.endress.com/de/cookies-endress+hauser-website.
Disclaimer:
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer. This e-mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer unless explicitly and conspicuously designated or stated as such.
Von: Lars Hvam [mailto:[email protected]] Gesendet: Freitag, 22. Juni 2018 16:22 An: larshp/abapOpenChecks [email protected] Cc: Stefan Riedel-Seifert [email protected]; Author [email protected] Betreff: Re: [larshp/abapOpenChecks] Check 46: Shadowed variable bug (#554)
Guess there are the following scenarios:
- FORM local var shadows global var
- FORM parameter shadows global var
- Local class local var shadows global var
- Local class local var shadows class attribute
- Local class method parameter shadows class attribute
- Local class method parameter shadows global var
- Global class local var shadows class attribute
- Global class method parameter shadows class var
- Function modules?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flarshp%2FabapOpenChecks%2Fissues%2F554%23issuecomment-399459218&data=02%7C01%7Cstefan.riedel-seifert%40infoserve.endress.com%7C84b8c190e92c46a5eb5e08d5d84b82b8%7C52daf2a93b734da4ac6a3f81adc92b7e%7C1%7C0%7C636652741180417461&sdata=FWx3mOz6vqBNIs0kKcseqI%2FFbUhIcZtj6d6dmRz0634%3D&reserved=0, or mute the threadhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMbiuJRV9YdZNQr30OWY5dlmVqqbU_dfks5t_P2DgaJpZM4UxwGp&data=02%7C01%7Cstefan.riedel-seifert%40infoserve.endress.com%7C84b8c190e92c46a5eb5e08d5d84b82b8%7C52daf2a93b734da4ac6a3f81adc92b7e%7C1%7C0%7C636652741180417461&sdata=oogkNdarsb7K6bbW1CvdDJjktkGtdD6kOZH1zpGYCT0%3D&reserved=0.
Adding to this, if several classes are implemented in one program and more than one of them has a constructor method, it will detect it as shadowing.
pull requests welcome