Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Updating a Z table using internal table

Former Member
0 Likes
1,634

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

7 REPLIES 7
Read only

Aiolos
Active Participant
0 Likes
1,435

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.

Read only

Sayan_C
Explorer
0 Likes
1,435

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.

Read only

Former Member
0 Likes
1,435

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

Read only

0 Likes
1,435

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

Read only

kumud
Active Contributor
0 Likes
1,435

Hi,

Why do you want to update the table in a specific order? What is the  use of Ztable?

Thanks.

Regards,

Kumud

Read only

amy_king
Active Contributor
0 Likes
1,435

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,435

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