목표: 특정 출력 필드를 포함한 ALV 출력 (서브 토탈 및 옵션/정렬 조건 포함)
- 출력 필드:
- CARRID: key필드
- CONNID: key필드
- PRICE: do_sum = 'X'. 조건
- CURRENCY: emphasize 옵션
- PLANETYPE: emphasize 옵션
- 정렬 조건 추가
- 서브토탈 구현하기
- CARRID: sub_tot up
- CONNID: sub_tot up
- 구현 코드
*&---------------------------------------------------------------------*
*& Report Z4WEEK_ASSN001
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z4WEEK_ASSN001.
TABLES: sflight.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
currency TYPE sflight-currency,
planetype TYPE sflight-planetype,
END OF t_sflight.
DATA: it_sflight TYPE STANDARD TABLE OF t_sflight INITIAL SIZE 0,
wa_sflight TYPE t_sflight.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
DATA : t TYPE slis_t_sp_group_alv .
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM build_sort.
PERFORM display_alv_report.
*Sort options
DATA: gt_sort TYPE slis_t_sortinfo_alv.
FORM build_sort.
DATA: wa_sort TYPE slis_sortinfo_alv.
CLEAR wa_sort.
wa_sort-fieldname = 'CARRID'.
wa_sort-tabname = 'SFLIGHT'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO gt_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'CONNID'.
wa_sort-tabname = 'SFLIGHT'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO gt_sort.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
fieldcatalog-fieldname = 'CARRID'.
fieldcatalog-seltext_m = 'Airline Code'.
fieldcatalog-col_pos = 0.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'CONNID'.
fieldcatalog-seltext_m = 'Flight Connection Number'.
fieldcatalog-col_pos = 1.
fieldcatalog-lzero = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'FLDATE'.
fieldcatalog-seltext_m = 'Flight date'.
fieldcatalog-col_pos = 2.
fieldcatalog-edit_mask = '________'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'PRICE'.
fieldcatalog-seltext_m = 'Airfare'.
fieldcatalog-col_pos = 3.
fieldcatalog-cfieldname = 'CURRENCY'.
fieldcatalog-do_sum = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'CURRENCY'.
fieldcatalog-seltext_m = 'Local currency of airline'.
fieldcatalog-col_pos = 4.
fieldcatalog-emphasize = 'C600'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'PLANETYPE'.
fieldcatalog-seltext_m = 'Aircraft Type'.
fieldcatalog-col_pos = 5.
fieldcatalog-decimals_out = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-zebra = 'X'.
* gd_layout-info_fieldname = 'LINE_COLOR'.
* gd_layout-def_status = 'A'.
ENDFORM. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_sort = gt_sort
i_save = 'X'
TABLES
t_outtab = it_sflight
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
DATA: ld_color(1) TYPE c.
SELECT carrid connid fldate price currency planetype
* UP TO 10 ROWS
FROM sflight
INTO TABLE it_sflight.
ENDFORM. " DATA_RETRIEVAL
- 구현 결과
- 사용 옵션 정리
사용 옵션 | 설명 | 코드 일부 |
서브토탈 옵션 선언 | 서브토탈 옵션 사용 선언 | sort-subtot = 'X'. |
오름차순 정렬 | up: 오름차순 | sort-up = 'X'. |
숫자 필드 사용 | 필드 카탈로그에 숫자 필드를 넣어줌 | fieldcatalog-do_sum = 'X'. |
'강의 > SAP ERP' 카테고리의 다른 글
[5주차 과제] 도움말 및 검색창 출력 (0) | 2025.07.30 |
---|---|
[4주차 서브과제] 레이아웃 옵션 및 ALV 출력 (0) | 2025.07.30 |
[3주차 과제] ALV 출력(2) (0) | 2025.07.30 |
[2주차 과제] ALV 출력(1) (0) | 2025.07.30 |
[1주차 과제] SAP 설치 과정 (SAP 실습 환경 구축 with Mac) (0) | 2025.05.09 |