{"id":760,"date":"2013-11-17T11:40:27","date_gmt":"2013-11-17T10:40:27","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=760"},"modified":"2013-11-17T18:54:58","modified_gmt":"2013-11-17T17:54:58","slug":"abap-alv-controlled-by-a-global-class","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=760","title":{"rendered":"ALV &#8211; Dynpro controlled by a global class"},"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 article I&#8217;ll present an approach how to handle a screen with a global ABAP class. The idea is simple &#8211; we will create a class which will listen to PAI and PBO events raised by the screen. All data processing and screen element manipulation is done in the class code. Let&#8217;s check out how exactly it is done<!--more--><\/p>\n<p>In SE80 create a function group with one function module and one screen. The function module will be the entry point from the class. The screen will be used to draw elements on the screen. The screen elements will be manipulated from the ABAP class code.<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"805\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=805\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION.png\" data-orig-size=\"539,346\" 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=\"Function group and FM creation\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION.png\" class=\"size-medium wp-image-805 alignnone\" alt=\"Function group and FM creation\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION-300x192.png\" width=\"300\" height=\"192\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION-300x192.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION-467x300.png 467w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_01_FUGR_CREATION.png 539w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>For demonstration purposes we will have only a screen with one grid and we will capture just the OKCODE. So we will have one global variable defined in TOP include:<\/p>\n<pre lang=\"abap\">FUNCTION-POOL ZCA_ALV.                      \r\n\r\nDATA:\r\n  g_okcode TYPE okcode.<\/pre>\n<p>The code of our new function module will also be simple:<\/p>\n<pre lang=\"abap\">FUNCTION ZCA_ALV_GRID1.\r\n* call the editor screen\r\n  call screen 100.\r\nENDFUNCTION.<\/pre>\n<p>Now we create the screen 0100.<br \/>\n<em>Please note the size of the screen<\/em> &#8211; this is because we would like the ALV grid to be stretched across the whole page and we don&#8217;t want double scroll bars (issue when grid is too large) &#8211; this will require also modification in the screen layout (explained later).<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"806\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=806\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION.png\" data-orig-size=\"602,511\" 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=\"Screen creation\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION.png\" class=\"size-medium wp-image-806 alignnone\" alt=\"Screen creation\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION-300x254.png\" width=\"300\" height=\"254\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION-300x254.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION-353x300.png 353w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_02_SCREEN_CREATION.png 602w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In the following picture you can see how the global variable G_OKCODE is connected to the screen (is passed in\/from the screen)<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"807\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=807\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE.png\" data-orig-size=\"712,180\" 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=\"Screen elements\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE.png\" class=\"size-medium wp-image-807 alignnone\" alt=\"Screen elements\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE-300x75.png\" width=\"300\" height=\"75\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE-300x75.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE-500x126.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_03_SCREEN_OKCODE.png 712w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The flow logic of our new screen is trivial:<\/p>\n<pre lang=\"abap\">PROCESS BEFORE OUTPUT.\r\n  MODULE pbo.\r\n*\r\nPROCESS AFTER INPUT.\r\n  MODULE pai.<\/pre>\n<p>In new include for modules PBO and PAI we put the following simple code<\/p>\n<pre lang=\"abap\">*&amp;---------------------------------------------------------------*\r\n*&amp;      Module  PBO  OUTPUT\r\n*&amp;---------------------------------------------------------------*\r\n*       text\r\n*----------------------------------------------------------------*\r\nMODULE pbo OUTPUT.\r\n  DATA:\r\n \u00a0\u00a0\u00a0lt_ucomm\u00a0TYPE\u00a0TABLE\u00a0OF\u00a0sy-ucomm.\r\n\r\n  FIELD-SYMBOLS:\r\n \u00a0\u00a0\u00a0&lt;fs_ucomm&gt;\u00a0type\u00a0sy-ucomm.\r\n\r\n* This will ensure some commands\/buttons will by hidden\/disabled\r\n\u00a0\u00a0CLEAR\u00a0lt_ucomm[].\r\n  APPEND\u00a0INITIAL\u00a0LINE\u00a0TO\u00a0lt_ucomm\u00a0ASSIGNING\u00a0&lt;fs_ucomm&gt;.\r\n \u00a0&lt;fs_ucomm&gt;\u00a0=\u00a0'EXECUTE'.\r\n\r\n  SET PF-STATUS\u00a0'MY_PF_STATUS'\u00a0excluding\u00a0lt_ucomm.\r\n \u00a0SET TITLEBAR\u00a0'MY_TITLEBAR'.\r\n  zcl_ca_grid_handling=&gt;raise_pbo( i_dynnr = sy-dynnr ).\r\nENDMODULE.                 \" PBO  OUTPUT\r\n*&amp;---------------------------------------------------------------*\r\n*&amp;      Module  PAI  INPUT\r\n*&amp;---------------------------------------------------------------*\r\n*       text\r\n*----------------------------------------------------------------*\r\nMODULE pai INPUT.\r\n  IF g_okcode = 'CANC'.\r\n    SET SCREEN 0.\r\n  ENDIF.\r\n\r\n  zcl_ca_grid_handling=&gt;raise_pai(\r\n    i_dynnr    = sy-dynnr\r\n    i_okcode   = g_okcode\r\n  ).\r\nENDMODULE.                 \" PAI  INPUT<\/pre>\n<p>Now in the layout editor for screen 0100 I&#8217;ll create the ALV grid container. <em>Again please note<\/em> &#8211; the grid size is the same as screen size (-1 so it fits in) and what is also important &#8211; note the Resize section &#8211; this will ensure the grid will not have it&#8217;s own scrollbar (no double scroll bars)<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_04_LAYOUT_EDITOR1.png\"><img decoding=\"async\" data-attachment-id=\"826\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=826\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_04_LAYOUT_EDITOR1.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"Screen layout\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_04_LAYOUT_EDITOR1.png\" class=\"wp-image-826 alignnone\" alt=\"Screen layout\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_04_LAYOUT_EDITOR1.png\" width=\"300\" \/><\/a><\/p>\n<p>Now let&#8217;s step forward to the class (Usual ABAP class) creation. In screen 0100 we are calling two static methods &#8211; RAISE_PAI and RAISE_PBO. We have to define the corresponding interface<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"812\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=812\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI.png\" data-orig-size=\"736,255\" 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=\"Raise PAI interface\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI.png\" class=\"size-medium wp-image-812 alignnone\" alt=\"Raise PAI interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI-300x103.png\" width=\"300\" height=\"103\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI-300x103.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI-500x173.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_08_RAISE_PAI.png 736w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"813\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=813\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO.png\" data-orig-size=\"689,231\" 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=\"SCREEN_CLASS_09_RAISE_PBO\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO.png\" class=\"size-medium wp-image-813 alignnone\" alt=\"Raise PBO interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO-300x100.png\" width=\"300\" height=\"100\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO-300x100.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO-500x167.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_09_RAISE_PBO.png 689w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Their code is simple:<\/p>\n<pre lang=\"abap\">METHOD raise_pai.\r\n  RAISE EVENT pai\r\n    EXPORTING\r\n      i_dynnr       = i_dynnr\r\n      i_okcode      = i_okcode.\r\nENDMETHOD.\r\n\r\nMETHOD raise_pbo.\r\n  RAISE EVENT pbo\r\n    EXPORTING i_dynnr = i_dynnr.\r\nENDMETHOD.<\/pre>\n<p>You can see we&#8217;re raising some non-standard events &#8211; so we have to define them with the corresponding interface:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_05_CLASS_EVENTS.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"Class events attributes\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_05_CLASS_EVENTS-300x116.png\" width=\"300\" height=\"116\" \/><\/a><\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_06_EVENT_PBO.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"PBO event interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_06_EVENT_PBO-300x114.png\" width=\"300\" height=\"114\" \/><\/a><\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_07_EVENT_PAI.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"PAI event interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_07_EVENT_PAI-300x111.png\" width=\"300\" height=\"111\" \/><\/a><\/p>\n<p>If we want to react on an event, we have to register a listener for it and have a method to handle it. The listener registration can be put directly in the class instance constructor:<\/p>\n<pre lang=\"abap\">METHOD constructor.\r\n* register for the events\r\n  SET HANDLER handle_pai.\r\n  SET HANDLER handle_pbo.\r\nENDMETHOD.<\/pre>\n<p>We have registered listener methods (HANDLE_PAI, HANDLE_PBO) but we actually don&#8217;t have them implemented yet so let&#8217;s create them now:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"814\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=814\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER.png\" data-orig-size=\"535,369\" 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=\"PAI Handler method interface\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER.png\" class=\"size-medium wp-image-814 alignnone\" alt=\"PAI Handler method interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER-300x206.png\" width=\"300\" height=\"206\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER-300x206.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER-434x300.png 434w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_10_PAI_HANDLER.png 535w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"827\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=827\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER.png\" data-orig-size=\"722,403\" 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=\"PBO Handler method interface\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER.png\" class=\"size-medium wp-image-827 alignnone\" alt=\"PBO Handler method interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER-300x167.png\" width=\"300\" height=\"167\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER-300x167.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER-500x279.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_11_PBO_HANDLER.png 722w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now we would like to implement our handlers. At first we have to define their interface &#8211; this is easy as class designer offers a button to fill the parameters automatically according to the event:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"816\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=816\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE.png\" data-orig-size=\"514,177\" 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=\"Event handler interface\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE.png\" class=\"size-medium wp-image-816 alignnone\" alt=\"Event handler interface\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE-300x103.png\" width=\"300\" height=\"103\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE-300x103.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE-500x172.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_12_PAI_HANDLER_INTERFACE.png 514w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"817\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=817\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED.png\" data-orig-size=\"469,255\" 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=\"Event handler interface auto-filled\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED.png\" class=\"size-medium wp-image-817 alignnone\" alt=\"Event handler interface auto-filled\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED-300x163.png\" width=\"300\" height=\"163\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED-300x163.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_13_PAI_HANDLER_INTERFACE_FILLED.png 469w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Finally we can fill our event handlers with some code:<\/p>\n<pre lang=\"abap\">METHOD handle_pbo.\r\n  CASE i_dynnr.\r\n    WHEN '0100'.\r\n      show_editor( ).\r\n*  \tWHEN OTHERS.\r\n  ENDCASE.\r\nENDMETHOD.\r\n\r\nMETHOD HANDLE_PAI.\r\n  CASE i_dynnr.\r\n    WHEN '0100'.\r\n      \"screen 0100: configuration\r\n      CASE i_okcode.\r\n        WHEN 'CANCEL' OR 'LEAVE' OR 'BACK'. \r\n          SET SCREEN 0.\r\n*      \tWHEN OTHERS.\r\n      ENDCASE.\r\n  ENDCASE.\r\nENDMETHOD.<\/pre>\n<p>Method SHOW_EDITOR in HANDLE_PBO is a method for creation of the container object, ALV grid object and displaying it.<br \/>\nIt uses standard ALV components CL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID and displays data of SFLIGHT &#8211; we will keep the data and references to container and grid in class attributes:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"819\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=819\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES.png\" data-orig-size=\"716,257\" 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=\"Class attributes\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES.png\" class=\"size-medium wp-image-819 alignnone\" alt=\"Class attributes\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES-300x107.png\" width=\"300\" height=\"107\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES-300x107.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES-500x179.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_15_CLASS_ATTRIBUTES.png 716w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The simplest form of the SHOW_EDITOR method might look like this:<\/p>\n<pre lang=\"abap\">METHOD show_editor.\r\n  DATA:\r\n    lt_fieldcat TYPE lvc_t_fcat,\r\n    ls_layout   TYPE lvc_s_layo,\r\n    ls_variant  TYPE disvariant.\r\n\r\n  IF me-&gt;mr_container IS INITIAL.\r\n\r\n    CREATE OBJECT me-&gt;mr_container\r\n      EXPORTING\r\n        container_name = 'GO_GRID_CONTAINER'.\r\n\r\n    CREATE OBJECT me-&gt;mr_grid\r\n      EXPORTING\r\n        i_parent = me-&gt;mr_container.\r\n\r\n    ls_layout-sel_mode = 'A'.\r\n    ls_layout-no_rowmark = abap_true.\r\n    ls_layout-cwidth_opt = abap_true.\r\n\r\n    ls_variant-report   = sy-repid.\r\n    ls_variant-username = sy-uname.\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      = lt_fieldcat.\r\n\r\n    SELECT * INTO TABLE mt_data FROM sflight.\r\n\r\n    me-&gt;mr_grid-&gt;set_table_for_first_display(\r\n      EXPORTING\r\n        is_layout             = ls_layout\r\n        is_variant            = ls_variant\r\n        i_save                = 'A'\r\n        i_default             = 'X'\r\n      CHANGING\r\n        it_fieldcatalog       = lt_fieldcat\r\n        it_outtab             = mt_data ).\r\n  ENDIF.\r\nENDMETHOD.<\/pre>\n<p>Now we have everything prepared&#8230;so we just add one more public class method to run the whole magic \ud83d\ude42<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_14_RUN_METHOD.png\"><img decoding=\"async\" data-attachment-id=\"828\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=828\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_14_RUN_METHOD.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"Method RUN\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_14_RUN_METHOD.png\" class=\"wp-image-828 alignnone\" alt=\"Method RUN\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_14_RUN_METHOD.png\" width=\"300\" \/><\/a><\/p>\n<p>The code is simple:<\/p>\n<pre lang=\"abap\">METHOD run.\r\n  CALL FUNCTION 'ZCA_ALV_GRID1'.\r\nENDMETHOD.<\/pre>\n<p>Here&#8217;s the output after ZCL_CA_GRID_HANDLING is instantiated and method RUN is called:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_16_OUTPUT1.png\"><img decoding=\"async\" data-attachment-id=\"830\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=830\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_16_OUTPUT1.png\" data-orig-size=\"\" data-comments-opened=\"1\" data-image-meta=\"[]\" data-image-title=\"ALV Grid output\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_16_OUTPUT1.png\" class=\"wp-image-830 alignnone\" alt=\"ALV Grid output\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_16_OUTPUT1.png\" width=\"300\" \/><\/a><\/p>\n<p>Let&#8217;s put a breakpoint on first line of method HANDLE_PAI to make sure the method is called when user performs an action in the screen (I pressed ESC&#8230;OK_CODE=&#8217;BACK&#8217;):<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"831\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=831\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER.png\" data-orig-size=\"973,354\" 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=\"Debugger started in class\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER.png\" class=\"size-medium wp-image-831 alignnone\" alt=\"Debugger started in class\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER-300x109.png\" width=\"300\" height=\"109\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER-300x109.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER-500x181.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/SCREEN_CLASS_17_DEBUGGER.png 973w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Voila ! We have fully functional ALV handled by an ABAP global class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I&#8217;ll present an approach how to handle a screen with a global ABAP class. The idea is simple &#8211; we will create a class which will listen to PAI and PBO events raised by the screen. All &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=760\">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":"ABAP - ALV controlled by a global class http:\/\/wp.me\/p3nYbe-cg","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,86,9],"tags":[446,447,221],"class_list":["post-760","post","type-post","status-publish","format-standard","hentry","category-abap","category-alv","category-development","tag-abap","tag-alv","tag-oo-abap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-cg","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/760","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=760"}],"version-history":[{"count":5,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/760\/revisions"}],"predecessor-version":[{"id":856,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/760\/revisions\/856"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}