{"id":7508,"date":"2025-08-19T16:33:18","date_gmt":"2025-08-19T11:03:18","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=ways-to-create-a-field-catalog-in-abap"},"modified":"2025-08-19T18:49:52","modified_gmt":"2025-08-19T13:19:52","slug":"ways-to-create-a-field-catalog-in-abap","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=ways-to-create-a-field-catalog-in-abap","title":{"rendered":"Ways to Create a Field Catalog in ABAP"},"content":{"rendered":"<p><strong>Automatically from a Dictionary Structure\/Table<\/strong><\/p>\n<ul>\n<li>The easiest way \u2014 ALV can build the field catalog from the DDIC (Data Dictionary).<\/li>\n<li>You just pass the internal table reference.<\/li>\n<li>ALV uses the metadata (field labels, data type, length) from DDIC.<\/li>\n<\/ul>\n<p>Example:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-css\" data-lang=\"CSS\"><code>CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'\nEXPORTING\ni_structure_name = 'SFLIGHT' \" Dictionary structure\/table\nCHANGING\nct_fieldcat = gt_fieldcat. \" Internal table for field catalog\n<\/code><\/pre>\n<p><strong>Manually by Filling Field Catalog Internal Table<\/strong><\/p>\n<ul>\n<li>You create and fill an internal table of type <code>SLIS_T_FIELDCAT_ALV<\/code> (for REUSE_ALV) or <code>LVC_T_FCAT<\/code> (for OO ALV).<\/li>\n<li>This gives <strong>maximum control<\/strong> (set column text, output length, hotspot, etc.).<\/li>\n<\/ul>\n<p>Example (REUSE_ALV):<\/p>\n<p>DATA: gs_fieldcat TYPE slis_fieldcat_alv,<br \/>\ngt_fieldcat TYPE slis_t_fieldcat_alv.<\/p>\n<p>CLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &#8216;CARRID&#8217;.<br \/>\ngs_fieldcat-seltext_m = &#8216;Airline&#8217;.<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&#8217;.<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<\/p>\n<\/div>\n<p><strong>Using Field Symbols at Runtime (Dynamic Field Catalog)<\/strong><\/p>\n<ul>\n<li>Useful when you don\u2019t know the structure at design time.<\/li>\n<li>You build the field catalog dynamically using field symbols and assign properties programmatically.<\/li>\n<\/ul>\n<h3 data-start=\"1821\" data-end=\"1835\">Example:<\/h3>\n<p>DATA: gt_fieldcat TYPE lvc_t_fcat,<br \/>\ngs_fieldcat TYPE lvc_s_fcat.<\/p>\n<p>LOOP AT gt_dyn_fields ASSIGNING FIELD-SYMBOL(&lt;fs_field&gt;).<br \/>\nCLEAR gs_fieldcat.<br \/>\ngs_fieldcat-fieldname = &lt;fs_field&gt;-fieldname.<br \/>\ngs_fieldcat-coltext = &lt;fs_field&gt;-description.<br \/>\nAPPEND gs_fieldcat TO gt_fieldcat.<br \/>\nENDLOOP.<\/p>\n<p>Useful for <strong>generic ALV reports<\/strong> where table structure is not known until runtime.<\/p>\n<p><strong>Using Class Method <code>CL_GUI_ALV_GRID-&gt;SET_TABLE_FOR_FIRST_DISPLAY<\/code><\/strong><\/p>\n<p>In <strong>OO ALV<\/strong>, if you don\u2019t pass a field catalog, the system can generate it automatically from the internal table\u2019s line type.<\/p>\n<p>CALL METHOD gr_alvgrid-&gt;set_table_for_first_display<br \/>\nEXPORTING<br \/>\ni_structure_name = &#8216;SFLIGHT&#8217;<br \/>\nCHANGING<br \/>\nit_outtab = gt_sflight<br \/>\nit_fieldcatalog = gt_fieldcat.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>If <code>i_structure_name<\/code> is given \u2192 system generates field cataloge.<\/li>\n<li>If not given \u2192 you can pass your own <code>gt_fieldcat<\/code>.<\/li>\n<\/ul>\n<p><strong>Using <code>CL_SALV_TABLE<\/code> (SALV Model)<\/strong><\/p>\n<ul>\n<li>In SALV (Simple ALV), field catalog creation is implicit.<\/li>\n<li>You don\u2019t create it manually \u2014 SALV builds it automatically from the internal table.<\/li>\n<\/ul>\n<p>DATA: gr_table TYPE REF TO cl_salv_table.<\/p>\n<p>cl_salv_table=&gt;factory(<br \/>\nIMPORTING r_salv_table = gr_table<br \/>\nCHANGING t_table = gt_sflight ).<\/p>\n<p>gr_table-&gt;display( ).<\/p>\n<p><strong>Note:<\/strong> SALV is <strong>simpler<\/strong> but less flexible than full OO ALV.<\/p>\n<p>In real projects, most developers use <strong>REUSE_ALV_FIELDCATALOG_MERGE<\/strong> (for standard reports) or <strong>manual field catalog<\/strong> (for custom reports).<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,345,152,155,346,344,213,177],"class_list":["post-7508","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-alv-grid","question_tags-alv-report-with-salv","question_tags-cl_salv_table","question_tags-cl_salv_tablefactory","question_tags-field-catalog","question_tags-reports","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7508","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=7508"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7508"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7508"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}