{"id":118,"date":"2012-08-07T09:08:41","date_gmt":"2012-08-07T08:08:41","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=118"},"modified":"2012-08-07T09:16:14","modified_gmt":"2012-08-07T08:16:14","slug":"adding-new-row-to-dynamically-selected-table","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=118","title":{"rendered":"Adding new row to dynamically selected table"},"content":{"rendered":"<p><!--more--><\/p>\n<pre lang=\"abap\"> *&amp;---------------------------------------------------------------------*\r\n *&amp;\u00a0Report\u00a0\u00a0TASK\u00a0#01\r\n *&amp;---------------------------------------------------------------------*\r\n *&amp;\u00a0Description:\u00a0'Let's\u00a0have\u00a0some\u00a0ABAP\u00a0fun'\u00a0contest\u00a0-\u00a0Task\u00a0#1\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0There\u00a0are\u00a0two\u00a0internal\u00a0tables\u00a0declared\u00a0in\u00a0the\u00a0program.\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0On\u00a0the\u00a0selection\u00a0screen,\u00a0there\u00a0is\u00a0a\u00a0parameter\u00a0(character)\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0where\u00a0user\u00a0can\u00a0specify\u00a0the\u00a0name\u00a0of\u00a0the\u00a0internal\u00a0table\u00a0that\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0should\u00a0be\u00a0added\u00a0with\u00a0one\u00a0line.\u00a0So,\u00a0the\u00a0name\u00a0of\u00a0the\u00a0table\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0in\u00a0account\u00a0is\u00a0stored\u00a0in\u00a0the\u00a0variable\u00a0in\u00a0the\u00a0runtime.\r\n *\r\n *\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0How\u00a0will\u00a0you\u00a0mangae\u00a0adding\u00a0the\u00a0row?\r\n *&amp;\u00a0Author\u00a0\u00a0\u00a0\u00a0\u00a0:\u00a0Miroslav\u00a0Oprsteny\r\n *&amp;\u00a0Date\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0:\u00a02011-10-14\r\n *&amp;---------------------------------------------------------------------*\r\n \r\n report\u00a0\u00a0task_#01.\r\n type-pools\u00a0:\u00a0abap.\r\n types:\r\n *\u00a0row\u00a0type\u00a0of\u00a0table\u00a0A\r\n \u00a0\u00a0begin\u00a0of\u00a0ls_line,\r\n \u00a0\u00a0\u00a0\u00a0value\u00a0type\u00a0c,\r\n \u00a0\u00a0end\u00a0of\u00a0ls_line,\r\n \r\n *row\u00a0type\u00a0of\u00a0table\u00a0B\r\n \u00a0\u00a0begin\u00a0of\u00a0ls_line2,\r\n \u00a0\u00a0\u00a0\u00a0name\u00a0type\u00a0c,\r\n \u00a0\u00a0\u00a0\u00a0value\u00a0type\u00a0c,\r\n \u00a0\u00a0end\u00a0of\u00a0ls_line2.\r\n \r\n \r\n data:\u00a0lt_a\u00a0type\u00a0table\u00a0of\u00a0ls_line,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0table\u00a0A\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0lt_b\u00a0type\u00a0table\u00a0of\u00a0ls_line2,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0table\u00a0B\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0l_data\u00a0type\u00a0ref\u00a0to\u00a0data,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0temp\u00a0variable\u00a0to\u00a0retrieve\u00a0the\u00a0table\u00a0structure\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0l_table_name(4)\u00a0type\u00a0c,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0dynamic\u00a0table\u00a0name\r\n \r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0idetails\u00a0type\u00a0abap_compdescr_tab,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0dynamic\u00a0table\u00a0fields\u00a0info\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0xdetails\u00a0type\u00a0abap_compdescr,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0info\u00a0of\u00a0one\u00a0field\u00a0of\u00a0dyn.\u00a0table\r\n \r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ref_table_des\u00a0type\u00a0ref\u00a0to\u00a0cl_abap_structdescr.\u00a0\"\u00a0class\u00a0reference\r\n \r\n field-symbols:\r\n \u00a0\u00a0\u00a0\u00a0\u00a0&lt;fs_table_line&gt;,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0line\u00a0of\u00a0dynamic\u00a0table\r\n \u00a0\u00a0\u00a0\u00a0\u00a0&lt;fs_table&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0type\u00a0standard\u00a0table,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0dynamic\u00a0table\r\n \u00a0\u00a0\u00a0\u00a0\u00a0&lt;comp&gt;.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0component\u00a0used\u00a0to\u00a0write\u00a0to\u00a0structures\r\n \r\n parameters\u00a0p_table\u00a0type\u00a0c.\r\n \r\n concatenate\u00a0'lt_'\u00a0p_table\u00a0into\u00a0l_table_name.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0contruct\u00a0dynamic\u00a0table\u00a0name\r\n \r\n assign\u00a0(l_table_name)\u00a0to\u00a0&lt;fs_table&gt;.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0pointer\u00a0to\u00a0selected\u00a0table\r\n \r\n create\u00a0data\u00a0l_data\u00a0like\u00a0line\u00a0of\u00a0&lt;fs_table&gt;.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0created\u00a0temp\u00a0data\r\n assign\u00a0l_data-&gt;*\u00a0to\u00a0&lt;fs_table_line&gt;.\r\n \r\n \"\u00a0Retrieve\u00a0table\u00a0structure\u00a0info\r\n ref_table_des\u00a0?=\u00a0cl_abap_typedescr=&gt;describe_by_data(\u00a0&lt;fs_table_line&gt;\u00a0).\r\n idetails[]\u00a0=\u00a0ref_table_des-&gt;components[].\r\n \r\n \"\u00a0Add\u00a0single\u00a0line\u00a0to\u00a0dynamic\u00a0table\r\n append\u00a0initial\u00a0line\u00a0to\u00a0&lt;fs_table&gt;\u00a0assigning\u00a0&lt;fs_table_line&gt;.\r\n \"\u00a0Loop\u00a0over\u00a0all\u00a0fields\u00a0of\u00a0a\u00a0dynamic\u00a0table\u00a0and\u00a0assign\u00a0values\r\n loop\u00a0at\u00a0idetails\u00a0into\u00a0xdetails.\r\n \u00a0\u00a0case\u00a0xdetails-name.\r\n \u00a0\u00a0\u00a0\u00a0when\u00a0'VALUE'.\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0&lt;fs_table_line&gt;\u00a0is\u00a0type\u00a0of\u00a0ANY\u00a0so\u00a0we\u00a0need\u00a0to\u00a0use\u00a0COMPONENT\u00a0approach\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0assign\u00a0component\u00a0'VALUE'\u00a0of\u00a0structure\u00a0&lt;fs_table_line&gt;\u00a0to\u00a0&lt;comp&gt;\u00a0casting\u00a0type\u00a0c.\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;comp&gt;\u00a0=\u00a0'X'.\r\n \r\n \u00a0\u00a0\u00a0\u00a0when\u00a0'NAME'.\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"\u00a0this\u00a0component\u00a0is\u00a0present\u00a0only\u00a0for\u00a0table\u00a0lt_b\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0assign\u00a0component\u00a0'NAME'\u00a0of\u00a0structure\u00a0&lt;fs_table_line&gt;\u00a0to\u00a0&lt;comp&gt;\u00a0casting\u00a0type\u00a0c.\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;comp&gt;\u00a0=\u00a0'Y'.\r\n \u00a0\u00a0endcase.\r\n endloop.\r\n \r\n \"\u00a0Now\u00a0write\u00a0contents\u00a0of\u00a0both\u00a0tables\u00a0to\u00a0output\r\n write\u00a0'Loop\u00a0at\u00a0table\u00a0A:'.\r\n loop\u00a0at\u00a0lt_a\u00a0assigning\u00a0&lt;fs_table_line&gt;.\r\n \u00a0\u00a0assign\u00a0component\u00a0'VALUE'\u00a0of\u00a0structure\u00a0&lt;fs_table_line&gt;\u00a0to\u00a0&lt;comp&gt;.\r\n \u00a0\u00a0write\u00a0\/\u00a0&lt;comp&gt;.\r\n endloop.\r\n \r\n write\u00a0\/\u00a0'Loop\u00a0at\u00a0table\u00a0B:'.\r\n loop\u00a0at\u00a0lt_b\u00a0assigning\u00a0&lt;fs_table_line&gt;.\r\n \u00a0\u00a0assign\u00a0component\u00a0'NAME'\u00a0of\u00a0structure\u00a0&lt;fs_table_line&gt;\u00a0to\u00a0&lt;comp&gt;.\r\n \u00a0\u00a0write\u00a0\/\u00a0&lt;comp&gt;.\r\n \r\n \u00a0\u00a0assign\u00a0component\u00a0'VALUE'\u00a0of\u00a0structure\u00a0&lt;fs_table_line&gt;\u00a0to\u00a0&lt;comp&gt;.\r\n \u00a0\u00a0write:\u00a0':',\u00a0&lt;comp&gt;.\r\n endloop.<\/pre>\n","protected":false},"excerpt":{"rendered":"","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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[446,17],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-sap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-1U","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/118","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=118"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}