‎2007 Jun 29 2:47 PM
I AM BEGGENER TO ABAP. CAN U CHECK THIS CODE. LOOP DOES NOT SHOW ANY THING. WHY ?
DATA : BEGIN OF ITAB1 OCCURS 0,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1 SORTED BY SALES.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1 SORTED BY SALES.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1 SORTED BY SALES.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
‎2007 Jun 29 4:55 PM
Hi,
Good question..
While doing Append we can do sorting at the same time.
I wil give you one example...
It is like Ranking of any Sprots. ( FIFA Ranking, ICC Ranking)
Say you give ranking from 1 to 10.
At any point of time u will find only 10 members in the ranking according to the points.
If a new member gains more points than the 10 nth member, he will be included in the TOP TEN and the other member will be taken off from the Ranking.
In your case....
You declared Internal table as OCCURS 0....
that means at any point of time, it can store ZERO records.
If you declare internal table as OCCURS 5...
that means at any point of time, it can store only 5 records...
If you declare internal table as OCCURS 10...
that means at any point of time, it can store only 10 records...
While using APPEND TAB SORTED BY SALES.
It sorts the record then only it appends.
‎2007 Jun 29 2:51 PM
Hi
Use
<b>APPEND ITAB1</b>.
After adding all records, just say
<b>SORT ITAB1 BY SALES.</b>
Regards
Raj
‎2007 Jun 29 2:51 PM
Hi Ravi,
Change your code as.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1. .
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1.
SORT ITAB1 BY SALES.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
Reward points if useful.
Regards,
Atish
‎2007 Jun 29 2:52 PM
Can you try this way.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1.
SORT itab1 by sales.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
‎2007 Jun 29 2:53 PM
I modified the program :
DATA : BEGIN OF ITAB1 OCCURS 0,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
start-of-selection.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1 ."SORTED BY SALES.
clear itab1.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1. "SORTED BY SALES.
clear itab1.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1. "SORTED BY SALES.
clear itab1.
sort itab1 by sales.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
do not use sort with append statement.
Thanks
Seshu
‎2007 Jun 29 2:55 PM
Yes, It won't work...
Use only append and sort it afterwards..
DATA : BEGIN OF ITAB1 OCCURS 0,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1 .
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1 .
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1 .
SORT itab1 BY SALES.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
‎2007 Jun 29 2:57 PM
Hi RAvi,
In append statement you no need to write sorted by. Just write Append ITAB1.
If you want to sort the table by Sales the use this follwoing after the last append statement:
SORT ITAB1 BY SALES.
Reward points if helpful answer.
Ashvender
‎2007 Jun 29 2:59 PM
hi there,
You please try this.
Declaration is ok.
avoid sorting all the time.
itab1-sales = 100 .
itab1-name = 'jack' .
append itab1 .
itab1-sales = 200 .
itab1-name = 'jacL' .
append itab1 .
itab1-sales = 300 .
itab1-name = 'jacM' .
append itab1 .
*****at the end of the program before write statement sort itab1.
SORT ITAB1 BY SALES.
LOOP AT ITAB1 .
WRITE : / ITAB1-SALES , 20 ITAB1-NAME .
ENDLOOP .
REEWARDS EILL BE APPRECIATED.
‎2007 Jun 29 3:04 PM
You try this it should work. i did not check as the server is down.
data : begin of itab1 occurs 0 with header line,
sales type p decimals 2 ,
name(10) type c ,
end of itab1 .
itab1-sales = 100 .
itab1-name = 'jack' .
append itab1 .
itab1-sales = 200 .
itab1-name = 'jacL' .
append itab1 .
itab1-sales = 300 .
itab1-name = 'jacM' .
append itab1 .
*****at the end of the program before write statement sort itab1.
SORT ITAB1 BY SALES.
LOOP AT ITAB1 .
WRITE : / ITAB1-SALES , 20 ITAB1-NAME .
ENDLOOP .
‎2007 Jun 29 3:50 PM
Hi,
Use this code it will store in ITAB1.
DATA : BEGIN OF ITAB1 OCCURS 0,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
IF HELPFULL REWARD
‎2007 Jun 29 3:55 PM
DATA : BEGIN OF ITAB1 OCCURS 0,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1..
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
Dont use APPEND SORTED BY..as it is used to create Ranked List..
If you still want to use APPEND SORTED BY then use the below code..
DATA : BEGIN OF ITAB1 OCCURS 3,
SALES TYPE P DECIMALS 2,
NAME(10),
END OF ITAB1.
ITAB1-SALES = 100.
ITAB1-NAME = 'JACK'.
APPEND ITAB1 SORTED BY SALES.
ITAB1-SALES = 200.
ITAB1-NAME = 'JACL'.
APPEND ITAB1 SORTED BY SALES.
ITAB1-SALES = 300.
ITAB1-NAME = 'ABCD'.
APPEND ITAB1 SORTED BY SALES.
LOOP AT ITAB1.
WRITE : / ITAB1-SALES, 20 ITAB1-NAME.
ENDLOOP.
‎2007 Jun 29 4:55 PM
Hi,
Good question..
While doing Append we can do sorting at the same time.
I wil give you one example...
It is like Ranking of any Sprots. ( FIFA Ranking, ICC Ranking)
Say you give ranking from 1 to 10.
At any point of time u will find only 10 members in the ranking according to the points.
If a new member gains more points than the 10 nth member, he will be included in the TOP TEN and the other member will be taken off from the Ranking.
In your case....
You declared Internal table as OCCURS 0....
that means at any point of time, it can store ZERO records.
If you declare internal table as OCCURS 5...
that means at any point of time, it can store only 5 records...
If you declare internal table as OCCURS 10...
that means at any point of time, it can store only 10 records...
While using APPEND TAB SORTED BY SALES.
It sorts the record then only it appends.
‎2009 May 31 5:29 PM