목표: 특정 출력 필드를 포함한 ALV 출력 (SQL 조건 및 옵션/정렬 조건 포함)
SBOOK 테이블... 사진 어디갔지 나중에 수정하기
- 출력 필드:
- CARRID
- CONNID
- LOCCURAM: do_sum 옵션
- LOCCURKEY
- SQL 조건: UP TO 2000 ROWS
- 레이아웃 옵션 사용
- totals_only
- totals_before_items
- 구현 코드
*&---------------------------------------------------------------------*
*& Report Z4WEEK_ASSN002
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z4WEEK_ASSN002.
TABLES: sbook.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_sbook,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
loccuram TYPE sbook-loccuram,
loccurkey TYPE sbook-loccurkey,
END OF t_sbook.
DATA: it_sbook TYPE STANDARD TABLE OF t_sbook INITIAL SIZE 0,
wa_sbook TYPE t_sbook.
*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 = 'SBOOK'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO gt_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'CONNID'.
wa_sort-tabname = 'SBOOK'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO gt_sort.
* CLEAR wa_sort.
* wa_sort-fieldname = 'LOCCURKEY'.
* wa_sort-tabname = 'SBOOK'.
* 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 = 'LOCCURAM'.
fieldcatalog-seltext_m = 'Price of booking in local currency of airline'.
fieldcatalog-col_pos = 2.
fieldcatalog-do_sum = 'X'.
fieldcatalog-cfieldname = 'LOCCURKEY'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'LOCCURKEY'.
fieldcatalog-seltext_m = 'Local currency of airline'.
fieldcatalog-col_pos = 3.
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-totals_only = 'X'.
gd_layout-totals_before_items = '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_sbook
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 loccuram loccurkey
UP TO 2000 ROWS
FROM sbook
INTO TABLE it_sbook.
ENDFORM. " DATA_RETRIEVAL
- 구현 결과
- 사용 옵션 정리
사용 옵션 | 설명 | 코드 일부 |
UP TO N ROWS | SQL 페이징 기능 | UP TO 2000 ROWS |
totals only | 합계만 보여줌 | gd_layout-totals_only = 'X'. |
totals before items | 합계를 리스트 전에 출력함 | gd_layout-totals_before_items = 'X'. |
'강의 > SAP ERP' 카테고리의 다른 글
[6주차 과제] 검색 화면 만들기 (0) | 2025.07.30 |
---|---|
[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 |