{"id":503,"date":"2013-04-28T07:52:06","date_gmt":"2013-04-28T06:52:06","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=503"},"modified":"2013-04-30T10:49:40","modified_gmt":"2013-04-30T09:49:40","slug":"alv-tutorial-03-icon-column","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=503","title":{"rendered":"ALV tutorial 03 &#8211; ICON column"},"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 show how to add a column which will hold a user defined icon\u00a0to the ALV grid. <!--more-->The core is:<\/p>\n<ol>\n<li><span style=\"line-height: 15px;\">Add new field to the output table <code>gt_data<\/code> (this will hold the icon information)<\/span><\/li>\n<li>Modify the field catalog <code>gt_fieldcat<\/code> so it&#8217;s updated with info about our new field and set this new field as icon<\/li>\n<li>Read and prepare data for output (read data from DB and update the icon field based on your criteria)<\/li>\n<li>Display or refresh our ALV grid (<code>g_grid-&gt;set_table_for_first_display<\/code>) using the modified field catalog<\/li>\n<\/ol>\n<h1>1. Data definition<\/h1>\n<p>Here we create the output table with field ICON &#8211; this will be used to store the icon name.<\/p>\n<pre lang=\"abap\">TYPES: BEGIN OF ty_data.\r\n        INCLUDE STRUCTURE sflight.\r\nTYPES:  icon(4) TYPE c,             \" field to hold the icon\r\n       END OF ty_data.\r\n\r\nDATA: gt_data TYPE TABLE OF ty_data,\r\n      g_grid TYPE REF TO cl_gui_alv_grid,\r\n      gs_layout TYPE lvc_s_layo,\r\n      gt_fieldcat TYPE lvc_t_fcat.<\/pre>\n<h1>2. Field catalog<\/h1>\n<p>Now we prepare field catalog for data structure we&#8217;re going to use and update it with the new ICON field<\/p>\n<pre lang=\"abap\">FORM get_fieldcat .\r\n  FIELD-SYMBOLS: &lt;fs_fcat&gt; TYPE lvc_s_fcat.\r\n\r\n  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'\r\n    EXPORTING\r\n      i_structure_name       = 'SFLIGHT'\r\n    CHANGING\r\n      ct_fieldcat            = gt_fieldcat\r\n    EXCEPTIONS\r\n      inconsistent_interface = 1\r\n      program_error          = 2\r\n      OTHERS                 = 3.\r\n  CHECK sy-subrc = 0.\r\n\r\n  APPEND INITIAL LINE TO gt_fieldcat ASSIGNING &lt;fs_fcat&gt;.\r\n  &lt;fs_fcat&gt;-fieldname = 'ICON'.\r\n  &lt;fs_fcat&gt;-icon = 'X'.\r\n  &lt;fs_fcat&gt;-outputlen = 3.\r\nENDFORM.<\/pre>\n<h1>3. Read data<\/h1>\n<p>In our example we would like to add &#8220;warning&#8221; icon when some of the travel classes is full (see the line <code>&lt;fs_data&gt;-icon = '@AH@'.<\/code>)<\/p>\n<pre lang=\"abap\">FORM read_data.\r\n  DATA:\r\n    l_color TYPE c.\r\n\r\n  FIELD-SYMBOLS:\r\n    &lt;fs_data&gt; TYPE ty_data.\r\n\r\n  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data\r\n    FROM sflight\r\n    UP TO c_max_rows ROWS.\r\n\r\n  LOOP AT gt_data ASSIGNING &lt;fs_data&gt;.\r\n    IF &lt;fs_data&gt;-seatsocc = &lt;fs_data&gt;-seatsmax OR\r\n       &lt;fs_data&gt;-seatsocc_b = &lt;fs_data&gt;-seatsmax_b OR\r\n      &lt;fs_data&gt;-seatsocc_f = &lt;fs_data&gt;-seatsmax_f.\r\n      \" Some class is full\r\n      &lt;fs_data&gt;-icon = '@AH@'.             \" Warning Icon\r\n    ENDIF.\r\n  ENDLOOP.\r\nENDFORM.<\/pre>\n<p>Together with field catalog we modified the ALV grid layout to display lines in &#8220;zebra&#8221; style<\/p>\n<pre lang=\"abap\">FORM get_layout .\r\n  gs_layout-zebra = 'X'.\r\nENDFORM.<\/pre>\n<h1>4. Display data<\/h1>\n<p>Now we display our data with new field containing a warning icon in case some of the travel classes is full<\/p>\n<pre lang=\"abap\">FORM display_grid.\r\n  PERFORM get_layout.\r\n  PERFORM get_fieldcat.\r\n\r\n  CREATE OBJECT g_grid\r\n    EXPORTING\r\n      i_parent = cl_gui_container=&gt;default_screen.\r\n\r\n  CALL METHOD g_grid-&gt;set_table_for_first_display\r\n    EXPORTING\r\n      i_structure_name              = 'SFLIGHT'\r\n      is_layout                     = gs_layout\r\n    CHANGING\r\n      it_outtab                     = gt_data\r\n      it_fieldcatalog               = gt_fieldcat\r\n    EXCEPTIONS\r\n      invalid_parameter_combination = 1\r\n      program_error                 = 2\r\n      too_many_lines                = 3\r\n      OTHERS                        = 4.\r\n  IF sy-subrc &lt;&gt; 0.\r\n    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno\r\n               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n  ENDIF.\r\nENDFORM.<\/pre>\n<p>The report output should now look like on the picture below<a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_03_output.png\"><img decoding=\"async\" data-attachment-id=\"507\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=507\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_03_output.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"ALV tutorial &amp;#8211; Icon column\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_03_output.png\" class=\"alignleft size-full wp-image-507\" alt=\"ALV tutorial - Icon column\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_03_output.png\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example I&#8217;ll show how to add a column which will hold a user defined icon\u00a0to the ALV grid.<\/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,136,9],"tags":[446,88,447,113,17],"class_list":["post-503","post","type-post","status-publish","format-standard","hentry","category-abap","category-alv-tutorial","category-development","tag-abap","tag-additional-fields","tag-alv","tag-icon","tag-sap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-87","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/503","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=503"}],"version-history":[{"count":6,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/503\/revisions"}],"predecessor-version":[{"id":526,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/503\/revisions\/526"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}