<?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: extracting only one record in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948492#M64734</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Taken from F1 help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;AT - Control breaks with extracts&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variants: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. AT NEW f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. AT END OF f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. AT FIRST. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. AT LAST.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. AT fg.&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;In a LOOP which processes a dataset created with EXTRACT, you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT. The sequence of statements which lies between is executed whenever a control break occurs. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use these key words for control break processing with extract datasets only if the active LOOP statement is processing an extract dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the end of a control group ( AT END OF, AT LAST), there are two types of control level information between AT and ENDAT: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER), the field CNT(h) contains the number of control breaks in the (subordinate) control level h. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For extracted number fields g (see also ABAP Number Types), the fields SUM(g) contain the relevant control totals. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF, AT LAST), not at the beginning (AT FIRST, AT NEW). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When calculating totals with SUM(g), the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use special control break control structures with LOOPs on internal tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 1 &lt;/P&gt;&lt;P&gt;AT NEW f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 2 &lt;/P&gt;&lt;P&gt;AT END OF f. &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;f is a field from the field group HEADER. The enclosed sequence of statements is executed if &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER) and &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the field f or a superior sort criterion has a different value in the current LOOP line than in the preceding (AT NEW) or subsequent (AT END OF) record of the extract dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If f is not an assigned field symbol, the control break criterion is ignored, and the subsequent sequence of statements is not executed. If a field symbol is assigned, but does not point to the HEADER field group, the system triggers a runtime error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;DATA: NAME(30), &lt;/P&gt;&lt;P&gt;      SALES TYPE I. &lt;/P&gt;&lt;P&gt;FIELD-GROUPS: HEADER, INFOS. &lt;/P&gt;&lt;P&gt;INSERT: NAME  INTO HEADER, &lt;/P&gt;&lt;P&gt;        SALES INTO INFOS. &lt;/P&gt;&lt;P&gt;... &lt;/P&gt;&lt;P&gt;LOOP. &lt;/P&gt;&lt;P&gt;  AT NEW NAME. &lt;/P&gt;&lt;P&gt;    NEW-PAGE. &lt;/P&gt;&lt;P&gt;  ENDAT. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  AT END OF NAME. &lt;/P&gt;&lt;P&gt;    WRITE: / NAME, SUM(SALES). &lt;/P&gt;&lt;P&gt;  ENDAT. &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;If the extract dataset is not sorted before processing with LOOP, no control level structure is defined and the statements following AT NEW or AT END OF are not executed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF. This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 3 &lt;/P&gt;&lt;P&gt;AT FIRST. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 4 &lt;/P&gt;&lt;P&gt;AT LAST. &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;Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST) or on the last loop pass (with AT LAST). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 5 &lt;/P&gt;&lt;P&gt;AT fg. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition: &lt;/P&gt;&lt;P&gt;... WITH fg1 &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;This statement makes single record processing dependent on the type of extracted record. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition &lt;/P&gt;&lt;P&gt;... WITH fg1 &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;Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additional help &lt;/P&gt;&lt;P&gt;Control Level Processing &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/i&amp;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;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jul 2005 17:47:54 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2005-07-07T17:47:54Z</dc:date>
    <item>
      <title>extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948484#M64726</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;I am using the Field Catalog to display the contents of my internal table. One of the entries being displayed is the payment date. I just want to display only entries corresponding to the last payment date. Should I make another internal table and move the entries which I require to the new table or is there a way by which I can display only entires I require in my first internal table with the given constraint?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know its a bit confusing but I can post my source code if you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gaurav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 16:20:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948484#M64726</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-07-07T16:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948485#M64727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would probably move the records to a new internal table.  You may want to use a the AT END OF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say that you have an internal table with the vendor and the payment date.  Sort the internal table by vendor and payment date.  Now loop at the internal table and when the last record for a specific vendor is read, move that record to another internal table.  Use the second internal table to show in ALV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a short sample.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0004 .


data: begin of itab occurs 0,
      lifnr type lfa1-lifnr,
      pydat type sy-datum,
      end of itab.

data: begin of itab2 occurs 0,
      lifnr type lfa1-lifnr,
      pydat type sy-datum,
      end of itab2.

data: wa like line of itab.

itab-lifnr = '1'.
itab-pydat = '20050709'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050708'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050707'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050712'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050711'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050710'.
append itab.


sort itab ascending by lifnr pydat.

loop at itab.
  wa = itab.
  at end of lifnr.
    move-corresponding wa to itab2.
    append itab2.
  endat.
endloop.


loop at itab2.
  write:/ itab2-lifnr, itab2-pydat.
endloop.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 16:31:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948485#M64727</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-07-07T16:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948486#M64728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gaurav,&lt;/P&gt;&lt;P&gt;it's pretty difficult for me to understand your question when you say "I am using the Field Catalog to display the contents of my internal table". I assume you are using ABAP List Viewer (ALV).&lt;/P&gt;&lt;P&gt;If so, and if you're using ALV based on function modules, there is an import parameter named IT_FILTER, which contains data to be filtered. Although the documentation on this parameter explicitly says "This table should never be built-up 'manually'", you may write your own test programs with this issue, at your own risk   &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps. BR,&lt;/P&gt;&lt;P&gt;Alvaro&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 16:38:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948486#M64728</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-07-07T16:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948487#M64729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alvaro,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have heard about the IT_FILTER but I am not familiar with the syntax and how it works. I will stick with the new internal table suggestion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gaurav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:12:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948487#M64729</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-07-07T17:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948488#M64730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your question has been answered please close the post and award points accordingly.  Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:21:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948488#M64730</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-07-07T17:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948489#M64731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have sorted the table in desecding order. So I have all the records arranged in descending order of payment date. So the structure of my table look like this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         10   03/04 ...&lt;/P&gt;&lt;P&gt;         11   03/04 ...&lt;/P&gt;&lt;P&gt;         12   03/04 ...&lt;/P&gt;&lt;P&gt;         13   02/04 ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I have to move the above records having different identification number to new table for the last date that is 03/04 in this case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am bit confused about how to use AT END OF statement. Can you please explain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gaurav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:31:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948489#M64731</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-07-07T17:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948490#M64732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you have sorting your table in descending order, then you will want to get the FIRST record of the sequence instead of the LAST.  The AT END OF statement would work for you if you table had been sorted in ASCENDING order.  You can use the AT NEW statement to get the first record of the sequence.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:44:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948490#M64732</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-07-07T17:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948491#M64733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check the changes to the sample program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


report zrich_0004 .


data: begin of itab occurs 0,
      lifnr type lfa1-lifnr,
      pydat type sy-datum,
      end of itab.

data: begin of itab2 occurs 0,
      lifnr type lfa1-lifnr,
      pydat type sy-datum,
      end of itab2.

data: wa like line of itab.

itab-lifnr = '1'.
itab-pydat = '20050709'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050708'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050707'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050712'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050711'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050710'.
append itab.


&amp;lt;b&amp;gt;sort itab by lifnr ascending
             pydat descending.&amp;lt;/b&amp;gt;

loop at itab.
  wa = itab.
&amp;lt;b&amp;gt;at new lifnr.&amp;lt;/b&amp;gt;
    move-corresponding wa to itab2.
    append itab2.
  endat.
endloop.


loop at itab2.
  write:/ itab2-lifnr, itab2-pydat.
endloop.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:46:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948491#M64733</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-07-07T17:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948492#M64734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Taken from F1 help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;AT - Control breaks with extracts&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variants: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. AT NEW f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. AT END OF f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. AT FIRST. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. AT LAST.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. AT fg.&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;In a LOOP which processes a dataset created with EXTRACT, you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT. The sequence of statements which lies between is executed whenever a control break occurs. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use these key words for control break processing with extract datasets only if the active LOOP statement is processing an extract dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the end of a control group ( AT END OF, AT LAST), there are two types of control level information between AT and ENDAT: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER), the field CNT(h) contains the number of control breaks in the (subordinate) control level h. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For extracted number fields g (see also ABAP Number Types), the fields SUM(g) contain the relevant control totals. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF, AT LAST), not at the beginning (AT FIRST, AT NEW). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When calculating totals with SUM(g), the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use special control break control structures with LOOPs on internal tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 1 &lt;/P&gt;&lt;P&gt;AT NEW f. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 2 &lt;/P&gt;&lt;P&gt;AT END OF f. &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;f is a field from the field group HEADER. The enclosed sequence of statements is executed if &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER) and &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the field f or a superior sort criterion has a different value in the current LOOP line than in the preceding (AT NEW) or subsequent (AT END OF) record of the extract dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If f is not an assigned field symbol, the control break criterion is ignored, and the subsequent sequence of statements is not executed. If a field symbol is assigned, but does not point to the HEADER field group, the system triggers a runtime error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;DATA: NAME(30), &lt;/P&gt;&lt;P&gt;      SALES TYPE I. &lt;/P&gt;&lt;P&gt;FIELD-GROUPS: HEADER, INFOS. &lt;/P&gt;&lt;P&gt;INSERT: NAME  INTO HEADER, &lt;/P&gt;&lt;P&gt;        SALES INTO INFOS. &lt;/P&gt;&lt;P&gt;... &lt;/P&gt;&lt;P&gt;LOOP. &lt;/P&gt;&lt;P&gt;  AT NEW NAME. &lt;/P&gt;&lt;P&gt;    NEW-PAGE. &lt;/P&gt;&lt;P&gt;  ENDAT. &lt;/P&gt;&lt;P&gt;  ... &lt;/P&gt;&lt;P&gt;  AT END OF NAME. &lt;/P&gt;&lt;P&gt;    WRITE: / NAME, SUM(SALES). &lt;/P&gt;&lt;P&gt;  ENDAT. &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes &lt;/P&gt;&lt;P&gt;If the extract dataset is not sorted before processing with LOOP, no control level structure is defined and the statements following AT NEW or AT END OF are not executed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF. This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 3 &lt;/P&gt;&lt;P&gt;AT FIRST. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 4 &lt;/P&gt;&lt;P&gt;AT LAST. &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;Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST) or on the last loop pass (with AT LAST). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 5 &lt;/P&gt;&lt;P&gt;AT fg. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition: &lt;/P&gt;&lt;P&gt;... WITH fg1 &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;This statement makes single record processing dependent on the type of extracted record. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition &lt;/P&gt;&lt;P&gt;... WITH fg1 &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;Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additional help &lt;/P&gt;&lt;P&gt;Control Level Processing &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/i&amp;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;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 17:47:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948492#M64734</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-07-07T17:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: extracting only one record</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948493#M64735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot. Its working fine now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gaurav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2005 19:04:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-only-one-record/m-p/948493#M64735</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-07-07T19:04:02Z</dc:date>
    </item>
  </channel>
</rss>

