SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

динамическая сортировка



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
corsair
Участник
Участник



Joined: 06 Feb 2008
Posts: 37

PostPosted: Wed Jul 30, 2008 2:46 pm    Post subject: динамическая сортировка Reply with quote

Коллеги, почему падает в дамп такой код. xtable не пустая.

Code:
TYPES: BEGIN OF xtable_type,
        ebeln     TYPE ekko-ebeln,
        ebelp     TYPE ekpo-ebelp,
        ekorg     TYPE ekko-ekorg,
        bukrs     TYPE ekko-bukrs,
        zekkn     TYPE ekkn-zekkn.
TYPES: END OF xtable_type.
DATA: xtable      TYPE xtable_type OCCURS 0
                  WITH HEADER LINE.


  DATA: str_order TYPE string
  str_order = 'ebeln ebelp'.
  SORT xtable BY (str_order).


Описание падения


Quote:
Error analysis


The current ABAP program "Zxxx " tried to process the internal
table
"XTABLE[]" with "SORT".
The component "ebeln ebelp" was specified dynamically as the contents of the
field "STR_ORDER".

One of the following errors occurred:

- The line type "XTABLE_TYPE" of the internal table "XTABLE[]" does not
contain a component "ebeln ebelp".

- "ebeln ebelp" contained a specification in the form "A->B" to signify
dynamic access to an object attribute.
This is currently only allowed statically.

- "ebeln ebelp" contained an invalid offset or length specification
(for example, you may have tried to access part of a field with
type I or STRING).

- "ebeln ebelp" contained significant trailing spaces
(only possible with type STRING).
Back to top
View user's profile Send private message
july7
Старший специалист
Старший специалист



Joined: 10 Oct 2007
Posts: 109
Location: Киров

PostPosted: Wed Jul 30, 2008 3:19 pm    Post subject: Reply with quote

str_order должен быть внутренней таблицей:

Code:
TYPES: BEGIN OF xtable_type,
        ebeln     TYPE ekko-ebeln,
        ebelp     TYPE ekpo-ebelp,
        ekorg     TYPE ekko-ekorg,
        bukrs     TYPE ekko-bukrs,
        zekkn     TYPE ekkn-zekkn.
TYPES: END OF xtable_type.
DATA: xtable      TYPE xtable_type OCCURS 0
                  WITH HEADER LINE.

DATA: lt_sort TYPE abap_sortorder_tab,
         ls_sort TYPE abap_sortorder.
ls_sort-name = 'EBELN'.
APPEND ls_sort TO lt_sort.
ls_sort-name = 'EBELP'.
APPEND ls_sort TO lt_sort.
SORT xtable BY (lt_sort).
Back to top
View user's profile Send private message
corsair
Участник
Участник



Joined: 06 Feb 2008
Posts: 37

PostPosted: Wed Jul 30, 2008 3:34 pm    Post subject: Reply with quote

July7, что это за типы abap_sortorder_tab, abap_sortorder?
в моей системе их нет.

Когда заменил на
DATA: lt_sort TYPE TABLE OF LINE72,
ls_sort TYPE LINE72.
ругается на синтаксис
"LT_SORT" must be a character data object (data type C, N, D, T or STRING). field string).
Back to top
View user's profile Send private message
july7
Старший специалист
Старший специалист



Joined: 10 Oct 2007
Posts: 109
Location: Киров

PostPosted: Wed Jul 30, 2008 3:55 pm    Post subject: Reply with quote

У меня система ERP2005, наверное, у Вас версия ниже Sad
Back to top
View user's profile Send private message
corsair
Участник
Участник



Joined: 06 Feb 2008
Posts: 37

PostPosted: Wed Jul 30, 2008 4:08 pm    Post subject: Reply with quote

july7 wrote:
У меня система ERP2005, наверное, у Вас версия ниже Sad


А вы можете сказать, что это за тип? Можно его создать в старой системе?
Back to top
View user's profile Send private message
Armann
Модератор
Модератор



Joined: 01 Jan 2008
Posts: 422
Location: Moscow

PostPosted: Wed Jul 30, 2008 4:20 pm    Post subject: Reply with quote

corsair, объявите str_order обычной внутренней таблицей, должно помочь

например:
Code:

data: str_order(72) type c occurs 2 with header line.

str_order = 'ebeln'. append str_order.
str_order = 'ebelp'. append str_order.

SORT xtable BY (str_order).
Back to top
View user's profile Send private message Blog
corsair
Участник
Участник



Joined: 06 Feb 2008
Posts: 37

PostPosted: Wed Jul 30, 2008 4:34 pm    Post subject: Reply with quote

Armann wrote:
corsair, объявите str_order обычной внутренней таблицей, должно помочь


Помогло, всем большое спасибо за участие!
Back to top
View user's profile Send private message
RA
Участник
Участник



Joined: 03 Dec 2007
Posts: 13

PostPosted: Fri Mar 11, 2011 4:22 pm    Post subject: Reply with quote

Добрый день!

Quote:
Помогло, всем большое спасибо за участие!


А какая версия у Вас?

Согласно help:

Quote:
With the addition BY (otab), the table is not sorted according to the table key, but instead according to the component specified dynamically in the internal table otab as of release 7.0).
...
For otab, a standard table of the table type ABAP_SORTORDER_TAB from the ABAP Dictionary must be specified.


поэтому код, приведенный Armann, не компилируется в 7.0


Создал пример в 4.7:

Code:
REPORT  zz_sort                                .

TYPES: BEGIN OF xtable_type,
        ebeln     TYPE ekko-ebeln,
        ebelp     TYPE ekpo-ebelp,
        ekorg     TYPE ekko-ekorg,
        bukrs     TYPE ekko-bukrs,
        zekkn     TYPE ekkn-zekkn.
TYPES: END OF xtable_type.
DATA: xtable      TYPE xtable_type OCCURS 0
                  WITH HEADER LINE.

DATA: str_order(72) TYPE c OCCURS 2 WITH HEADER LINE.

str_order = 'ebeln'. APPEND str_order.
str_order = 'ebelp'. APPEND str_order.


xtable-ebeln = '300'.
xtable-ebelp = '10'.
APPEND xtable.

xtable-ebeln = '200'.
xtable-ebelp = '30'.
APPEND xtable.

xtable-ebeln = '200'.
xtable-ebelp = '10'.
APPEND xtable.



BREAK-POINT.

CLEAR str_order.
SORT xtable BY (str_order). " нет сортировки

READ TABLE str_order INDEX 1. " по ebeln
SORT xtable BY (str_order).

READ TABLE str_order INDEX 2. " по ebelp
SORT xtable BY (str_order).

BREAK-POINT.


таблица сортируется только по одному полю, тому что лежит в header line таблицы str_order.

Выходит, что для 4.7 так сортировать нельзя или я ошибаюсь?

P.S. может кому пригодится в 4.7 нашел ФМ:
Code:
'C140_TABLE_DYNAMIC_SORT'
на основе
SORT X_TAB BY (A01) .... (A10) .
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.