03-08-2007 6:28 AM
Hi folks,
I have created a sorted internal table of type MARA and have populated the internal table with values from the MARA table. Now, I have to insert a record into the internal table. If I insert the record using INSERT statement, it is giving me a runtime error. I know I have to use the sort key somewhere in the syntax, but am not able to figure it out. Can anyone give me a snippet of code to do the insert functionality into a sorted table.
Thanks in advance.
Helpful answers will be rewarded.
03-08-2007 6:53 AM
Instead of using the INSERT Statement use APPEND and then sort the whole table again.
03-08-2007 6:54 AM
Hi Aarthy,
INSERT wa INTO TABLE table_name.
wa -
> Work Area
Here, You must use the TABLE keyword, so that u can avoid runtime error.This will work your internal table i.e., Sorted table.
You can not use INDEX keyword INSERT statement.OK.
If you have any further queries, you are welcome.
if problem solved, reward.
Hope, the problem solved.
Regards,
V.Raghavender.
Message was edited by:
Raghavender Vadakattu
03-08-2007 6:55 AM
Hi Arthy,
Can you paste the existing code with syntax you used for creating sorted table ?
Regards
Kapadia
03-08-2007 9:25 AM
Hi,
check this link.
Hope this helps.
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htm
Regards,
Sruthi
03-09-2007 4:37 AM
for a sorted table you can append values using the statement.... APPEND..SORTED BY....
here is the example.....
Example
Creating a ranking of the three flights of a connection showing the most free seats.
PARAMETERS: p_carrid TYPE sflight-carrid,
p_connid TYPE sflight-connid.
DATA: BEGIN OF seats,
fldate TYPE sflight-fldate,
seatsocc TYPE sflight-seatsocc,
seatsmax TYPE sflight-seatsmax,
seatsfree TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE STANDARD TABLE OF seats
INITIAL SIZE 3.
SELECT fldate seatsocc seatsmax
FROM sflight
INTO seats
WHERE carrid = p_carrid AND
connid = p_connid.
seats-seatsfree = seats-seatsmax - seats-seatsocc.
APPEND seats TO seats_tab SORTED BY seatsfree.
ENDSELECT.
03-09-2007 5:27 AM
Hi Arthy!
Inserting a record in sorted table can be done by using TABLE keyword in your INSERT statement, like,
INSERT <record> INTO TABLE <table name>.
It will not give any run-time error and the record will be inserted at an appropriate position , i.e. in sorted order.
Regards,
Neha Bansal.
03-09-2007 9:29 AM
Hii,
Its really very simple ,you know sorted tables are itself sorted,you just need to append the record into the table it will automatically sort it ,no need to write any sort or binary search statement after it,this is the benifit of sorted tables, i think ur problem is solved.
one more thing if you are appending records one or two times then its ok go ahead but if your requirement is to append records very frequently then better go for standard tables and use statement SORT ITAB BINARY SEARCH after that,
and further you cannot enter record into a sorted table on your specified index becouse it will sort it always according to the primary key(s) so it may not come at that position what you gave,
sorted tables can be a performance issue if you append records again and again.
please give details about your RUNTIME DUMP,
thanks
vikas
03-10-2007 7:54 AM
The sorted tables are having the feature that the recorted to be inserted into sorting order.
the case that if u manually enter the record in correct posotion it well and good.
if not before inserting the record into sorted table the data will be sorted.which is happend in data base tables.
see an example of this code.
DATA FS_TABLE LIKE MARA.
DATA: T_TABLE LIKE SORTED TABLE OF FS_TABLE WITH UNIQUE KEY MATNR.
SELECT *
FROM MARA
INTO FS_TABLE
UP TO 10 ROWS
.
INSERT FS_TABLE INTO TABLE T_TABLE.
ENDSELECT.
if it is advantages to u justify properly.