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

CREATING INTERNAL TABLE DYNAMICALY

Former Member
0 Likes
498

Hi All ,

I have a scenario like i need to develop a table control /input enabled alv grid at run time .My scenario is when ever i select a customer a table control/input enabled alv grid should be generated with all the customer deails along with ship-to-party(the number of ship-to-party fields vary from customer to customer ) . My problem is how to generate internal table dynamically which can hold this data.

How to convert internal table into alvgrid at runtime i have idea.

Kindly show some light on this issue.

Thank you all

Sreejith

Edited by: sri on Aug 6, 2009 7:30 AM

1 ACCEPTED SOLUTION
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
457
data: itab_drds_struc type ref to data.
field-symbols: <drds_tab> type any table.
create data itab_drds_struc type (table_name).
assign itab_drds_struc->* to <drds_tab>.

You can create internal table dynamically like this. table_name is a variable which should hold the table name to which you are referring to.

After this create an ALV grid and assign this internal table values.

Regards,

Siva.

3 REPLIES 3
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
458
data: itab_drds_struc type ref to data.
field-symbols: <drds_tab> type any table.
create data itab_drds_struc type (table_name).
assign itab_drds_struc->* to <drds_tab>.

You can create internal table dynamically like this. table_name is a variable which should hold the table name to which you are referring to.

After this create an ALV grid and assign this internal table values.

Regards,

Siva.

Read only

Former Member
0 Likes
457

Hi sri,

1.

For this purpose,

in my program,

<b> there is an INDEPENDENT FORM</b>

whose inputs are

<b> LIST OF FIELDS, (just as u require)</b>

and from those, it consructs dynamic table.

2. Here is the program.

the dynamic table name will be

<DYNTABLE>.

3. U can use this program (FORM in this program)

to generate any kind of internal table

by specifying list of fields.

4.



REPORT abc.


*------------- COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.


*--------------------


START-OF-SELECTION.

*-------------- field list
  ddfields-fieldname = 'BUKRS'.
  APPEND DDFIELDS.
  ddfields-fieldname = 'MATNR'.
  APPEND DDFIELDS.

*----------------------------

  PERFORM mydyntable .


*-------- see <DYNTABLE> in debug mode.
  BREAK-POINT.






*---------------------------------------------------------------
* INDEPENDENT FORM
*---------------------------------------------------------------

FORM mydyntable .




*-------------- Create Dyn Table From FC

  FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
  FIELD-SYMBOLS: <fs_1>.
  FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
  DATA: lt_data TYPE REF TO data.
  data : lt TYPE lvc_t_fcat .


*------------- CONSTRUCT FIELD LIST

  LOOP AT ddfields.
    ls-fieldname = ddfields-fieldname.
    APPEND ls TO lt.
  ENDLOOP.


  ASSIGN lt_data TO <fs_data>.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = lt
    IMPORTING
      ep_table                  = <fs_data>
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc <> 0.
  ENDIF.



*------------- Assign Dyn Table To Field Sumbol

  ASSIGN <fs_data>->* TO <fs_1>.
  ASSIGN <fs_1> TO <fs_2>.
  ASSIGN <fs_1> TO <dyntable>.


ENDFORM. "MYDYNTABLE

regards,

amit m.

Read only

Former Member
0 Likes
457

Hi Sri,

u might find the links useful.....

https://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable

https://wiki.sdn.sap.com/wiki/display/Snippets/sample+dynamicinternal+table

Regards.