<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: basic query regarding work-area and select query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204441#M471353</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The standard format of using internal tables is by using the work area..If u provide header line then there is no need for work area..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The header line will be at the top of the internal table itself but it is not like in work area..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ecc 6.0 we only use work area..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 May 2007 11:25:21 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-10T11:25:21Z</dc:date>
    <item>
      <title>basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204434#M471346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi &lt;/P&gt;&lt;P&gt;dear sdn members,&lt;/P&gt;&lt;P&gt;thanks too all for solving all my query's up till now &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am stuck in a problem need help &lt;/P&gt;&lt;P&gt;1)  why basically work-area has been used ? the sole purpose&lt;/P&gt;&lt;P&gt;2)  different types of select query ? only coding examples &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note: no links pls &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;virus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:11:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204434#M471346</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-08T06:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204435#M471347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While adding or retrieving records to / from internal table we have to keep the record temporarily. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The area where this record is kept is called as work area for the internal table.  The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look at the below link&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm" target="test_blank"&gt;http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt; Sudheer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:16:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204435#M471347</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-08T06:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204436#M471348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Virus , &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use a query&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT &lt;/P&gt;&lt;P&gt;WHERE SEATSOCC &amp;lt; F~SEATSMAX &lt;/P&gt;&lt;P&gt;AND EXISTS ( SELECT * FROM SPFLI &lt;/P&gt;&lt;P&gt;WHERE CARRID = F~CARRID &lt;/P&gt;&lt;P&gt;AND CONNID = F~CONNID &lt;/P&gt;&lt;P&gt;AND CITYFROM = 'FRANKFURT' &lt;/P&gt;&lt;P&gt;AND CITYTO = 'NEW YORK' ) &lt;/P&gt;&lt;P&gt;AND FLDATE BETWEEN '19990101' AND '19990331'. &lt;/P&gt;&lt;P&gt;WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID, &lt;/P&gt;&lt;P&gt;WA_SFLIGHT-FLDATE. &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or simply query the first table and then the second table with select endselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from table a.&lt;/P&gt;&lt;P&gt;select * from table b into output_table&lt;/P&gt;&lt;P&gt;where b-field1 eq a-field2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or read the data into one internal table loop at it and then query the other table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INTERNAL Table and it's background:&lt;/P&gt;&lt;P&gt;===================================&lt;/P&gt;&lt;P&gt;Internal table acts as a container which is used to store the record sets. That is used to store the data fetched from the database table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So due to performance reason every time access to database would not be so good and decrease the performance. So you just select the data from the database and store it in the intermediate table. This table is called INTERNAL TABLE. So it's an replica of the database. The design foes like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PRESENTATION SERVER &amp;lt;&lt;DEL&gt;&amp;gt; APPLICATION SERVER &amp;lt;&lt;/DEL&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;DATABASE SERVER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So everytime gain accessing to database results in high resource usage and bad permformance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So always play around with internal tables. So obviously the whenever you access the data in the INTERNAL TABLE, the application server will be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WORK AREA:&lt;/P&gt;&lt;P&gt;==========&lt;/P&gt;&lt;P&gt;When ever you loop at the internal table, the current record should be stored in a temporary work place. That is called WORK AREA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB INTO WORKAREA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ITAB :An internal table&lt;/P&gt;&lt;P&gt;WORKAREA:An instance of internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;Reward Points if helpful..&amp;lt;/i&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;Amber S&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:21:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204436#M471348</guid>
      <dc:creator>former_member198270</dc:creator>
      <dc:date>2007-05-08T06:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204437#M471349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;      Wok area is used for temp storage of data.&lt;/P&gt;&lt;P&gt;If ur internal table is defined without header line then we  require work area to deal with internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_mara into wa_mara.&lt;/P&gt;&lt;P&gt;write: wa_mara-matnr.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Write select in ur report . press F1 u will get all select ststement queries.&lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hemant&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hemant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:22:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204437#M471349</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-08T06:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204438#M471350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;Work Area &lt;/P&gt;&lt;P&gt;Description for a data object that is particularly useful when working with internal tables or database tables as a source for changing operations or a target for reading operations. &lt;/P&gt;&lt;P&gt;WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.&lt;/P&gt;&lt;P&gt;Each row in a table is a record and each column is a field.&lt;/P&gt;&lt;P&gt;While adding or retrieving records to / from internal table we have to keep the record temporarily. &lt;/P&gt;&lt;P&gt;The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not. &lt;/P&gt;&lt;P&gt;.g.&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 10,&lt;/P&gt;&lt;P&gt;ab type c,&lt;/P&gt;&lt;P&gt;cd type i,&lt;/P&gt;&lt;P&gt;end of itab. " this table will have the header line.&lt;/P&gt;&lt;P&gt;data: wa_itab like itab. " explicit work area for itab&lt;/P&gt;&lt;P&gt;data: itab1 like itab occurs 10. " table is without header line. &lt;/P&gt;&lt;P&gt;The header line is a field string with the same structure as a row of the body, but it can only hold a single row.&lt;/P&gt;&lt;P&gt;It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table. &lt;/P&gt;&lt;P&gt;With header line&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT.&lt;/P&gt;&lt;P&gt;Put the curson on that word and press F1 . You can see the whole documentation for select statements.&lt;/P&gt;&lt;P&gt;select statements :&lt;/P&gt;&lt;P&gt;SELECT result &lt;/P&gt;&lt;P&gt;FROM source &lt;/P&gt;&lt;P&gt;INTO|APPENDING target &lt;/P&gt;&lt;P&gt;[[FOR ALL ENTRIES IN itab] WHERE sql_cond] &lt;/P&gt;&lt;P&gt;&lt;A href="GROUP BY group"&gt;&lt;/A&gt; &lt;A href="HAVING group_cond"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="ORDER BY sort_key"&gt;&lt;/A&gt;. &lt;/P&gt;&lt;P&gt;... &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/ENDSELECT"&gt;&lt;/A&gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions. &lt;/P&gt;&lt;P&gt;System Fields &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt. &lt;/P&gt;&lt;P&gt;sy-subrc Relevance &lt;/P&gt;&lt;P&gt;0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop. &lt;/P&gt;&lt;P&gt;4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database. &lt;/P&gt;&lt;P&gt;8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE. &lt;/P&gt;&lt;P&gt;After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0. &lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close. &lt;/P&gt;&lt;P&gt;SELECT - result &lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;... lines columns ... . &lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data in result consists of data for the rows lines and for the columns columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT - lines &lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;... { SINGLE &lt;A href="FOR UPDATE"&gt;&lt;/A&gt; } &lt;/P&gt;&lt;P&gt;| { &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; { } } ... . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatives: &lt;/P&gt;&lt;P&gt;1. ... SINGLE &lt;A href="FOR UPDATE"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. ... &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; { } &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;The data in lines specifies that the resulting set has either multiple lines or a single line. &lt;/P&gt;&lt;P&gt;Alternative 1 &lt;/P&gt;&lt;P&gt;... SINGLE &lt;A href="FOR UPDATE"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternative 2 &lt;/P&gt;&lt;P&gt;... &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; { } &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the system tries to access pool or cluster tables and single columns are specified in columns. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.&lt;/P&gt;&lt;P&gt;SELECT - columns &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;... * &lt;/P&gt;&lt;P&gt;| { {col1|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col1 )} &lt;A href="AS a1"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;{col2|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col2 )} &lt;A href="AS a2"&gt;&lt;/A&gt; ... } &lt;/P&gt;&lt;P&gt;| (column_syntax) ... . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatives: &lt;/P&gt;&lt;P&gt;1. ... * &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. ... {col1|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col1 )} &lt;A href="AS a1"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;{col2|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col2 )} &lt;A href="AS a2"&gt;&lt;/A&gt; ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. ... (column_syntax) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;The input in columns determines which columns are used to build the resulting set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternative 1 &lt;/P&gt;&lt;P&gt;... * &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternative 2 &lt;/P&gt;&lt;P&gt;... {col1|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col1 )} &lt;A href="AS a1"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;{col2|aggregate( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col2 )} &lt;A href="AS a2"&gt;&lt;/A&gt; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Column labels &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following column labels are possible: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If only a single database table or a single view is specified after FROM, the column labels in the database table - that is, the names of the components comp1 comp2... - can be specified directly for col1 col2 ... in the structure of the ABAP Dictionary. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the name of the component occurs in multiple database tables of the FROM addition, but the desired database table or the view dbtab is only specified once after FROM, the names dbtab~comp1 dbtab~comp2 ... have to be specified for col1 col2 .... comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the desired database table or view occurs multiple times after FROM, the names tabalias~comp1 tabalias~comp2 ... have to be specified for col1 col2 .... tabalias is the alternative table name of the database table or view defined after FROM, and comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data type of a single column in the resulting list is the datatype of the corresponding component in the ABAP Dictionary. The corresponding data object after INTO or APPENDING has to be selected accordingly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;If multiple database tables are specified after FROM, you can use alternative names when specifying single columns to avoid having multiple columns with the same name. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Read specific columns of a single row. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA wa TYPE spfli. &lt;/P&gt;&lt;P&gt;SELECT SINGLE carrid connid cityfrom cityto &lt;/P&gt;&lt;P&gt;INTO CORRESPONDING FIELDS OF wa &lt;/P&gt;&lt;P&gt;FROM spfli &lt;/P&gt;&lt;P&gt;WHERE carrid EQ 'LH' AND connid EQ '0400'. &lt;/P&gt;&lt;P&gt;IF sy-subrc EQ 0. &lt;/P&gt;&lt;P&gt;WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto. &lt;/P&gt;&lt;P&gt;ENDIF. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternative 3 &lt;/P&gt;&lt;P&gt;... (column_syntax) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;Instead of static data, a data object column_syntax in brackets can be specified, which, when the command is executed, either contains the syntax shown with the static data, or is initial. The data object column_syntax can be a character-type data object or an internal table with a character-type data type. The syntax in column_syntax, like in the ABAP editor, is not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If column_syntax is initial when the command is executed, columns is implicitly set to * and all columns are read. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If columns are specificied dynamically without the SINGLE addition, the resulting set is always regarded as having multiple rows. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;Before Release 6.10, you could only specify an internal table with a flat character-type row type for column_syntax with a maximum of 72 characters. Also, before Release 6.10, if you used the DISTINCT addition for dynamic access to pool tables or cluster tables, this was ignored, but since release 6.10, this causes a known exception. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If column_syntax is an internal table with header line, the table body and not the header line is evaluated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM my_select USING `CITYFROM`. &lt;/P&gt;&lt;P&gt;ULINE. &lt;/P&gt;&lt;P&gt;PERFORM my_select USING `CITYTO`. &lt;/P&gt;&lt;P&gt;FORM my_select USING l_group TYPE string. &lt;/P&gt;&lt;P&gt;DATA: l_columns TYPE TABLE OF string, &lt;/P&gt;&lt;P&gt;l_container TYPE string, &lt;/P&gt;&lt;P&gt;l_count TYPE i. &lt;/P&gt;&lt;P&gt;APPEND l_group TO l_columns. &lt;/P&gt;&lt;P&gt;APPEND `count( * )` TO l_columns. &lt;/P&gt;&lt;P&gt;SELECT (l_columns) &lt;/P&gt;&lt;P&gt;FROM spfli &lt;/P&gt;&lt;P&gt;INTO (l_container, l_count) &lt;/P&gt;&lt;P&gt;GROUP BY (l_group). &lt;/P&gt;&lt;P&gt;WRITE: / l_count, l_container. &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;ENDFORM. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT - aggregate &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;... { MAX( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) &lt;/P&gt;&lt;P&gt;| MIN( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) &lt;/P&gt;&lt;P&gt;| AVG( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) &lt;/P&gt;&lt;P&gt;| SUM( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) &lt;/P&gt;&lt;P&gt;| COUNT( DISTINCT col ) &lt;/P&gt;&lt;P&gt;| COUNT( * ) &lt;/P&gt;&lt;P&gt;| count(*) } ... . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation): &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MAX( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) Determines the maximum value of the value in the column col in the resulting set or in the current group. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MIN( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) Determines the minimum value of the content of the column col in the resulting set or in the current group. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AVG( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SUM( &lt;A href="https://community.sap.com/DISTINCT"&gt;&lt;/A&gt; col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note the following points when using aggregate expressions: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the addition FOR ALL ENTRIES is used in front of WHERE, or if cluster or pool tables are listed after FROM, no other aggregate expressions apart from COUNT( * ) can be used. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Columns of the type STRING or RAWSTRING cannot be used with aggregate functions. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When aggregate expressions are used, the SELECT command makes it unnecessary to use SAP buffering. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Null values are not included in the calculation for the aggregate functions. The result is a null value only if all the rows in the column in question contain the null value. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If only aggregate expressions are used after SELECT, the results set has one row and the addition GROUP BY is not necessary. If a non-table type target area is specified after INTO, the command ENDSELECT cannot be used together with the addition SINGLE. If the aggregate expression count( * ) is not being used, an internal table can be specified after INTO, and the first row of this table is filled. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If aggregate functions are used without GROUP BY being specified at the same time, the resulting set also contains a row if no data is found in the database. If count( * ) is used, the column in question contains the value 0. The columns in the other aggregate functions contain initial values. This row is assigned to the data object specified after INTO, and unless count( * ) is being used exclusively, sy-subrc is set to 0 and sy-dbcnt is set to 1. If count( *) is used exclusively, the addition INTO can be omitted and if no data can be found in the database, sy-subrc is set to 4 and sy-dbcnt is set to 0.&lt;/P&gt;&lt;P&gt;if helpful reward points&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:25:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204438#M471350</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-08T06:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204439#M471351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; workarea is used to load data into internal table.and also it should have the same structure as that of internal table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let us consider an example where in &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.internal table with header line.&lt;/P&gt;&lt;P&gt;in this default work area will be created.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab : means it is looping at default work area.&lt;/P&gt;&lt;P&gt;itab[] means internal table.&lt;/P&gt;&lt;P&gt;so we are loading data from itab(work area) to itab[].&lt;/P&gt;&lt;P&gt;and then we will clear the work area.&lt;/P&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;internal table with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : begin of itab_mara,&lt;/P&gt;&lt;P&gt;           matnr like mara-matnr,&lt;/P&gt;&lt;P&gt;           enum like mara-enum,&lt;/P&gt;&lt;P&gt;           end of itab_mara.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : begin of itab_marc,&lt;/P&gt;&lt;P&gt;           matnr like marc-matnr,&lt;/P&gt;&lt;P&gt;           werks like marc-werks,&lt;/P&gt;&lt;P&gt;          end of itab_marc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : begin of itab_final,&lt;/P&gt;&lt;P&gt;         matnr like mara-matnr,&lt;/P&gt;&lt;P&gt;         enum like mara-enum,&lt;/P&gt;&lt;P&gt;        werks like marc-werks.&lt;/P&gt;&lt;P&gt;        end of itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;selection-screen : begin of block blk1 with frame title text-001.&lt;/P&gt;&lt;P&gt;    select-options : s_matnr for mara-matnr,&lt;/P&gt;&lt;P&gt;                            s_werks for marc-werks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;selection-screen : end of block blk1.&lt;/P&gt;&lt;P&gt;there are mainly four types of select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. select * from table itab_mara  where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;   *selecting all fields from mara.&lt;/P&gt;&lt;P&gt;2.select matnr  from  table itab_mara where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;   *selecting only material number fro mara table.&lt;/P&gt;&lt;P&gt;3.select single * from table itab_mara where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;selecting single field.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;4. select upto one row from table itab_mara where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;selecting only one row in the mara table.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. internal table without header line.&lt;/P&gt;&lt;P&gt;in this there is no default work area so we need to create workarea which has a similar structure as internal table.&lt;/P&gt;&lt;P&gt;loop at itab into wa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward with points if helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2007 06:34:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204439#M471351</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-08T06:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204440#M471352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;with the help of forum&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 10:17:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204440#M471352</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T10:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: basic query regarding work-area and select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204441#M471353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The standard format of using internal tables is by using the work area..If u provide header line then there is no need for work area..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The header line will be at the top of the internal table itself but it is not like in work area..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ecc 6.0 we only use work area..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 11:25:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-query-regarding-work-area-and-select-query/m-p/2204441#M471353</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T11:25:21Z</dc:date>
    </item>
  </channel>
</rss>

