09-09-2008 4:49 AM
Hi All,
Currently i have a z-table with records.
How do i perform a sort with one of the fields before i do a Loop through all the records?
If i were to do a SORT <ZTABLE> BY <FIELD>, en error will occur indicating that this is not an internal table - the "OCCURS n" specification is missing.
Can some experts advise on how to solve this?
Thanks.
Regards,
JL
09-09-2008 6:16 AM
Hi, do u know what is the problem to sort an ztable created in SE11??
Actually it is a database table and we cannot sort a database table directly ,but we can bring all data in the ztable in an interbnal table and then we can perform the sort technique on any of the field.
you declare an internal table like the structure of ztable and select all data from database table to the internal table.
Data : i_table type standard table of ztable.
start-of-selection.
*select * from ztable into table i_table.*
Now apply sorting on the internal table.
Then modify the ztable from the internal table.
Please have a look in the answer. hope this will help.
regards
jayati.
09-09-2008 4:51 AM
hi,
have declared it as an internal table in your program?
declare it like this.
DATA: ztable TYPE STANDARD TABLE OF ztable WITH HEADER LINE.
regards,
Peter
09-09-2008 4:51 AM
hi,
have declared it as an internal table in your program?
declare it like this.
DATA: ztable TYPE STANDARD TABLE OF ztable WITH HEADER LINE.
regards,
Peter
09-09-2008 4:53 AM
Hi,
First bring all the data of z table into an internal table of type 'STANDARD TABLE OF <Z table>'.
Sort the internal table and then modify the z table from that internal table.
09-09-2008 4:55 AM
09-09-2008 5:20 AM
Hi,
u can use this code
DATA: BEGIN OF line,
t1(4) TYPE c,
t2 TYPE i,
END OF line.
DATA : tot TYPE I,
GRTOT TYPE I.
*DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY t1.
DATA : ITAB LIKE TABLE OF LINE .
line-t1 = 'aaaa'.
line-t2 = 1.
INSERT line INTO TABLE itab.
line-t1 = 'aaaa'.
line-t2 = 1.
INSERT line INTO TABLE itab.
line-t1 = 'aaaa'.
line-t2 = 1.
INSERT line INTO TABLE itab.
line-t1 = 'bbbb'.
line-t2 = 2.
INSERT line INTO TABLE itab.
line-t1 = 'bbbb'.
line-t2 = 2.
INSERT line INTO TABLE itab.
line-t1 = 'bbbb'.
line-t2 = 2.
INSERT line INTO TABLE itab.
line-t1 = 'cccc'.
line-t2 = 3.
INSERT line INTO TABLE itab.
line-t1 = 'cccc'.
line-t2 = 3.
INSERT line INTO TABLE itab.
line-t1 = 'cccc'.
line-t2 = 3.
INSERT line INTO TABLE itab.
line-t1 = 'aaaa'.
line-t2 = 1.
INSERT line INTO TABLE itab.
SORT itab.
PERFORM loop_at_itab.
FORM loop_at_itab.
SORT itab by t1.
LOOP AT itab INTO line.
On change of line-t1.
if sy-tabix = 1.
else.
ULINE.
WRITE: /'Sum:', 10 tot.
GRTOT = GRTOT + TOT.
clear tot.
ULINE.
endif.
endon.
WRITE 😕 line-t1,line-t2.
tot = tot + line-t2.
ENDLOOP.
ULINE.
WRITE:/ 'Sum:', 10 tot.
ULINE.
ULINE.
GRTOT = GRTOT + TOT.
WRITE:/ 'GR.TOT:', 10 GRtot.
ULINE.
SKIP.
ENDFORM.
Hope this helps
Regards,
Manish
09-09-2008 5:39 AM
Hi All,
Sorry for any misunderstanding.
I created my z-table using SE11. So there is no need to declare again in my program right?
so, can i still sort all the records when i loop through this table?
09-09-2008 5:48 AM
Hi
u cannot sort a Ztable created in Se11 directly from ur program.
first declare an internal table type ztable and then sort the internal table.
Regards,
naveen
09-09-2008 5:56 AM
Hi Chong,
You need to define <Internal Table> TYPE <Z-TABLE> in program:
1. Define <Internal Table> TYPE <Z-TABLE> in program
2. Move <z-table> data to <internal table>
3. Sort <internal table>
Regards,
Moqeeth.
09-09-2008 6:16 AM
Hi, do u know what is the problem to sort an ztable created in SE11??
Actually it is a database table and we cannot sort a database table directly ,but we can bring all data in the ztable in an interbnal table and then we can perform the sort technique on any of the field.
you declare an internal table like the structure of ztable and select all data from database table to the internal table.
Data : i_table type standard table of ztable.
start-of-selection.
*select * from ztable into table i_table.*
Now apply sorting on the internal table.
Then modify the ztable from the internal table.
Please have a look in the answer. hope this will help.
regards
jayati.
09-09-2008 6:29 AM
hello,
you cant directly sort a DB table .... for this u have to declare a internal table in your program of type that ZTABLE with occurs 0 with header line specification....
then through a select query get the data in the ZTABLE into INT_ZTABLE i.e. the internal table of type ZTABLE and then sort the int_ZTABLE by field u want and do ur computation on the internal table and then update the DB table with internal table
09-09-2008 6:41 AM
Hi,
Please make use of occurs 0 with header line in declaration of the internal table.
Thanks,
Sriram Ponna.