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
Hanna_89
Участник
Участник



Joined: 01 Nov 2011
Posts: 29

PostPosted: Mon Dec 05, 2011 1:25 pm    Post subject: Как получить тип переменной метода класса? Reply with quote

Добрый день!

Есть класс ZNYXTEST с методом INPARM_2_1(Static, Public), у которого входной параметр INPARM_2_1(TYPE ZSTR - структура ABAP словаря).
Как получить тип параметра INPARM_2_1?

Так вот не работает: DESCRIBE FIELD INPARM_2_1 HELP-ID hlp, в hlp пусто. Может быть это потому, что ZSTR структура?
Back to top
View user's profile Send private message
John Doe
Модератор
Модератор


Age: 45
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Mon Dec 05, 2011 5:52 pm    Post subject: Reply with quote

Как-то так
Code:
METHOD meth1.

  *  ispfli TYPE spfli - входной параметр в методе

  TYPE-POOLS: abap.
  DATA: ls_components TYPE abap_compdescr.
  DATA: lo_strucdescr TYPE REF TO cl_abap_structdescr.

  FIELD-SYMBOLS: <carrid> TYPE ANY.

  lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( ispfli ).

  LOOP AT lo_strucdescr->components INTO ls_components.
    CASE ls_components-name.
      WHEN 'CARRID'.
        " Что-то делаем с Краткое название авиакомпании
        ASSIGN COMPONENT ls_components-name OF STRUCTURE ispfli
          TO <carrid>.

    ENDCASE.
  ENDLOOP.

ENDMETHOD.

_________________
FunCoding.ru
KicksCollector.ru
Back to top
View user's profile Send private message Blog
Hanna_89
Участник
Участник



Joined: 01 Nov 2011
Posts: 29

PostPosted: Mon Dec 05, 2011 5:59 pm    Post subject: Reply with quote

Спасибо, сейчас попробуем...
Back to top
View user's profile Send private message
Hanna_89
Участник
Участник



Joined: 01 Nov 2011
Posts: 29

PostPosted: Mon Dec 05, 2011 6:08 pm    Post subject: Reply with quote

У меня происходит дамп на строчке
lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( ispfli ).

Не знаете, в чём дело???
Back to top
View user's profile Send private message
John Doe
Модератор
Модератор


Age: 45
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Mon Dec 05, 2011 6:15 pm    Post subject: Reply with quote

Шутите? Замените ISPFLI на свой INPARM_2_1 ...
_________________
FunCoding.ru
KicksCollector.ru
Back to top
View user's profile Send private message Blog
Hanna_89
Участник
Участник



Joined: 01 Nov 2011
Posts: 29

PostPosted: Mon Dec 05, 2011 6:18 pm    Post subject: Reply with quote

Наверное, я не так выразилась.
Вываливаюсь в дамп именно при передаче своего параметра!
Back to top
View user's profile Send private message
Удав
Гуру
Гуру


Age: 48
Joined: 25 Jan 2008
Posts: 580
Location: Москва

PostPosted: Tue Dec 06, 2011 3:34 pm    Post subject: Reply with quote

Вот так точно работает
Code:

FORM get_type USING p_data TYPE any.
  DATA: g_descr TYPE REF TO cl_abap_structdescr,
        g_type TYPE REF TO cl_abap_typedescr.

  CALL METHOD cl_abap_structdescr=>describe_by_data
    EXPORTING
      p_data      = p_data
    RECEIVING
      p_descr_ref = g_type.

  g_descr ?= g_type.

_________________
С уважением,
Удав.
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.