Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regarding Internal table

Former Member
0 Likes
362

Hi all

1)..Is there any key word to find no of fields in an

Internal table.?

2) There is a require ment like this

User enters 5 names through select-options..

depending on that there must be that no of fields in the

internal tables...or more no of fields?

How can we do this......?

Is there any idea for that.......?

Thanks in advance.......?

KK

2 REPLIES 2
Read only

Former Member
0 Likes
338

Search the forum on "dynamic table" and you will find many postings on how to create a dynamic internal table. Let us know if that does not meet your needs.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
338

Here is a sample program showing use of dynamic internal table.



report zrich_0003
       no standard page heading.

type-pools: slis.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.


selection-screen begin of block b1 with frame title text-001.
parameters: p_check type c.
selection-screen end of block b1.

start-of-selection.

  perform build_dyn_itab.
  perform build_report.

  loop at <dyn_table> into <dyn_wa>.
    write:/ <dyn_wa>.
  endloop.


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

  data: index(3) type c.

  data: new_table type ref to data,
        new_line  type ref to data,
        wa_it_fldcat type lvc_s_fcat.

* Create fields
  clear index.
  do 10 times.
    index = sy-index.
    clear wa_it_fldcat.
    concatenate 'Field' index into
             wa_it_fldcat-fieldname .
    condense  wa_it_fldcat-fieldname no-gaps.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
  enddo.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = it_fldcat
               importing
                  ep_table        = new_table.

  assign new_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data new_line like line of <dyn_table>.
  assign new_line->* to <dyn_wa>.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: <fs1>.

  do 10 times.

    index = sy-index.

* Set up fieldname
    concatenate 'FIELD' index into
             fieldname .
    condense   fieldname  no-gaps.

* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.

    assign component  fieldname  of structure <dyn_wa> to <fs1>.
    <fs1> =  fieldvalue.

  enddo.

* Append to the dynamic internal table
  append <dyn_wa> to <dyn_table>.

endform.

Regards,

Rich Heilman