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

Unable to exit on change , at new of new field

Hi Techies ,

i have a requirement where need to collect all my latest dates's records and place in another table.

types :

begin of ty_tab ,

costobject type char20,

gctbill type char7

end of ty_tab.

data : it_tab type table of ty_tab,

wa_tab type ty_tab,

it_final type table of ty_tab,

wa_final type ty_tab.

i have 10 records in it_tab (snapshot of records attached).

i want to collect the latest records and place them in another table it_final.

so am doing following :

sort it_tab descending by gctbill . "to get latest

loop at it_tab into wa_tab .

AT NEW GCTBILL . "used on change also

EXIT.

ENDAT.

append wa_tab to it_final . "filling the final table with the latest records.

endloop.

contents of it_final expected : i thought at new GCTBILL it would exit , but it is not , instead it is reading only first record and coming out of loop.

, so after , the it_final has only one record .

it_final

COSTOBJECT GCTBILL 810456 2014005

it_final expected :

COSTOBJECT GCTBILL 810456 2014005 810789 2014005 910123 2014005 910456 2014005 910789 2014005 910852 2014005
it_tab.jpg (104.1 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jul 11, 2014 at 06:11 PM

    Hi Ajay,

    Please find the following code.

    "Copy the Internal Table

    it_final[] = it_tab[].

    "Sort the Internal Table based on Latest Records

    SORT it_final

    BY costobject ASCENDING

    gctbill DESCENDING.

    "Delete the Adjacent Duplicate records

    DELETE ADJACENT DUPLICATES FROM it_final COMPARING costobject.

    Now IT_FINAL contains the required output.

    Regards

    Rajkumar Narasimman

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2014 at 06:11 PM

    Hi Ajay,

    Try

    loop at it_tab into wa_tab .

    AT NEW GCTBILL .

    append wa_tab to it_final .

    ENDAT.

    endloop.

    Regards,

    Kannan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2014 at 06:15 PM

    Hi

    AT NEW will be triggered by the firrst record of your table, so the reult will be the system will go out from the loop at the beginning.

    You should append the record in the AT NEW instead of EXIT:

    loop at it_tab into wa_tab .

    AT NEW GCTBILL . "used on change also

    EXIT.

    append wa_tab to it_final . "filling the final table with the latest records.

    ENDAT.

    append wa_tab to it_final . "filling the final table with the latest records.

    endloop.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      I don't know what you mean,

      your code was good except for the moment for the appending: it needs to do into AT NEW statament.

      The solution of Rajkumur using DELETE ADIACENT is the same but it's better, anyway I prefer to suggest you a solution based on your code in order to understand what doesn't work.

      You need to get the first record of a table so you can use all solution you want: but the table has to be sorted before (of course)

      Max

  • Posted on Jul 11, 2014 at 07:28 PM

    Hi Ajay

    why dont you change the place of

    costobject type char20,

    gctbill type char7

    use this:

    types :

    begin of ty_tab ,

    gctbill type char7,

    costobject type char20,

    end of ty_tab.


    sort it_tab


    loop at it_tab into wa_tab .

    AT END OF GCTBILL .

    append wa_tab to it_final . "filling the final table with the latest records.

    ENDAT.

    endloop.


    think like if every record becomes one string from the field you want to make the at new/end to the left

    example

    At New FIELD1 Will occur in lines: 1, 4 At New FIELD2 Will occur in lines: 1, 3, 4, 6 At New FIELD3 Will occur in every line At End Of FIELD1 Will occur in lines: 3, 7 At End Of FIELD1 Will occur in lines: 2, 3, 5, 7 At End Of FIELD1 Will occur in every line

    thats why you need to be careful with the order of the internal table when using "AT"


    Regards

    MC


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi marco ,

      thanks for explaning.

      but if i write append inside loop .

      i.e :

      loop at it_tab into wa_tab .

      AT END OF GCTBILL .

      append wa_tab to it_final . "filling the final table with the latest records.

      ENDAT.

      endloop.

      so it_final also has same records as it_tab .

      please revert

  • author's profile photo Former Member
    Former Member
    Posted on Jul 24, 2014 at 06:10 AM

    Hi Sreekanth ,
    Can you please clear my following doubts , please take your time and read my query .
    Am very clear with the Check table , i.e putting cursor on field in the table and clicking on key symbol(foreign key relationship) and maintaining the 'Check table' makes us enter(while creating entries for the table) only those values which are there in Master table(Check Table) and also we will get the F4 option in the selection screen when we display the records of the table , but my doubt is, this happens only when creating the records in se11 ?
    or is it like when i declare a parameter in program(se38) of type above field(which has foreign key relation defined) and in selection screen will it makes us enter only those values which are in master table(Check Table) ?
    (I tried above but in se11 it is fine it is giving an error if we try to make entries apart from the master table values)
    (and in se38 I defined : PARAMETERS type p_check , and in selection screen it was accepting all the values different from master table entries also)

    And coming to value table :
    What is the difference between value table and check table?
    When I go inside domain and give 'value table' and come out and if I maintain foreign key relation then it becomes same as check table ..
    Can you explain me the scenarios where exactly we use these tables ?

    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.