cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting

Former Member
0 Kudos

Hello Gurus !!!

I would like to SORT my list with the field

WA_ITAB-VVVPR (PRICE).

WHEN i USE

Sort wa_itab-vvvpr the error syntax error shows <b>'WA_ITAB is not an Internal table'</b>

well its the Work area...

and when I mention Sort itab by VPRSV <b>it shows itab has no header line..</b> I am working with 4.7c and We must use work area not header line while defining ITAB:

PLS HELP...

DATA: i_mbew TYPE TABLE OF mbew,

wa_mbew TYPE mbew.

SELECT * FROM mbew INTO TABLE i_mbew where

BWKEY Between '4010''4020' and '4030' .

LOOP AT itab INTO wa_itab.

READ TABLE i_mbew INTO wa_mbew WITH KEY

matnr = wa_itab-artnr.

IF wa_mbew-vprsv = 'V'.

wa_itab-vvvpr = wa_mbew-verpr.

ELSE.

wa_itab-vvvpr = wa_mbew-stprs.

ENDIF.

MODIFY itab FROM wa_itab.

WRITE:/4 wa_itab-artnr,

15 wa_itab-vvvpr,

41 wa_mbew-vprsv,

53 wa_mbew-bwkey,

71 wa_mbew-peinh.

ENDLOOP.

Message was edited by: Preetham

Accepted Solutions (0)

Answers (7)

Answers (7)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You should specify the type of table in the declaration.You cannot sort the workarea wa_itab,since it's already having one record.You should only sort internal table.Check the below sample code and reward points by clicking the star on the left of reply,if it helps.

DATA: i_mbew TYPE <b>standard</b> TABLE OF mbew,

wa_mbew TYPE mbew.

SELECT * FROM mbew INTO TABLE i_mbew where

BWKEY Between '4010''4020' and '4030' .

<b>sort itab by VPRSV.</b>

LOOP AT itab INTO wa_itab.

READ TABLE i_mbew INTO wa_mbew WITH KEY

<b>matnr = wa_itab-matnr</b>.

IF wa_mbew-vprsv = 'V'.

wa_itab-vvvpr = wa_mbew-verpr.

ELSE.

wa_itab-vvvpr = wa_mbew-stprs.

ENDIF.

MODIFY itab FROM wa_itab.

WRITE:/4 wa_itab-artnr,

15 wa_itab-vvvpr,

41 wa_mbew-vprsv,

53 wa_mbew-bwkey,

71 wa_mbew-peinh.

ENDLOOP.

Former Member
0 Kudos

Hi gurus.. Thanx ... But check the following CODE this is my FULL CODE...

and I need to sort the PRICE which is in the Structure...

wa_itab-vvvpr



Thanx..

Preetham

REPORT zcopa_bw_1 NO STANDARD PAGE HEADING
LINE-COUNT 65(1)
LINE-SIZE 235.
*Local Variables

DATA: line(2000),
rc TYPE sy-subrc,
file TYPE filetable,
file_name TYPE string,
itab TYPE TABLE OF zcopa080,
wa_itab TYPE zcopa080.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

CHANGING

file_table = file

rc = rc

  • USER_ACTION =

  • EXCEPTIONS

  • FILE_OPEN_DIALOG_FAILED = 1

  • CNTL_ERROR = 2

  • ERROR_NO_GUI = 3

  • NOT_SUPPORTED_BY_GUI = 4

  • others = 5

.

IF sy-subrc <> 0.

ENDIF.

READ TABLE file INTO file_name INDEX 1.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = file_name

CHANGING

data_tab = itab

.

IF sy-subrc <> 0.

ENDIF.

DATA: i_mbew TYPE standard TABLE OF mbew,

wa_mbew TYPE mbew.

SELECT * FROM mbew INTO TABLE i_mbew WHERE

bwkey BETWEEN '4010''4020' and '4030' .

LOOP AT itab INTO wa_itab.

READ TABLE i_mbew INTO wa_mbew WITH KEY

matnr = wa_itab-artnr.

IF wa_mbew-vprsv = 'V'.

wa_itab-vvvpr = wa_mbew-verpr.

ELSE.

wa_itab-vvvpr = wa_mbew-stprs.

ENDIF.

MODIFY itab FROM wa_itab.

WRITE:/4 wa_itab-artnr,

15 wa_itab-vvvpr,

41 wa_mbew-vprsv,

53 wa_mbew-bwkey,

71 wa_mbew-peinh.

ENDLOOP.

TOP-OF-PAGE.

FORMAT COLOR COL_HEADING INTENSIFIED ON.

WRITE: /50 'Report Für Material Preis Östereich',

108 'Records', syst-dbcnt,

130 'page', syst-pagno,

235 ''.

SKIP 1.

WRITE : /2 'Material Number',

24 'Preis',

39 'Preis Typ',

53 'BWKEY',

69 'Preis Einheit'.

Former Member
0 Kudos

Add the statement "SORT itab BY vvvpr" right before the "LOOP AT itab INTO wa_itab" statement.

Srinivas

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Wa_itab will have only one record inside the loop.Each time in the loop,it will have the previous record overwritten.

So you cannot sort a single record.

Normally we will sort the table records for the read operation.

Wa_itab is not an internal table.It is a workarea.

Work area will have only one record at a time.

So we can sort only internal table which is having more than one record.

Hope this answers your question.If so,kindly reward points.

SELECT * FROM mbew INTO TABLE i_mbew WHERE

bwkey BETWEEN '4010''4020' and '4030' .

<b>

sort itab by vvvpr.</b>

LOOP AT itab INTO wa_itab.

READ TABLE i_mbew INTO wa_mbew WITH KEY

matnr = wa_itab-artnr.

IF wa_mbew-vprsv = 'V'.

wa_itab-vvvpr = wa_mbew-verpr.

ELSE.

wa_itab-vvvpr = wa_mbew-stprs.

ENDIF.

MODIFY itab FROM wa_itab.

WRITE:/4 wa_itab-artnr,

15 wa_itab-vvvpr,

41 wa_mbew-vprsv,

53 wa_mbew-bwkey,

71 wa_mbew-peinh.

ENDLOOP.

Former Member
0 Kudos

Hello Preetham,

There's no version called 4.7C. We only have 4.6C. Furthermore, starting from SAP release 4.7, it is better to specify the ABAP / Basis release that you're working on, like 620, 640 etc.,

Your code snippet doesn't have any SORT statement. and nor do you have a declaration for "itab" and "wa_itab". So it's difficult to say the reason for the syntax error.

Regards,

Anand Mandalika.

Former Member
0 Kudos

i m agree with max bianchi.

he is right and it is orking for me.

Regards

Siddarth

Former Member
0 Kudos

hi,

just add

sort i_mbew by vvvpr above the loop

cheers,

sasi

Former Member
0 Kudos

Preetam,

it seems you defined wa as work_area not inernal table, thats why yu get the error.

do the following to sort by vvvpr.

sort itab by vvvpr.

you can use addition ASCENDING or decending DESCENDING also.

sort itab by vvvpr ASCENDING. or

sort itab by vvvpr DESCENDING.

Former Member
0 Kudos

Hi,

Use as

DATA: i_mbew TYPE <b>STANDARD</b> TABLE OF mbew,
            wa_mbew TYPE mbew.

Hope this helps.

Former Member
0 Kudos

Hi

I'm using working on 4.7C, but your statament works fine:

DATA: i_mbew TYPE TABLE OF mbew.

Sort i_mbew by VPRSV.

Only error is occured was there isn't VRPSV, but VPRSV.

Max

Message was edited by: max bianchi

Former Member
0 Kudos

Hi,

check this it may help you...

data : begin of wa.
        include structure mbew.
data   end of wa.

data : itab like table of wa with header line.

SELECT * FROM mbew INTO corresponding field of wa where
BWKEY Between '4010''4020' and '4030' .

loop at itab into wa.

endloop.


hope this helps you...

regards,

venu.

Former Member
0 Kudos

declare your itab like this

DATA ITAB LIKE STANDARD TABLE OF wa WITH NON-UNIQUE KEY VRPSV .

Then use.

SORT ITAB.