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

Dynically change report output columns

Former Member
0 Likes
871

Hi,

In my selection-screen contains two parameters are period from

and period to.

if user enters 1 to 12 i need 12 columns in my report output.

if user enters 1 to 8 i need 8 columns in my report output.

how can i get columns dynamically?

Regards,

Suresh

1 ACCEPTED SOLUTION
Read only

h_senden2
Active Contributor
0 Likes
818

Use ALV (OO) grid, and define all the 12 columns in the output table, but do some selection based on the input screen to set the fieldcatalog.

See the Wiki or the SAP examples (BCALV*) to see an example.

regards,

Hans

5 REPLIES 5
Read only

Former Member
0 Likes
818

Check out the below report u will get the idea.

REPORT Z_DYNALV .

*Type pools declaration for ALV

TYPE-POOLS: SLIS. " ALV Global Types

*data declaration for dynamic internal table and alv

DATA: L_STRUCTURE TYPE REF TO DATA,

L_TABLE TYPE REF TO DATA,

STRUC_DESC TYPE REF TO CL_ABAP_STRUCTDESCR,

LT_LAYOUT TYPE SLIS_LAYOUT_ALV,

LS_LVC_FIELDCATALOGUE TYPE LVC_S_FCAT,

LT_LVC_FIELDCATALOGUE TYPE LVC_T_FCAT,

LS_FIELDCATALOGUE TYPE SLIS_FIELDCAT_ALV,

LT_FIELDCATALOGUE TYPE SLIS_T_FIELDCAT_ALV.

*field symbols declaration

FIELD-SYMBOLS :

<IT_TABLE> TYPE STANDARD TABLE,

<DYN_STR> TYPE ANY,

<STR_COMP> TYPE ABAP_COMPDESCR.

*declarations for grid title

DATA : T1(30),

T2(10),

T3(50).

*selection screen declaration for table input

PARAMETERS : P_TABLE LIKE DD02L-TABNAME.

*initialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

*texts for grid title

T1 = 'Dynamic ALV display for table'.

T2 = P_TABLE.

CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.

  • Dynamic creation of a structure

CREATE DATA L_STRUCTURE TYPE (P_TABLE).

ASSIGN L_STRUCTURE->* TO <DYN_STR>.

  • Fields Structure

STRUC_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).

LOOP AT STRUC_DESC->COMPONENTS ASSIGNING <STR_COMP>.

  • Build Fieldcatalog

LS_LVC_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.

  • Build Fieldcatalog

LS_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_FIELDCATALOGUE-REF_TABNAME = P_TABLE.

APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.

ENDLOOP.

  • Create internal table dynamic

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE

IMPORTING

EP_TABLE = L_TABLE.

ASSIGN L_TABLE->* TO <IT_TABLE>.

  • Read data from the table selected.

SELECT * FROM (P_TABLE)

INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.

  • ALV Layout

LT_LAYOUT-ZEBRA = 'X'.

LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LT_LAYOUT-WINDOW_TITLEBAR = T3.

*ALV output

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IS_LAYOUT = LT_LAYOUT

IT_FIELDCAT = LT_FIELDCATALOGUE

TABLES

T_OUTTAB = <IT_TABLE>

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Output:

Read only

h_senden2
Active Contributor
0 Likes
819

Use ALV (OO) grid, and define all the 12 columns in the output table, but do some selection based on the input screen to set the fieldcatalog.

See the Wiki or the SAP examples (BCALV*) to see an example.

regards,

Hans

Read only

Former Member
0 Likes
818

Hi,

With this code u can build a dynamic internal table...


  DATA: struct_type TYPE REF TO cl_abap_structdescr,
        comp_tab    TYPE cl_abap_structdescr=>component_table,
        dref        TYPE REF TO data,
        itab_type   TYPE REF TO cl_abap_tabledescr,
        wa_comp     LIKE LINE OF comp_tab,
        index1      TYPE char10,
        gr_table      TYPE REF TO cl_salv_table.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
               <dyn_wa>.

PARAMETERS:  p TYPE i.

DO p TIMES
      index1 = sy-index.
"Preparing the Column names
      CONCATENATE 'COL' '_' index1 INTO wa_comp-name.
      CONDENSE wa_comp-name NO-GAPS.
"Preparing the Column Data type
      wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
      APPEND  wa_comp TO comp_tab.
ENDDO.

"Creating the Structure...
  struct_type = cl_abap_structdescr=>create( comp_tab ).
"Creating the Table...
  itab_type   = cl_abap_tabledescr=>create( struct_type ).
  CREATE DATA dref TYPE HANDLE itab_type.
  ASSIGN dref->* TO <dyn_table>.         "Table
  CREATE DATA dref TYPE HANDLE struct_type.
  ASSIGN dref->* TO <dyn_wa>.             "Workarea

*&--Display the ALV
    cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyn_table> ).
    gr_table->display( ).

Edited by: Sukriti Saha on Oct 10, 2008 8:47 AM

Read only

Former Member
0 Likes
818

Hi,

Thanks for replies.

Regards,

Suresh

Read only

Former Member
0 Likes
818

Hi,

Thanks for replies.

Regards,

Suresh