{"id":496,"date":"2013-04-26T10:20:37","date_gmt":"2013-04-26T09:20:37","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=496"},"modified":"2013-04-30T10:49:49","modified_gmt":"2013-04-30T09:49:49","slug":"alv-tutorial-02-pf-status-gui-title-and-exception-lights","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=496","title":{"rendered":"ALV tutorial 02 &#8211; PF-STATUS, GUI title and exception lights"},"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 step we&#8217;ll customize our ALV with custom PF-STATUS (buttons, menu, &#8230;), GUI title and we&#8217;ll also add a column with exception lights (Red\/Yellow\/Green)<!--more--><\/p>\n<ol>\n<li><span style=\"line-height: 15px;\">We need to modify our table <code>gt_data<\/code> with <code>SFLIGHT<\/code> data to hold one more information &#8211; exception light.<\/span>\n<pre lang=\"abap\">TYPES: BEGIN OF ty_data.\r\n        INCLUDE STRUCTURE sflight.\r\nTYPES:   exc_light(1) TYPE c,        \" new field to hold the exception light\r\n       END OF ty_data.\r\n\r\nDATA: gt_data TYPE TABLE OF ty_data.<\/pre>\n<\/li>\n<li>Then we have to fill this info field with data &#8211; most probably during data retrieval so in our case in <code>FORM get_data<\/code>:\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      &lt;fs_data&gt;-exc_light = 2.             \" Yellow - some class is full\r\n    ELSEIF &lt;fs_data&gt;-seatsocc = &lt;fs_data&gt;-seatsmax AND\r\n           &lt;fs_data&gt;-seatsocc_b = &lt;fs_data&gt;-seatsmax_b AND\r\n           &lt;fs_data&gt;-seatsocc_f = &lt;fs_data&gt;-seatsmax_f.\r\n      &lt;fs_data&gt;-exc_light = 1.             \" Red - the flight is full\r\n    ELSE.\r\n      &lt;fs_data&gt;-exc_light = 3.             \" Green - seats available\r\n    ENDIF.\r\n  ENDLOOP.\r\nENDFORM.<\/pre>\n<\/li>\n<li>We have to tell our ALV which field holds the exception light information so we have to add this information to layout (new variable <code>ls_layout<\/code>) of ALV used during it&#8217;s display:\n<pre lang=\"abap\">FORM display_grid.\r\n  DATA: ls_layout TYPE lvc_s_layo.\r\n\r\n  ls_layout-excp_fname = 'EXC_LIGHT'.\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                     = ls_layout\r\n    CHANGING\r\n      it_outtab                     = gt_data\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<\/li>\n<li>We are now done with the exception light and we can step into adding the PF-STATUS (modify the toolbar, define response on user actions, &#8230;)<br \/>\nFirst of all we will separate the PF-STATUS and titlebar modification from our code so we&#8217;ll add new module into screen 0100 PBO section (we&#8217;ll put it&#8217;s definition into main program).<br \/>\nAt the same time we add new module for handling user actions to the PAI section (we&#8217;ll create it&#8217;s definition in the main program)<\/p>\n<pre lang=\"abap\">PROCESS BEFORE OUTPUT.\r\n  MODULE status_0100.\r\n  MODULE display_grid.\r\n*\r\nPROCESS AFTER INPUT.\r\n  MODULE user_command_0100.<\/pre>\n<\/li>\n<li>We&#8217;ll take it step-by step so the first will be <code>MODULE status_0100<\/code>\n<pre lang=\"abap\">MODULE status_0100 OUTPUT.\r\n  SET PF-STATUS 'MAIN'.\r\n  SET TITLEBAR 'ALV_EXAMPLES'.\r\nENDMODULE.<\/pre>\n<p>In the above code you can see we set the <code>TITLEBAR<\/code> to <code>ALV_EXAMPLES<\/code>\u00a0&#8211; double click on\u00a0<code>ALV_EXAMPLES<\/code>, create new GUI title object and set your desired title text. We alse set name of the <code>PF-STATUS 'MAIN'<\/code>. We&#8217;ll create this status in object tree by right-click on the program name -&gt; Create -&gt; GUI status and name it <code>MAIN<\/code>. In our program we won&#8217;t handle any special user commands so we&#8217;ll implement only the <code>BACK<\/code>, <code>EXIT<\/code> and <code>CANCEL<\/code> actions.<br \/>\n<a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02.png\"><img decoding=\"async\" data-attachment-id=\"481\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=481\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"ALV PF-STATUS creation\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02.png\" class=\"size-full wp-image-481 alignnone\" alt=\"ALV PF-STATUS creation\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02.png\" \/><\/a><\/li>\n<li>The next is new <code>MODULE display_grid<\/code> where we moved our data handling and calling the ALV display (separation into modules depends only on your choice)\n<pre lang=\"abap\">MODULE display_grid OUTPUT.\r\n  PERFORM read_data.\r\n  PERFORM display_grid.\r\nENDMODULE.<\/pre>\n<\/li>\n<li>The last part is handling user input in <code>MODULE user_command_0100<\/code>\n<pre lang=\"abap\">MODULE user_command_0100 INPUT.\r\n*   to react on oi_custom_events:\r\n    call method cl_gui_cfw=&gt;dispatch.\r\n  CASE sy-ucomm.\r\n    WHEN 'BACK' OR \r\n         'EXIT' OR \r\n         'CANCEL'.\r\n      LEAVE PROGRAM.\r\n    WHEN OTHERS.\r\n*     do nothing\r\n  ENDCASE.  \r\nENDMODULE.<\/pre>\n<\/li>\n<li>Output of our program will be like on the following picture<a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02_02.png\"><img decoding=\"async\" data-attachment-id=\"482\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=482\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02_02.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"PF-STATUS, GUI title and Exception lights\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02_02.png\" class=\"size-full wp-image-482 alignnone\" alt=\"PF-STATUS, GUI title and Exception lights\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ALV_DEMO_02_02.png\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this step we&#8217;ll customize our ALV with custom PF-STATUS (buttons, menu, &#8230;), GUI title and we&#8217;ll also add a column with exception lights (Red\/Yellow\/Green)<\/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":[123,124,114,17],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-abap","category-alv-tutorial","category-development","tag-abap-pf-status","tag-gui-title","tag-lights","tag-sap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-80","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/496","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=496"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/496\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/496\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}