Foro -Documentación -Código fuente -Contacto -Empleo

Buscar

Traducir

Amazon

Z_ALV_DYNAMIC_DATA PDF Imprimir E-mail
Usar puntuación: / 0
MaloBueno 
Código fuente - Ejemplos ALV
Viernes, 02 de Enero de 2004 07:28
Muestra contenida de tablas (como transacción SE16)
REPORT z_alv_dynamic_data.
*>*********************************************************************
* This report displays data from SAP tables, views (like SE16)        *
* FM : REUSE_ALV_GRID_DISPLAY                                         *
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : 
 Esta dirección electrónica esta protegida contra spam bots. Necesita activar JavaScript para visualizarla
   HomePage : http://www.geocities.com/mpioud *
*>*********************************************************************
*    __o      __o      __o      __o      __o      __o      __o      _ *
*  _(\<._   _(\<._   _(\<._   _(\<._   _(\<._   _(\<._   _(\<._   _(\ *
* (_)/ (_) (_)/ (_) (_)/ (_) (_)/ (_) (_)/ (_) (_)/ (_) (_)/ (_) (_)/ *
***********************************************************************
TABLES::
   dd02l,                               " SAP tables
   dd03l.                               " Table Fields

 TYPE-POOLS:  slis.                      " ALV Global Types

SELECTION-SCREEN :
BEGIN OF LINE COMMENT 1(35) v_1 FOR FIELD p_table.         "#EC NEEDED
PARAMETERS p_table LIKE dd03l-tabname OBLIGATORY MEMORY ID dtb.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :
BEGIN OF LINE COMMENT 1(35) v_2 FOR FIELD p_max.           "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

*---------------------------------------------------------------------*
AT SELECTION-SCREEN.

  SELECT SINGLE * FROM dd02l WHERE tabname = p_table
                               AND as4local = 'A' 
                               AND as4vers = '0000'. 
  IF SY-SUBRC NE 0.
*   Table & is not active in the Dictionary
     MESSAGE e402(mo) WITH p_table.
  ELSEIF dd02l-tabclass = 'INTTAB'. 
*   & is a structure, not a table
     MESSAGE e403(mo) WITH p_table.
  ENDIF.

*---------------------------------------------------------------------*
INITIALIZATION.

   v_1 = 'Table'. 
   v_2 = 'Maximum of records'. 

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*      Form  F_DISPLAY_DATA
*---------------------------------------------------------------------*
FORM f_display_data.

* Macro definition
   DEFINE m_sort.
    ADD 1 TO ls_sort-spos.
     ls_sort-fieldname = &1.
     ls_sort-up = 'X'. 
    APPEND ls_sort TO lt_sort.
   END-OF-DEFINITION.

  DATA::
     l_long TYPE i,
     lp_struct TYPE REF TO DATA,
     lp_table TYPE REF TO DATA,      " Pointer to dynamic table
     of_sdescr TYPE REF TO cl_abap_structdescr,
     ls_lvc_cat TYPE lvc_s_fcat,
     lt_lvc_cat TYPE lvc_t_fcat,       " Field catalog
     ls_fieldcat TYPE slis_fieldcat_alv,
     lt_fieldcat TYPE slis_t_fieldcat_alv,  " Field catalog
     ls_layout TYPE slis_layout_alv,
     lt_sort TYPE slis_t_sortinfo_alv,  " Sort table
     ls_sort TYPE slis_sortinfo_alv.

   FIELD-SYMBOLS:
     <fieldcat> TYPE slis_fieldcat_alv,
     <lt_data> TYPE TABLE,           " Data to display
     <fs> TYPE ANY,
     <components> TYPE abap_compdescr.

* Dynamic creation of a structure
   CREATE DATA lp_struct TYPE (p_table).
   ASSIGN lp_struct->* TO <fs>.

* Fields Structure
   of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).

  LOOP AT of_sdescr->components ASSIGNING <components>.
*   Field MANDT not displayed
    IF SY-TABIX = 1 AND <components>-name = 'MANDT'. 
      CONTINUE.                        " Next loop
    ENDIF.
*   Build Fieldcatalog
     ls_lvc_cat-fieldname = <components>-name.
     ls_lvc_cat-ref_table = p_table.
    APPEND ls_lvc_cat TO lt_lvc_cat.
*   Build Fieldcatalog
     ls_fieldcat-fieldname = <components>-name.
     ls_fieldcat-ref_tabname = p_table.
    APPEND ls_fieldcat TO lt_fieldcat.
  ENDLOOP.

* Create internal table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING it_fieldcatalog = lt_lvc_cat
    IMPORTING ep_table = lp_table.

   ASSIGN lp_table->* TO <lt_data>.

* Read data
  SELECT * FROM (p_table) UP TO p_max ROWS
    INTO CORRESPONDING FIELDS OF TABLE <lt_data>
    ORDER BY PRIMARY KEY.

  IF <lt_data>[] IS INITIAL.
*   No table entries found for specified key
     MESSAGE i429(mo).
    EXIT.
  ENDIF.

* Read key field to Build Sort Table
  SELECT * FROM dd03l WHERE tabname = p_table
                        AND fieldname <> '.INCLUDE' 
                        AND as4vers = '0000' 
                        AND as4local = 'A' 
                       ORDER BY position.
    READ TABLE lt_fieldcat ASSIGNING <fieldcat>
                            WITH KEY fieldname = dd03l-fieldname.
     CHECK SY-SUBRC EQ 0.
    ADD dd03l-leng TO l_long.
    IF dd03l-keyflag = 'X'. 
*     Build Sort Table
       m_sort dd03l-fieldname.
       <fieldcat>-key = 'X'. 
    ELSEIF l_long > 150.
       <fieldcat>-tech = 'X'. 
    ENDIF.
  ENDSELECT.

   ls_layout-zebra = 'X'. 
   ls_layout-colwidth_optimize = 'X'. 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
       EXPORTING
             is_layout = ls_layout
             it_fieldcat = lt_fieldcat
             it_sort = lt_sort
       TABLES
             t_outtab = <lt_data>.

ENDFORM.                               " F_DISPLAY_DATA
*************** END OF PROGRAM Z_ALV_DYNAMIC_DATA *********************



Comentarios
Buscar
¡Sólo los usuarios registrados pueden escribir comentarios!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
home search