REPORT Z_SWR_H1_ALV MESSAGE-ID f5 NO STANDARD PAGE HEADING
LINE-SIZE 150
LINE-COUNT 65.
************************************************************************
* TABLES
************************************************************************
TABLES : bkpf, "Accounting Document Header
bseg. "Accounting Document Segment
************************************************************************
* DATA ( &TYPE)
************************************************************************
DATA : it_01 LIKE bkpf OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF it_02 OCCURS 0,
bukrs LIKE bkpf-bukrs, "회사코드
belnr LIKE bkpf-belnr, "전표번호
gjahr LIKE bkpf-gjahr, "회계연도
blart LIKE bkpf-blart, "전표유형
bldat LIKE bkpf-bldat, "증빙일
budat LIKE bkpf-budat, "전기일
stblg LIKE bkpf-stblg, "역분개전표
stjah LIKE bkpf-stjah, "역분개저너표 회계연도
waers LIKE bkpf-waers, "통화키
monat LIKE bkpf-monat, "회계기간
buzei LIKE bseg-buzei, "개별항목번호
bschl LIKE bseg-bschl, "전기키
shkzg LIKE bseg-shkzg, "차변/대변지시자
dmbtr LIKE bseg-dmbtr, "현지통화금액
wrbtr LIKE bseg-wrbtr, "전표통화금액
sgtxt LIKE bseg-sgtxt, "적요
END OF it_02.
TYPE-POOLS : slis.
DATA : 1_pos TYPE i VALUE 0.
DATA : fieldcat TYPE slis_t_fieldcat_alv,
fieldcat_ln LIKE LINE OF fieldcat.
DATA : sortcat TYPE slis_t_sortinfo_alv,
sortcat_ln LIKE LINE OF sortcat.
DATA : eventcat TYPE slis_t_event,
eventcat_ln like line of eventcat.
************************************************************************
*SELECTION SCREEN( SELECT OPTIONS & PARAMETERS)
************************************************************************
selection-screen BEGIN OF block b1 WITH frame title text-001.
PARAMETERS : p_bukrs LIKE bkpf-bukrs OBLIGATORY MEMORY ID buk,
p_gjahr LIKE bkpf-gjahr OBLIGATORY DEFAULT sy-datum,
SELECT-OPTIONS : s_belnr FOR bkpf-belnr.
SELECTION-SCREEN END OF BLOCK b1.
************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
* BKPF READ
PERFORM read_bkpf.
* BSEG READ
PERFORM read_bseg.
* IT_02 -> IT_01
PERFORM merge_data.
***********************************************************************
* END-OF_SELECTION
***********************************************************************
END-OF-SELECTION.
* PERFORM write_data.
PERFORM build_fieldcat.
PERFORM build_sortcat.
PERFORM build_eventcat.
PERFORM ALV_WRITE.
*&---------------------------------------------------------------------*
*& Form READ_BKPF
*&---------------------------------------------------------------------*
* BKPF 내역 READ
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM read_bkpf.
CLEAR it_01.
REFRESH it_01. "모든 INTERNAL TABLE이 가지고 있는 ENTRY삭제
SELECT *
INTO CORRESPONDING FIELDS OF TABLE it_01
FROM bkpf
WHERE bukrs = p_bukrs
AND gjahr = p_gjahr
AND belnr IN s_belnr.
ENDFORM. " READ_BKPF
*&---------------------------------------------------------------------*
*& Form READ_BSEG
*&---------------------------------------------------------------------*
* BSEG 내역 READ
*-----------------------------------------------------------------------
FORM read_bseg.
CLEAR it_02.
REFRESH it_02.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE it_02
FROM bseg
WHERE bukrs = p_bukrs
AND gjahr = p_gjahr
AND belnr IN s_belnr.
ENDFORM. " READ_BSEG
*IT_02의 정보를 IT_01에 넣어주도록 하자
*&----------------------------------------------------------------------
*& FORM MERGE_DATA
*&----------------------------------------------------------------------
* IT_01 + iT_02 MERGE
*&---------------------------------------------------------------------*
FORM merge_data.
SORT it_01 BY bukrs gjahr belnr.
SORT it_02 BY bukrs gjahr belnr.
LOOP AT it_02.
READ TABLE it_01 WITH KEY bukrs = it_02-bukrs
gjahr = it_02-gjahr
belnr = it_02-belnr
BINARY SEARCH.
IF sy-subrc <> 0.
ELSE.
it_02-blart = it_01-blart.
it_02-bldat = it_01-bldat.
it_02-budat = it_01-budat.
it_02-stblg = it_01-stblg.
it_02-stjah = it_01-stjah.
it_02-waers = it_01-waers.
ENDIF.
IF it_02-shkzg = 'H'. "대변이면,
it_02-dmbtr = it_02-dmbtr * -1.
it_02-wrbtr = it_02-wrbtr * -1.
ENDIF.
MODIFY it_02.
ENDLOOP.
ENDFORM. "MERGE_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BUKRS'.
fieldcat_ln-key = 'X'. "필드고정역할, 색이다르게 나타남!!
fieldcat_ln-emphasize = 'C600'. "COL_NEGATIVE색이다
* 색이두가지(빨강,파랑)가 같이 나타남(실행시에)
fieldcat_ln-reptext_ddic = '회사코드'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'GJAHR'.
* fieldcat_ln-key = 'X'.
fieldcat_ln-reptext_ddic = '회계연도'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BELNR'.
fieldcat_ln-reptext_ddic = '전표번호'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BLART'.
fieldcat_ln-reptext_ddic = '전표유형'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BLDAT'.
fieldcat_ln-emphasize = 'C400'.
fieldcat_ln-reptext_ddic = '증빙일'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BUDAT'.
fieldcat_ln-emphasize = 'C100'.
fieldcat_ln-reptext_ddic = '전기일'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'WARES'.
fieldcat_ln-reptext_ddic = '통화키'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BUZEI'.
fieldcat_ln-reptext_ddic = '항목'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'BSCHL'.
fieldcat_ln-reptext_ddic = '전기키'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'DMBTR'.
fieldcat_ln-currency = 'KRW'.
fieldcat_ln-reptext_ddic = '현지통화금액'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'WRBTR'.
fieldcat_ln-do_sum = 'X'.
fieldcat_ln-reptext_ddic = '전표통화금액'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'SGTXT'.
fieldcat_ln-reptext_ddic = '적요'.
APPEND fieldcat_ln TO fieldcat.
1_pos = 1_pos + 1.
CLEAR fieldcat_ln.
fieldcat_ln-col_pos = 1_pos.
fieldcat_ln-fieldname = 'STBLG'.
fieldcat_ln-reptext_ddic = '역분개전표'.
APPEND fieldcat_ln TO fieldcat.
ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form build_sortcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_sortcat.
sortcat_ln-spos = '1'. "정렬하고자 하는 필드 순서를 지정
sortcat_ln-fieldname = 'BUKRS'. "정렬하고자하는 FIELD명
sortcat_ln-up = 'X'. "오름차순
sortcat_ln-down = space. "내림차순정렬
sortcat_ln-subtot = space.
APPEND sortcat_ln TO sortcat.
ENDFORM. " build_sortcat
*&---------------------------------------------------------------------*
*& Form build_eventcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_eventcat.
EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
EVENTCAT_LN-FORM = 'PAGE_HEADER'.
APPEND EVENTCAT_ln TO EVENTCAT.
endform. " build_eventcat
*&---------------------------------------------------------------------*
*& Form ALV_WRITE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form ALV_WRITE.
DATA : PGM LIKE SY-REPID. "PGM 변수선언
PGM = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING "Function으로 Data전송
I_CALLBACK_PROGRAM = PGM
I_CLAABACK_USER_COMMNAD = 'USER_COMMMAND'
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'U'
IT_EVENTS = EVENTCAT
TABLES
T_OUTTAB = IT_02
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
endform. " ALV_WRITE
*&---------------------------------------------------------------------*
* 사용자 EVENT
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
*더블클릭
WHEN '&IC1'.
READ TABLE it_02 INDEX rs_selfield-tabindex.
IF it_02-belnr <> ' '.
SET PARAMETER ID 'BLN' FIELD it_02-belnr.
SET PARAMETER ID 'BUK' FIELD it_02-bukrs.
SET PARAMETER ID 'GJR' FIELD it_02-gjahr.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------
*
*& Form PAGE_HEADER
*&---------------------------------------------------------------------
FORM PAGE_HEADER.
SKIP 1.
WRITE : '전표내역 ALV 프로그램 HEADER'.
ENDFORM.
ALV조회시 Double click해서 해당내역을 조회하려 합니다만(FB03)
어찌된 일인지 Double Click해봐도 먹통이네요...;;;
고수분들의 답변 기다립니다..ㅠ
FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM
P_SELFIELD TYPE SLIS_SELFIELD.
*- " ALV Refresh : 변경된 Internal Table 값에 따라서 화면 변경.
P_SELFIELD-REFRESH = 'X'.
P_SELFIELD-COL_STABLE = 'X'.
P_SELFIELD-ROW_STABLE = 'X'.
P_SELFIELD-IGNORE_MULTI = 'X'.
CASE P_UCOMM.
WHEN '&IC1'.
CHECK P_SELFIELD-TABINDEX > 0.
READ TABLE IT_TBL INDEX P_SELFIELD-TABINDEX.
CASE P_SELFIELD-FIELDNAME.
WHEN 'BELNR'.
SET PARAMETER ID 'BLN' FIELD it_02-belnr.
SET PARAMETER ID 'BUK' FIELD it_02-bukrs.
SET PARAMETER ID 'GJR' FIELD it_02-gjahr.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDFORM. "user_command
참고하세요..