{"id":629,"date":"2013-08-19T15:31:26","date_gmt":"2013-08-19T14:31:26","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=629"},"modified":"2013-08-19T15:31:26","modified_gmt":"2013-08-19T14:31:26","slug":"abap-change-documents-example-with-z-table","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=629","title":{"rendered":"ABAP &#8211; Change Documents example with Z-table"},"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\" \/>In this example I&#8217;ll follow on the theory of Change Documents presented in previous article (<a title=\"ABAP \u2013 Change Documents (theory)\" href=\"http:\/\/oprsteny.cz\/?p=623\">ABAP &#8211; Change Documents (theory)<\/a>) and I&#8217;ll show how to create(or update an existing) Z-table where each modification will be logged into CDHRD and CDPOS tables<!--more--><\/p>\n<h1>Z-Table modifications<\/h1>\n<p>In our example we will create a completely new Z-table<\/p>\n<p>The table consists of three fields:<\/p>\n<ul>\n<li>EMPID (Employee id)<\/li>\n<li>ENAME (Employee name)<\/li>\n<li>ELOC (Employee Location)<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"alignnone size-full\" style=\"font-style: normal; color: #000000;\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121c8312093.png\" \/><\/p>\n<p>We will also create new Z-data element for each of the fields above and in the <em>&#8216;Further characteristics&#8217;<\/em> tab of each data element you want to have the changes being logged in CDHDR and CDPOS\u00a0select the check box <em>&#8216;Change document&#8217;.<br \/>\n<\/em><img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121bdcd0e60.png\" \/><\/p>\n<h1>Change Document creation<\/h1>\n<p>Run transaction <em>SCDO<\/em>.<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121ca07c14c.png\" \/><\/p>\n<p>Click on the <em>&#8216;Create&#8217;<\/em> button, enter the name of the change document object and click on the <em>&#8216;Continue&#8217;<\/em>\u00a0button<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121cf341b13.png\" \/><\/p>\n<p>On the screen that appears\u00a0enter some description into the <em>&#8216;Text&#8217;\u00a0<\/em>field and name of the Z-table.<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121d2c960d9.png\" \/><\/p>\n<p>Save the changes, go back to list of all available Change Documents and find your new Change Document.\u00a0Select it by clicking on its name and press\u00a0<em>&#8216;Generate update pgm&#8217;\u00a0<\/em>button<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121d741f18f.png\" \/><\/p>\n<p>On the screen that is displayed enter name of the function group that will contain function modules to handle the CDHDR and CDPOS manipulation for your Change Document (for your Z-table) and press <em>&#8216;Generate&#8217; <\/em>button<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121dd710e33.png\" \/><\/p>\n<p>The screen that appears contains information about your new function module(name will be like &lt;Name of your Change Document&gt;_WRITE_DOCUMENT) and other related info.<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121e2a431ea.png\" \/><\/p>\n<p>Click on the <em>&#8216;Save&#8217;<\/em> button and from now on you can log your changes using the new function module in CDHDR and CDPOS tables.<\/p>\n<h1>Coding part<\/h1>\n<p>Let&#8217;s check what are the import parameters of your new function module:<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121e8fae89d.png\" \/><\/p>\n<p>&#8230; and tables<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52121ea64f55b.png\" \/><\/p>\n<p>In the list you can see this function module has 2 parameters named<\/p>\n<ul>\n<li>N_&lt;your_Z_table&gt;\u00a0&#8230; in our case N_ZCA_EMPLOYEE<\/li>\n<li>O_&lt;your_Z_table&gt; &#8230; in our case\u00a0O_ZCA_ZEMPLOYEE<\/li>\n<\/ul>\n<p>Where<\/p>\n<ul>\n<li>N stands for new data<\/li>\n<li>O stands for old data.<\/li>\n<\/ul>\n<h2><b>Important note<\/b><\/h2>\n<ul>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Log INSERT Z-table entries<\/span>\n<ul>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Pass data to the new parameter only (N_ZCA_EMPLOYEE). <\/span><\/li>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">The old parameter (O_ZCA_EMPLOYEE)\u00a0is ignored.<\/span><\/li>\n<\/ul>\n<\/li>\n<li>Log UPDATE Z-table entries\n<ul>\n<li>Pass the new data to the new parameter (N_ZCA_EMPLOYEE)<\/li>\n<li>Pass the\u00a0old data to the old parameter. (O_ZCA_EMPLOYEE)<\/li>\n<\/ul>\n<\/li>\n<li>Log DELETE Z-table entries\n<ul>\n<li>Pass the data to the old parameter (O_ZCA_EMPLOYEE)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Log INSERT table entry<\/h2>\n<pre lang=\"abap\">DATA:\r\n     ls_emp_new\u00a0TYPE\u00a0zca_employee,\r\n     ls_emp_old\u00a0TYPE\u00a0zca_employee,\r\n     lt_cdtxt\u00a0TYPE\u00a0TABLE\u00a0OF\u00a0cdtxt,\r\n     lv_objectid\u00a0TYPE\u00a0cdhdr-objectid.\r\n\r\nls_emp_new-empid\u00a0=\u00a0'1'.\r\nls_emp_new-ename\u00a0=\u00a0'John Malkovich'.\r\nls_emp_new-eloc\u00a0 =\u00a0'Paris'.\r\n\r\nINSERT\u00a0zca_employee\u00a0FROM\u00a0ls_emp_new.\r\n\r\nlv_objectid\u00a0=\u00a0ls_emp_new-empid.\r\n\r\nCALL\u00a0FUNCTION\u00a0'Z_EMPLOYEE_WRITE_DOCUMENT'\r\n  EXPORTING\r\n    objectid\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0=\u00a0lv_objectid\r\n    tcode\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0=\u00a0sy-tcode\r\n    utime\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0=\u00a0sy-uzeit\r\n    udate\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0\u00a0\u00a0=\u00a0sy-datum\r\n    username   \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0=\u00a0sy-uname\r\n    n_zca_employee\u00a0 \u00a0\u00a0=\u00a0ls_emp_new\r\n    o_zca_employee \u00a0\u00a0\u00a0=\u00a0ls_emp_old\r\n    upd_zca_employee \u00a0=\u00a0'I'\r\n  TABLES\r\n    icdtxt_z_employee\u00a0=\u00a0lt_cdtxt.<\/pre>\n<p><em><b>Note<\/b>:<\/em> In case of insertion pass the value of the parameter UPD_ZCA_EMPLOYEE = \u2018I\u2019.<\/p>\n<p>After execution of the piece of code above the ZCA_EMPLOYEE table will contain the following data<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_5212209bc3ef6.png\" \/><\/p>\n<p>Execute Report\u00a0<strong>RSSCD200 <\/strong>for your Z-table (ZCA_EMPLOYEE) and you should see the following<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52122b27c5de5.png\" \/><\/p>\n<h2>Log UPDATE table entry<\/h2>\n<pre lang=\"abap\">ls_emp_new-empid\u00a0=\u00a0'1'.\r\nls_emp_new-ename\u00a0=\u00a0'Johny Depp'.\r\nls_emp_new-eloc\u00a0 =\u00a0'Los Angeles'.\r\n\r\nMODIFY\u00a0zca_employee\u00a0FROM\u00a0ls_emp_new.\r\n\r\nls_emp_old-empid\u00a0=\u00a0'1'.\r\nls_emp_old-ename\u00a0=\u00a0'John Malkovich'.\r\nls_emp_old-eloc\u00a0 =\u00a0'Paris'.\r\n\r\nlv_objectid\u00a0=\u00a0ls_emp_new-empid.\r\n\r\nCALL\u00a0FUNCTION\u00a0'Z_EMPLOYEE_WRITE_DOCUMENT'\r\n  EXPORTING\r\n    objectid   \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0=\u00a0lv_objectid\r\n    tcode\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0\u00a0\u00a0\u00a0=\u00a0sy-tcode\r\n    utime\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0\u00a0=\u00a0sy-uzeit\r\n    udate\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0=\u00a0sy-datum\r\n    username\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   =\u00a0sy-uname\r\n    n_zca_employee \u00a0\u00a0\u00a0=\u00a0ls_emp_new\r\n    o_zca_employee \u00a0\u00a0\u00a0=\u00a0ls_emp_old\r\n    upd_zca_employee \u00a0=\u00a0'U'\r\n  TABLES\r\n    icdtxt_z_employee\u00a0=\u00a0lt_cdtxt.<\/pre>\n<p><em><b>Note<\/b><\/em>: In case of Update pass the value of the parameter UPD_ZCA_EMPLOYEE = \u2018U\u2019.<\/p>\n<p>After execution of the piece of code above the ZCA_EMPLOYEE table will contain the following data<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_5212219b14b31.png\" \/><\/p>\n<p>Execute Report\u00a0<strong>RSSCD200 <\/strong>for your Z-table (ZCA_EMPLOYEE)\u00a0and you should see the following<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52122b70462f8.png\" \/><\/p>\n<h2>Log DELETE table entry<\/h2>\n<pre lang=\"abap\">ls_emp_old-empid\u00a0=\u00a0'1'.\r\nDELETE\u00a0zca_employee\u00a0FROM\u00a0ls_emp_old.\r\n\r\nlv_objectid\u00a0=\u00a0ls_emp_old-empid.\r\n\r\nCALL\u00a0FUNCTION\u00a0'Z_EMPLOYEE_WRITE_DOCUMENT'\r\n  EXPORTING\r\n    objectid\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   =\u00a0lv_objectid\r\n    tcode\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0=\u00a0sy-tcode\r\n    utime\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   \u00a0\u00a0\u00a0\u00a0=\u00a0sy-uzeit\r\n    udate   \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0=\u00a0sy-datum\r\n    username   \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0=\u00a0sy-uname\r\n    n_zca_employee\u00a0\u00a0\u00a0 =\u00a0ls_emp_new\r\n    o_zca_employee\u00a0\u00a0\u00a0 =\u00a0ls_emp_old\r\n    upd_zca_employee \u00a0=\u00a0'D'\r\n  TABLES\r\n    icdtxt_z_employee\u00a0=\u00a0lt_cdtxt.<\/pre>\n<p><em><b>Note<\/b><\/em>: In case of Deletion pass the value of the parameter UPD_ZCA_EMPLOYEE = \u2018D\u2019.<\/p>\n<p>After execution of the piece of code above the ZCA_EMPLOYEE table will contain the following data<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_5212232e56b3f.png\" \/><\/p>\n<p>Execute Report\u00a0<strong>RSSCD200\u00a0<\/strong>for your Z-table (ZCA_EMPLOYEE)\u00a0and you should see the following<br \/>\n<img decoding=\"async\" class=\"alignnone size-full\" alt=\"\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/img_52122c0aa3235.png\" \/><\/p>\n<h1>Table Maintenance events<\/h1>\n<p>The log changes can be automatically written by your table maintenance view if you implement the above code in table maintenance events: row creation\/update\/deletion.<\/p>\n<p>If you are not sure how to do it please visit my <a href=\"http:\/\/oprsteny.cz\/?p=375\">tutorial on how to maintain events of table maintenance view<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example I&#8217;ll follow on the theory of Change Documents presented in previous article (ABAP &#8211; Change Documents (theory)) and I&#8217;ll show how to create(or update an existing) Z-table where each modification will be logged into CDHRD and CDPOS &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=629\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/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,167,168,166,62,170,169,171],"class_list":["post-629","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-cdhdr","tag-cdpos","tag-change-documents","tag-events","tag-rsscd200","tag-scdo","tag-table-maintenance"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-a9","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/629","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=629"}],"version-history":[{"count":5,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/629\/revisions"}],"predecessor-version":[{"id":706,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/629\/revisions\/706"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}