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

Dynamic Internal table Based on records

Former Member
0 Likes
916

Hi,I need to create an internal table depending on no.of records I found in a standard table.In my dynamic internal table I have first 4 columns fixed and next columns should be genreted dynamically at run time.I searched the forum,every example I found was with using classes,as I dont have any Idea of classes I couldnot understand those programs.PLZ If anyone can provide an example exactly on my requirement without any classes used or with CLEAR explanation.Thanks in advance.

Points will be rewarded for every helpful answer.

6 REPLIES 6
Read only

pavel_parshenkov2
Participant
0 Likes
851

Hi

You can use:

1) Class Method:

CALL METHOD cl_alv_table_create=>create_dynamic_table

2) Look at CLASS CL_ABAP_TABLEDESCR (If you have SAP version higher then 4.7 ) in this class you can crate internal table dynamically.

Best Regards.

Read only

0 Likes
851

Hi,thanks for u r feedback,but as I said I dont have any Idea of using classes,I need an example without classes and give me example similar to my requirement like this :

Fixed1 Fixed2 Fixed3 Fixed4 Dynamic1 Dynamic2..........

Read only

0 Likes
851

use Function Module:

call function 'LVC_TABLE_CREATE'.

fill it_fieldcatalog like for usual ALV report. and all.

Read only

Former Member
0 Likes
851

Try this example: This is the smallest program to create dynamic internal table. You have no way to escape from learning Class concepts.

DATA: struct_type TYPE REF TO cl_abap_structdescr,

comp_tab TYPE cl_abap_structdescr=>component_table,

comp LIKE LINE OF comp_tab,

dref TYPE REF TO data.

FIELD-SYMBOLS: <struc> TYPE ANY,

<comp> TYPE ANY.

comp-name = 'column1'.

comp-type = cl_abap_elemdescr=>get_c( 40 ).

APPEND comp TO comp_tab.

comp-name = 'column2'.

comp-type = cl_abap_elemdescr=>get_i( ).

APPEND comp TO comp_tab.

struct_type = cl_abap_structdescr=>create( comp_tab ).

CREATE DATA dref TYPE HANDLE struct_type.

ASSIGN dref->* TO <struc>.

ASSIGN COMPONENT 'COLUMN1' OF STRUCTURE <struc> TO <comp>.

<comp> = 'Amount'.

ASSIGN dref->* TO <struc>.

ASSIGN COMPONENT 'COLUMN2' OF STRUCTURE <struc> TO <comp>.

<comp> = 11.

Read only

0 Likes
851

On what basis the example program is creating Dynamic IT? or if u can create one program as my requirement is,I will change it as I want.Thanks.

Read only

0 Likes
851

I have just made a program like you're requirements



DATA: ta_output TYPE REF TO data.
DATA: new_table TYPE REF TO data,
      new_line  TYPE REF TO data,
      is_lvc_cat TYPE lvc_s_fcat,
      it_lvc_cat TYPE lvc_t_fcat.


FIELD-SYMBOLS: <ta_output> TYPE table,
              <ta_color> TYPE table,
              <l_line>  TYPE ANY,
               <l_field> TYPE ANY,
               <fs> TYPE ty_pernrs.
.

  SELECT pernr ename FROM pa0001
    INTO CORRESPONDING FIELDS OF TABLE ta_pernrs
    WHERE pernr IN so_pernr
      AND werks IN so_werks
      AND begda <= '99991231'
      AND endda >  h_begin.


*build fields for dynamic table

* static fields

  is_lvc_cat-fieldname = 'VALIDITYDATE'.
  is_lvc_cat-ref_field = 'VALIDITYDATE'.
  is_lvc_cat-ref_table = 'BAPI7013_1'.
  is_lvc_cat-scrtext_s  = is_lvc_cat-scrtext_m =
  is_lvc_cat-scrtext_l  = 'Datum'.
  APPEND is_lvc_cat TO it_lvc_cat.

  is_lvc_cat-fieldname = 'DAY_STRING'.
  is_lvc_cat-ref_field = 'DAY_STRING'.
  is_lvc_cat-ref_table = 'CASDAYATTR'.
  is_lvc_cat-scrtext_s  = is_lvc_cat-scrtext_m =
  is_lvc_cat-scrtext_l  = 'Datum'.
  APPEND is_lvc_cat TO it_lvc_cat.

* dynamic fields

  LOOP AT ta_pernrs INTO wa_pernrs.

    FREE it_0002.
    WRITE wa_pernrs-pernr TO h_ri_pernr.
    is_lvc_cat-fieldname = wa_pernrs-pernr.
    is_lvc_cat-ref_field = 'massn'.
    is_lvc_cat-ref_table = 'PERNR'.
    is_lvc_cat-just = 'C'.
    is_lvc_cat-scrtext_s  =    is_lvc_cat-scrtext_m  =   is_lvc_cat-scrtext_l  =  wa_persnrs-pernr.

    APPEND is_lvc_cat TO it_lvc_cat.

endloop.


* create table
* Create a new Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_lvc_cat
    IMPORTING
      ep_table        = ta_output.

* Create a new Line with the same structure of the table.
  ASSIGN ta_output->* TO <ta_output>.
  CREATE DATA new_line LIKE LINE OF <ta_output>.
  ASSIGN new_line->* TO <l_line>.

kind regards

arthur

Edited by: A. de Smidt on Jun 4, 2008 10:08 AM

Edited by: A. de Smidt on Jun 4, 2008 10:09 AM