{"id":7129,"date":"2025-07-30T01:02:30","date_gmt":"2025-07-29T19:32:30","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=use-of-me-keyword"},"modified":"2025-07-31T10:39:22","modified_gmt":"2025-07-31T05:09:22","slug":"use-of-me-keyword","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=use-of-me-keyword","title":{"rendered":"Use of Me Keyword in SAP ABAP"},"content":{"rendered":"<p>When we create a variable in the public section of a class, we can use it within the methods of that class. Let&#8217;s say we assign it an initial value. Later, if we create another variable with the same name inside a method and assign it a new value, this new (local) value will be used within that method.<\/p>\n<p>To access the original value from the class, we need to use the <strong>ME operator<\/strong>.<\/p>\n<p>Example:<\/p>\n<p>We first create a public variable v_txt with an initial value &#8216;Class Variable&#8217;. Then, inside a method, we declare another variable (local to the method) with the same name v_txt, but assign it a different value: &#8216;Method Variable&#8217;.<\/p>\n<p>If we use v_txt directly in the method, it will reference the local variable, and we will get &#8216;Method Variable&#8217;.<\/p>\n<p>If we use me-&gt;v_txt, we explicitly refer to the class attribute, and we get &#8216;Class Variable&#8217;.<\/p>\n<p>Similarly, private and protected methods cannot be accessed directly from outside the class. However, we can call them from within another public method using the ME operator.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code><\/code><!--StartFragment --><!--StartFragment --><!--StartFragment --><span><span>*&amp;---------------------------------------------------------------------*<\/span><br \/><span>*&amp;\u00a0Report\u00a0\u00a0ZREP_LCLCLASS<\/span><br \/><span>*&amp;<\/span><br \/><span>*&amp;---------------------------------------------------------------------*<\/span><br \/><span>*&amp;<\/span><br \/><span>*&amp;<\/span><br \/><span>*&amp;---------------------------------------------------------------------*<\/span><br \/><br \/><span>REPORT\u00a0<\/span>zrep_lclclass<span>.<\/span><br \/><br \/><span>\"\u00a0local\u00a0class\u00a0definition.<\/span><br \/><span>CLASS\u00a0<\/span>lcl_operator\u00a0\u00a0<span>DEFINITION<\/span><span>.<\/span><br \/><br \/>\u00a0\u00a0<span>PUBLIC\u00a0<\/span><span>SECTION<\/span><span>.<\/span><br \/><br \/>\u00a0\u00a0\u00a0\u00a0<span>DATA\u00a0<\/span><span>:\u00a0<\/span>v_txt\u00a0<span>TYPE\u00a0<\/span>string\u00a0<span>VALUE\u00a0<\/span>'Class\u00a0Variable'<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>METHODS<\/span><span>:\u00a0<\/span>m_operator<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<br \/>\u00a0\u00a0<span>PROTECTED\u00a0<\/span><span>SECTION<\/span><span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>METHODS<\/span><span>:\u00a0<\/span>m_protectedmethod<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<br \/>\u00a0\u00a0<span>PRIVATE\u00a0<\/span><span>SECTION<\/span><span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>METHODS<\/span><span>:\u00a0<\/span>m_privatemethod<span>.<\/span><br \/><span>ENDCLASS<\/span><span>.<\/span><br \/><br \/><span>\"\u00a0local\u00a0class\u00a0implementation<\/span><br \/><span>CLASS\u00a0<\/span>lcl_operator\u00a0<span>IMPLEMENTATION<\/span><span>.<\/span><br \/>\u00a0\u00a0<span>METHOD\u00a0<\/span>m_protectedmethod<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>WRITE\u00a0<\/span><span>:<\/span>\/\u00a0'Hi\u00a0<span>from\u00a0<\/span><span>protected\u00a0<\/span>method'<span>.<\/span><br \/>\u00a0\u00a0<span>ENDMETHOD<\/span><span>.<\/span><br \/>\u00a0\u00a0<span>METHOD\u00a0<\/span>m_privatemethod<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>WRITE\u00a0<\/span><span>:<\/span>\/\u00a0'Hi\u00a0<span>from\u00a0<\/span><span>private\u00a0<\/span>method'<span>.<\/span><br \/>\u00a0\u00a0<span>ENDMETHOD<\/span><span>.<\/span><br \/>\u00a0\u00a0<span>METHOD\u00a0<\/span>m_operator<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0<span>DATA\u00a0<\/span>v_txt\u00a0<span>TYPE\u00a0<\/span>string\u00a0<span>VALUE\u00a0<\/span>'Method\u00a0Variable'<span>.<\/span><br \/><br \/>\u00a0\u00a0\u00a0\u00a0<span>WRITE<\/span><span>:\u00a0<\/span>\/\u00a0v_txt<span>,<\/span><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\u00a0me<span>-&gt;<\/span>v_txt<span>.<\/span><br \/>\u00a0\u00a0\u00a0\u00a0me<span>-&gt;<\/span>m_protectedmethod<span>(\u00a0<\/span><span>)<\/span><span>.\u00a0<\/span><span>\"\u00a0protected\u00a0method<\/span><br \/>\u00a0\u00a0\u00a0\u00a0me<span>-&gt;<\/span>m_privatemethod<span>(\u00a0<\/span><span>)<\/span><span>.\u00a0<\/span><span>\"\u00a0private\u00a0method<\/span><br \/>\u00a0\u00a0<span>ENDMETHOD<\/span><span>.<\/span><br \/><span>ENDCLASS<\/span><span>.<\/span><br \/><br \/><br \/><span>START-OF-SELECTION<\/span><span>.<\/span><br \/><br \/>\u00a0\u00a0<span>\"\u00a0object\u00a0for\u00a0class.<\/span><br \/>\u00a0\u00a0<span>DATA<\/span><span>(<\/span>lo_class<span>)\u00a0<\/span><span>=\u00a0<\/span><span>NEW\u00a0<\/span>lcl_operator<span>(\u00a0<\/span><span>)<\/span><span>.<\/span><br \/>\u00a0\u00a0lo_class<span>-&gt;<\/span>m_operator<span>(\u00a0<\/span><span>)<\/span><span>.<br \/><br \/><strong>OUTPUT : <\/strong><\/span><\/span><\/pre>\n<p><img decoding=\"async\" class=\"content-img\" src=\"https:\/\/www.sapewmhelp.com\/wp-content\/uploads\/2025\/07\/Me-operator.png\" \/><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[171,169,167,170,168],"class_list":["post-7129","question","type-question","status-publish","hentry","question-category-abap","question_tags-class","question_tags-me-in-method","question_tags-me-keyword","question_tags-methods","question_tags-ooabap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7129"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7129"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7129"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}