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

Dump In Dynamic Internal Table

Former Member
0 Likes
1,022

REPORT ZDYNAMIC_INTERNAL_TABLE.

TYPE-POOLS : abap.

FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,

<fs_wa>,

<fs_field>.

DATA: it_table TYPE REF TO data,

it_line TYPE REF TO data,

xfc TYPE LVC_S_FCAT,

ifc TYPE lvc_t_fcat.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

PERFORM get_structure.

PERFORM create_dynamic_itab.

PERFORM get_data.

PERFORM write_out.

&----


*& Form get_structure

&----


  • text

----


FORM get_structure.

DATA : idetails TYPE abap_compdescr_tab,

xdetails TYPE abap_compdescr.

DATA : ref_table_des TYPE REF TO cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

LOOP AT idetails INTO xdetails.

CLEAR xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

APPEND xfc TO ifc.

  • WA_XFC-FIELDNAME = P_NAME.

  • WA_XFC-DATATYPE = 'C'.

  • WA_XFC-INTTYPE = 'C'.

  • WA_XFC-INTLEN = P_LEN.

  • WA_XFC-DECIMALS = 0.

  • APPEND WA_XFC TO IST_IFC.

ENDLOOP.

ENDFORM. "get_structure

&----


*& Form create_dynamic_itab

&----


  • text

----


FORM create_dynamic_itab.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = ifc

IMPORTING

ep_table = it_table.

ASSIGN it_table->* TO <fs_table>.

  • Create dynamic work area and assign to FS

CREATE DATA it_line LIKE LINE OF <fs_table>.

ASSIGN it_line->* TO <fs_wa>.

ENDFORM. "create_dynamic_itab

&----


*& Form get_data

&----


  • text

----


FORM get_data.

  • Select Data from table.

SELECT * INTO CORRESPONDING FIELDS OF TABLE <fs_table>

FROM (p_table).

ENDFORM. "get_data

&----


*& Form write_out

&----


  • text

----


FORM write_out.

  • Print data from table.

*call function 'reuse_alv_grid_display'.

*pass <fs_table> as internal table to the function **

BREAK-POINT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = ifc[]

  • IT_SORT = IST_SORT_SUBTOTAL[]

  • IT_EVENTS = IST_EVENT[]

  • IS_LAYOUT = WA_LAYOUT

I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_SAVE = 'X'

TABLES

T_OUTTAB = <fs_table>.

ENDFORM. "write_out

It was tried to transfer the internal table "IFC" to the formal parameter

"IT_FIELDCAT". In doing so, a type conflict occurred between the formal.

here how can i resolve it.

thanks ,

rajan.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
803

Try like following

TYPE-POOLS : abap,SLIS.
FIELD-SYMBOLS: <TABLE> TYPE STANDARD TABLE.
DATA: it_table TYPE REF TO data,
      it_line  TYPE REF TO data,
      xfc      TYPE LVC_S_FCAT,
      ifc      TYPE LVC_T_FCAT.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
 PERFORM get_structure.
 PERFORM create_dynamic_itab.
 PERFORM get_data.
 PERFORM write_out.

FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
            xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
  ref_table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[]     = ref_table_des->components[].
  LOOP AT idetails INTO xdetails.
   CLEAR xfc.
   xfc-fieldname = xdetails-name .
   xfc-datatype  = xdetails-type_kind.
   xfc-inttype   = xdetails-type_kind.
   xfc-intlen    = xdetails-length.
   xfc-decimals  = xdetails-decimals.
   APPEND xfc TO ifc.
  ENDLOOP.
ENDFORM. "get_structure

FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
 CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table = it_table.
 ASSIGN it_table->* TO <TABLE>.
* Create dynamic work area and assign to FS
* CREATE DATA it_line LIKE LINE OF .
* ASSIGN it_line->* TO .
ENDFORM. "create_dynamic_itab

FORM get_data.
* Select Data from table.
 SELECT * INTO CORRESPONDING FIELDS OF TABLE <TABLE> FROM (p_table).
 ENDFORM.
 "get_data

 FORM write_out.
*REPLACE FM REUSE_ALV_GRID_DISPLAY WITH REUSE_ALV_GRID_DISPLAY_LVC
 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
   EXPORTING
     I_CALLBACK_PROGRAM = SY-REPID
     IT_FIELDCAT_LVC        = ifc[]
     I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
     I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
     I_SAVE = 'X'
  TABLES
     T_OUTTAB = <TABLE>.
ENDFORM.

5 REPLIES 5
Read only

faisalatsap
Active Contributor
0 Likes
803

Hi, Rajan

Please Have a look

Faisal

Read only

Former Member
0 Likes
804

Try like following

TYPE-POOLS : abap,SLIS.
FIELD-SYMBOLS: <TABLE> TYPE STANDARD TABLE.
DATA: it_table TYPE REF TO data,
      it_line  TYPE REF TO data,
      xfc      TYPE LVC_S_FCAT,
      ifc      TYPE LVC_T_FCAT.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
 PERFORM get_structure.
 PERFORM create_dynamic_itab.
 PERFORM get_data.
 PERFORM write_out.

FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
            xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
  ref_table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[]     = ref_table_des->components[].
  LOOP AT idetails INTO xdetails.
   CLEAR xfc.
   xfc-fieldname = xdetails-name .
   xfc-datatype  = xdetails-type_kind.
   xfc-inttype   = xdetails-type_kind.
   xfc-intlen    = xdetails-length.
   xfc-decimals  = xdetails-decimals.
   APPEND xfc TO ifc.
  ENDLOOP.
ENDFORM. "get_structure

FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
 CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table = it_table.
 ASSIGN it_table->* TO <TABLE>.
* Create dynamic work area and assign to FS
* CREATE DATA it_line LIKE LINE OF .
* ASSIGN it_line->* TO .
ENDFORM. "create_dynamic_itab

FORM get_data.
* Select Data from table.
 SELECT * INTO CORRESPONDING FIELDS OF TABLE <TABLE> FROM (p_table).
 ENDFORM.
 "get_data

 FORM write_out.
*REPLACE FM REUSE_ALV_GRID_DISPLAY WITH REUSE_ALV_GRID_DISPLAY_LVC
 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
   EXPORTING
     I_CALLBACK_PROGRAM = SY-REPID
     IT_FIELDCAT_LVC        = ifc[]
     I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
     I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
     I_SAVE = 'X'
  TABLES
     T_OUTTAB = <TABLE>.
ENDFORM.

Read only

Former Member
0 Likes
803

Hello Rajan,

You are trying to pass tables parameter to exporting parameter which is of type structure.

Remove "[]" and pass only ifc to IT_FIELDCAT parameter.

Hope this helps!

Thanks,

Augustin.

Read only

venkat_o
Active Contributor
0 Likes
803

Hi Rajan, <li>Fieldcatalog ifc passed to below method type is lvc_t_fcat.


* Create dynamic internal table and assign to FS
 CALL METHOD cl_alv_table_create=>create_dynamic_table
   EXPORTING
     it_fieldcatalog = ifc
   IMPORTING
     ep_table        = it_table.
<li>But Fieldcatalog table which is passed to below function should have type SLIS_T_FIELDCAT_ALV.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       I_CALLBACK_PROGRAM       = SY-REPID
       IT_FIELDCAT              = ifc[]
*        IT_SORT                  = IST_SORT_SUBTOTAL[]
*        IT_EVENTS                = IST_EVENT[]
*        IS_LAYOUT                = WA_LAYOUT
       I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
       I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
       I_SAVE                   = 'X'
     TABLES
       T_OUTTAB                 = <fs_table>.
Thanks Venkat.O

Read only

Clemenss
Active Contributor
0 Likes
803

Hi rajan,

1 Please mark your code and push the <_> button on top. This enables us to read your code

2 it is a good approach to use the modern concept with run time type info using cl_abap_structdescr

3 There is a small bug in SAP standard: If your fields are assigned to a data dictionary type (data element) without domain (direct type info), you will run into problems using ALV

4 Please so not use method cl_alv_table_create=>create_dynamic_table because the functionality is achieved using GENERATE SUBROUTINE POOL. This includes an implicit but possibly unwanted internal COMMIT WORK.

5 Look at blogs, wiki and e-learning: I rememember there are good examples on Dynamic Internal Table

Kind regards,

Clemens