2012 Aug 14 8:20 PM
Hi Experts,
I have created a ztable and using ALV I am updating this table. But while updating from internal table, the records are stored into this table in sorted order. I want to update this table as per the order in internal table. What is the procedure to do this?
Regards,
Sibin
Hi Experts,
I have created a ztable and using ALV I am updating this table. But while updating from internal table, the records are stored into this table in sorted order. I want to update this table as per the order in internal table. What is the procedure to do this?
Regards,
Sibin
2012 Aug 15 1:10 AM
Hi Sibin,
i think in database table, data is sorted by key.
but in your ALV, it can be sort by anyway you want, so i think it is not possible to update the table as per your internal table only you also sort internal table by table primary keys.
2012 Aug 15 3:49 AM
Hi,
I sugguest you to add 2 more fields which are
1. TIMESTAMP to store timestamp of posting time.
2. ORDER TYPE I. to store increment number of soted interanl table .
Now you can have the sorted table.
Hope it help,
Sayan.
2012 Aug 15 1:36 PM
Thanks a lot for your replies. I am using following code to update the table.
INSERT ZTABLE FROM IT_TABLE.
In IT_TABLE, records are in the same order as that mentioned in the ALV. But is getting updated in Ztable in sorted order.There are 5 fields in my Ztable all of which are primary keys.
Regards,
Sibin
2012 Aug 15 1:58 PM
Hi Sibin,
in some standard transactions (like SE16 in the ABAP standard list mode), the entries of a database table will always be shown in the order of the primary key. You can't avoid this.
In your own applications, however, you can influence the order according to your own needs.
If you want another order than that given by the primary key, you will usually have an extra column SORTFIELD TYPE I in the non-key part of the database table, denoting the sort order you really wish.
You can then perform the sort yourself, when reading the data in.
Regards, Rüdiger
2012 Aug 27 12:25 PM
Hi,
Why do you want to update the table in a specific order? What is the use of Ztable?
Thanks.
Regards,
Kumud
2012 Aug 27 4:25 PM
Hi Sibin,
If the stored order is important, you can include another key field in your table to indicate the sequence of the records. See for example table LIPS, where the full key is MANDT-VBELN-POSNR and POSNR contains the item number, i.e., the sequence number of the item in the delivery.
Keep in mind though, you do not necessarily need to store records in a particular order since you can always read them out of the database in any sort order by using the ORDER BY addition in your query statement:
SELECT carrid connid fldate
FROM sflight
INTO TABLE sflight_tab
ORDER BY carrid connid.
Or by explicitly sorting an internal table with keyword, SORT itab BY field.
Cheers,
Amy
2012 Aug 27 6:37 PM
You cannot, SAP works with relational database and not hierarchical database or flat files. The "sort" order of physical records can not be managed via Open SQL or even Native SQL statements.
Your request has "a whiff of good old days" when programmers could use low-level statement with database.
What is your exact requirement, as usually SQL database can extract the data in any order, if you don't specify a ORDER BY option in your statement.
(If SE16/SE16n may give the impression that data comes sorted comes usually from SQL optimizer and the implicit criteria on CLIENT field, I remember some years ago when many programmers get in trouble when some update of Kernel changed some default implicit order...).
Regards,
Raymond