Skip to Content
author's profile photo Former Member
Former Member

TYPE or LIKE when using the internal table for ALV?

Hi all,

I have a doubt about alv programs. Why does it work ONLY when the main internal table's (ie which contains the data to be displayed, (here itab_t001)) fields are declared with 'LIKE' ? and not if 'TYPE' is used. It does not give any error with 'TYPE' but does not show the ALV grid either. Why?

ie if you use:

TYPES: BEGIN OF t_t001,
  bukrs TYPE t001-bukrs, "company code
  butxt TYPE t001-butxt, "company name
END OF t_t001.

DATA: wa_t001 TYPE t_t001,
      itab_t001 TYPE t_t001.

it will not work but if you use:

DATA: BEGIN OF wa_t001,
  bukrs TYPE t001-bukrs, "company code
  butxt TYPE t001-butxt, "company name
END OF wa_t001.

DATA: BEGIN OF itab_t001 OCCURS 0,
      bukrs LIKE wa_t001-bukrs, "company code
      butxt LIKE wa_t001-butxt, "company name
END OF itab_t001.

it works fine..

Thanks.

Charles.

+++++++++++++

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 29, 2006 at 12:35 AM

    hi Brown,

    Yes when you are building fieldcatlog manually in your program then your fields in your internal table should refer to data objects(using like addition) otherwise when you are using reuse_fieldcatlog_merge function then you can have your fields reffering data types(using type addition).

    when using like addition(referring data objects) internally sap knows the tabname,cfieldname and ctabname......for your fieldcatlog.

    i hope now you understand the difference between using type and like.

    Add a comment
    10|10000 characters needed characters exceeded

    • Not really sure what the problem is here, I never use LIKE, I always use TYPE and I have no problems with ALV. See example program below. Maybe its the way you are building your fieldcat.

      
      report zrich_0004
             no standard page heading.
      tables: mara.
      
      type-pools slis.
      
      data: fieldcat type slis_t_fieldcat_alv.
      
      Types: begin of tmara,
             matnr type mara-matnr,
             maktx type makt-maktx,
             end of tmara.
      
      data: imara type table of tmara.
      
      * Selection Screen
      selection-screen begin of block b1 with frame title text-001 .
      select-options: s_matnr for mara-matnr .
      selection-screen end of block b1.
      
      start-of-selection.
      
        perform get_data.
        perform write_report.
      
      
      ************************************************************************
      *  Get_Data
      ************************************************************************
      form get_data.
      
        select  mara~matnr makt~maktx
                  into corresponding fields of table imara
                    from mara
                     inner join makt
                       on mara~matnr = makt~matnr
                          where mara~matnr in s_matnr
                            and makt~spras = sy-langu.
      
      endform.
      
      ************************************************************************
      *  WRITE_REPORT
      ************************************************************************
      form write_report.
      
        perform build_field_catalog.
      
      * CALL ABAP LIST VIEWER (ALV)
        call function 'REUSE_ALV_GRID_DISPLAY'
             exporting
                  it_fieldcat = fieldcat
             tables
                  t_outtab    = imara.
      
      endform.
      
      ************************************************************************
      * BUILD_FIELD_CATALOG
      ************************************************************************
      form build_field_catalog.
      
        data: fc_tmp type slis_fieldcat_alv .
        clear fieldcat. refresh fieldcat.
      
        clear: fc_tmp.
        fc_tmp-reptext_ddic    = 'Material Number'.
        fc_tmp-fieldname  = 'MATNR'.
        fc_tmp-tabname   = 'IMARA'.
        fc_tmp-outputlen  = '18'.
        append fc_tmp to fieldcat.
      
      
        clear: fc_tmp.
        fc_tmp-reptext_ddic    = 'Material'.
        fc_tmp-fieldname  = 'MAKTX'.
        fc_tmp-tabname   = 'IMARA'.
        fc_tmp-outputlen  = '40'.
        append fc_tmp to fieldcat.
      
      endform.
      
      

      Regards,

      Rich Heilman

  • Posted on Aug 28, 2006 at 11:03 PM

    The problem here is that in the first case, you are not declaring an internal table. YOu need to specify like this.

    
    TYPES: BEGIN OF t_t001,
      bukrs TYPE t001-bukrs, "company code
      butxt TYPE t001-butxt, "company name
    END OF t_t001.
     
    DATA: wa_t001 TYPE t_t001,
          itab_t001 TYPE <b>TABLE OF</b> t_t001.
    
    
    

    Then it should work.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 28, 2006 at 11:11 PM

    Hi,

    Because wa_t001 or itab_t001 is not an internal table..

    you have to declare the following..

    data: wa_t001 type standard table of t_t001 with header line.

    data: itab_t001 type standard table of t_t001 with header line.

    Thanks,

    Naren

    Message was edited by: Narendran Muthukumaran

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 28, 2006 at 11:25 PM

    hi brown,

    u should declare like

    <b>data itab_t001 type table of t_t001.</b>

    Cheers,

    Abdul Hakim

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 29, 2006 at 09:04 PM

    Hi all,

    I made a mistake while giving the code..

    EVEN IF I WRITE:

    DATA: wa_t001 TYPE t_t001,
          itab_t001 TYPE TABLE OF t_t001.

    the ALV is not generated... there is an exception and sy-subrc is set to 1 after the call to REUSE_ALV_LIST_DISPLAY.

    For it to work, the only change I make in the entire program is USE 'LIKE' for the ALV to run.. Only Kishore Maddu has given some reason (though not clear at first or second reading though, sorry Mr. Maddu). All other answers pointed the error without checking if it works like that or not..

    Please explicate Kishore's answer or give your reasons.

    Thanks,

    Charles.

    ++++++++++++++++++++++++

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.