안녕하십니까? 질문이 있어서 이렇게 글을 올리게 되었습니다.^^
저번에 많은 분들의 답변으로 소계와 총계를 나타 낼 수 있었습니다.
그런데 이렇게 출력된 리스트를 엑셀로 저장을 할 때 소계와 총계를 같이 저장하고 싶은데
어떻게 해야 되는지 모르겠습니다.
엑셀로 저장을 하면 소계와 총계를 빼버리고 그냥 리스트들만 출력 됩니다.
도와주세요~ㅜㅜ
노락색 부분이 소계와 합계 구하는 부분이고,
하늘색 부분이 엑셀로 다운로드 하는 부분입니다.
REPORT TRTM_RI_065 NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZTM.
TABLES: ZTRTM_SCHEDULE.
DATA: BEGIN OF WA_LIST,
TRDAT TYPE ZTRTM_SCHEDULE-TRDAT, " 일자
SEQ TYPE ZTRTM_SCHEDULE-SEQ, " 순번
KOSTL TYPE ZTRTM_SCHEDULE-KOSTL, " 부서
KOSTLN(18) TYPE C, " 부서명
TR_GBN TYPE ZTRTM_SCHEDULE-TR_GBN, " 구분
TR_GBNN(10) TYPE C, " 구분명
REMARK TYPE ZTRTM_SCHEDULE-REMARK, " 적요
AMT TYPE ZTRTM_SCHEDULE-AMT, " 금액
PERNR TYPE ZTRTM_SCHEDULE-PERNR, " 담당자
PERNRR(10) TYPE C, " 담당자명
PHONE TYPE ZTRTM_SCHEDULE-PHONE, " 전화번호
NOTE TYPE ZTRTM_SCHEDULE-NOTE, " 비고
END OF WA_LIST.
DATA : BEGIN OF WA_DOWN,
SEQ(4),
TRDAT(8),
KOSTLN(20),
TR_GBNN(10),
REMARK(60),
AMT(15),
PERNR(8),
PERNRR(8),
PHONE(14),
NOTE(50),
END OF WA_DOWN.
*화면 분기용
DATA : IT_LIST LIKE TABLE OF WA_LIST,
IT_DOWN LIKE TABLE OF WA_DOWN.
DATA : LAST_DATE LIKE SY-DATUM.
DATA : ILIN TYPE I.
*-- SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS : S_DATE FOR ZTRTM_SCHEDULE-TRDAT NO-EXTENSION.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK BLK1.
*-- INITIALIZATION
INITIALIZATION.
PERFORM SET_DATE.
*-- TOP OF PAGE
TOP-OF-PAGE.
PERFORM TOP_OF_PAGE.
*-- START OF SELECTION
START-OF-SELECTION.
PERFORM SET_MENU_TOOLBAR.
PERFORM GET_DATA.
DESCRIBE TABLE IT_LIST LINES ILIN.
IF ILIN > 0.
MESSAGE S223 WITH ILIN.
ELSE.
MESSAGE S222.
LEAVE LIST-PROCESSING.
ENDIF.
PERFORM WRITE_DATA.
END-OF-SELECTION.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'DOWN'.
PERFORM EXCEL_DOWN.
ENDCASE.
*&---------------------------------------------------------------------
*
*& FORM SET_DATE
*&---------------------------------------------------------------------
*
* 조회일자를 초기화한다. 해당달의 1일 ~ 마지막날
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM SET_DATE.
CONCATENATE SY-DATUM+0(6) '01' INTO S_DATE-LOW.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = SY-DATUM "기준이 되는 임의의 일자
IMPORTING
LAST_DAY_OF_MONTH = LAST_DATE "해당월의 마지막 일자
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
S_DATE-HIGH = LAST_DATE.
APPEND S_DATE.
ENDFORM. " SET_DATE
*&---------------------------------------------------------------------*
*& FORM GET_DATA
*&---------------------------------------------------------------------*
* LIST DATA를 DB에서 가져온다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA.
*--조회기간에 해당하는 예상자금내역을 조회
SELECT *
INTO CORRESPONDING FIELDS OF WA_LIST
FROM ZTRTM_SCHEDULE
WHERE TRDAT IN S_DATE.
*--부서명 조회
SELECT SINGLE KTEXT
INTO WA_LIST-KOSTLN
FROM CSKT
WHERE SPRAS = SY-LANGU
AND KOKRS = 'S100'
AND KOSTL = WA_LIST-KOSTL.
*--구분명 조회
SELECT SINGLE DDTEXT
INTO WA_LIST-TR_GBNN
FROM DD07T
WHERE DOMNAME = 'ZTR_GBN'
AND DDLANGUAGE = SY-LANGU
AND AS4LOCAL = 'A'
AND DOMVALUE_L = WA_LIST-TR_GBN.
*--사원명 조회
SELECT SINGLE ENAME
INTO WA_LIST-PERNRR
FROM PA0001
WHERE PERNR = WA_LIST-PERNR.
APPEND WA_LIST TO IT_LIST.
CLEAR WA_LIST.
ENDSELECT.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA
*&---------------------------------------------------------------------*
* LIST DATA를 출력 처리한다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_DATA.
SORT IT_LIST BY TRDAT.
LOOP AT IT_LIST INTO WA_LIST.
PERFORM COL_TEXT.
WRITE : /1 SY-VLINE,
(4) WA_LIST-SEQ RIGHT-JUSTIFIED NO-GAP,
SY-VLINE NO-GAP,
(10) WA_LIST-TRDAT USING EDIT MASK '____/__/__' NO-GAP,
SY-VLINE NO-GAP,
(18) WA_LIST-KOSTLN NO-GAP,
SY-VLINE NO-GAP,
(8) WA_LIST-TR_GBNN CENTERED NO-GAP,
SY-VLINE NO-GAP,
(20) WA_LIST-REMARK NO-GAP,
SY-VLINE NO-GAP,
(15) WA_LIST-AMT NO-GAP,
SY-VLINE NO-GAP,
(10) WA_LIST-PERNR CENTERED NO-GAP,
SY-VLINE NO-GAP,
(10) WA_LIST-PERNRR CENTERED NO-GAP,
SY-VLINE NO-GAP,
(13) WA_LIST-PHONE,
SY-VLINE NO-GAP,
(30) WA_LIST-NOTE NO-GAP,
SY-VLINE NO-GAP.
WRITE: /1 SY-ULINE(151).
PERFORM COL_DAYSUM.
AT END OF TRDAT.
SUM.
WRITE : /1 SY-VLINE,
(4) '' NO-GAP,
SY-VLINE NO-GAP,
(10) '소계' NO-GAP,
SY-VLINE NO-GAP,
(18) '' NO-GAP,
SY-VLINE NO-GAP,
(8) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(20) '' NO-GAP,
SY-VLINE NO-GAP,
(15) WA_LIST-AMT NO-GAP,
SY-VLINE NO-GAP,
(10) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(10) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(13) '',
SY-VLINE NO-GAP,
(30) '' NO-GAP,
SY-VLINE NO-GAP.
WRITE: /1 SY-ULINE(151).
ENDAT.
PERFORM COL_ALLSUM.
AT LAST.
SUM.
WRITE : /1 SY-VLINE,
(4) '' NO-GAP,
SY-VLINE NO-GAP,
(10) '총계' NO-GAP,
SY-VLINE NO-GAP,
(18) '' NO-GAP,
SY-VLINE NO-GAP,
(8) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(20) '' NO-GAP,
SY-VLINE NO-GAP,
(15) WA_LIST-AMT NO-GAP,
SY-VLINE NO-GAP,
(10) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(10) '' CENTERED NO-GAP,
SY-VLINE NO-GAP,
(13) '',
SY-VLINE NO-GAP,
(30) '' NO-GAP,
SY-VLINE NO-GAP.
WRITE: /1 SY-ULINE(151).
ENDAT.
ENDLOOP.
ENDFORM. " WRITE_DATA
*&---------------------------------------------------------------------*
*& FORM TOP_OF_PAGE
*&---------------------------------------------------------------------*
* HEADING을 표시한다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
WRITE: /52 '<',
S_DATE-LOW,
'부터',
S_DATE-HIGH,
'까지의 자금지불요청 >' CENTERED.
SKIP.
WRITE: /1 SY-ULINE(151).
WRITE: /1 SY-VLINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: (4) '순번' CENTERED NO-GAP,
SY-VLINE NO-GAP, (10) '일자' CENTERED NO-GAP,
SY-VLINE NO-GAP, (18) '부서명' CENTERED NO-GAP,
SY-VLINE NO-GAP, (8) '구분종류' CENTERED NO-GAP,
SY-VLINE NO-GAP, (20) '적요' CENTERED NO-GAP,
SY-VLINE NO-GAP, (15) '금액' CENTERED NO-GAP,
SY-VLINE NO-GAP, (10) '담당자' CENTERED NO-GAP,
SY-VLINE NO-GAP, (10) '담당자명' CENTERED NO-GAP,
SY-VLINE NO-GAP, (14) '전화번호' CENTERED NO-GAP,
SY-VLINE NO-GAP, (30) '비고' CENTERED NO-GAP,
SY-VLINE NO-GAP.
WRITE: /1 SY-ULINE(151).
ENDFORM. " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& FORM EXCEL_DOWN
*&---------------------------------------------------------------------*
* EXCEL로 다운 로드를 할 수 있도록 한다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM EXCEL_DOWN.
CLEAR WA_DOWN.
REFRESH IT_DOWN.
*-- HEADER
WA_DOWN-SEQ = '순번'.
WA_DOWN-TRDAT = '일자'.
WA_DOWN-KOSTLN = '부서명'.
WA_DOWN-TR_GBNN = '구분명'.
WA_DOWN-REMARK = '적요'.
WA_DOWN-AMT = '금액'.
WA_DOWN-PERNR = '담당자'.
WA_DOWN-PERNRR = '담당자명'.
WA_DOWN-PHONE = '전화번호'.
WA_DOWN-NOTE = '비고'.
APPEND WA_DOWN TO IT_DOWN.
*-- CONTENTS
LOOP AT IT_LIST INTO WA_LIST.
MOVE-CORRESPONDING WA_LIST TO WA_DOWN.
APPEND WA_DOWN TO IT_DOWN.
CLEAR WA_DOWN.
ENDLOOP.
CALL FUNCTION 'Z_EXCEL_DOWNLOAD'
EXPORTING
FILENAME = '차주예상자금 조회.XLS'
TABLES
DOWN_TAB = IT_DOWN
EXCEPTIONS
OTHERS = 1.
ENDFORM. " EXCEL_DOWN
*&---------------------------------------------------------------------*
*& FORM SET_MENU_TOOLBAR
*&---------------------------------------------------------------------*
* 화면에 툴바를 뿌려준다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SET_MENU_TOOLBAR.
SET PF-STATUS 'PF0100'.
ENDFORM. " SET_MENU_TOOLBAR
*&---------------------------------------------------------------------*
*& FORM COL_DAYSUM
*&---------------------------------------------------------------------*
* 소계부분의 색깔을 바꿔준다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM COL_DAYSUM.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
ENDFORM. "COL_DAYSUM
*&---------------------------------------------------------------------*
*& FORM COL_ALLSUM
*&---------------------------------------------------------------------*
* 총계부분의 색깔을 바꿔준다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM COL_ALLSUM.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
ENDFORM. "COL_ALLSUM
*&---------------------------------------------------------------------*
*& FORM COL_TEXT
*&---------------------------------------------------------------------*
* 조회내역부분의 색깔을 바꿔준다.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM COL_TEXT.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
ENDFORM. "COL_TEXT
총합계와 소계를 구한 다음 반드시 ITAB에 저장 하여야 합니다.
그래야 DOWNLOAD시 나타 날수가 있습니다.
즉,IT_DOWN테이블에 저장을 하셨는지 확인 하십시요!