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.
INSERT wa INTO TABLE table_name.
> 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.
Message was edited by:
for a sorted table you can append values using the statement.... APPEND..SORTED BY....
here is the 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
WHERE carrid = p_carrid AND
connid = p_connid.
seats-seatsfree = seats-seatsmax - seats-seatsocc.
APPEND seats TO seats_tab SORTED BY seatsfree.
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.
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,
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.
UP TO 10 ROWS
INSERT FS_TABLE INTO TABLE T_TABLE.
if it is advantages to u justify properly.