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

report

Former Member
0 Likes
730

hi all,

what is the main use of sort while writing a report program.?give with small ex.

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
701

hi sort is used at the subtotals and is used at the read statement using binary search..

read table itab1 with key field = itab-field binary search.

here the sort is essential ...otherwise it will gives u dump some times..

regards,

venkat

8 REPLIES 8
Read only

Former Member
0 Likes
701

to put it in the order you want or user wants in a more orderly fashion.. there are a tremendous number of reasons you would sort.

Sorting an internal table is as simple as

SORT ITAB.

Which will sort using the entire row as the sort critieria.

Read only

Former Member
0 Likes
702

hi sort is used at the subtotals and is used at the read statement using binary search..

read table itab1 with key field = itab-field binary search.

here the sort is essential ...otherwise it will gives u dump some times..

regards,

venkat

Read only

Former Member
0 Likes
701

HI,

The SORT ITAB is used to sort (small to large OR A to Z) the data as assending or desending order based on ur selection.

by default it sort assending order.

If u want to sort iternal table by the specified field.

sort itab by field1.

Gupta.....................

Read only

Former Member
0 Likes
701

Sorts an internal table on the fields U want .. either Ascending

descending ..

sort itab by field1 descending. (default ascending)

If U want to use control break statements .. the internal table

must be sorted with proper keys .

Also If U want to read internal table using binary search ..

internal table must be sorted ...

Read only

Former Member
0 Likes
701

Hi,

Sort is mainly used when we use control break statement such as at new, on change, at end of etc. It also increases the performance if we sort the internal table before using For all entries in a select query .

Go through this link.

http://help.sap.com/saphelp_nw04s/helpdata/en/d0/a76d420a00de54e10000000a155106/frameset.htm

this are the main place where sort keeps lots of importance.

Reward some points.

Bye,

Anomitro

Read only

Former Member
0 Likes
701

hi

sort is used for internal table in reports becoz if we read we read or search or delete the adjacent record from the internal table than it improves the processing

EX

like it i use DELETE satement on an internal table for duplicate entry then i have to write condition where i frist read it and then compare and then delete .

instead if i use sort like

sort itab by field1.

and now if i use the

DELETE ADJACENT staement then it does the same as previous one

it is ALso neaded it u r uding read statement with addition binary search

cheers

Snehi Chouhan

Read only

Former Member
0 Likes
701

THE MAIN USE OF SORT STATEMENT IS TO SORT AN INTERNAL TABLE CONTENTS

GENERALLY IN REPORTING IF WE DATA THE RECORDS TO BE DISPLAY IN ORDER(ASCENDING OR DESCENDING)

AND ALSO IF DO SUBTOTAL,TOTALS WE USE SORT

ALSO BEFORE READ STATEMENTS

AND DELETE STATEMENTS

This statement sorts an internal table itab. As standard, numeric and byte-type components are sorted by their value and character-type components according to their binary representation code page). Textual sorting of character-type components is performed using the addition AS TEXT.

If no explicit sort key is entered using the BY addition, the internal table itab is sorted according to the table key. In this case, the table key can contain a maximum of 250 components. The priority of the sort is based on the order in which the die key field are specified in the table definition. In standard keys, the sort is prioritized according to the order of the key fields in the line type of the table.

For itab, a standard table or a hashed table is expected. Sorted tables cannot be sorted using SORT and the application of the SORT statement on sorted tables is syntactically prohibited. If the system does not notice until runtime that a sorted table is to be sorted, an untreatable exception occurs if this could result in change in the existing sorting. The latter occurs in the following cases:

If the BY addition is used to enter a different addition than the initial part of the table key

If the addition DESCENDING is used,

If the addition AS TEXT is used,

If an attribute of an object is entered as a component in the BY addition.

Edited by: moazam hai on May 12, 2008 3:14 PM

Read only

Former Member
0 Likes
701

Hi ! Shirish kumar

Please view the example for Sort.

Report Zcontrol_break.

DATA : BEGIN OF ITAB OCCURS 0,

ebeln LIKE ekko-ebeln,

bsart LIKE ekko-bsart,

ekorg LIKE ekko-ekorg,

ekgrp LIKE ekko-ekgrp,

bukrs LIKE ekko-bukrs,

ebelp LIKE ekpo-ebelp,

END OF ITAB.

START-OF-SELECTION.

SELECT EBELN

BSART

EKORG

EKGRP

BUKRS FROM EKKO INTO TABLE ITAB.

**Important to sort the internal table first.*

Sort itab by EBELN.

LOOP AT ITAB .

AT FIRST.

WRITE: /5'Purchas_Doc_No',

22'Purchasing_Document_Type',

47'Sales_organization',

67'Sales_Group'.

ENDAT.

AT NEW bsart .

SKIP.

WRITE:/ ITAB-EBELN.

ENDAT.

WRITE: 9 ITAB-EBELN,

22 ITAB-BSART,

47 ITAB-EKORG,

67 ITAB-EKGRP.

ENDLOOP.

Dont forget to reward points

Thanks & regards

Basheer