*&---------------------------------------------------------------------*
*& Report ZRED_TEST2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRED_TEST2 MESSAGE-ID f5 NO STANDARD PAGE HEADING LINE-SIZE 150.
TABLES: bkpf, bseg.
DATA: it_01 LIKE bkpf OCCURS 0 WITH HEADER LINE.
TYPE-POOLS:slis.
DATA: l_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.
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, "통화키
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.
******************************************************************************
* SELECTION SCREEN
******************************************************************************
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.
* READ BKPF
PERFORM read_bkpf.
* READ BSEG
PERFORM read_bseg.
* MERGE_DATA
PERFORM merge_data.
******************************************************************************
* END-OF-SELECTION
******************************************************************************
END-OF-SELECTION.
* AVL report
PERFORM build_filedcat. " 필드 지정을 위한 폼
PERFORM build_eventcat. " 이벤트 처리 폼[선택사항]
PERFORM build_sortcat. " 정렬 폼[선택사항]
PERFORM alv_write USING 'G'. " 출력 폼
* 처리에 필요한 form정보 포함. (inc)
* INCLUDE zred_test2_dataproc. "[기본 입력처리 폼 구성]
* INCLUDE zred_test2_header. "[ALV 출력처리 폼 구성]
*
* INCLUDE문장 구성 * ZRED_TEST2_DATAPROC "(dataproc) △
*--------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include ZRED_TEST2_DATAPROC
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form READ_BKPF
*&---------------------------------------------------------------------*
* BKPF 내역 READ
*----------------------------------------------------------------------*
form read_bkpf.
clear it_01. "INTERNAL 테이블 초기화
select *
into corresponding fields of table it_01
from bkpf
where bukrs = p_bukrs
and gjahr = p_gjahr
and belnr in s_belnr .
if sy-subrc <> 0. "오류체크
message s170.
leave list-processing.
endif.
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
*&---------------------------------------------------------------------*
*& 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
* INCLUDE문장 구성 * ZRED_TEST2_HEADER (header) △
*&---------------------------------------------------------------------*
*& Include ZRED_TEST2_HEADER
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form BULLD_FILEDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_filedcat ." (fieldcat)
* 회사코드
l_pos = l_pos + 1.
clear fieldcat_ln.
fieldcat_ln-col_pos = l_pos. " 필드 위치
fieldcat_ln-fieldname = 'BUKRS'. " 필드명
fieldcat_ln-reptext_ddic = '회사코드'. " 필드 레이블
append fieldcat_ln to fieldcat.
* 회계연도
l_pos = l_pos + 1.
clear fieldcat_ln.
fieldcat_ln-col_pos = l_pos.
fieldcat_ln-fieldname = 'GJAHR'.
fieldcat_ln-reptext_ddic = '회계연도'.
append fieldcat_ln to fieldcat.
* 전표번
l_pos = l_pos + 1.
clear fieldcat_ln.
fieldcat_ln-col_pos = l_pos.
fieldcat_ln-fieldname = 'BELNR'.
fieldcat_ln-reptext_ddic = '전표번'.
append fieldcat_ln to fieldcat.
endform. " BULLD_FILEDCAT
*&---------------------------------------------------------------------*
*& Form build_sortcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_sortcat. "(sortcat)
sortcat_ln-spos = '1'. " 정렬하고자 하는 필드 순서.
sortcat_ln-fieldname = 'BUKRS'. " 정렬 필드 지정.
sortcat_ln-up = 'X'. " 정렬(asc) 설정 'X', 해제 space.
sortcat_ln-down = space. " 정렬(desc) 설정 'X', 해제 space.
sortcat_ln-subtot = space. " 합계 지정 'X', 해제 space.
append sortcat_ln to sortcat.
endform. "build_sortcat
*&---------------------------------------------------------------------*
*& Form eventcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_eventcat. "(eventcat)
eventcat_ln-name = 'TOP_OF_PAGE'.
eventcat_ln-form = 'PAGE_HEADER'.
append eventcat_ln to eventcat.
endform. "build_eventcat
*&---------------------------------------------------------------------*
*& Form alv_write
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FLAG text
*----------------------------------------------------------------------*
form alv_write using flag type c. "(write)
data: pgm like sy-repid.
pgm = sy-repid.
data: disp_mode(30).
*출력 형식을 그리드와 리스트형으로 구분하여 출력.
if flag = 'G'.
disp_mode = 'REUSE_ALV_GRID_DISPLAY'. " 그리드 형식
else.
disp_mode = 'REUSE_ALV_LIST_DISPLAY'. " 리스트 형
endif.
call function disp_mode
exporting
i_callback_program = pgm
i_callback_user_command = 'USER_COMMAND'
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
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form page_header.
skip 1.
write : '전표내역 ALV 프로그램 HEADER'.
skip 1.
endform. "page_header
전표 번호 더블클릭 : Pameter id에 회사코드, 회계연도, 전표번호를 저장하고 FB03 T-Code를 Call 하면 아래와 같은 세부정보를 보여준다.