일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 유닉스
- KOSA
- function
- 스마트폼
- Smart Forms
- fi
- List box
- UTF-8
- FI 용어정리
- 머니플랜
- 오라클 함수
- Standard Function
- ALV
- 방화벽
- badi
- Java
- gimp
- EXIT
- sapa
- selection screen
- ABAP
- 이명박
- ole
- EUC-kr
- SAP
- 엑소버드
- 가계부
- alv 정형화
- 동적 쿼리
- Enhancement
- Today
- Total
Drunken Lion
Partial 로 반제, 역분개시 체크로직 본문
출처 : 갓동빈
DATA : ls_bkpf LIKE bkpf.
DATA: lt_bseg LIKE TABLE OF bseg.
DATA: ls_bseg LIKE LINE OF lt_bseg.
DATA: lv_temp_tot LIKE bseg-wrbtr,
lv_clear_tot LIKE bseg-wrbtr.
TYPES: BEGIN OF ts_bseg,
shkzg LIKE bseg-shkzg,
wrbtr LIKE bseg-wrbtr,
END OF ts_bseg.
DATA: ls_org TYPE ts_bseg,
lt_part TYPE ts_bseg OCCURS 0.
DATA: lv_only_part. "완전반제시 부분반제 전표만 있는경우
DATA: ls_ausz3 LIKE ausz_clr.
DATA: lv_amt_display(16).
CLEAR ls_bkpf.
READ TABLE t_bkpf INTO ls_bkpf INDEX 1.
* 반제 일경우 확인
IF sy-tcode = 'FB05'.
lt_bseg[] = t_bseg[].
* 부분반제시 남은 금액 확인
LOOP AT lt_bseg INTO ls_bseg WHERE rebzg <> ''.
* 원전표 금액 추출
SELECT SINGLE shkzg, wrbtr INTO @ls_org
FROM bseg
WHERE bukrs = @ls_bkpf-bukrs
AND belnr = @ls_bseg-rebzg
AND gjahr = @ls_bseg-rebzj
AND buzei = @ls_bseg-rebzz.
* 부분반제 전표 추출
SELECT shkzg, SUM( wrbtr ) INTO TABLE @lt_part
FROM bseg AS g JOIN bkpf AS f
ON g~bukrs = f~bukrs
AND g~belnr = f~belnr
AND g~gjahr = f~gjahr
WHERE g~bukrs = @ls_bkpf-bukrs
AND g~rebzg = @ls_bseg-rebzg
AND g~rebzj = @ls_bseg-rebzj
AND g~rebzz = @ls_bseg-rebzz
AND f~stblg = @space
GROUP BY shkzg.
LOOP AT lt_part INTO DATA(ls_part).
IF ls_org-shkzg = ls_part-shkzg. "동일변인경우
ls_org-wrbtr = ls_org-wrbtr + ls_part-wrbtr.
ELSE. " 상대변인경우
ls_org-wrbtr = ls_org-wrbtr - ls_part-wrbtr.
ENDIF.
ENDLOOP.
* 현재 전표의 금액도 같이 계산
IF ls_org-shkzg = ls_bseg-shkzg. "동일변인경우 원전표에 추가
ls_org-wrbtr = ls_org-wrbtr + ls_bseg-wrbtr.
ELSE. " 상대변인경우 차감
ls_org-wrbtr = ls_org-wrbtr - ls_bseg-wrbtr.
ENDIF.
IF ls_org-wrbtr < 0.
CLEAR lv_temp_tot.
lv_temp_tot = abs( ls_org-wrbtr ).
WRITE lv_temp_tot TO lv_amt_display CURRENCY ls_bkpf-waers.
MESSAGE e000(zmfi1) WITH ls_bseg-rebzg TEXT-m06 lv_amt_display TEXT-m07 .
" 전표에 금액 " 만큼 반제 금액 부족, 반제금액을 확인하세요
* MESSAGE e000(zmfi1) WITH ls_bseg-rebzg TEXT-m04.
" 반제할 금액이 부족합니다. 부분반제된 금액을 확인하세요
EXIT.
ENDIF.
ENDLOOP.
* 완전반제 대상 포함여부 확인
LOOP AT lt_bseg INTO ls_bseg WHERE augbl = '*'.
CLEAR lv_temp_tot.
lv_only_part = 'X'.
* 부분반제 전표는 제외한다.
LOOP AT t_ausz3 INTO ls_ausz3 WHERE agbuz = ls_bseg-buzei.
SELECT shkzg, SUM( wrbtr ) INTO TABLE @lt_part
FROM bseg AS g JOIN bkpf AS f
ON g~bukrs = f~bukrs
AND g~belnr = f~belnr
AND g~gjahr = f~gjahr
WHERE g~bukrs = @ls_ausz3-bukrs
AND g~belnr = @ls_ausz3-belnr
AND g~gjahr = @ls_ausz3-gjahr
AND g~buzei = @ls_ausz3-buzei
AND g~rebzg <> @space " 부분반제 제외용
AND f~stblg = @space
GROUP BY shkzg.
IF sy-subrc = 0. " 부분반제 전표 제외
CONTINUE.
ENDIF.
CLEAR lv_only_part. " 원전표가 포함되어 있기 때문에 삭제
SELECT shkzg, SUM( wrbtr ) INTO TABLE @lt_part
FROM bseg AS g JOIN bkpf AS f
ON g~bukrs = f~bukrs
AND g~belnr = f~belnr
AND g~gjahr = f~gjahr
WHERE g~bukrs = @ls_ausz3-bukrs
AND g~rebzg = @ls_ausz3-belnr
AND g~rebzj = @ls_ausz3-gjahr
AND g~rebzz = @ls_ausz3-buzei
AND f~stblg = @space
GROUP BY shkzg.
lv_temp_tot = ls_ausz3-wrbtr.
LOOP AT lt_part INTO ls_part.
IF ls_ausz3-shkzg = ls_part-shkzg. "동일변인경우 추가
lv_temp_tot = lv_temp_tot + ls_part-wrbtr.
ELSE. " 상대변인경우 차감
lv_temp_tot = lv_temp_tot - ls_part-wrbtr.
ENDIF.
ENDLOOP.
* 현재 전표의 금액도 같이 계산
IF ls_ausz3-shkzg = ls_bseg-shkzg. "동일변인경우 원전표에 추가
lv_temp_tot = lv_temp_tot + ls_bseg-wrbtr.
ELSE. " 상대변인경우 차감
lv_temp_tot = lv_temp_tot - ls_bseg-wrbtr.
ENDIF.
ENDLOOP.
IF lv_temp_tot < 0.
lv_temp_tot = abs( lv_temp_tot ).
WRITE lv_temp_tot TO lv_amt_display CURRENCY ls_bkpf-waers.
MESSAGE e000(zmfi1) WITH ls_ausz3-belnr TEXT-m06 lv_amt_display TEXT-m07 .
" 전표에 금액 " 만큼 반제 금액 부족, 반제금액을 확인하세요
EXIT.
ENDIF.
IF lv_only_part = 'X'.
MESSAGE e000(zmfi1) WITH ls_ausz3-belnr TEXT-m09 .
" 전표만 단독으로 반제불가능합니다. 원천전표와 같이 반제하세요
EXIT.
ENDIF.
ENDLOOP.
ENDIF. " FB05일때 확인
* 역분개일때 부분반제 된것이 있는지 확인
IF sy-tcode = 'FB08'.
* 부분반제시 남은 금액 확인
LOOP AT t_ausz3 INTO ls_ausz3 .
* 공통코드에 존재하면 역분개 반제여부 체크제외
SELECT SINGLE chr05 INTO @DATA(lv_check)
FROM zcmt0011
WHERE zcode = 'Z014'
AND chr04 = @ls_ausz3-bukrs
AND chr05 = @ls_ausz3-gjahr
AND chr06 = @ls_ausz3-belnr.
IF sy-subrc = 0.
CONTINUE.
ENDIF.
SELECT SINGLE f~belnr INTO @DATA(lv_belnr_part)
FROM bseg AS g JOIN bkpf AS f
ON g~bukrs = f~bukrs
AND g~belnr = f~belnr
AND g~gjahr = f~gjahr
WHERE g~bukrs = @ls_bkpf-bukrs
AND g~rebzg = @ls_ausz3-belnr
AND g~rebzj = @ls_ausz3-gjahr
AND g~rebzz = @ls_ausz3-buzei
AND f~stblg = @space.
IF sy-subrc = 0.
MESSAGE e000(zmfi1) WITH lv_belnr_part TEXT-m05.
" 전표로 반제가 존재합니다. 부분반제된 전표 취소후 역분개 하세요
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
'SAP > FI' 카테고리의 다른 글
자산 생성시 클래스별 기본값 세팅 (0) | 2021.02.05 |
---|---|
Classic AA, New AA 비교? (0) | 2020.11.11 |
BP Enhance (0) | 2020.11.10 |
FI 역분개 전표 역분개 방지. (0) | 2020.11.07 |
BP 조회 ( CALL TRANSACTION ) (0) | 2020.10.07 |