{"id":7854,"date":"2025-09-15T01:31:24","date_gmt":"2025-09-14T20:01:24","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=what-is-cl_gui_alv_grid"},"modified":"2025-09-15T01:31:24","modified_gmt":"2025-09-14T20:01:24","slug":"what-is-cl_gui_alv_grid","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=what-is-cl_gui_alv_grid","title":{"rendered":"What is CL_GUI_ALV_GRID?"},"content":{"rendered":"<ul>\n<li>\n<p>It\u2019s an <strong>ABAP OO class<\/strong> that displays data in a <strong>grid (table-like format)<\/strong> inside a screen container.<\/p>\n<\/li>\n<li>\n<p>Unlike the simpler <code>CL_SALV_TABLE<\/code>, this grid is <strong>fully interactive and customizable<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p>Main Features<\/p>\n<ol>\n<li>\n<p><strong>Editable cells<\/strong> \u2192 You can let users change data directly in the grid.<\/p>\n<\/li>\n<li>\n<p><strong>Field catalog<\/strong> \u2192 You define which columns to show, their titles, and if they\u2019re editable.<\/p>\n<\/li>\n<li>\n<p><strong>Layout control<\/strong> \u2192 Zebra patterns, column widths, key columns, hotspots, etc.<\/p>\n<\/li>\n<li>\n<p><strong>Events<\/strong> \u2192 You can react to user actions (e.g., double-click, toolbar buttons, cell value changes).<\/p>\n<\/li>\n<li>\n<p><strong>Container-based<\/strong> \u2192 You need a custom control on a dynpro (screen) to host the ALV Grid.<\/p>\n<\/li>\n<\/ol>\n<p>How it Works (Step-by-Step Flow)<\/p>\n<ol>\n<li>\n<p><strong>Create a Screen (Dynpro)<\/strong><\/p>\n<ul>\n<li>\n<p>Add a <strong>Custom Control<\/strong> (like a placeholder on the screen).<\/p>\n<\/li>\n<li>\n<p>Give it a name, e.g., <code>CC_ALV<\/code>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Create Container<\/strong><\/p>\n<ul>\n<li>\n<p>In your program, create an object of class <code>CL_GUI_CUSTOM_CONTAINER<\/code> linked to <code>CC_ALV<\/code>.<\/p>\n<\/li>\n<li>\n<p>This is the &#8220;holder&#8221; where the ALV will appear.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Create ALV Grid<\/strong><\/p>\n<ul>\n<li>\n<p>Instantiate <code>CL_GUI_ALV_GRID<\/code> using the container as its parent.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Build Field Catalog<\/strong><\/p>\n<ul>\n<li>\n<p>Define column properties (<code>FIELDNAME<\/code>, <code>SELTEXT_M<\/code>, <code>EDIT<\/code>, etc.).<\/p>\n<\/li>\n<li>\n<p>Each entry describes how a column is shown in the ALV grid.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Pass Data to ALV<\/strong><\/p>\n<ul>\n<li>\n<p>Call method <code>set_table_for_first_display<\/code> with your internal table (<code>IT_OUTTAB<\/code>) and the field catalog.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Display Grid<\/strong><\/p>\n<ul>\n<li>\n<p>The ALV Grid now shows inside the screen.<\/p>\n<\/li>\n<li>\n<p>Users can scroll, filter, sort, and (if allowed) edit data.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Steps to Implement <code>CL_GUI_ALV_GRID<\/code><\/p>\n<h3 data-start=\"182\" data-end=\"223\">1. Create a Screen (e.g., Screen 100)<\/h3>\n<ul>\n<li>\n<p>Go to SE80 \u2192 your program \u2192 create a screen (No. 100).<\/p>\n<\/li>\n<li>\n<p>On the screen, draw a <strong>Custom Control<\/strong> (name it <code>CC_ALV<\/code>).<\/p>\n<\/li>\n<li>\n<p>Add a GUI status (with functions BACK, EXIT, CANCEL).<\/p>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>REPORT z_alv_grid_editable.<\/p>\n<p>************************************************************************<br \/>\n* TYPES &amp; DATA DECLARATIONS<br \/>\n************************************************************************<br \/>\nTYPES: BEGIN OF ty_spfli,<br \/>\ncarrid TYPE spfli-carrid,<br \/>\nconnid TYPE spfli-connid,<br \/>\ncityfrom TYPE spfli-cityfrom,<br \/>\ncityto TYPE spfli-cityto,<br \/>\nEND OF ty_spfli.<\/p>\n<p>DATA: gt_spfli TYPE TABLE OF ty_spfli,<br \/>\ngs_spfli TYPE ty_spfli.<\/p>\n<p>&#8221; ALV references<br \/>\nDATA: go_container TYPE REF TO cl_gui_custom_container,<br \/>\ngo_alv TYPE REF TO cl_gui_alv_grid.<\/p>\n<p>&#8221; Field catalog &amp; layout<br \/>\nDATA: gt_fieldcat TYPE lvc_t_fcat,<br \/>\ngs_fieldcat TYPE lvc_s_fcat,<br \/>\ngs_layout TYPE lvc_s_layo.<\/p>\n<p>************************************************************************<br \/>\n* START-OF-SELECTION<br \/>\n************************************************************************<br \/>\nSTART-OF-SELECTION.<br \/>\n&#8221; Fetch some demo data<br \/>\nSELECT carrid connid cityfrom cityto<br \/>\nFROM spfli<br \/>\nINTO TABLE gt_spfli.<\/p>\n<p>&#8221; Call ALV screen<br \/>\nCALL SCREEN 100.<\/p>\n<p>************************************************************************<br \/>\n* MODULES FOR SCREEN 100<br \/>\n************************************************************************<br \/>\nMODULE status_0100 OUTPUT.<br \/>\nSET PF-STATUS &#8216;MAIN&#8217;. &#8221; Create a status MAIN in GUI status<\/p>\n<p>IF go_container IS INITIAL.<br \/>\n&#8221; Create container linked to CC_ALV on screen<br \/>\nCREATE OBJECT go_container<br \/>\nEXPORTING container_name = &#8216;CC_ALV&#8217;.<\/p>\n<p>&#8221; Create ALV Grid object<br \/>\nCREATE OBJECT go_alv<br \/>\nEXPORTING i_parent = go_container.<\/p>\n<p>&#8221; Layout options<br \/>\ngs_layout-zebra = abap_true. &#8221; striped display<\/p>\n<p>&#8221; Build field catalog<br \/>\nCLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &#8216;CARRID&#8217;.<br \/>\ngs_fieldcat-seltext_m = &#8216;Carrier ID&#8217;.<br \/>\ngs_fieldcat-edit = abap_true. &#8221; Editable<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<\/p>\n<p>CLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &#8216;CONNID&#8217;.<br \/>\ngs_fieldcat-seltext_m = &#8216;Connection ID&#8217;.<br \/>\ngs_fieldcat-edit = abap_true. &#8221; Editable<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<\/p>\n<p>CLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &#8216;CITYFROM&#8217;.<br \/>\ngs_fieldcat-seltext_m = &#8216;From City&#8217;.<br \/>\ngs_fieldcat-edit = abap_true. &#8221; Editable<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<\/p>\n<p>CLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &#8216;CITYTO&#8217;.<br \/>\ngs_fieldcat-seltext_m = &#8216;To City&#8217;.<br \/>\ngs_fieldcat-edit = abap_true. &#8221; Editable<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<\/p>\n<p>&#8221; Display data in ALV<br \/>\nCALL METHOD go_alv-&gt;set_table_for_first_display<br \/>\nEXPORTING<br \/>\nis_layout = gs_layout<br \/>\nCHANGING<br \/>\nit_fieldcatalog = gt_fieldcat<br \/>\nit_outtab = gt_spfli.<br \/>\nENDIF.<br \/>\nENDMODULE.<\/p>\n<p>************************************************************************<br \/>\n* Handle user commands<br \/>\n************************************************************************<br \/>\nMODULE user_command_0100 INPUT.<br \/>\nCASE sy-ucomm.<br \/>\nWHEN &#8216;BACK&#8217; OR &#8216;EXIT&#8217; OR &#8216;CANCEL&#8217;.<br \/>\nLEAVE PROGRAM.<br \/>\nENDCASE.<br \/>\nENDMODULE.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[174],"question_tags":[178,426,168,177],"class_list":["post-7854","question","type-question","status-publish","hentry","question-category-ooabap","question_tags-abap","question_tags-cl_gui_alv_grid","question_tags-ooabap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7854"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7854"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7854"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}