报表练习

TYPE-POOLS: SLIS.
DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
      WA_FIELDCAT  TYPE SLIS_FIELDCAT_ALV,
      GT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV.


TYPES: BEGIN OF TY_SFLIGHT_SPFLI,
        CARRID TYPE SFLIGHT-CARRID,
        FLDATE TYPE SFLIGHT-FLDATE,
        PRICE TYPE SFLIGHT-PRICE,
        PLANETYPE TYPE SFLIGHT-PLANETYPE,
        CITYFROM TYPE SPFLI-CITYFROM,
        CITYTO TYPE SPFLI-CITYTO,
        FLTIME TYPE SPFLI-FLTIME,
       END OF TY_SFLIGHT_SPFLI.

DATA: GT_ITAB TYPE TABLE OF TY_SFLIGHT_SPFLI,
      GT_WSPACE TYPE TY_SFLIGHT_SPFLI.

PERFORM LAYOUT.
PERFORM FIELDCAT.
PERFORM GETDATA_01.
PERFORM ALVPRINT_01.




*&---------------------------------------------------------------------*
*&      Form  LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM LAYOUT .
  WA_LAYOUT-ZEBRA = 'X'.
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM.                    " LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FIELDCAT .

  WA_FIELDCAT-FIELDNAME = 'CARRID'.
  WA_FIELDCAT-SELTEXT_S = 'Airline Code'.
  WA_FIELDCAT-SELTEXT_L = 'Airline Code'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'FLDATE'.
*  WA_FIELDCAT-SELTEXT_S = 'Flight date'.
  WA_FIELDCAT-SELTEXT_L = 'Flight date'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'PRICE'.
*  WA_FIELDCAT-SELTEXT_S = 'Airfare'.
  WA_FIELDCAT-SELTEXT_L = 'Airfare'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'PLANETYPE'.
  WA_FIELDCAT-SELTEXT_S = 'Aircraft Type'.
  WA_FIELDCAT-SELTEXT_L = 'Aircraft Type'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'CITYFROM'.
*  WA_FIELDCAT-SELTEXT_S = 'Departure city'.
  WA_FIELDCAT-SELTEXT_L = 'Departure city'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'CITYTO'.
*  WA_FIELDCAT-SELTEXT_S = 'Arrival city'.
  WA_FIELDCAT-SELTEXT_L = 'Arrival city'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'FLTIME'.
*  WA_FIELDCAT-SELTEXT_S = 'Flight time'.
  WA_FIELDCAT-SELTEXT_L = 'Flight time'.
  APPEND WA_FIELDCAT TO GT_FIELDCAT.
  CLEAR WA_FIELDCAT.
ENDFORM.                    " FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  GETDATA_01
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GETDATA_01.
  SELECT
  SFLIGHT~CARRID
  SFLIGHT~FLDATE
  SFLIGHT~PRICE
  SFLIGHT~PLANETYPE
  SPFLI~CITYFROM
  SPFLI~CITYTO
  SPFLI~FLTIME
FROM SFLIGHT INNER JOIN SPFLI ON SFLIGHT~CONNID = SPFLI~CONNID
INTO CORRESPONDING FIELDS OF TABLE GT_ITAB
WHERE SFLIGHT~PLANETYPE = 'DC-10-10' AND SFLIGHT~FLDATE BETWEEN '20190101' AND '20190701'.

ENDFORM.                    " GETDATA_01
*&---------------------------------------------------------------------*
*&      Form  ALVPRINT_01
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ALVPRINT_01 .
  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                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
      IS_LAYOUT   = WA_LAYOUT
      IT_FIELDCAT = GT_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_ITAB
*   EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS      = 2
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

ENDFORM.                    " ALVPRINT_01

e

你可能感兴趣的:(报表练习)