{"id":466,"date":"2013-04-23T17:49:26","date_gmt":"2013-04-23T16:49:26","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=466"},"modified":"2013-04-24T14:15:36","modified_gmt":"2013-04-24T13:15:36","slug":"add-leading-spaces-to-a-string-in-abap","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=466","title":{"rendered":"Add leading spaces to a string in ABAP"},"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\" \/><\/p>\n<p>If you have a requirement where some strings need to be aligned at some column and these strings have a common label so the output is two columns where the label is in the first column, values in the second, you can use the following piece of code as an example to create such list.<!--more--><\/p>\n<pre lang=\"abap\">REPORT  z_text_spaces.\r\nDATA:\r\n  lt_text       TYPE STANDARD TABLE OF tline INITIAL SIZE 0,\r\n  l_spaces      TYPE i,\r\n  l_header_size type i,\r\n  l_spacechars(255).\r\n\r\nCONSTANTS:\r\n  c_header(9)  TYPE c VALUE 'Value(s):'.    \" Size of the header (char10) is taken into account !!!\r\n\r\nFIELD-SYMBOLS:\r\n  &lt;fs_text&gt; TYPE tline.\r\n\r\nl_spaces = 20.  \" TAB settings\r\nl_header_size = STRLEN( c_header ).\r\n\r\n\" Printing first line together with value label (header)\r\nAPPEND INITIAL LINE TO lt_text ASSIGNING &lt;fs_text&gt;.\r\n&lt;fs_text&gt;-tdline = 'Value 1'.\r\nIF l_spaces &gt; l_header_size.\r\n  l_spaces = l_spaces - l_header_size.\r\n  CONCATENATE '' &lt;fs_text&gt;-tdline INTO &lt;fs_text&gt;-tdline SEPARATED BY l_spacechars(l_spaces).\r\n  l_spaces = l_spaces + l_header_size.\r\nENDIF.\r\nCONCATENATE c_header &lt;fs_text&gt;-tdline INTO &lt;fs_text&gt;-tdline RESPECTING BLANKS.\r\n\r\n\" Printing second (and further) value(s)\r\nAPPEND INITIAL LINE TO lt_text ASSIGNING &lt;fs_text&gt;.\r\n&lt;fs_text&gt;-tdline = 'Value 2'.\r\nCONCATENATE '' &lt;fs_text&gt;-tdline INTO &lt;fs_text&gt;-tdline SEPARATED BY l_spacechars(l_spaces).\r\n\r\nloop AT lt_text ASSIGNING &lt;fs_text&gt;.\r\n  write \/ &lt;fs_text&gt;-tdline.\r\nENDLOOP.<\/pre>\n<p>The output will then look like as on the picture below.<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"470\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=470\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces.png\" data-orig-size=\"343,155\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"ABAP leading spaces\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces.png\" class=\"size-full wp-image-470 alignnone\" alt=\"ABAP leading spaces\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces.png\" width=\"343\" height=\"155\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces.png 343w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ABAP_leading_spaces-300x135.png 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/a><\/p>\n<p>In systems where the RESPECTING BLANKS option for CONCATENATE command is not supported you can use the following piece of code<\/p>\n<pre lang=\"abap\">DATA:\r\n  a TYPE string VALUE 'ABC',\r\n  b TYPE string,\r\n  position TYPE i VALUE 20,\r\n  l_spacechars TYPE string.\r\n\r\nDO 255 TIMES.\r\n  CONCATENATE l_spacechars ` ` INTO l_spacechars.\r\nENDDO.\r\n\r\nCONCATENATE l_spacechars(position) '' INTO b SEPARATED BY a.\r\nWRITE:\/ b.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you have a requirement where some strings need to be aligned at some column and these strings have a common label so the output is two columns where the label is in the first column, values in the second, &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=466\">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_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},"jetpack_post_was_ever_published":false},"categories":[16,9],"tags":[446,109,35,107,110,17,108],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-concatenation","tag-format","tag-leading-space","tag-respecting-blanks","tag-sap","tag-trailing-space"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-7w","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/466","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=466"}],"version-history":[{"count":6,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/466\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/466\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}