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

Sample ECC 6.0 program to display table structure

Former Member
0 Likes
955

As an exercise after taking a OO class, I created the following. Hope some people can find it useful. I have to admidt, I do not really understand everything it does. It was created by reviewing some of the SAP Demo programs and some notes from class. Comments are welcome.

**

Sorry about the formatting. I tried using the formatting to display as code but it did not work. Even tried to split it up into smaller sections and mark each as code, but it still did not work.

REPORT  ZCA_BOB_CL_ABAP_STRUCTDESCR.

PARAMETERS P_TABNAM type TABNAME OBLIGATORY.

Data: wa_spfli type spfli,
      r_descr type REF TO cl_abap_structdescr,
      wa_comp TYPE abap_compdescr.


** Create references to the needed ALV Global Classes
  data: lr_events type ref to cl_salv_events_table.
  data: gr_table   type ref to cl_salv_table.
  Data: r_grid TYPE REF TO cl_salv_table.
  data: r_title_text TYPE REF TO cl_alv_variant,
        r_grid_title TYPE LVC_TITLE.

Data:  abap_compdescr_tab TYPE STANDARD TABLE OF abap_compdescr
                     WITH KEY name.

Data: wk_length(6) type n,
      wk_decimals(6) type n.

START-OF-SELECTION.

**         ?=   means cast
** r_descr ?= cl_abap_typedescr=>describe_by_data( wa_spfli ).
 r_descr ?= cl_abap_typedescr=>describe_by_name( P_TABNAM ).

 Loop at r_descr->components into wa_comp.

*   write:/ wa_comp-name, wa_comp-type_kind, wa_comp-length,
*            wa_comp-decimals.
  If wa_comp-type_kind = 'C'
   or wa_comp-type_kind = 'D'
   or wa_comp-type_kind = 'N'.
    Divide wa_comp-length by 2.
  Else.
** go out to table DD02L to get LENG and DECIMALS
   SELECT single LENG DECIMALS from DD03L
     into (wk_length, wk_decimals)
      where tabname = p_tabnam
        and fieldname = wa_comp-name.
    wa_comp-length = wk_length.
    wa_comp-decimals = wk_decimals.
  Endif.
   append wa_comp to abap_compdescr_tab.

 EndLoop. 

    • Call the method to create the ALV output

TRY.

CALL METHOD CL_SALV_TABLE=>FACTORY

EXPORTING

LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE

  • R_CONTAINER =

  • CONTAINER_NAME =

IMPORTING

R_SALV_TABLE = r_grid

CHANGING

T_TABLE = abap_compdescr_tab.

CATCH CX_SALV_MSG .

ENDTRY.

*... §3 Functions

*... §3.1 activate ALV generic Functions

data: lr_functions type ref to cl_salv_functions_list.

lr_functions = r_grid->get_functions( ).

lr_functions->set_default( abap_true ).

*... set the columns technical

data: lr_columns type ref to cl_salv_columns.

lr_columns = r_grid->get_columns( ).

lr_columns->set_optimize( abap_true ).

perform set_columns_technical using lr_columns.

**----


**

    • this will overwrite the data element specified in the data dictionary

**----


**

data: l_column TYPE REF TO CL_SALV_COLUMN.

l_column ?= lr_columns->get_column( 'LENGTH' ).

l_column->set_long_text( 'Length' ).

l_column->set_medium_text( 'LENGTH' ).

l_column->set_short_text( 'LEN' ).

l_column ?= lr_columns->get_column( 'NAME' ).

l_column->set_long_text( 'Field Name' ).

l_column->set_medium_text( 'Field Nm' ).

l_column->set_short_text( 'Field' ).

l_column ?= lr_columns->get_column( 'TYPE_KIND' ).

l_column->set_long_text( 'Type' ).

l_column->set_medium_text( 'Type' ).

l_column->set_short_text( 'Type' ).

l_column ?= lr_columns->get_column( 'DECIMALS' ).

l_column->set_long_text( 'Decimals' ).

l_column->set_medium_text( 'DECIMALS' ).

l_column->set_short_text( 'DEC' ).

perform create_header_and_footer .

    • code needed for Event Handling

*lr_events = r_grid->get_event( ).

  • create object gr_events.

  • set handler gr_events->on_double_click for lr_events.

r_grid->display( ).

*&----


*

*& Form set_columns_technical

*&----


*

  • text

*----


*

form set_columns_technical using ir_columns type ref to cl_salv_columns.

data: lr_column type ref to cl_salv_column.

try.

lr_column = ir_columns->get_column( 'MANDT' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'FLOAT_FI' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'STRING_F' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'XSTRING' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'INT_FIEL' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'HEX_FIEL' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'DROPDOWN' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'TAB_INDEX' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

endform. " set_columns_technical

*&----


*

*& Form set_columns_technical

*&----


*

  • text

*----


*

form set_columns_technical using ir_columns type ref to cl_salv_columns.

data: lr_column type ref to cl_salv_column.

try.

lr_column = ir_columns->get_column( 'MANDT' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'FLOAT_FI' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'STRING_F' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'XSTRING' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'INT_FIEL' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'HEX_FIEL' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'DROPDOWN' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

try.

lr_column = ir_columns->get_column( 'TAB_INDEX' ).

lr_column->set_technical( if_salv_c_bool_sap=>true ).

catch cx_salv_not_found. "#EC NO_HANDLER

endtry.

endform. " set_columns_technical

Edited by: Bob Ackerman on Oct 7, 2010 9:29 AM

Edited by: Bob Ackerman on Oct 7, 2010 9:31 AM

Edited by: Neil Gardiner on Oct 8, 2010 1:20 PM

4 REPLIES 4
Read only

Former Member
0 Likes
880

This is a link to the code in the original post [https://doc-14-3k-docs.googleusercontent.com/docs/secure/ad8oc7ng8nd82tpkp8r54v1qsr81p1c3/h9parppirlu2qium8s2i9jbba47n8l6h/1286452800000/18076731927072634844/18076731927072634844/0B0hRsCI-bphRNjQ3ZDI3ZjAtM2MwMS00NzYwLWI3NTQtNjkxNzQ1YmMzNmY0?nonce=vvc7c51u8m01s&user=18076731927072634844&hash=k89v9fpcnmmj3bme88q9d9dbq9meavfm]

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
880

Easier way: Post a Wiki at SDN.

Read only

0 Likes
880
Read only

0 Likes
880

This message was moderated.