{"id":735,"date":"2013-10-15T13:25:29","date_gmt":"2013-10-15T12:25:29","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=735"},"modified":"2013-10-15T13:25:29","modified_gmt":"2013-10-15T12:25:29","slug":"abap-oo-access-class-attributes-dynamically","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=735","title":{"rendered":"ABAP OO &#8211; Access class attributes dynamically"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"358\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=358\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" data-orig-size=\"44,50\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Picasa&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1365690880&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"SAP\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" class=\"alignleft size-full wp-image-358\" alt=\"SAP\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" width=\"44\" height=\"50\" \/>The piece of code presented in this article is just a short demonstration of how you can access class attributes dynamically &#8211; when the attribute name is stored in a variable which value is determined during run time.<!--more--><\/p>\n<pre lang=\"abap\">CLASS lcl_myclass DEFINITION.\r\n  PUBLIC SECTION.\r\n    DATA:\r\n      m_dynvar TYPE char10,\r\n      m_var_a  TYPE c VALUE 'X',\r\n      m_var_b  TYPE c VALUE 'Y'.\r\nENDCLASS.\r\n\r\nDATA:\r\n  lr_myclass TYPE REF TO lcl_myclass.\r\n\r\nFIELD-SYMBOLS:\r\n  &lt;fs_var&gt; TYPE any.\r\n\r\nCREATE OBJECT lr_myclass.\r\n\r\nlr_myclass-&gt;m_dynvar = 'm_var_A'.\r\nASSIGN lr_myclass-&gt;(lr_myclass-&gt;m_dynvar) TO &lt;fs_var&gt;.\r\nWRITE &lt;fs_var&gt;.\r\n\r\nlr_myclass-&gt;m_dynvar = 'm_var_B'.\r\nASSIGN lr_myclass-&gt;(lr_myclass-&gt;m_dynvar) TO &lt;fs_var&gt;.\r\nWRITE &lt;fs_var&gt;.<\/pre>\n<p>Output:<\/p>\n<pre lang=\"abap\">X Y<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The piece of code presented in this article is just a short demonstration of how you can access class attributes dynamically &#8211; when the attribute name is stored in a variable which value is determined during run time.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[446,146,179,195],"class_list":["post-735","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-class","tag-dynamic-programming","tag-oo"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-bR","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=735"}],"version-history":[{"count":1,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions"}],"predecessor-version":[{"id":736,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions\/736"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}