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

Problem in SORT statement

Former Member
0 Likes
773

Hi Gurus,

I have this problem, I am trying to sort a internal table with the syntax after endselect statement and before read table statement

SORT ITAB_SBOOK BY NAME

name is a field in the table of type CHAR length 25 in actual table and here is how i am declaring name

in internal table

name LIKE stravelag-name

but the sort statement is not executing properly, names are being printed on the screen but they are not

being formated.

can some one tell me whare am i wrong ?

thanks.

Moderator Message: Please use more descriptive subject line in future post.

Edited by: Suhas Saha on Dec 25, 2011 7:55 PM

1 ACCEPTED SOLUTION
Read only

jitendra_it
Active Contributor
0 Likes
735

Hi hisheeraz,

Please use " As text " addition of sort statement for sorting character strings.

Pls see this

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm

Thanks

Jitendra soni

5 REPLIES 5
Read only

jitendra_it
Active Contributor
0 Likes
736

Hi hisheeraz,

Please use " As text " addition of sort statement for sorting character strings.

Pls see this

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm

Thanks

Jitendra soni

Read only

Former Member
0 Likes
735

Use 'type' instead of 'like'.

Read only

0 Likes
735

@ jitu188 thank man, your comment did not solve the problem but it definately lead me to the solution,

all i had to do was declare a string variable, transfer the value accross and then sort SOLVED

@ AnupamPratapSingh as of my understanding there is no difference between LIKE and TYPE there are 100% same.

i think one is newer version and other one is classic i am not sure which one though.

correct me if i am wrong

Cheers

Read only

sreenivas_pachva
Participant
0 Likes
735

Hi

as per my knowledge there is slight diff between type and like keywords

type key refer the data type of a field where as like key refer the reference of existing internal table in this just refer the data types not content(data)

example:

types:BEGIN OF ty_itab,

matnr type mara-matnr,

matkl type mara-matkl,

mbrsh type mara-mbrsh,

ersda type mara-ersda,

END OF ty_itab.

data:itab type STANDARD TABLE OF ty_itab.

data:wa_itab type ty_itab.

we want to create one more internal table with the existing structure at this time we will go through the like keyword.

jtab like itab occurs 10.

-


and also check the following code.

REPORT  sort.
types:BEGIN OF ty_itab,
      matnr type mara-matnr,
      matkl type mara-matkl,
      mbrsh type mara-mbrsh,
      ersda type mara-ersda,
  END OF ty_itab.

 data:itab type STANDARD TABLE OF ty_itab.

  data:wa_itab type ty_itab.


  select matnr matkl mbrsh ersda from mara into wa_itab.

    APPEND wa_itab to itab.
ENDSELECT.

SORT itab by mbrsh.

write:/ 'matno',' mat group','industry sector','created on'.
loop at itab into wa_itab.

  write:/ wa_itab-matnr,wa_itab-matkl,wa_itab-mbrsh,wa_itab-ersda.

  endloop.

best regards

sreenivas p

Read only

sreenivas_pachva
Participant
0 Likes
735

Hi

as per my knowledge there is slight diff between type and like keywords

type key refer the data type of a field where as like key refer the reference of existing internal table in this just refer the data types not content(data)

example:

types:BEGIN OF ty_itab,

matnr type mara-matnr,

matkl type mara-matkl,

mbrsh type mara-mbrsh,

ersda type mara-ersda,

END OF ty_itab.

data:itab type STANDARD TABLE OF ty_itab.

data:wa_itab type ty_itab.

we want to create one more internal table with the existing structure at this time we will go through the like keyword.

jtab like itab occurs 10.

-


and also check the following code.

REPORT  sort.
types:BEGIN OF ty_itab,
      matnr type mara-matnr,
      matkl type mara-matkl,
      mbrsh type mara-mbrsh,
      ersda type mara-ersda,
  END OF ty_itab.

 data:itab type STANDARD TABLE OF ty_itab.

  data:wa_itab type ty_itab.


  select matnr matkl mbrsh ersda from mara into wa_itab.

    APPEND wa_itab to itab.
ENDSELECT.

SORT itab by mbrsh.

write:/ 'matno',' mat group','industry sector','created on'.
loop at itab into wa_itab.

  write:/ wa_itab-matnr,wa_itab-matkl,wa_itab-mbrsh,wa_itab-ersda.

  endloop.

best regards

sreenivas p