{"id":306,"date":"2013-03-31T19:19:46","date_gmt":"2013-03-31T18:19:46","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=306"},"modified":"2013-05-30T06:04:49","modified_gmt":"2013-05-30T05:04:49","slug":"sapscript-different-column-headers-for-different-lists","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=306","title":{"rendered":"SAPScript: different column headers for different lists"},"content":{"rendered":"<p><img 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  wp-image-358\" alt=\"SAP\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" width=\"50\" \/>Once I needed to have several lists in MAIN window output and each of these lists needed to have different column headers. As\u00a0usually, there are several ways how to achieve this and I&#8217;ll try to present two possible ways:<\/p>\n<ul>\n<li><a title=\"SAPScript: different column headers for different lists\" href=\"http:\/\/oprsteny.cz\/?p=306#Using_header_window_of_type_VAR\">Using header window of type VAR<\/a><\/li>\n<li><a title=\"SAPScript: different column headers for different lists\" href=\"http:\/\/oprsteny.cz\/?p=306#Using_a_TOP_section_in_MAIN_window\">Using a TOP section in MAIN window<\/a><\/li>\n<\/ul>\n<p><!--more--><a name=\"Using_header_window_of_type_VAR\"><\/a><\/p>\n<h1>Using header window of type VAR<\/h1>\n<p>Window of type VAR is printed on each page of SAPScript so you can use the code inside to determine which list is currently on output and\u00a0print the headers\u00a0according to it. Let&#8217;s imagine you have 3 types of lists:<\/p>\n<ul>\n<li>Material with info about its UOM, Quantity and Price<\/li>\n<li>Approval list (imagine you need to have more aprovers)<\/li>\n<li>Change log<\/li>\n<\/ul>\n<pre lang=\"abap\">\/: CASE &amp;LIST_TYPE&amp;\r\n\/: WHEN '1'\r\n*  Material,,UOM,,Quantity,,Price\r\n\/: WHEN '2'\r\n*  Aprover,,Signed,,Date,,Time\r\n\/: WHEN '3'\r\n*  Change date,,Version,,Description\r\n\/: ENDCASE<\/pre>\n<p>Because it&#8217;s not possible to pass variables between windows directly, you need to use a program where your global data will be stored during program runtime.<br \/>\nYou can call this program to set or get the variables.<br \/>\nIn the VAR window you need to read data to get current list type. So we need to modify the code above a bit:<\/p>\n<pre lang=\"abap\">\/: DEFINE &amp;LIST_TYPE&amp; = ''\r\n\/: PERFORM GET_LIST_TYPE IN PROGRAM &lt;XYZ&gt; \r\n\/: CHANGING &amp;LIST_TYPE&amp;\r\n\/: END PERFORM\r\n\/*\r\n*  &amp;ULINE(70)&amp;\r\n\/: CASE &amp;LIST_TYPE&amp;\r\n\/: WHEN '1'\r\n*  Material,,UOM,,Quantity,,Price\r\n\/: WHEN '2'\r\n*  Aprover,,Signed,,Date,,Time\r\n\/: WHEN '3'\r\n*  Change date,,Version,,Description\r\n\/: ENDCASE\r\n*  &amp;ULINE(70)&amp;<\/pre>\n<p>The code above is now complete for the header window (type VAR). Now we need to prepare the MAIN window:<\/p>\n<pre lang=\"abap\">\/* Set list type = 1\r\n\/: DEFINE &amp;LIST_TYPE&amp; = '1'\r\n\/: PERFORM SET_LIST_TYPE IN PROGRAM &lt;XYZ&gt; \r\n\/: USING &amp;LIST_TYPE&amp;\r\n\/: END PERFORM\r\n\/* ...\r\n\/* Printing the list of materials\r\n\/* ...<\/pre>\n<pre lang=\"abap\">\/* Set list type = 2 \r\n\/: DEFINE &amp;LIST_TYPE&amp; = '2' \r\n\/: PERFORM SET_LIST_TYPE IN PROGRAM &lt;XYZ&gt; \r\n\/: USING &amp;LIST_TYPE&amp; \r\n\/: END PERFORM\r\n\/* The following NEW-PAGE command is important: \r\n\/* a forced pagebreak and new column headers for list of type 2\r\n\/* are printed in header window\r\n\/: NEW-PAGE\r\n\/* ... \r\n\/* Printing list of approvers\r\n\/* ...<\/pre>\n<pre lang=\"abap\">\/* Set list type = 3\r\n\/: DEFINE &amp;LIST_TYPE&amp; = '3'\r\n\/: PERFORM SET_LIST_TYPE IN PROGRAM &lt;XYZ&gt;\r\n\/: USING &amp;LIST_TYPE&amp;\r\n\/: END PERFORM\r\n\/: NEW-PAGE\r\n\/* ...\r\n\/* Printing change log\r\n\/* ...<\/pre>\n<p>In the code above you can see there\u00a7s always a definition of list type (1, 2, or 3) followed by the list contents itself ended by a NEW-PAGE command (after list 1 and two) so the start of the subsequent list is on separate page and the headers are printed correctly.<\/p>\n<p>Now we have to code the program &lt;XYZ&gt; that will manage the &#8220;set&#8221; and &#8220;get&#8221; actions for list type:<\/p>\n<pre lang=\"abap\">* Declare global variable for list_type\r\nDATA: g_list_type type i.\r\n\r\nFORM get_list_type tab_in  STRUCTURE itcsy\r\n                   tab_out STRUCTURE itcsy.\r\n\r\n  FIELD-SYMBOLS: &lt;fs_out&gt; type any.\r\n\r\n  READ TABLE tab_out ASSIGNING &lt;fs_out&gt; INDEX 1.\r\n  IF sy-subrc = 0.\r\n    &lt;fs_out&gt;-value = g_list_type.\r\n  ENDIF.\r\nENDFORM.\r\n\r\nFORM set_list_type tab_in  STRUCTURE itcsy\r\n                   tab_out STRUCTURE itcsy.\r\n\r\n  FIELD-SYMBOLS: &lt;fs_in&gt; type any.\r\n\r\n  READ TABLE tab_in ASSIGNING &lt;fs_in&gt; INDEX 1.\r\n  IF sy-subrc = 0.\r\n    CHECK &lt;fs_in&gt;-value = 1 \r\n       OR &lt;fs_in&gt;-value = 2\r\n       OR &lt;fs_in&gt;-value = 3.\r\n\r\n    g_list_type = &lt;fs_in&gt;-value.\r\n  ENDIF.\r\nENDFORM.<\/pre>\n<p><a name=\"Using_a_TOP_section_in_MAIN_window\"><\/a><\/p>\n<h1>\u00a0Using a TOP section in MAIN window<\/h1>\n<p>This approach is a bit simpler and can be used\u00a0without external program because everything is maintained within the MAIN window.<\/p>\n<p>For printing the list headers we will use the TOP section of the MAIN window (TOP section is triggered on each page)<\/p>\n<pre lang=\"abap\">\/: TOP\r\n\/* commands\r\n\/: ENDTOP<\/pre>\n<p>Before the TOP section is reached, we need to set the LIST_TYPE variable and fill it with initial value so the header is printed correctly on first page. In our scenario the TOP section can be like the following:<\/p>\n<pre lang=\"abap\">\/: DEFINE &amp;LIST_TYPE&amp; = '1'\r\n\/*\r\n\/: TOP\r\n*  &amp;ULINE(70)&amp;\r\n\/: CASE &amp;LIST_TYPE&amp;\r\n\/: WHEN '1'\r\n*  Material,,UOM,,Quantity,,Price\r\n\/: WHEN '2'\r\n*  Aprover,,Signed,,Date,,Time\r\n\/: WHEN '3'\r\n*  Change date,,Version,,Description\r\n\/: ENDCASE\r\n*  &amp;ULINE(70)&amp;\r\n\/: ENDTOP<\/pre>\n<p>The following code in MAIN window will handle the rest of printing the data:<\/p>\n<pre lang=\"abap\">\/* ...\r\n\/* printing the first list type data\r\n\/* ...\r\n\/*\r\n\/: DEFINE &amp;LIST_TYPE&amp; = '2'\r\n\/: NEW-PAGE\r\n\/* ...\r\n\/* printing the second list type data\r\n\/* ...\r\n\/*\r\n\/: DEFINE &amp;LIST_TYPE&amp; = '3'\r\n\/: NEW-PAGE\r\n\/* ...\r\n\/* printing the third list type data\r\n\/* ...<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Once I needed to have several lists in MAIN window output and each of these lists needed to have different column headers. As\u00a0usually, there are several ways how to achieve this and I&#8217;ll try to present two possible ways: Using &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=306\">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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[446,55,73,17,71,72,74],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-development-2","tag-main-window","tag-sap","tag-sapscript","tag-top-section","tag-var-window"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-4W","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/306","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=306"}],"version-history":[{"count":11,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}