<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SAP Training, Tutorials, How-tos, News, Weblogs, Screencasts, SAP Jobs, Forums and much more, all on SAP &#187; Dynamic Tables</title>
	<atom:link href="http://saplab.org/tag/dynamic-tables/feed/" rel="self" type="application/rss+xml" />
	<link>http://saplab.org</link>
	<description>SAP Training, Tutorials, How-tos, News, Weblogs, Screencasts, SAP Jobs, Forums and much more, all on SAP</description>
	<lastBuildDate>Mon, 16 Jan 2012 12:19:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>One Minute, One Great ABAP Tip</title>
		<link>http://saplab.org/2009/10/one-minute-one-great-abap-tip/</link>
		<comments>http://saplab.org/2009/10/one-minute-one-great-abap-tip/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 14:27:57 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[ABAP]]></category>
		<category><![CDATA[Great SAP Tips]]></category>
		<category><![CDATA[Dynamic Tables]]></category>

		<guid isPermaLink="false">http://saplab.org/?p=973</guid>
		<description><![CDATA[This is my first post for SAPLAB.org, so I&#8217;ve decided to write about something really simple yet powerful &#8211; building ABAP Dynamic Tables using RTTS ( From Release 6.40). RTTS stands for Run Time Type Services. Creating dynamic internal tables in ABAP programs can be very useful, dynamic coding can provide fast program running and [...]
Related posts:<ol>
<li><a href='http://saplab.org/2009/03/alv-report-sample/' rel='bookmark' title='ALV Report Sample'>ALV Report Sample</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_jade" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fsaplab.org%252F2009%252F10%252Fone-minute-one-great-abap-tip%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22One%20Minute%2C%20One%20Great%20ABAP%20Tip%22%20%7D);"></div>
<p>This is my first post for SAPLAB.org, so I&#8217;ve decided to write about something really simple yet powerful &#8211; building ABAP Dynamic Tables using RTTS ( From Release 6.40). RTTS stands for <strong>Run Time Type Services</strong>.</p>
<p>Creating dynamic internal tables in ABAP programs can be very useful, dynamic coding can provide fast program running and easier maintenance. From release 6.40, RTTS has provided a new approach to dynamic table programming. Here’s an example of what I mean:</p>
<pre lang="abap">
REPORT Z_1MIN_1GREATTIP_RTTS.

TABLES PA0002.

* Table type
TYPES: BEGIN OF TY_PERNR_LIST,
         PERNR TYPE PERNR_D,
         BEGDA TYPE BEGDA,
         ENDDA TYPE ENDDA,
       END   OF TY_PERNR_LIST.

* Dynamic Table
DATA: LO_STRUCTDESCR   TYPE REF TO CL_ABAP_STRUCTDESCR,
      LO_ELEMDESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      LO_STRUCTDESCR_NEW TYPE REF TO CL_ABAP_STRUCTDESCR,
      LO_TABLEDESCR  TYPE REF TO CL_ABAP_TABLEDESCR,
      LO_DATA     TYPE REF TO DATA,
      LT_COMPONENT     TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
      LT_TOT_COMPONENT TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
      LA_COMPONENT     LIKE LINE OF LT_COMPONENT.

* Dynamic Selection fields
TYPES: BEGIN OF TY_FIELDCATALOG,
         FIELDNAME TYPE CHAR30,
       END   OF TY_FIELDCATALOG.
*
DATA:  LT_FIELDCATALOG TYPE STANDARD TABLE OF TY_FIELDCATALOG,
       LA_FIELDCATALOG TYPE TY_FIELDCATALOG.

* field symbols to access the dynamic table
FIELD-SYMBOLS: <FS_TAB>   TYPE ANY TABLE,
               <FS_LINE>  TYPE ANY,
               <FS_FIELD> TYPE ANY.
*
* Selection Screen
SELECT-OPTIONS: SO_PERNR FOR PA0002-PERNR.

START-OF-SELECTION.

* 1- Getting Components of type
  LO_STRUCTDESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'TY_PERNR_LIST' ).
  LT_COMPONENT  = LO_STRUCTDESCR->GET_COMPONENTS( ).
  APPEND LINES OF LT_COMPONENT TO LT_TOT_COMPONENT.

*   Element Description Last Name
  LO_ELEMDESCR ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( 'PAD_NACHN' ).
*
*   Field name
  LA_COMPONENT-NAME = 'NACHN'.
*
*   Field type
  LA_COMPONENT-TYPE = CL_ABAP_ELEMDESCR=>GET_C(
                    P_LENGTH   = LO_ELEMDESCR->LENGTH ).
*
*   Filling the component table
  APPEND LA_COMPONENT TO LT_TOT_COMPONENT.
  CLEAR: LA_COMPONENT.

*   Element Description First Name
  LO_ELEMDESCR ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( 'PAD_VORNA' ).
*
*   Field name
  LA_COMPONENT-NAME = 'VORNA'.
*
*   Field type
  LA_COMPONENT-TYPE = CL_ABAP_ELEMDESCR=>GET_C(
                     P_LENGTH   = LO_ELEMDESCR->LENGTH ).
*
*   Filling the component table
  APPEND LA_COMPONENT TO LT_TOT_COMPONENT.
  CLEAR: LA_COMPONENT.

*
* 3. Create a New Type
  LO_STRUCTDESCR_NEW = CL_ABAP_STRUCTDESCR=>CREATE( LT_TOT_COMPONENT ).
*
* 4. New Table type
  LO_TABLEDESCR = CL_ABAP_TABLEDESCR=>CREATE(
                  P_LINE_TYPE  = LO_STRUCTDESCR_NEW
                  P_TABLE_KIND = CL_ABAP_TABLEDESCR=>TABLEKIND_STD
                  P_UNIQUE     = ABAP_FALSE ).
*
* 5. data to handle the new table type
  CREATE DATA LO_DATA TYPE HANDLE LO_TABLEDESCR.
*
* 6. New internal table in the fieldsymbols
  ASSIGN LO_DATA->* TO <FS_TAB>.
*
*$*$*...............Dynamic Selection.............................*$*$*
* Filling up the table for the Selection fields of Select Query
  LOOP AT LT_TOT_COMPONENT INTO LA_COMPONENT.
    LA_FIELDCATALOG-FIELDNAME = LA_COMPONENT-NAME.
    APPEND LA_FIELDCATALOG TO LT_FIELDCATALOG.
    CLEAR: LA_COMPONENT, LA_FIELDCATALOG.
  ENDLOOP.
*
* Selecting data
  SELECT (LT_FIELDCATALOG)
         INTO  TABLE <FS_TAB>
         FROM  PA0002
         UP TO 10 ROWS
         WHERE PERNR IN SO_PERNR.
*
*$*$*...............Accessing dynamic table.......................*$*$*
  LOOP AT <FS_TAB> ASSIGNING <FS_LINE>.
    ASSIGN COMPONENT 'VORNA' OF STRUCTURE <FS_LINE> TO <FS_FIELD>.
    CONCATENATE 'Mr.' <FS_FIELD> INTO <FS_FIELD> SEPARATED BY SPACE.
  ENDLOOP.
*
*
*$*$*...............Displaying using SALV model...................*$*$*
*
  DATA: LO_ALV TYPE REF TO CL_SALV_TABLE.
*
  TRY.
      CL_SALV_TABLE=>FACTORY(
        EXPORTING
          LIST_DISPLAY = ABAP_FALSE
        IMPORTING
          R_SALV_TABLE = LO_ALV
        CHANGING
          T_TABLE      = <FS_TAB> ).
    CATCH CX_SALV_MSG .
  ENDTRY.
*
  LO_ALV->DISPLAY( ).
</pre>
<p>This is a good and quick way to create a dynamic <a title="ALV Sample Report" href="http://saplab.org/2009/03/alv-report-sample/">ALV report</a> in just a few lines of code. Please be sure to read up next on &#8220;1 minute &#8211; 1 Great Tip&#8221;: <em>ECC6 Enhancement Framework in 100 lines</em>.</p>
<p><strong><em>About the author</em></strong></p>
<p><img src="http://en.gravatar.com/userimage/7650615/451b534d28fc8e08f85c5cd93c7126ba.jpeg" alt="" width="50" height="50" align="left" />Helder Goncalves (hfgoncalves) has been working with ABAP development for more than 9 years, covering all major modules, releases and technologies. <a href="http://saplab.org/about/#hfgoncalves" title="About SAPLAB - Helder Gonçalves">Click here</a> to view Helder&#8217;s full profile.</p>

<p>Related posts:<ol>
<li><a href='http://saplab.org/2009/03/alv-report-sample/' rel='bookmark' title='ALV Report Sample'>ALV Report Sample</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://saplab.org/2009/10/one-minute-one-great-abap-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

