:::: MENU ::::

este blog tiene como objetivo de compartir los conocimientos prĆ”cticos de cada lenguaje de programaciĆ³n mĆ”s conocidos.

  • Lo mejor estĆ” por suceder

  • Easy to Customize

  • Customizable fonts.

miƩrcoles, 11 de septiembre de 2013

Generalmente cuando realizamos reportes en ABAP, obtenemos informaciĆ³n en formato de listado, en plano, muchas veces sin ninguna funcionalidad aparte que la simple visualizaciĆ³n de los datos.

En SAP existe algo llamado ALV (Abap List Viewer) que es el encargado de presentar nuestros reportes de una manera mƔs prƔctica y funcional, su interfaz es mƔs elegante y nos permite realizar mƔs funcionalidades que un reporte normal.

AGREGAR ICONO A ALV 1


OPCIƓN 1: 

1.TOP
Agregar campo a icon(30), estructura alv.

2.construir_catalogo
PERFORM llenar_fieldcat USING  'ICON' 'GTD_ASPIRANTE_ALV' '' 'X'
                                                       '' text-r03 text-r04 '' '' '11' 
                                CHANGING po_gtd_fieldcat. 
3.Llenar_fieldcat

IF pi_campo = 'ICON'.

    lwa_fieldcat-icon = 'X'.

 ENDIF. 

4.cargar_data
*   cargar icono dependiendo del estado del aspirante

    CASE lwa_aspirante_alv-estad.
     WHEN 'Registrado'.
                   lwa_aspirante_alv-icon = icon_checked.
      WHEN 'Aprobado'.
                   lwa_aspirante_alv-icon = icon_positive.
      WHEN 'Desaprobado'.
                   lwa_aspirante_alv-icon = icon_negative.
      WHEN 'Cargado'.
                   lwa_aspirante_alv-icon = icon_complete.
    ENDCASE. 

6.actualiazar_tabla_alv

CASE lwa_aspirante_alv-estad.
      WHEN 'Registrado'.
                   lwa_aspirante_alv-icon = icon_checked.
      WHEN 'Aprobado'.
                    lwa_aspirante_alv-icon = icon_positive.
      WHEN 'Desaprobado'.
                    lwa_aspirante_alv-icon = icon_negative.
      WHEN 'Cargado'.
                    lwa_aspirante_alv-icon = icon_complete.
    ENDCASE.



AGREGAR ICONO A ALV 2


OPCIƓN 2:

&---------------------------------------------------------------------*
*& Report  ZALV_ICON                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZALV_ICON                               .
************************************************************************
* Include Programs
************************************************************************
INCLUDE <icon>.

************************************************************************
* Database Tables
************************************************************************
TABLES: kna1.                  "Customer Master

************************************************************************
* Types
************************************************************************
TYPE-POOLS: kkblo.

************************************************************************
* Structures
************************************************************************
* Structure to hold the Color Information
DATA: BEGIN OF st_color,
        color(3) TYPE c,
      END OF st_color.

* Structure to hold the Icon Information
DATA: BEGIN OF st_icon,
        icon(4) TYPE c,
      END OF st_icon.

* ALV Field Catalog Structure
DATA: st_fieldcat   TYPE slis_fieldcat_alv.

* ALV Layout Structure
DATA: st_layout     TYPE slis_layout_alv.

************************************************************************
* Internal Tables
************************************************************************
* Output Table
DATA: BEGIN OF tbl_kna1 OCCURS 0.
        INCLUDE STRUCTURE st_icon.   "Icon Structure
        INCLUDE STRUCTURE kna1.      "Customer Master Structure
        INCLUDE STRUCTURE st_color.  "Color Structure
DATA: END OF tbl_kna1.

* ALV Field Catalog Table
DATA: tbl_fieldcat  TYPE slis_t_fieldcat_alv.

************************************************************************
* Variables
************************************************************************
DATA: fieldname(30) TYPE c,
      g_repid       LIKE sy-repid.

************************************************************************
* Start of Selection
************************************************************************
START-OF-SELECTION.

  g_repid = sy-repid.

  PERFORM get_data.

************************************************************************
* End of Selection
************************************************************************
END-OF-SELECTION.

  PERFORM do_fancy_stuff.
  PERFORM get_layout.
  PERFORM get_fieldcat.
  PERFORM create_report.


*&---------------------------------------------------------------------*
*&      Form  CREATE_REPORT
*&---------------------------------------------------------------------*
*       Learn to read the subroutine name!
*----------------------------------------------------------------------*
FORM create_report.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            i_interface_check       = ' '
            i_callback_program      = g_repid
            i_callback_user_command = 'PROCESS_USER_COMMANDS'
            it_fieldcat             = tbl_fieldcat
            i_default               = 'X'
            i_save                  = ' '
            is_layout               = st_layout
       TABLES
            t_outtab                = tbl_kna1
       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.

ENDFORM.                               " CREATE_REPORT

*&---------------------------------------------------------------------*
*&      Form  GET_FIELDCAT
*&---------------------------------------------------------------------*
*       Build the Field Catalog
*----------------------------------------------------------------------*
FORM get_fieldcat.
* Here the field catalog is created. To display more fields simply
* 'uncomment' the additional lines and add the field name. Also note
* that the field catalog is much more powerful than this. You can
* intensify fields, change the colour, assign reference fields, etc.
* Look at type slis_fieldcat_alv for more options.
  PERFORM write_fieldcat USING 'ICON'  'TBL_KNA1' '    ' 'X' 1 '2' 'X'
                               ' '.
  PERFORM write_fieldcat USING 'KUNNR' 'TBL_KNA1' 'KNA1' 'X' 2 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'NAME1' 'TBL_KNA1' 'KNA1' ' ' 3 '10' ' '
                               'X'.
  PERFORM write_fieldcat USING 'STRAS' 'TBL_KNA1' 'KNA1' ' ' 4 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'TELF1' 'TBL_KNA1' 'KNA1' ' ' 5 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'ORT01' 'TBL_KNA1' 'KNA1' ' ' 6 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'PSTLZ' 'TBL_KNA1' 'KNA1' ' ' 7 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'SORTL' 'TBL_KNA1' 'KNA1' ' ' 8 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'ERNAM' 'TBL_KNA1' 'KNA1' ' ' 9 ' ' ' '
                               ' '.
  PERFORM write_fieldcat USING 'SPRAS' 'TBL_KNA1' 'KNA1' ' ' 10 ' ' ' '
                               ' '.
*  perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 10 ' '.
*  perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 11 ' '.
*  perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 12 ' '.

ENDFORM.                               " GET_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  WRITE_FIELDCAT
*&---------------------------------------------------------------------*
*       Write the Field Catalog data to the Field Catalog Table
*----------------------------------------------------------------------*
*      -->name   Field name
*      -->tab    Table name
*      -->st     Structure Name
*      -->key    Is this field a Key?
*      -->pos    Position Number
*      -->length Field Length
*      -->icon   Display as Icon
*      -->hot    Hotspot
*----------------------------------------------------------------------*
FORM write_fieldcat USING name tab st key pos length icon hot.

  st_fieldcat-fieldname   = name.
  st_fieldcat-tabname     = tab.
  st_fieldcat-ref_tabname = st.
  st_fieldcat-key         = key.
  st_fieldcat-col_pos     = pos.
  st_fieldcat-outputlen   = length.
  st_fieldcat-icon        = icon.
  st_fieldcat-hotspot     = hot.
  APPEND st_fieldcat TO tbl_fieldcat.
  CLEAR st_fieldcat.

ENDFORM.                               " WRITE_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  PROCESS_USER_COMMANDS
*&---------------------------------------------------------------------*
*       Interactive Reporting Commands
*----------------------------------------------------------------------*
FORM process_user_commands USING syst-ucomm LIKE syst-ucomm
                                 selfield TYPE slis_selfield.

* This subroutine is called when there is user interaction in the output
* In this case if the user double clicks the Customer Number then the
* program will call transaction XD03 and display the Customer Master
* Data

  CASE syst-ucomm.
    WHEN '&IC1'.
*  get cursor field fieldname.
      READ TABLE tbl_kna1 INDEX selfield-tabindex.
      SET PARAMETER ID 'KUN' FIELD tbl_kna1-kunnr.
      CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                               " PROCESS_USER_COMMANDS

*&---------------------------------------------------------------------*
*&      Form  GET_LAYOUT
*&---------------------------------------------------------------------*
*   set the layout of the ALV.
*   add color to the row?
*----------------------------------------------------------------------*
FORM get_layout.

  st_layout-info_fieldname    = 'COLOR'.
  st_layout-colwidth_optimize = 'X'.
  st_layout-get_selinfos      = 'X'.

ENDFORM.                    " GET_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       Get some data to play with
*----------------------------------------------------------------------*
FORM get_data.

  SELECT * FROM kna1 INTO CORRESPONDING FIELDS OF TABLE tbl_kna1
         UP TO 30 ROWS.

ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  do_fancy_stuff
*&---------------------------------------------------------------------*
*       Do some fancy pants stuff for example changing the color of
*       lines and adding icons
*----------------------------------------------------------------------*
FORM do_fancy_stuff.

* Here we will demonstrate changing the color of ALV Record lines as
* well as displaying Icons
  LOOP AT tbl_kna1.
* All records where NAME1 begins with 'M', will be displayed in Bluish
* Green
    IF tbl_kna1-name1(1) EQ 'M'.
      tbl_kna1-color = 'C41'.  "Bluish Green
      MODIFY tbl_kna1 TRANSPORTING color.
    ENDIF.

* All records with no TELF1 will be displayed in White and have a
* Warning Icon
    IF tbl_kna1-telf1 IS INITIAL.
      tbl_kna1-color = 'C00'.  "White
      tbl_kna1-icon  = '@AH@'. "Warning Icon
      MODIFY tbl_kna1 TRANSPORTING icon color.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " do_fancy_stuff

0 comentarios:

Publicar un comentario

A call-to-action text Contact us