Skip to Content
author's profile photo Former Member
Former Member

Using at last

i want to using at last to trigger the last record, but it can't work, my source like this,

loop at itab1.

loop at itab2 where vbeln = itab1-vbeln and vbelp=itab1-vbelp.

....................

at last.

do somethings.

endat.

endloop.

endloop.

Is the code correct?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2007 at 09:49 AM

    Hi,

    Before ENDAT use EX I T as under:

    loop at itab1.

    loop at itab2 where vbeln = itab1-vbeln and vbelp=itab1-vbelp.

    ....................

    at last.

    do somethings.

    <b>exit.</b>

    endat.

    endloop.

    endloop.

    Hope this helps.

    Reward if helpful.

    Regards,

    Sipra

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 18, 2007 at 09:52 AM

    AT LAST will not work in this case... instead try this logic

    data tabix type syst-tabix .

    loop at itab1. 
    clear tabix.
    loop at itab2 where vbeln = itab1-vbeln and vbelp=itab1-vbelp.
    tabix = sy-tabix .
    ....................
    endloop.
    if not tabix is initial.
       read table itab2 index tabix .
       do somethings.
    endif.
    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2007 at 09:55 AM

    hi port,

    its correct but how can we know ur requirement......

    ok. read this....

    <b>Using the at last Statements</b>

    Use the at last statements to perform processing during the last loop pass of an internal table.

    Syntax for the at last Statements:

    The following is the syntax for the at first and at last statements.

    loop at it.

    ---

    at last.

    ---

    endat.

    ---

    endloop.

    where:

    it is an internal table.

    --- represents any number of lines of code (even zero).

    The following points apply:

    These statements can only be used within loop at; they cannot be used within select.

    at first does not have to come before at last. The order of these statements can be interchanged.

    The last time through the loop, the lines of code between at last and endat are executed. If there are multiple occurrences of at last, they are all executed.

    <b>An example Code:</b>

    -


    1 report ztx1307.

    2 tables ztxlfc3.

    3 data it like ztxlfc3 occurs 25 with header line.

    4 select * from ztxlfc3 into table it where shbkz = 'Z'.

    5 loop at it.

    6 at first.

    7 write: / 'Vendor',

    8 12 'Cpny',

    9 17 'Year',

    10 22 'Bal C/F'.

    11 uline.

    12 endat.

    13 write: / it-lifnr,

    14 12 it-bukrs,

    15 17 it-gjahr,

    16 22 it-saldv.

    17 at last.

    18 write: / '----


    ',

    19 12 '----',

    20 17 '----',

    21 22 '----


    '.

    22 endat.

    23 endloop.

    24 free it.

    <b>Use at last for:</b>

    1)Loop termination processing

    2)Writing totals at the bottom of a report

    3)Writing footings

    Between the at last and endat, the component values of the work area row will not contain any data. The default key fields are filled with * (asterisks) and the numeric fields are set to zeros. The endat restores the contents to the values they had prior to entering the at. Changes to the work area within at and endat are lost.

    Reward me if useful,

    Harimanjesh AN

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2007 at 09:59 AM

    hi,

    at last ....endat is for to do some operations like sum and display the sum of

    all the records numc & curr field values while the last record is

    getting trigger.

    Your query is to access the last record

    this you can achieve like this

    describe table itab1.

    read table itab1 index sy-tfill.

    i think this will help you.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2007 at 10:08 AM

    Hi,

    sample code

    loop at it_ekko1 into wa_ekko.
    
        skip.
    
        clear v_row_flag.
    
        write:/ wa_ekko-ebeln under 'PO Number',
                wa_ekko-bedat under 'PO Date',
                wa_ekko-ernam under 'Created By',
                wa_ekko-bukrs under 'Company',
                wa_ekko-waers under 'Curr',
                wa_ekko-lifnr under 'Vendor'.
    
        loop at it_ekpo1 into wa_ekpo where ebeln = wa_ekko-ebeln.
    
    
          if v_row_flag is initial.
    
            write: wa_ekpo-werks under 'Plant',
                   wa_ekpo-matnr under 'Material No.',
                   wa_ekpo-ebelp under 'Item No.',
                   wa_ekpo-lgort under 'St.Loc.',
                   wa_ekpo-menge under '      Order Qty' ,
                   wa_ekpo-meins under 'UOM',
                   wa_ekpo-peinh under 'P/U',
                   wa_ekpo-netwr under 'Net Value',
                   wa_ekpo-eindt under 'Del. Date.'.
            v_row_flag = 'X'.
          else.
    
            write:/ wa_ekpo-werks under 'Plant',
                    wa_ekpo-matnr under 'Material No.',
                    wa_ekpo-ebelp under 'Item No.',
                    wa_ekpo-lgort under 'St.Loc.',
                    wa_ekpo-menge under '      Order Qty' ,
                    wa_ekpo-meins under 'UOM',
                    wa_ekpo-peinh under 'P/U',
                    wa_ekpo-netwr under 'Net Value',
                    wa_ekpo-eindt under 'Del. Date.'.
    
          endif.
    
          at end of ebeln.
            sum.
            uline.
    
            write:/100 'TOTAL :-' inverse color 6, 142 wa_ekpo-netwr
            inverse color 6.
            uline.
          endat.
    
    
          at last.
            sum.
            uline.
            write:/100 ' GRAND TOTAL OF NET VALUE :-' inverse color 6 ,142
            wa_ekpo-netwr inverse color 6 .
            uline.
          endat.
    
        endloop.
    
      endloop.

    reward if useful.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.