Class reference internal table

Hello Gurus,
i have an internal table filled with class references and i need to acces the one field of a structure of every class.
I am now trying something like this:
loop ref_table assigning <l_wrk_ref_but0id>.
      IF <l_wrk_ref_but0id>->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv.
      ENDIF.
endloop.
I need the field "type" in the structure "m_str_but0id" of every class (reference) in the table. The error that i'm getting is: "Field m_str_but0id unknown".
Please help.
Ioan Constantin.

Hello Ioan
You have to access the field dynamically as well:
DATA:
   ld_structure  TYPE <name of structure>,
   ld_attribute    TYPE tabname,
   ld_field          TYPE fieldname.
FIELD-SYMBOLS:
  <ls_struct>     TYPE any,
  <ld_fld>           TYPE any.
ld_attribute = 'M_STR_BUT0ID'.
ld_field       = 'TYPE'. 
loop ref_table assigning <l_wrk_ref_but0id>.
     ASSIGN <l_wrk_ref>but0id>->(ld_attribute) TO <ls_struct>.
     ASSIGN COMPONENT (ld_field) OF STRUCTURE <ls_struct> TO <ld_fld>.
"      IF <l_wrk_ref_but0id>->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv.
       IF ( <ld_fld> = /gkv/cd40_cl_const=>con_pkkv ).
      ENDIF.
endloop.
Even simpler might be the following approach:
LOOP AT ref_table assigning <l_wrk_ref_but0id>
                WHERE ( table_line->m_str_but0id-type = /gkv/cd40_cl_const=>con_pkkv ).
ENDLOOP.
" Assumption: Itab has class reference type as line type.
Regards
  Uwe

Similar Messages

  • Class contructor internal table

    Hi epert,
    I am new for abap objects and i am trying to change the standard program.Please refer below.
    CLASS a DEFINITION.
      CLASS-METHODS b.
      METHODS: constructor.
      METHODS: my,
               name.
    ENDCLASS.                    "A DEFINITION
    CLASS a IMPLEMENTATION.
      METHOD b.
        DATA screen TYPE REF TO a.
        CREATE OBJECT screen.
      ENDMETHOD.                    "B
      METHOD constructor.
        CALL METHOD : me->my.
      ENDMETHOD.                    "Constructor
    ENDCLASS.                    "A IMPLEMENTATION
    START-OF-SELECTION.
      CALL METHOD a=>b.
    How it is possbile for me to pass a internal table to the method MY. I have internal table and i need to assign to the method MY.
    Please guide me.  standard program DEMO_ABAP_OBJECTS_SPLIT_SCREEN
    Edited by: Matt on Sep 30, 2010 4:47 PM - added  tags
    Edited by: Matt on Sep 30, 2010 4:49 PM

    >
    mrsaravannan wrote:
    > How it is possbile for me to pass a internal table to the method MY.
    Hello,
    You have to create a formal parameter for the method MY & pass your internal table to it:
    Something like this:
    Class A definition.
    class-methods B.
    methods: constructor.
    methods: my IMPORTING im_itab TYPE <line type of your internal table>,
    name.
    Endclass.
    In your CONSTRUCTOR pass the Internal Table value:
    Method Constructor.
    call method me->my EXPORTING im_tab = itab[].
    endmethod.
    BR,
    Suhas

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • How to pass internal table to method of class

    Hi all,
    I am new to abap objects, i want to pass one internal table to class.
    i am trying in this way.
    class c1 definition.
    method get_material importing t_stpo  type any table
                                   exporting t_mast type any table.
    endmethod.
    endclass.
    class c1 implementation.
    method get_material.
    select f1 f2 f3 from <tab> into table t_mast
            for all entries in t_stpo
            where stlnr = t_stpo-stlnr.
    endmethod.
    endclass.
    ERROR:
    "stlnr" is not available
    if i use this way. its not giing error.
    class c1 definition.
    method get_material exporting t_mast type any table.
    endmethod.
    endclass.
    class c1 implementation.
    method get_material.
    select f1 f2 f3 from <tab> into table t_mast
            for all entries in it_stpo
            where stlnr = it_stpo-stlnr.
    endmethod.
    endclass.
    how to pass internal table with some specific reference may be using like or type <it_xxxx>
    thanks

    Try this.
    TYPES : BEGIN OF ty_stpo,
             stlnr TYPE stpo-stlnr,
             idnrk TYPE stpo-idnrk,
             menge TYPE stpo-menge,
            END OF ty_stpo,
            BEGIN OF ty_mast,
             matnr TYPE mast-matnr,
             werks TYPE mast-werks,
             stlnr TYPE mast-stlnr,
            END OF ty_mast,
            tt_stpo TYPE TABLE OF ty_stpo,
            tt_mast TYPE TABLE OF ty_mast.
    DATA : it_stpo TYPE tt_stpo,
           it_mast TYPE tt_mast.
    *       CLASS c1 DEFINITION
    CLASS c1 DEFINITION.
      PUBLIC SECTION.
        METHODS : get_bom_numbers EXPORTING ex_stpo type tt_stpo,
                  get_parent_material IMPORTING im_stpo TYPE tt_stpo
                                      EXPORTING ex_mast TYPE tt_mast.
        endclass.
    *       CLASS c1 IMPLEMENTATION
    CLASS c1 IMPLEMENTATION.
      METHOD get_bom_numbers.
      ENDMETHOD.                    "get_bom_numbers
      METHOD get_parent_material.
      ENDMETHOD.                    "get_parent_material
    START-OF-SELECTION.
      DATA : obj TYPE REF TO c1.
      CREATE OBJECT obj.
      CALL METHOD obj->get_bom_numbers
        IMPORTING
          t_stpo = it_stpo.
      CALL METHOD obj->get_parent_material
        EXPORTING
          im_stpo = it_stpo
        IMPORTING
          ex_mast = it_mast.
    Regards,
    Rich Heilman

  • Defining attribute for internal table within class builder?

    Hello there,
    I use an function module that provides me an internal table which has the reference type of the DDIC object zml_output. Furthermore I call this function module within a global class that should keep the result of the function module into the attribute lt_result, that is declared as private and typed with
    lt_result TYPE zml_output.
    Even the definition of that attribute causes the following error message:
    "lt_result" is not an internal table.
    I don't have any clue how to type lt_result differently. Actually I would need the following type of typing "TYPE TABLE OF" but that does not exist within the class builder.
    Thanks for your help in advanced!
    Robert

    Hi Konstantinidis ...
    Of course I can provide it to you. The code of my methode load_data reads as follows:
    method LOAD_DATA.
        CALL FUNCTION 'ZDATAGET'
        EXPORTING
          iv_dat    = iv_dat
          iv_time1  = iv_time1
          iv_delta  = iv_delta
        TABLES
          et_result = lt_result.
    endmethod.
    Especially the lt_result causes the mentioned error message
    The compiler seems to expect something "TABLE" like for attribute lt_result. But whatever I tried it doesn't seem to work out.
    Many thanks for help...

  • ABAP Objects: Private variable with reference to global internal table

    Hello. I want an object that can hold a private reference
    to a global internal table so that when one of it's methods are invoked, the global table contents are modified.
    Simplification of scenario:
    class myObject definition.
      public section.
        methods:
          set_global_table
            importing reference(i_table) type standard table,
          change_global_table.
      private section.
        data:
          m_pointer_to_table " not sure how to type this"
    endclass.
    class myObject implementation.
      method set_global_table.
        m_pointer_to_table = i_table. " this needs to  "
                                      " assign a pointer to "
                                      " the global variable "
      endmethod.
      method change_global_table.
        refresh m_pointer_to_table. "this should change "
                                    "the contents of global "
                                    "variable "
      endmethod.
    endclass.
    data: gt_itable   type standard table of t_widget,
          go_myobject type ref to myobject.
    * Main code
      create object go_myobject.
    * phantom code fills gt_itable
      call method go_myobject->set_global_table
                    exporting i_table = gt_itable.
      call method go_myobject->change_global_table.
      if gt_itable is initial.
         write 'this should output'.
      endif.
    The code here doesn't work and I've tried messing with field-symbols, etc. all to no avail. Thank you for any help you could provide!
    Brett

    Just typed in this editor - so no syntax-check but you will get the idea:
    Pass the internal table and get the reference of it
    Store the reference and manipulate the global contents with local field-symbols to which you have assigned the reference.
    Hope this helps
    Christian
    >
    > class myObject definition.
    > *
    >   public section.
    > *
    >     methods:
    >       set_global_table
    > importing reference(i_table) type standard
    > standard table,
    > *
    >       change_global_table.
    > *
    >   private section.
    > *
    >     data:
    > m_pointer_to_table type ref to data
    > *
    > endclass.
    > *
    > class myObject implementation.
    > *
    >   method set_global_table.
    > *
         GET REFERENCE of i_table into m_pointer_to_table.
    >   endmethod.
    > *
    > *
    >   method change_global_table.
    > *
      field-symbols: <lit_table> type any table.
        assign m_pointer_to_table to <lit_table>.
    * manipulate <lit_table>
    >   endmethod.
    > *
    > endclass.
    > *
    > *
    > data: gt_itable   type standard table of t_widget,
    >       go_myobject type ref to myobject.
    > *
    > * Main code
    > *
    >   create object go_myobject.
    > *
    > *
    > *
    > * phantom code fills gt_itable
    > *
    > *
    >   call method go_myobject->set_global_table
    >                 exporting i_table = gt_itable.
    > *
    >   call method go_myobject->change_global_table.
    > *
    > *
    >   if gt_itable is initial.
    > *
    >      write 'this should output'.
    > *
    >   endif.
    >
    >
    > The code here doesn't work and I've tried messing
    > with field-symbols, etc. all to no avail. Thank you
    > for any help you could provide!
    >
    > Brett

  • Reference comp in dynamic internal table using CL_ALV_TABLE_CREATE

    Hi,
    I am using CL_ALV_TABLE_CREATE to create a dynamic internal table. Everything works fine, but there is one problem with it. How can i create a component in the internal table that is actually a REF TO a certain data type. i.e. later i would like to store a reference to some dataobj in this component of the internal table.
    I cannot use cl_abap_*descr classes to create internal table because of some other reasons, otherwise it would have been easy to do it.
    Any kind of help would be highly appreciated.
    Thanks and best regards,
    Ghufran

    Hi Ghufran,
    I do have an idea about the class <b>CL_ALV_TABLE_CREATE</b> , but i have writen an exmaple code to create a Dynamic Iternal table, please have a look, it may help you
    *& Report  Z_DYNAMIC_INTERNALTABLE                                 *
    report  z_dynamic_internaltable             .
    data: d_ref type ref to data,
    d_ref2 type ref to data ,
    i_alv_cat type table of lvc_s_fcat,
    ls_alv_cat like line of i_alv_cat.
    types tabname like dcobjdef-name .
    parameter: p_tablen type tabname.
    data: begin of itab occurs 0.
    include structure dntab.
    data: end of itab.
    field-symbols : <f_fs> type table,
    <f_fs1> type table,
    <f_fs2> type any,
    <f_fs3> type table,
    <f_fs4> type any.
    refresh itab.
    call function 'NAMETAB_GET'
    exporting
    langu = sy-langu
    tabname = p_tablen
    tables
    nametab = itab
    exceptions
    no_texts_found = 1.
    loop at itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = p_tablen.
    ls_alv_cat-ref_field = itab-fieldname.
    append ls_alv_cat to i_alv_cat.
    endloop.
    internal table build
    call method cl_alv_table_create=>create_dynamic_table
    exporting it_fieldcatalog = i_alv_cat
    importing ep_table = d_ref .
    assign d_ref->* to <f_fs>.
    select * from (p_tablen) into corresponding fields of table <f_fs>.
    loop at <f_fs> assigning <f_fs2>.
    assign itab-fieldname to <f_fs4>.
    loop at itab.
    write: / <f_fs4>.
    endloop.
    endloop.
    Thanks
    Sudheer

  • Pass the internal table with different structures to the class module

    Hi ,
    I have created a class method to fill up the data in XML format. the method can be called from various programs with internal table with different structures. I want to pass it as dynamic How can I do that.
    I tried to declare that as type any.
    but not working.
    regards,
    Madhuri

    Hi,
    You could work with data reference.
    Use GET REFERENCE OF itab INTO data_ref for passing the internal table to your method, and dereference it within the method with ASSIGN statement...
    DATA: lr_data TYPE REF TO data.
    GET REFERENCE OF itab INTO lr_data.
    CALL METHOD meth EXPORTING pr_data = lr_data.
    METHOD meth.
      FIELD-SYMBOLS <fs> TYPE ANY TABLE
      ASSIGN pr_data->* TO <fs>.
    ENDMETHOD.
    Kr,
    Manu.

  • Internal table in method of class (BADI)

    Hello people !!
    I need to use an internal table into method of class. I don´t know very well how to use it. I know that it hasn´t a header; but I don´t know how to defined and use it.
    I need to use in a method of badi.-
    I will be grateful by the help that your could offer to me.-
    Thank you so much,
    Esther.-

    Thank you for your answer.
    But, I had defined as de fist item, but I had defined with a structure of dictinary.
    Now, in my code, I need to deposit information to the above mentioned table. Then, when I try to accede to the fields of the estructure, when I compile it gives me the following mistake:
    "ACC_DATA" is a table without a header line and therefore has no          
    component called "CUENTA".     
    I attach departs from the code:
    types: es_accdata type standard table of Z_ES_ACCDATA.
    data: acc_data  type es_accdata.
          loop at it_mseg into r_mseg.
          si es Entrada de Mercancía
            if r_mseg-bwart = '101'.
              at first.
                acc_data-cuenta = r_mseg-sakto.
                if not r_mseg-kostl is initial.
                  acc_data-centro_coste = r_mseg-kostl.
                else.
                  acc_data-orden_inversion = r_mseg-aufnr.
                endif.
              endat.
              monto = monto + r_mseg-dmbtr.
            endif.
          endloop.
    Thank you againg, for a new answer !!!!
    bye, Esther.-

  • Delete Duplicates from internal table with object references

    Hi
    How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
    I have created a method, with the following code:
      LOOP AT me->business_document_lines INTO l_add_line.
        CREATE OBJECT ot_line_owner
          EXPORTING
            i_user      = l_add_line->add_line_data-line_owner
            i_busdoc = me->business_document_id.
          APPEND ot_line_owner TO e_line_owners.
      ENDLOOP.
    e_line_owners are defined as a table containing only object references.
    One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
    How can do this?
    Regards,
    Morten Nielsen

    Hello Morten
    Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
      SORT e_line_owners BY table_line->user.
      DELETE ADJACENT DUPLICATES FROM e_line_owners
        COMPARING table_line->user.
    However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
    Alternative solution:
      DATA:
         ld_idx    TYPE sy-tabix.
      LOOP AT e_line_owners INTO ls_line.
        ld_idx = syst-tabix + 1.
        LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
                       WHERE ( table_line->user = ls_line->user ).
          DELETE e_line_owners INDEX syst-tabix.
        ENDLOOP.
      ENDLOOP.
    Regards
      Uwe

  • Internal table my_items not getting populated in class CL_HANDLE_MANAGER_MM

    hi experts,
    i have a problem while using ME38 transaction.
    ME38 calls exit EXIT_SAPMM06E_012
    inside this exit we are calling macro   mmpur_business_obj_id tekpo-id. in turn it goes to method search of class CL_HANDLE_MANAGER_MM where internal table my_items is not getting filled. due to that we are getting dump "Exception FAILURE".
    Thanks in advance
    Chandra

    hi
    put break point before the step and find out the value of your table or check the paramter value you are passing

  • XML to internal table conversion within ABAP mapping class

    I am doing a ABAP mapping for file to Idoc. My requirement is to convert XML file into ABAP internal table (within ABAP mapping class). Is there any standard FM, method, transformation etc, which can be used here.
    Thanks, Dehra

    Dehra,
    Have you seen this weblogs which talks about this:
    /people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
    /people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
    /people/r.eijpe/blog/2006/02/19/xml-dom-processing-in-abap-part-iiia150-xml-dom-within-sap-xi-abap-mapping
    /people/r.eijpe/blog/2006/02/20/xml-dom-processing-in-abap-part-iiib150-xml-dom-within-sap-xi-abap-mapping
    Hope this helps you....
    ---Satish

  • Internal table when creating a class

    Hi everybody
    im defining parameters when defining a class
    one of the parameters is IT_MARA, of type MARA
    Ive declared a method - SELECT_DATA, where the code is
    SELECT * FROM MARA
    INTO TABLE IT_MARA....
    When activating it
    Im getting the error - IT_MARA is not an internal table 'OCCURS n ' specification is missing
    anybody knows how to solve that issue?

    Hi Anjali,
    I figure out you are having trouble passing an internal table out of a method of a class.
    The error you get is because the parameter you have declared using TYPE MARA actually creates a line type and not an internal table in the signature of the method.
    You have to declare the parameter with a 'table type' rather, and it will create an internal table.
    You could use either a global table type or a local one.
    Please have a look at the code below using a local table type for this problem:
    CLASS a DEFINITION.
      PUBLIC SECTION.
        TYPES ty_mara TYPE TABLE OF mara.     "Local Table Type
        METHODS meth EXPORTING et_mara TYPE ty_mara.   "This makes an internal table
    ENDCLASS.
    CLASS a IMPLEMENTATION.
      METHOD meth.
        SELECT * FROM mara INTO TABLE et_mara UP TO 10 ROWS.
      ENDMETHOD.
    ENDCLASS.
    START-OF-SELECTION.
      DATA lt_mara TYPE TABLE OF mara.
      DATA lr_a    TYPE REF TO a.
      CREATE OBJECT lr_a.
      CALL METHOD lr_a->meth
        IMPORTING
          et_mara = lt_mara.
      BREAK-POINT.

  • Global Class that returns an internal table

    Hello,
       Is it possible to create a global class (under class builder) that returns an internal table like we used to do in a function module?
        e.g. call function '<Function module name>'
                        tables = i_tab.
    Thanks,
    Jeffrey

    Hi Jeffrey,
      Yeah u can do that by specifying importing parameters
      to method.You can give table type for the parameters.
    Thanks&Regards,
    Siri.

  • It cannot reference the dynamic internal table in memory as an object.

    Hi,
    I am getting the syntax error in the second select. I guest it cannot reference the dynamic internal table in memory as an object.
    The internal table contains different fields from multiple tables and it gets created OK. Then the first select within the loop executes OK allowing me to read the multiple tables in ITABLES.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = dy_table.
    ***OK, the dynamic tables is created here
      assign dy_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    loop at ITABLES.
    ***OK, no syntax errors in this select here
      select * appending corresponding fields of table <dyn_table>
                 from (ITABLES-TABNAME).
    endloop.
    data: ikonp like konp occurs 0 with header line.
    ***NOT OK, there is syntax errors
      select * into table ikonp
      from KONP for all entries in <dyn_table>
      where knumh = <dyn_table>-knumh.
    Some of the tables in ITABLES are pooled tables which does not allow me to use INNER JOINS. Therefore I need a second select in order to read the pricing table KONP.
    Thanks in advance for any hint.

    Hi Abel,
    You must be getting the syntax error that <dyn_table> does not contain the field knumh.
    try putiing the entire where clause in a char type variable say wa_char and then use in ur query as
    where (wa_char) .. it may work..
    concatenate 'knumh' '=' '<dyn_table>-knumh' INTO wa_char SEPARATED BY SPACES.
    SELECT ... from konp...
    where (wa_char).
    Revert if it doesnt work.

Maybe you are looking for

  • Petition: Make the headphone jack problem's status publ

    Dear CEO of Creative Labs [I still have to find out how to contact the CEO]: I was very excited about buying your product, the Creative Nomad Zen Micro, as an alternati've to competitors such as Apple's iPod mini and the Rio Carbon. I was impressed b

  • How to know a table is using in any packeges or procedures

    Dear All How can I know that a table is using in any packege or procedure or function ? I mean , let say I have 10 Packages , 10 Procedures and 5 Functions . I need to know in which Packages , Procedures or Functions are using the table EMP . How can

  • PO doc. not clear due to po block

    Dear SAP Gurus, After run the F.13 few GRIR not clear yet and these grir's PO are still showing in F.19. Then I noticed that these PO are blocked by the user. 1st I unblock the PO, then run the MR11 against the PO no. After that the PO no. is not sho

  • Screen locked and dont know password

    My screen locked and i have never set up password.  Now i cant get my ipod to work without password.

  • Square photos in apple photo books

    I have a lot of square photos, which I love, due to instagram and other photo editing apps.  I'd like to include them in my Apple photo books, but Apple doesn't seem to allow square photos. It crops the photos into rectangles. Is there a way to inclu