Mittwoch, 9. November 2011

ABAP - ALV Grid Grundbausteine

Hier die Grundbausteine um ein vernünftiges ALV Grid zu produzieren:

Im DATA-Bereich:
* Daten für Ausgabebaustein
....
TYPE-POOLS: SLIS.

DATA: FIELDCAT_ALV    TYPE SLIS_T_FIELDCAT_ALV,
      FIELDCAT_ALV_WA TYPE SLIS_FIELDCAT_ALV,
      SORT_ALV        TYPE SLIS_T_SORTINFO_ALV,
      SORT_ALV_WA     TYPE SLIS_SORTINFO_ALV,
      LAYOUT_ALV      TYPE SLIS_LAYOUT_ALV,
      FILTER_ALV      TYPE SLIS_T_FILTER_ALV,
      FILTER_ALV_WA   TYPE SLIS_FILTER_ALV,
      EVENTS_ALV      TYPE SLIS_T_EVENT,
      EVENTS_ALV_WA   TYPE SLIS_ALV_EVENT,
      HEADER_ALV      TYPE SLIS_T_LISTHEADER,
      HEADER_ALV_WA   TYPE SLIS_LISTHEADER,
      FOOTER_ALV      TYPE SLIS_T_LISTHEADER,
      FOOTER_ALV_WA   TYPE SLIS_LISTHEADER,
      GS_VARIANT      TYPE DISVARIANT.

DATA: G_REPID LIKE SY-REPID.
DATA: L_TITLE TYPE LVC_TITLE.
....
* Am Ende des Datenselektion
....
  PERFORM DISPLAY_ALVLIST.

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALVLIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_ALVLIST .
*----Anzeigevarianten
  GS_VARIANT-REPORT = SY-REPID.
*-----Headeraufbau
  HEADER_ALV_WA-TYP  = 'H'.
  HEADER_ALV_WA-INFO = '<<Überschrift>>'.
  APPEND HEADER_ALV_WA TO HEADER_ALV.


*  PERFORM STANDARD_HEADER_INFO2 CHANGING HEADER_ALV_WA.

*  APPEND HEADER_ALV_WA TO HEADER_ALV.

*  HEADER_ALV_WA-TYP  = 'S'.
*  HEADER_ALV_WA-KEY  = '<<Zweite Überschrift>>'.
**  WRITE DDAY TO HEADER_ALV_WA-INFO.
*  APPEND HEADER_ALV_WA TO HEADER_ALV.

  CLEAR HEADER_ALV_WA.
*  HEADER_ALV_WA-TYP  = 'S'.
*  APPEND HEADER_ALV_WA TO HEADER_ALV.

  G_REPID = SY-REPID.

*-----Aufbau des Feldkatalogs
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = G_REPID
      I_STRUCTURE_NAME       = '<<Ausgabestruktur aus DDIC>>'
      I_INCLNAME             = G_REPID
      I_BYPASSING_BUFFER     = 'X'
    CHANGING
      CT_FIELDCAT            = FIELDCAT_ALV
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2.

  LOOP AT FIELDCAT_ALV INTO FIELDCAT_ALV_WA.
    CASE FIELDCAT_ALV_WA-FIELDNAME.

      WHEN '<<Feldname>>'.
        FIELDCAT_ALV_WA-OUTPUTLEN = 10.
        FIELDCAT_ALV_WA-SELTEXT_S = '<<gewünschte Bezeichnung>>'.
        FIELDCAT_ALV_WA-DDICTXT   = 'S'.

      WHEN '<<Feldname2>>'.
....
* Hier alle Felder mit Überschriften versehen wenn gewünscht


    ENDCASE.
    MODIFY FIELDCAT_ALV FROM FIELDCAT_ALV_WA.
  ENDLOOP.

*-----Listlayout
*  LAYOUT_ALV-COLWIDTH_OPTIMIZE = 'X'.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM       = G_REPID
*            I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
            I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
            I_CALLBACK_TOP_OF_PAGE   = 'TOP_OF_PAGE'
            IS_LAYOUT                = LAYOUT_ALV
            IT_FIELDCAT              = FIELDCAT_ALV
            IT_SORT                  = SORT_ALV
*            IT_EVENTS                = EVENTS_ALV
*            IT_EVENTS                = ZTEVENTS
            I_SAVE                   = 'A'
*           IS_VARIANT               = GS_VARIANT
            I_GRID_TITLE             = L_TITLE
       TABLES
            T_OUTTAB                 = <<Ergebnistabelle wie Ausgabestruktur>>
       EXCEPTIONS
            PROGRAM_ERROR            = 1.


ENDFORM.                    " DISPLAY_ALVLIST

*---------------------------------------------------------------------*
*       FORM top_of_page                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = HEADER_ALV.
ENDFORM.                    "top_of_page

*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  P_UCOMM                                                       *
*  -->  P_SELFELD                                                     *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM
                        P_SELFELD TYPE SLIS_SELFIELD.

  CONSTANTS: LC_DEL LIKE SY-UCOMM VALUE 'DEL'.
  DATA: L_GRID TYPE REF TO CL_GUI_ALV_GRID.
  DATA: FIELDCAT TYPE LVC_T_FCAT.

  CASE P_UCOMM.
    WHEN LC_DEL.

...
    WHEN OTHERS.
      " ignorieren
  ENDCASE.

ENDFORM.     " USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  SET_PF_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

* DATA: ANWSTATUS LIKE PNPSTATU VALUE '<<XYZ>>'.

*  SET PF-STATUS ANWSTATUS EXCLUDING RT_EXTAB.

ENDFORM.                    " SET_PF_STATUS

Keine Kommentare:

Kommentar veröffentlichen