matinal:ABAP GRID LVS

2023-10-13 16:58:19 浏览数 (1)

代码语言:javascript复制
REPORT ZBC_ALV_01 MESSAGE-ID ZBC.

INCLUDE ZBC_ALV_01TOP.
INCLUDE ZBC_ALV_01FORM.

START-OF-SELECTION.
  PERFORM get_data.
END-OF-SELECTION.
  IF GT_STU IS NOT INITIAL.
      PERFORM display_data.
  ELSE.
      MESSAGE S001 WITH 'STUDENT INFO . iS EMPTY!' DISPLAY LIKE 'E'.
  ENDIF.
ZBC_ALV_01TOP
*&---------------------------------------------------------------------*
*&  Include           ZBC_ALV_01TOP
*&---------------------------------------------------------------------*

TYPE-POOLs: SLIS .

TYPES: BEGIN OF GTY_STU .
TYPES: BOX TYPE C LENGTH 1.
  INCLUDE STRUCTURE ZSTU .
TYPES: ICON TYPE C LENGTH 4 .  "icon
TYPES: CHECK TYPE C LENGTH 1 . "checkbox
TYPES: LINE_COLOR TYPE C LENGTH 4 . "coloer
TYPES: FIELD_COLOR TYPE LVC_T_SCOL.  " filed color
TYPES: END OF GTY_STU .

DATA: GS_VARIANT TYPE DISVARIANT.

DATA GT_STU TYPE TABLE OF GTY_STU .
DATA GS_STU TYPE GTY_STU .

DATA GS_LAYOUT TYPE SLIS_LAYOUT_ALV .

DATA GT_FIELDCAT TYPE slis_t_fieldcat_alv .
DATA GS_FIELDCAT TYPE slis_fieldcat_alv .

DATA GT_SORT TYPE slis_t_sortinfo_alv.
DATA GS_SORT TYPE slis_sortinfo_alv.

DATA GT_FILTER TYPE slis_t_filter_alv.
DATA GS_FILTER TYPE slis_filter_alv.

DATA GT_EVENTS TYPE slis_t_event.
DATA GS_EVENTS TYPE slis_alv_event.



** marco at most 9 parameters
DEFINE %%APPEND_FIELDCAT.
    CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = &1 .
    GS_FIELDCAT-FIELDNAME = &2.
    GS_FIELDCAT-OUTPUTLEN = &3.
    GS_FIELDCAT-SELTEXT_M = &4.

    CASE &2 .
      WHEN 'ZCODE'.
        GS_FIELDCAT-KEY = 'X'.
      WHEN 'ICON' .
        GS_FIELDCAT-ICON = 'X'.
      WHEN 'CHECK'.
        GS_FIELDCAT-CHECKBOX = 'X'.
      WHEN 'WEIGHT'.
        GS_FIELDCAT-DO_SUM = 'X' .
        GS_FIELDCAT-HOTSPOT = 'X' .
*        GS_FIELDCAT-QUANTITY = 'KG' .
        GS_FIELDCAT-qfieldname = 'ZUNIT' .
        GS_FIELDCAT-EMPHASIZE =  'C601' .
      WHEN 'ZUNIT'.
        GS_FIELDCAT-EMPHASIZE =  'C600' .

    ENDCASE.

    APPEND GS_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.

SELECT-OPTIONS R_ZCODE FOR GS_STU-ZSCHOOL.
ZBC_ALV_01FORM
*&---------------------------------------------------------------------*
*&  Include           ZBC_ALV_01FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .
  DATA LS_SCOL TYPE LVC_S_SCOL.
    SELECT *
      FROM ZSTU
      INTO CORRESPONDING FIELDS OF TABLE GT_STU
      WHERE ZSCHOOL IN R_ZCODE.

    LOOP AT GT_STU INTO GS_STU.
     "icon setting
      IF GS_STU-SEX = 'F'.
        GS_STU-ICON = ICON_GREEN_LIGHT.
      ELSE.
        GS_STU-ICON = ICON_RED_LIGHT.
      ENDIF.
     " line color
      IF GS_STU-SEX IS INITIAL.
        GS_STU-LINE_COLOR = 'C611'.
      ENDIF.

      "cell color
      IF GS_STU-SEX IS INITIAL.
        CLEAR LS_SCOL .
        LS_SCOL-FNAME = 'ZCODE'.  "filed
        LS_SCOL-COLOR-COL = 5 .  "color
        LS_SCOL-COLOR-INT = 0 .  "weight
        LS_SCOL-COLOR-INV = 0 .  "inverse
        APPEND LS_SCOL TO GS_STU-FIELD_COLOR .
      ENDIF.

      IF GS_STU-SEX IS INITIAL.
        CLEAR LS_SCOL .
        LS_SCOL-FNAME = 'ZNAME'.  "filed
        LS_SCOL-COLOR-COL = 4 .  "color
        LS_SCOL-COLOR-INT = 0 .  "weight
        LS_SCOL-COLOR-INV = 0 .  "inverse
        APPEND LS_SCOL TO GS_STU-FIELD_COLOR .
      ENDIF.

      MODIFY GT_STU FROM GS_STU.
    ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_data .
    PERFORM build_fieldcat.
    PERFORM build_layout.
    PERFORM build_sort.
    PERFORM build_filetr.
    PERFORM build_events.
    PERFORM build_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_alv .
    GS_VARIANT-REPORT = SY-REPID.
*    GS_VARIANT-VARIANT = '/BC01'.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
*       I_INTERFACE_CHECK                 = ' '
*       I_BYPASSING_BUFFER                = ' '
*       I_BUFFER_ACTIVE                   = ' '
        I_CALLBACK_PROGRAM                = SY-CPROG
        I_CALLBACK_PF_STATUS_SET          = 'SET_STATUS'
        I_CALLBACK_USER_COMMAND           = 'FM_USER_COMMAND'
        I_CALLBACK_TOP_OF_PAGE            = 'FM_TOP_OF_PAGE'
        I_CALLBACK_HTML_TOP_OF_PAGE       = 'FM_HTML_TOP_OF_PAGE' "high priorty
*       I_CALLBACK_HTML_END_OF_LIST       = ' '
*       I_STRUCTURE_NAME                  = ZSTU
*       I_BACKGROUND_ID                   = ' '
        I_GRID_TITLE                      = 'GRID TITLE'
*       I_GRID_SETTINGS                   =
        IS_LAYOUT                         = GS_LAYOUT
        IT_FIELDCAT                       = GT_FIELDCAT
*       IT_EXCLUDING                      =
*       IT_SPECIAL_GROUPS                 =
        IT_SORT                           = GT_SORT
        IT_FILTER                         = GT_FILTER
*       IS_SEL_HIDE                       =
*       I_DEFAULT                         = 'X'
        I_SAVE                            = 'A'
        IS_VARIANT                        = GS_VARIANT
        IT_EVENTS                         = GT_EVENTS
*       IT_EVENT_EXIT                     =
*       IS_PRINT                          =
*       IS_REPREP_ID                      =
*       I_SCREEN_START_COLUMN             = 0
*       I_SCREEN_START_LINE               = 0
*       I_SCREEN_END_COLUMN               = 0
*       I_SCREEN_END_LINE                 = 0
*       I_HTML_HEIGHT_TOP                 = 0
*       I_HTML_HEIGHT_END                 = 0
*       IT_ALV_GRAPHICS                   =
*       IT_HYPERLINK                      =
*       IT_ADD_FIELDCAT                   =
*       IT_EXCEPT_QINFO                   =
*       IR_SALV_FULLSCREEN_ADAPTER        =
*     IMPORTING
*       E_EXIT_CAUSED_BY_CALLER           =
*       ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = GT_STU
*     EXCEPTIONS
*       PROGRAM_ERROR                     = 1
*       OTHERS                            = 2
              .
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcat .
  %%APPEND_FIELDCAT: '1' 'ZCODE' '10' 'STUDENCODE',
                     '2' 'ZNAME' '20' 'STUDENNAME',
                     '3' 'SEX'  '3'  'SEX',
                     '4' 'ZSCHOOL' '10' 'ZSCHOOL',
                     '5' 'WEIGH' '10' 'WEIGHT',
                     '6' 'ZUNIT' '10' 'ZUNIT',
                     '7' 'ICON' '6'  'ICON',
                     '8' 'CHECK' '3'  'ICON'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_layout .
 GS_LAYOUT-colwidth_optimize = 'X'.
 GS_LAYOUT-ZEBRA = 'X' .
 GS_LAYOUT-KEY_HOTSPOT = 'X'.
 GS_LAYOUT-BOX_FIELDNAME = 'BOX'.
 GS_LAYOUT-DETAIL_INITIAL_LINES = 'BOX'.
 GS_LAYOUT-WINDOW_TITLEBAR = 'windows_title'.
 GS_LAYOUT-confirmation_prompt = 'X'.
 GS_LAYOUT-INFO_fieldname = 'LINE_COLOR'. "line color
 GS_LAYOUT-COLTAB_FIELDNAME = 'FIELD_COLOR'. "field color
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_SORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_sort .
    clear GS_SORT.
    GS_SORT-spos = '1'.
    GS_SORT-fieldname = 'ZSCHOOL'.
    GS_SORT-UP        = 'X'.
    GS_SORT-subtot    = 'X'.
    APPEND GS_SORT TO GT_SORT.

    clear GS_SORT.
    GS_SORT-spos = '2'.
    GS_SORT-fieldname = 'SEX'.
    GS_SORT-DOWN      = 'X'.
    APPEND GS_SORT TO GT_SORT.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FILETR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_filetr .
    clear GS_FILTER.
    GS_FILTER-fieldname = 'SEX'.
    GS_FILTER-sign0    = 'E'.
    GS_FILTER-optio    = 'EQ'.
    GS_FILTER-valuf    = ''.
    APPEND GS_FILTER to GT_FILTER.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_events .
"" regester event list in REUSE_ALV_EVENTS_GET
  CLEAR GS_EVENTS.
  GS_EVENTS-name ='PF_STATUS_SET'.
  GS_EVENTS-form ='SET_STATUS'.   "" write this subform
  APPEND GS_EVENTS TO GT_EVENTS.

  CLEAR GS_EVENTS.
  GS_EVENTS-name ='USER_COMMAND'.
  GS_EVENTS-form ='FM_USER_COMMAND'. "" write this subform
  APPEND GS_EVENTS TO GT_EVENTS.

  CLEAR GS_EVENTS.
  GS_EVENTS-name ='TOP_OF_PAGE'.
  GS_EVENTS-form ='FM_TOP_OF_PAGE'. "" write this subform
  APPEND GS_EVENTS TO GT_EVENTS.
ENDFORM.

FORM SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
*   SET PF-STATUS 'STATUS' EXCLUDING RT_EXTAB.
   SET PF-STATUS 'ST_STATUS' EXCLUDING RT_EXTAB.
ENDFORM.


FORM FM_USER_COMMAND USING R_UCOM LIKE SY-UCOMM
                           RS_SELFIELD TYPE SLIS_SELFIELD .
  CASE R_UCOM.
    WHEN '&IC1'.
     CASE RS_SELFIELD-fieldname.
       WHEN 'ZCODE'.
*         MESSAGE S000 WITH 'click studen code' RS_SELFIELD-value ' line'.
         SET PARAMETER ID 'LIF' FIELD RS_SELFIELD-VALUE.
         CALL TRANSACTION 'FK02'.
       WHEN 'WEIGH'.
       WHEN OTHERS.
         READ TABLE GT_STU INTO GS_STU INDEX RS_SELFIELD-TABINDEX.
         PERFORM display_alv_school USING GS_STU-ZSCHOOL.
     ENDCASE.

    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'CALLSF'.

    WHEN 'DOWNLOAD'.

  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_SCHOOL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv_school USING P_ZSCHOOL.
  DATA GT_SCHOOL TYPE TABLE OF ZSCHOOL_HQ_03.
  SELECT *
    FROM ZSCHOOL_HQ_03
    INTO CORRESPONDING FIELDS OF TABLE GT_SCHOOL
    WHERE ZSCHOOL = P_ZSCHOOL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
    I_STRUCTURE_NAME                  = 'ZSCHOOL_HQ_03'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
*   IT_FIELDCAT                       =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = GT_SCHOOL
 EXCEPTIONS
   PROGRAM_ERROR                     = 1
   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.


FORM FM_TOP_OF_PAGE.
  DATA LT_HEADER TYPE slis_t_listheader.
  DATA LS_HEADER TYPE slis_listheader.

  clear LS_HEADER.
  LS_HEADER-TYP = 'H'.
*  LS_HEADER-KEY = .
  LS_HEADER-INFO = 'STUDENT INFORMATION'.
  APPEND LS_HEADER TO LT_HEADER.

  clear LS_HEADER.
  LS_HEADER-TYP = 'S'.
* LS_HEADER-KEY = 'DATE'.
  LS_HEADER-INFO = SY-DATUM .
  APPEND LS_HEADER TO LT_HEADER.

  clear LS_HEADER.
  LS_HEADER-TYP = 'A'.
*  LS_HEADER-KEY = .
  LS_HEADER-INFO = 'Available School information'.
  APPEND LS_HEADER TO LT_HEADER.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = LT_HEADER
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .
ENDFORM.

FORM FM_HTML_TOP_OF_PAGE USING PR_DOCUMENT TYPE REF TO CL_DD_DOCUMENT.
  DATA LV_DATUM TYPE SDYDO_TEXT_ELEMENT.

 CALL METHOD PR_DOCUMENT->ADD_TEXT
    EXPORTING
       TEXT          = 'Student Information '
       SAP_STYLE = CL_DD_DOCUMENT=>TABLE_HEADING .
* SAP_STYLE = CL_DD_DOCUMENT=>SUCCESS .

 CALL METHOD PR_DOCUMENT->NEW_LINE .

 CALL METHOD PR_DOCUMENT->ADD_TEXT
     EXPORTING
       TEXT          = 'DATE: '
       SAP_STYLE = CL_DD_DOCUMENT=>MEDIUM .

 CALL METHOD PR_DOCUMENT->ADD_GAP
     EXPORTING
       WIDTH          = 3.

 WRITE SY-DATUM TO LV_DATUM USING EDIT MASK '____Year__Month__Day'.
 CALL METHOD PR_DOCUMENT->ADD_TEXT
     EXPORTING
       TEXT          = LV_DATUM
       SAP_STYLE = CL_DD_DOCUMENT=>MEDIUM .

 CALL METHOD PR_DOCUMENT->NEW_LINE .

 CALL METHOD PR_DOCUMENT->ADD_TEXT
     EXPORTING
       TEXT          = 'Link'
       SAP_FONTSTYLE = CL_DD_DOCUMENT=>MEDIUM .

 CALL METHOD PR_DOCUMENT->ADD_GAP
     EXPORTING
       WIDTH          = 3.

 CALL METHOD PR_DOCUMENT->ADD_LINK
     EXPORTING
       NAME         = 'google'
       URL          = 'http://bzo.bosch.com/'
       TEXT         = 'bosch' .
ENDFORM.

0 人点赞