Alv

Colapsar
X
 
  • Tiempo
  • Mostrar
Limpiar Todo
nuevos mensajes
  • MariLu
    Junior Member
    • jul
    • 5

    #1

    Alv

    Buenas!
    Tengo un problemilla con un ALV, Quiero hacer varios en la misma pantalla, recojo los datos de varias tablas en mi tabla interna, y este parece ser el problema porque si lo hago con una tabla del diccionario funciona pero con mi tabla interna me da un error que dice que 't_datos no vale como tipo de datos' He probado ya de todo y no sé como hacerlo.
    El código es el siguiente:

    type-pools: slis.

    *----------------------------------------------------------------------*
    * DECLARACION DE TABLAS *
    *----------------------------------------------------------------------*
    tables: pa0000, pa0002, pa0001.

    *----------------------------------------------------------------------*
    * VARIABLES *
    *----------------------------------------------------------------------*
    data: g_fieldcat type slis_t_fieldcat_alv,
    g_sort type slis_t_sortinfo_alv with header line,
    gt_print type slis_print_alv,
    gs_layout type slis_layout_alv,
    gt_events type slis_t_event,
    g_program type sy-repid,
    tab_name type string,
    tabname type tabname,
    w_tabix type string,
    g_lines type string.

    *----------------------------------------------------------------------*
    * TYPES *
    *----------------------------------------------------------------------*
    types: begin of ti_datos,
    pernr type pa0002-pernr,
    nachn type pa0002-nachn,
    bukrs type pa0001-bukrs.
    types: end of ti_datos.


    types: begin of alvdat,
    tabname type tabname,
    tdref type ref to data,
    end of alvdat.


    data t_alvdat type table of alvdat with non-unique key tabname.

    data: descr_struct_ref type ref to cl_abap_structdescr,
    dataref type ref to data,
    wa_fcat type lvc_s_fcat,
    it_fieldcatalog type lvc_t_fcat.

    *data ti_datos TYPE TABLE OF REF TO datos.

    data: begin of ti_cab occurs 0,
    cab type abap_compdescr.
    data: end of ti_cab.

    *----------------------------------------------------------------------*
    * TABLAS INTERNAS *
    *----------------------------------------------------------------------*
    data: t_datos type standard table of ti_datos with header line,
    t_datos_header type standard table of ti_datos with header line,
    t_datos_detail type standard table of ti_datos with header line.

    *----------------------------------------------------------------------*
    * FIELD-SYMBOLS *
    *----------------------------------------------------------------------*
    field-symbols: <line> type any,
    <field> type any,
    <component> type abap_compdescr,
    <dyn_table> type standard table,
    <fs> type any,
    <dyn_wa>,
    <table>.
    *----------------------------------------------------------------------*
    * MACROS *
    *----------------------------------------------------------------------*
    define limpiar_tabla.
    clear &1.
    refresh &1.
    end-of-definition.

    *----------------------------------------------------------------------*
    * CRITERIOS DE SELECCIÓN *
    *----------------------------------------------------------------------*
    selection-screen begin of block b01 with frame title text-b01.
    select-options s_pernr for pa0002-pernr .
    selection-screen end of block b01.


    *----------------------------------------------------------------------*
    * PRINCIPAL
    *----------------------------------------------------------------------*
    start-of-selection.
    perform rellenar_cab.
    perform obtener_datos.
    perform generar_alv.
    perform generar_alv_list.

    *---------------------------------------------------------------------*
    * FORM OBTENER_DATOS *
    *---------------------------------------------------------------------*
    * Obtenemos los datos *
    *---------------------------------------------------------------------*
    form obtener_datos.

    select pernr nachn
    into table t_datos
    from pa0002
    where pernr in s_pernr.

    if not t_datos[] is initial.
    t_datos_header[] = t_datos[].
    delete adjacent duplicates from t_datos_header
    comparing pernr.
    endif.


    endform.

    *&---------------------------------------------------------------------*
    *& Form GENERAR_ALV *
    *&---------------------------------------------------------------------*
    * Creamos el ALV *
    *----------------------------------------------------------------------*
    form generar_alv.

    if not t_datos_header[] is initial.
    perform formatear_datos_alv using g_fieldcat[].
    perform build_sort.
    endif.

    endform. "GENERAR_ALV

    *&---------------------------------------------------------------------*
    *& Form FORMATEAR_DATOS_ALV *
    *&---------------------------------------------------------------------*
    * Establecemos el catalogo de ALV. *
    *----------------------------------------------------------------------*
    form formatear_datos_alv using t_fieldcat type slis_t_fieldcat_alv.

    data: l_fieldcat type slis_fieldcat_alv.

    clear: t_fieldcat.
    refresh: t_fieldcat.

    clear l_fieldcat.
    l_fieldcat-tabname = 'T_DATOS'.
    l_fieldcat-fieldname = 'PERNR'.
    l_fieldcat-seltext_l = 'Nº personal'.
    l_fieldcat-col_pos = 1.
    l_fieldcat-outputlen = 8.
    append l_fieldcat to t_fieldcat.

    clear l_fieldcat.
    l_fieldcat-tabname = 'T_DATOS'.
    l_fieldcat-fieldname = 'NACHN'.
    l_fieldcat-seltext_l = 'Nombre'.
    l_fieldcat-col_pos = 2.
    l_fieldcat-outputlen = 50.
    append l_fieldcat to t_fieldcat.

    endform. "FORMATEAR_DATOS_ALV

    *&---------------------------------------------------------------------*
    *& Form BUILD_SORT
    *&---------------------------------------------------------------------*
    * Crea el ordenamiento del reporte
    *----------------------------------------------------------------------*
    form build_sort.

    clear g_sort.

    g_sort-spos = 1.
    g_sort-fieldname = 'PERNR'.
    g_sort-up = 'X'.
    append g_sort.

    endform.

    *---------------------------------------------------------------------*
    * FORM CREAR_ALV_LIST *
    *---------------------------------------------------------------------*
    * ........ *
    *---------------------------------------------------------------------*
    form generar_alv_list.

    data l_alvdat type alvdat.

    g_program = sy-repid.

    call function 'REUSE_ALV_BLOCK_LIST_INIT'
    exporting
    i_callback_program = g_program.

    loop at t_datos_header.
    w_tabix = sy-tabix.
    limpiar_tabla t_datos_detail.

    loop at t_datos into t_datos_detail
    where pernr eq t_datos_header-pernr.
    append t_datos_detail.
    endloop.

    concatenate 'TABLE_' w_tabix into
    tab_name.

    ***************En este perform es donde me da el error*************
    perform create_table using 't_datos' tab_name.
    ************************************************** ********
    loop at t_datos_detail assigning <line>.
    g_lines = <line>.
    assign <dyn_wa> to <table>.
    <table> = g_lines.
    append <dyn_wa> to <dyn_table>.
    endloop.

    perform crear_alv_list tables <dyn_table>.

    endloop.

    call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    exporting
    is_print = gt_print.

    endform.

    *---------------------------------------------------------------------*
    * FORM CREAR_ALV_LIST *
    *---------------------------------------------------------------------*
    * ........ *
    *---------------------------------------------------------------------*
    form crear_alv_list tables t_table structure t_datos_detail.
    *LISTADO
    call function 'REUSE_ALV_BLOCK_LIST_APPEND'
    exporting
    it_fieldcat = g_fieldcat
    is_layout = gs_layout
    i_tabname = 'T_DATOS'
    it_events = gt_events
    tables
    t_outtab = t_table.

    endform.

    *---------------------------------------------------------------------*
    * FORM CREATE_TABLE *
    *---------------------------------------------------------------------*
    * ........ *
    *---------------------------------------------------------------------*
    form create_table using my_tab tab_name.


    data l_alvdat type alvdat.


    create data dataref type (my_tab).
    assign dataref->* to <fs>.

    descr_struct_ref ?= cl_abap_typedescr=>describe_by_data( <fs> ).

    limpiar_tabla it_fieldcatalog.

    loop at descr_struct_ref->components assigning <component>.
    read table ti_cab with key cab = <component>-name.
    if sy-subrc eq 0.
    wa_fcat-fieldname = <component>-name.
    wa_fcat-ref_table = my_tab.
    wa_fcat-ref_field = <component>-name.
    append wa_fcat to it_fieldcatalog.
    endif.
    endloop.

    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = it_fieldcatalog
    importing
    ep_table = dataref
    exceptions
    others = 1.

    assign dataref->* to <dyn_table>.

    l_alvdat-tabname = tab_name.
    create data l_alvdat-tdref like line of <dyn_table>.
    assign l_alvdat-tdref->* to <dyn_wa>.

    endform. "CREATE_TABLE
    *&---------------------------------------------------------------------*
    *& Form RELLENAR_CAB
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    form rellenar_cab.
    ti_cab-cab = 'PERNR'.
    append ti_cab.
    ti_cab-cab = 'NACHN'.
    append ti_cab.
    endform. " RELLENAR_CAB
    Marilu
  • orlava
    Junior Member
    • dic
    • 9

    #2
    ¿ Has probado crearte una estructura en el diccionario de datos con los
    campos de ti_datos, y referenciarlo a esta estructura?

    Comentario

    • MariLu
      Junior Member
      • jul
      • 5

      #3
      Si eso ya lo había pensado, pero creí que se podría hacer desde código de alguna manera para que cada vez que quisiera usarlo no tuviera que crearme una estructura. Pero la verdad es que no encuentro solución y finalmente tendré que hacerlo así.
      Muchas gracias.
      Marilu

      Comentario

      Trabajando...