*&---------------------------------------------------------------------*
*& REPORT Z_TRFI0003
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_OO_TEST.
TYPE-POOLS:SLIS.
TABLES:FAGLFLEXT,LFC1,LFC3,KNC1,KNC3,BSIK,BSAK,BSID,BSAD,BSEG,SKA1,SETHIER_CO,LFA1,KNA1,TKA02.
TYPES:
* LFC1
BEGIN OF S_LFC1,
LIFNR TYPE LFC1-LIFNR,
UMSAV TYPE LFC1-UMSAV,
UM01S TYPE UMXXS,
UM02S TYPE UMXXS,
UM03S TYPE UMXXS,
UM04S TYPE UMXXS,
UM05S TYPE UMXXS,
UM06S TYPE UMXXS,
UM07S TYPE UMXXS,
UM08S TYPE UMXXS,
UM09S TYPE UMXXS,
UM10S TYPE UMXXS,
UM11S TYPE UMXXS,
UM12S TYPE UMXXS,
UM13S TYPE UMXXS,
UM14S TYPE UMXXS,
UM15S TYPE UMXXS,
UM16S TYPE UMXXS,
UM01H TYPE UMXXH,
UM02H TYPE UMXXH,
UM03H TYPE UMXXH,
UM04H TYPE UMXXH,
UM05H TYPE UMXXH,
UM06H TYPE UMXXH,
UM07H TYPE UMXXH,
UM08H TYPE UMXXH,
UM09H TYPE UMXXH,
UM10H TYPE UMXXH,
UM11H TYPE UMXXH,
UM12H TYPE UMXXH,
UM13H TYPE UMXXH,
UM14H TYPE UMXXH,
UM15H TYPE UMXXH,
UM16H TYPE UMXXH,
END OF S_LFC1,
IT_LFC1 TYPE STANDARD TABLE OF S_LFC1 ,
*LFC3
BEGIN OF S_LFC3,
LIFNR TYPE LFC3-LIFNR,
SHBKZ TYPE LFC3-SHBKZ,
SALDV TYPE LFC3-SALDV,
END OF S_LFC3,
IT_LFC3 TYPE STANDARD TABLE OF S_LFC3,
*LFB1
BEGIN OF S_LFB1,
LIFNR TYPE LIFNR,
BUKRS TYPE BUKRS,
AKONT TYPE AKONT,
END OF S_LFB1,
IT_LFB1 TYPE STANDARD TABLE OF S_LFB1,
*T074
BEGIN OF S_T074,
SKONT TYPE SKONT,
UMSKZ TYPE UMSKZ,
HKONT TYPE HKONT,
END OF S_T074,
IT_T074 TYPE STANDARD TABLE OF S_T074,
BEGIN OF S_T001,
KTOPL TYPE T001-KTOPL,
BUTXT TYPE T001-BUTXT,
END OF S_T001,
IT_T001 TYPE STANDARD TABLE OF S_T001,
* BSIK
BEGIN OF S_BSIK,
HKONT TYPE HKONT,
LIFNR TYPE LIFNR,
SHKZG TYPE SHKZG,
GJAHR TYPE GJAHR,
MONAT TYPE MONAT,
DMBTR TYPE DMBTR,
WAERS TYPE WAERS,
END OF S_BSIK,
IT_BSIK TYPE STANDARD TABLE OF S_BSIK,
*BSAK
BEGIN OF S_BSAK,
HKONT TYPE HKONT,
LIFNR TYPE LIFNR,
SHKZG TYPE SHKZG,
GJAHR TYPE GJAHR,
MONAT TYPE MONAT,
DMBTR TYPE DMBTR,
WAERS TYPE WAERS,
END OF S_BSAK,
IT_BSAK TYPE STANDARD TABLE OF S_BSAK,
* DATAOUT2
BEGIN OF S_DATAOUT2,
AKONT TYPE LFB1-AKONT, "統制鑑定
LIFNR TYPE LFC1-LIFNR, "仕入先
UMSAV TYPE LFC1-UMSAV,"前期残高
UMS TYPE UMXXS,"J方
UMH TYPE UMXXS,"貸方
UML TYPE UMXXS,"当期残高
WAERS TYPE BSIK-WAERS, "通貨コード
END OF S_DATAOUT2,
IT_DATAOUT2 TYPE STANDARD TABLE OF S_DATAOUT2,
* DATAOUT21
BEGIN OF S_DATAOUT21,
AKONT TYPE LFB1-AKONT, "統制鑑定
LIFNR TYPE LFC1-LIFNR, "仕入先
UMSAV TYPE LFC1-UMSAV,"前期残高
UMS TYPE UMXXS,"J方
UMH TYPE UMXXS,"貸方
UML TYPE UMXXS,"当期残高
END OF S_DATAOUT21,
IT_DATAOUT21 TYPE STANDARD TABLE OF S_DATAOUT21,
BEGIN OF S_SHBKZ,
SIGN(1),
OPTION(2),
LOW TYPE LFC3-SHBKZ,
END OF S_SHBKZ,
IT_SHBKZ TYPE RANGE OF LFC3-SHBKZ,
"STANDARD TABLE OF S_SHBKZ.
BEGIN OF S_UMSAV,
SIGN(1),
OPTION(2),
UMSAV TYPE LFC1-UMSAV,
END OF S_UMSAV,
IT_UMSAV TYPE RANGE OF LFC1-UMSAV,
"会計期間レンジ
BEGIN OF T_STR_RPMAX,
SIGN(1) TYPE C,
OPTION(2) TYPE C,
LOW TYPE FAGLFLEXT-RPMAX,"会計期間
HIGH TYPE FAGLFLEXT-RPMAX,
END OF T_STR_RPMAX,
IT_RPMAX TYPE STANDARD TABLE OF T_STR_RPMAX.
TYPES:SLIS_T_FIELDCAT_ALV TYPE SLIS_FIELDCAT_ALV OCCURS 1.
DATA: G_REPID LIKE SY-REPID,
LINE TYPE I,
CS_BNAME TYPE STRING
VALUE ‘会社コード‘, "会社コードテキスト
IT_RPMAX TYPE IT_RPMAX, "会計期間レンジテーブル
RPMAX TYPE FAGLFLEXT-RPMAX, "会計期間
PERIV TYPE T001-PERIV, "会計年度バリアント
DATELOW TYPE SY-DATUM, "開始会計期間の最終日
DATEHIGH TYPE SY-DATUM, "終了会計期間の最終日
EXIT_FLG TYPE I ,
KTOPL TYPE T001-KTOPL,
BUTXT TYPE T001-BUTXT, "会社名前 "勘定コード表
WAERS TYPE T001-WAERS. "通貨コード
DATA: I_TKA02 LIKE TABLE OF TKA02 WITH HEADER LINE,
W_TKA02 LIKE I_TKA02.
* DATA: I_K_GROUP_REMOTE_READ LIKE K_GROUP_REMOTE_READ.
* W_K_GROUP_REMOTE_READ LIKE I_K_GROUP_REMOTE_READ.
DATA : I_FAGLFLEXT LIKE TABLE OF FAGLFLEXT,
W_FAGLFLEXT LIKE I_FAGLFLEXT.
*仕入先DATA 定義
DATA: W_LFC1 TYPE S_LFC1 ,
I_LFC1 TYPE IT_LFC1,
I_LFC3 TYPE IT_LFC3 ,
W_LFC3 TYPE S_LFC3,
W_LFB1 TYPE S_LFB1,
I_LFB1 TYPE IT_LFB1,
I_T074 TYPE IT_T074,
W_T074 TYPE S_T074,
I_BSIK TYPE IT_BSIK,
W_BSIK TYPE S_BSIK,
I_BSAK TYPE IT_BSAK,
W_BSAK TYPE S_BSAK,
I_T001 TYPE IT_T001,
W_T001 TYPE S_T001,
I_DATAOUT2 TYPE IT_DATAOUT2,
W_DATAOUT2 TYPE S_DATAOUT2,
I_DATAOUT21 TYPE IT_DATAOUT21,
W_DATAOUT21 TYPE S_DATAOUT21,
I_SHBKZ TYPE IT_SHBKZ,
W_SHBKZ TYPE S_SHBKZ,
I_UMSAV TYPE IT_UMSAV,
W_UMSAV TYPE S_UMSAV.
DATA:UMS TYPE UMXXS,"J方
UMH TYPE UMXXS,"貸方
UML TYPE UMXXS."当期残高
DATA: W_FIELD TYPE SLIS_FIELDCAT_ALV,
I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
CONSTANTS CNS_PF_STATUS TYPE SLIS_FORMNAME VALUE ‘ALV_PF_STATUS‘ ."ALV自定义按钮
CONSTANTS CNS_USER_COMMAND TYPE SLIS_FORMNAME VALUE‘ALV_USER_COMMAND‘."ALV自定义按钮响应事件
DATA: V_EXCEL TYPE OBJ_RECORD ,
V_BOOK TYPE OBJ_RECORD ,
V_CELL TYPE OBJ_RECORD ,
V_FONT TYPE OBJ_RECORD ,
V_RANGE TYPE OBJ_RECORD ,
V_COLUMN TYPE OBJ_RECORD .
DATA: I_KNC1 LIKE TABLE OF KNC1 WITH HEADER LINE,
I_KNC3 LIKE TABLE OF KNC3 WITH HEADER LINE,
I_KNB1 LIKE TABLE OF KNB1 WITH HEADER LINE,
"I_T074 LIKE TABLE OF T074 ,
I_BSAD LIKE TABLE OF BSAD,
I_BSID LIKE TABLE OF BSID,
I_SKA1 LIKE TABLE OF SKA1.
DATA: I_BKPF TYPE STANDARD TABLE OF BKPF,
I_BSEG TYPE STANDARD TABLE OF BSEG,
"I_BSIK TYPE STANDARD TABLE OF BSIK,
"I_BSAK TYPE STANDARD TABLE OF BSAK,
"I_BSID TYPE STANDARD TABLE OF BSID,
"I_BSAD TYPE STANDARD TABLE OF BSAD,
I_SKAT TYPE STANDARD TABLE OF SKAT,
I_SETHEADERT TYPE STANDARD TABLE OF SETHEADERT.
*选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
"会社コード "事業領域
PARAMETERS:
P_BUKRS TYPE T001-BUKRS OBLIGATORY MEMORY ID BUK,
P_RBUSA TYPE FAGLFLEXT-RBUSA MODIF ID RBU .
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-004.
"会計年度
PARAMETERS P_RYEAR TYPE FAGLFLEXT-RYEAR OBLIGATORY MEMORY ID GJR.
SELECT-OPTIONS
"会計期間
S_RPAMAX FOR FAGLFLEXT-RPMAX NO-EXTENSION OBLIGATORY.
"決算仕訳除外
PARAMETERS: CB_CHAN1 AS CHECKBOX .
SELECTION-SCREEN END OF BLOCK B4.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
"勘定科目
SELECT-OPTIONS: S_SAKNR FOR SKA1-SAKAN.
"仕訳除外特定勘定
SELECT-OPTIONS: S_HKONT FOR SKA1-SAKNR MODIF ID HKO.
*SELECT-OPTIONS P_RBUSA FOR FAGLFLEXT-RBUSA.
SELECTION-SCREEN BEGIN OF LINE.
"利益センターグループ
PARAMETERS: RB_SELE1 RADIOBUTTON GROUP RAD1 DEFAULT ‘X‘ USER-COMMAND SINGLECLICK .
SELECTION-SCREEN COMMENT 5(20) TEXT-005.
SELECTION-SCREEN POSITION 25.
SELECT-OPTIONS RB_NOTE1 FOR SETHIER_CO-GROUPNAME DEFAULT ‘X‘ MODIF ID RB1.
SELECTION-SCREEN END OF LINE.
"仕入先コード
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_SELE2 RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN COMMENT 5(20) TEXT-006.
SELECTION-SCREEN POSITION 25.
SELECT-OPTIONS RB_NOTE2 FOR LFA1-LIFNR MODIF ID RB2.
SELECTION-SCREEN END OF LINE.
"得意先コード
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: RB_SELE3 RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN COMMENT 5(20) TEXT-007.
SELECTION-SCREEN POSITION 25.
SELECT-OPTIONS RB_NOTE3 FOR KNA1-KUNNR MODIF ID RB3.
SELECTION-SCREEN END OF LINE.
"反対仕訳除外
PARAMETERS CB_CHAN2 AS CHECKBOX DEFAULT ‘X‘.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.
PARAMETERS: RB_MON1 RADIOBUTTON GROUP RAD2 DEFAULT ‘X‘,
RB_MON2 RADIOBUTTON GROUP RAD2,
RB_MON3 RADIOBUTTON GROUP RAD2.
SELECTION-SCREEN END OF BLOCK B3.
INITIALIZATION .
G_REPID = SY-REPID.
*&---------------------------------------------------------------------*
*& 前処理
*&---------------------------------------------------------------------*
* 事業領域の状態変化
AT SELECTION-SCREEN OUTPUT.
CASE ‘X ‘ .
WHEN RB_SELE1.
CLEAR RB_NOTE2[].
CLEAR RB_NOTE3[].
LOOP AT SCREEN.
IF SCREEN-GROUP1 = ‘RB2‘ OR SCREEN-GROUP1 = ‘RB3‘.
SCREEN-INPUT = ‘0‘.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
WHEN RB_SELE2.
P_RBUSA = SPACE.
CLEAR RB_NOTE1[].
CLEAR RB_NOTE3[].
CLEAR S_HKONT[].
LOOP AT SCREEN.
IF SCREEN-GROUP1 = ‘RB1‘ OR SCREEN-GROUP1 = ‘RB3‘ OR SCREEN-GROUP1 = ‘RBU‘ OR SCREEN-GROUP1 = ‘HKO‘.
SCREEN-INPUT = ‘0‘.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
WHEN RB_SELE3.
P_RBUSA = SPACE.
CLEAR RB_NOTE1[].
CLEAR RB_NOTE2[].
CLEAR S_HKONT[].
LOOP AT SCREEN.
IF SCREEN-GROUP1 = ‘RB1‘ OR SCREEN-GROUP1 = ‘RB2‘ OR SCREEN-GROUP1 = ‘RBU‘ OR SCREEN-GROUP1 = ‘HKO‘.
SCREEN-INPUT = ‘0‘.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDCASE.
AT SELECTION-SCREEN.
* 会社コードチェック
PERFORM CHECK_BUKRS
USING
P_BUKRS
CHANGING
WAERS
KTOPL
BUTXT
RPMAX.
* この会社コードは存在しません
IF EXIT_FLG = 1.
EXIT_FLG = 0.
MESSAGE E888(ABAPDOCU) WITH ‘この会社コードは存在しません‘.
"MESSAGE S001 WITH CS_BNAME.
RETURN.
ENDIF.
* 会計期間チェック
PERFORM CHECK_YEARMON
USING
P_BUKRS
P_RYEAR
S_RPAMAX[]
CHANGING
IT_RPMAX.
START-OF-SELECTION.
* 会社コードチェック
PERFORM CHECK_BUKRS
USING
P_BUKRS
CHANGING
WAERS
KTOPL
BUTXT
RPMAX.
* この会社コードは存在しません
IF EXIT_FLG = 1.
EXIT_FLG = 0.
MESSAGE E888(ABAPDOCU) WITH ‘この会社コードは存在しません‘.
"MESSAGE S610 WITH CS_BNAME.
LEAVE LIST-PROCESSING.
ENDIF.
IF RB_SELE1 = ‘X‘.
PERFORM GETDATA1.
ELSEIF RB_SELE2 = ‘X‘.
PERFORM SETFIELDCAT.
PERFORM GETDATA2.
DATA LIN TYPE I.
DESCRIBE TABLE I_DATAOUT2 LINES LIN.
IF LIN = 0.
MESSAGE E888(ABAPDOCU) WITH ‘データは存在しません‘.
ELSE.
PERFORM DISPLAYBYALV USING I_DATAOUT2 I_FIELDCAT[].
ENDIF.
ELSEIF RB_SELE3 = ‘X‘.
PERFORM GETADATA3.
ENDIF.
FORM ALV_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS ‘STANDARD_004‘ EXCLUDING RT_EXTAB.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM CHECK_BUKRS
*&---------------------------------------------------------------------*
* 会社コードチェック
*----------------------------------------------------------------------*
* -->LI_BUKRS 会社コード
* <--LO_WAERS 通貨コード
* <--LO_KTOPL 勘定コード表
* <--LO_BUTXT 会社名前
* <--LO_ANZAP 会計期間
*----------------------------------------------------------------------*
FORM CHECK_BUKRS
USING
LI_BUKRS TYPE T001-BUKRS
CHANGING
LO_WAERS TYPE T001-WAERS
LO_KTOPL TYPE T001-KTOPL
LO_BUTXT TYPE T001-BUTXT
LO_ANZAP TYPE FAGLFLEXT-RPMAX.
* 会社コードチェック
SELECT SINGLE KTOPL WAERS
INTO (LO_KTOPL,LO_WAERS)
FROM T001
WHERE BUKRS = LI_BUKRS.
* DBに指定会社コードがない場合
IF SY-SUBRC <> 0.
EXIT_FLG = 1."この会社コードは存在しません
RETURN.
ENDIF.
* 会計期間数、会社名前取得
" CALL FUNCTION ‘Z_TR00005‘
" EXPORTING
" BUKRS = LI_BUKRS
"IMPORTING
" ANZAP = LO_ANZAP
"BUTXT = LO_BUTXT.
ENDFORM. " CHECK_BUKRS
*&---------------------------------------------------------------------*
*& FORM CHECK_YEARMON
*&---------------------------------------------------------------------*
* ①会計年度と会計期間チェック
* ②決算月レンジテーブル取得
*----------------------------------------------------------------------*
* -->LI_BUKRS 会社コード
* -->LI_RYEAR 会計年度
* -->LI_IT_RPMAX 会計期間
* <--LO_IT_RPMAX 決算月レンジ
*----------------------------------------------------------------------*
FORM CHECK_YEARMON
USING
LI_BUKRS TYPE T001-BUKRS
LI_RYEAR TYPE FAGLFLEXT-RYEAR
LI_IT_RPMAX TYPE IT_RPMAX
CHANGING
LO_IT_RPMAX TYPE IT_RPMAX.
DATA:
W_LGJA TYPE BKPF-GJAHR, "入力期間の最大値
W_BKPF TYPE BKPF-MONAT, "システム会計期間
W_GJAHR TYPE BKPF-GJAHR, "システム会計年度
W_STR_RPMAX TYPE T_STR_RPMAX, "最大会計期間取得用
W_STR_RANG TYPE T_STR_RPMAX. "会計期間用
READ TABLE LI_IT_RPMAX
INTO W_STR_RANG INDEX 1.
* 入力会計期間最大値取得
W_LGJA = W_STR_RANG-LOW.
IF W_STR_RANG-HIGH IS NOT INITIAL.
IF W_STR_RANG-HIGH <= RPMAX.
W_LGJA = W_STR_RANG-HIGH.
ELSE.
W_LGJA = RPMAX.
ENDIF.
ENDIF.
* システム会計年度、会計期間取得
CALL FUNCTION ‘GET_CURRENT_YEAR‘
EXPORTING
BUKRS = LI_BUKRS
DATE = SY-DATUM
IMPORTING
CURRM = W_BKPF
CURRY = W_GJAHR.
* 会計年度チェック
IF LI_RYEAR = W_GJAHR. "入力年度=システム年度
"システム期間<>12 && 入力最大期間>システム期間
IF W_BKPF <> 12 AND W_LGJA > W_BKPF.
MESSAGE E888(ABAPDOCU) WITH ‘当月期間内で入力してください‘.
"MESSAGE E105. "当月期間内で入力してください
LEAVE LIST-PROCESSING.
ENDIF.
ELSEIF LI_RYEAR > W_GJAHR. "入力会計年度 > システム会計年度
MESSAGE E888(ABAPDOCU) WITH ‘来年度以降の会計年度は入力できませ‘. "来年度以降の会計年度は入力できません
LEAVE LIST-PROCESSING.
ENDIF.
* 決算月のチェック
"決算仕訳除外を選択したら
IF CB_CHAN1 = ‘X‘.
IF W_STR_RANG-LOW < 13.
CASE W_LGJA.
WHEN 01 OR 02 OR 04 OR 05 OR 07 OR 08 OR 10 OR 11.
MESSAGE E888(ABAPDOCU) WITH ‘決算月ではありません‘.
"MESSAGE E305.
WHEN 03.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = 03.
WHEN 06.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = 06.
WHEN 09.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = 09.
WHEN 12.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = 12.
WHEN 13.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = 13.
WHEN 14.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘BT‘.
W_STR_RPMAX-LOW = 13.
W_STR_RPMAX-HIGH = 14.
WHEN 15.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘BT‘.
W_STR_RPMAX-LOW = 13.
W_STR_RPMAX-HIGH = 15.
WHEN 16.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘BT‘.
W_STR_RPMAX-LOW = 13.
W_STR_RPMAX-HIGH = 16.
ENDCASE.
ELSE.
IF W_STR_RANG-HIGH IS INITIAL.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘EQ‘.
W_STR_RPMAX-LOW = W_STR_RANG-LOW.
ELSE.
W_STR_RPMAX-SIGN = ‘I‘.
W_STR_RPMAX-OPTION = ‘BT‘.
W_STR_RPMAX-LOW = W_STR_RANG-LOW.
W_STR_RPMAX-HIGH = W_LGJA.
ENDIF.
ENDIF.
CLEAR LO_IT_RPMAX.
APPEND W_STR_RPMAX TO LO_IT_RPMAX.
ENDIF.
"会計年度バリアント
SELECT SINGLE PERIV
INTO PERIV
FROM T001
WHERE BUKRS = LI_BUKRS.
"会計期間の日付下限
IF LI_RYEAR = W_GJAHR
AND S_RPAMAX-LOW = W_BKPF.
CALL FUNCTION ‘FIRST_DAY_IN_PERIOD_GET‘
EXPORTING
I_GJAHR = LI_RYEAR
I_PERIV = PERIV
I_POPER = S_RPAMAX-LOW
IMPORTING
E_DATE = DATELOW
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATEHIGH = SY-DATUM.
ELSE.
CALL FUNCTION ‘FIRST_DAY_IN_PERIOD_GET‘
EXPORTING
I_GJAHR = LI_RYEAR
I_PERIV = PERIV
I_POPER = S_RPAMAX-LOW
IMPORTING
E_DATE = DATELOW
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION ‘LAST_DAY_IN_PERIOD_GET‘
EXPORTING
I_GJAHR = LI_RYEAR
I_PERIV = PERIV
I_POPER = S_RPAMAX-LOW
IMPORTING
E_DATE = DATEHIGH
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
"会計期間の日付上限
IF S_RPAMAX-HIGH IS NOT INITIAL.
IF LI_RYEAR = W_GJAHR
AND S_RPAMAX-HIGH = W_BKPF.
DATEHIGH = SY-DATUM.
ELSE.
CALL FUNCTION ‘LAST_DAY_IN_PERIOD_GET‘
EXPORTING
I_GJAHR = LI_RYEAR
I_PERIV = PERIV
I_POPER = S_RPAMAX-HIGH
IMPORTING
E_DATE = DATEHIGH
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " CHECK_YEARMON
*&---------------------------------------------------------------------*
*& FORM GETDATA2
*&---------------------------------------------------------------------*
* TEXT
*---------------* 仕入先データ取得-------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GETDATA2 .
* 通常の統制鑑定残高の取得
SELECT LIFNR
UMSAV
UM01S
UM02S
UM03S
UM04S
UM05S
UM06S
UM07S
UM08S
UM09S
UM10S
UM11S
UM12S
UM13S
UM14S
UM15S
UM16S
UM01H
UM02H
UM03H
UM04H
UM05H
UM06H
UM07H
UM08H
UM09H
UM10H
UM11H
UM12H
UM13H
UM14H
UM15H
UM16H
INTO TABLE I_LFC1
FROM LFC1
WHERE LIFNR IN RB_NOTE2
AND BUKRS = P_BUKRS
AND GJAHR = P_RYEAR.
LOOP AT I_LFC1 INTO W_LFC1.
W_UMSAV-SIGN =‘I‘.
W_UMSAV-OPTION = ‘EQ‘.
W_UMSAV-UMSAV = W_LFC1-UMSAV.
APPEND W_UMSAV TO I_UMSAV.
ENDLOOP.
SORT I_UMSAV.
DELETE ADJACENT DUPLICATES FROM I_UMSAV.
*特仕訳とき引き金額
SELECT LIFNR
SHBKZ
SALDV
INTO TABLE I_LFC3
FROM LFC3
WHERE
LIFNR IN RB_NOTE2
AND BUKRS = P_BUKRS
AND GJAHR = P_RYEAR.
LOOP AT I_LFC3 INTO W_LFC3.
W_SHBKZ-SIGN = ‘I‘.
W_SHBKZ-OPTION = ‘EQ‘.
W_SHBKZ-LOW = W_LFC3-SHBKZ.
APPEND W_SHBKZ TO I_SHBKZ.
ENDLOOP.
SORT I_SHBKZ.
DELETE ADJACENT DUPLICATES FROM I_SHBKZ.
*統制鑑定取得
SELECT LIFNR
BUKRS
AKONT
INTO TABLE I_LFB1
FROM LFB1
WHERE LIFNR IN RB_NOTE2
AND BUKRS = P_BUKRS.
* 鑑定コード取得
SELECT SKONT
UMSKZ
HKONT
INTO TABLE I_T074
FROM T074
WHERE KTOPL = W_T001-KTOPL
AND KOART = ‘K‘
AND UMSKZ IN I_SHBKZ
AND HKONT IN I_UMSAV.
* BSIKデータ取得
SELECT HKONT
LIFNR
SHKZG
GJAHR
MONAT
DMBTR
WAERS
INTO TABLE I_BSIK
FROM BSIK
WHERE BUKRS = P_BUKRS
AND GJAHR = P_RYEAR
AND MONAT <= S_RPAMAX
AND UMSKZ <> SPACE
AND HKONT IN S_SAKNR
AND LIFNR IN RB_NOTE2.
* BSAKデータ取得
SELECT HKONT
LIFNR
SHKZG
GJAHR
MONAT
DMBTR
WAERS
INTO TABLE I_BSAK
FROM BSAK
WHERE BUKRS = P_BUKRS
AND GJAHR = P_RYEAR
AND MONAT <= S_RPAMAX
AND UMSKZ <> SPACE
AND HKONT IN S_SAKNR
AND LIFNR IN RB_NOTE2.
SELECT SAKNR
XBILK
INTO TABLE I_SKA1
FROM SKA1
WHERE KTOPL = W_T001-KTOPL
AND SAKNR = S_SAKNR.
LOOP AT I_LFC1 INTO W_LFC1.
READ TABLE I_LFB1 WITH KEY LIFNR = W_LFC1-LIFNR INTO W_LFB1.
IF S_RPAMAX-LOW = 2.
UMS = W_LFC1-UM01S.
UMH = W_LFC1-UM01H.
ELSEIF S_RPAMAX-LOW = 3.
UMS = W_LFC1-UM01S + W_LFC1-UM02S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H.
ELSEIF S_RPAMAX-LOW = 4.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H.
ELSEIF S_RPAMAX-LOW = 5.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H.
ELSEIF S_RPAMAX-LOW = 6.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H.
ELSEIF S_RPAMAX-LOW = 7.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H .
ELSEIF S_RPAMAX-LOW = 8.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H.
ELSEIF S_RPAMAX-LOW = 9.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H.
ELSEIF S_RPAMAX-LOW = 10.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H.
ELSEIF S_RPAMAX-LOW = 11.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H.
ELSEIF S_RPAMAX-LOW = 12.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S + W_LFC1-UM11S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H + W_LFC1-UM11H.
ELSEIF S_RPAMAX-LOW = 13.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S + W_LFC1-UM11S + W_LFC1-UM12S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H + W_LFC1-UM11H + W_LFC1-UM12H.
ELSEIF S_RPAMAX-LOW = 14.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S + W_LFC1-UM11S + W_LFC1-UM12S + W_LFC1-UM13S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H + W_LFC1-UM11H + W_LFC1-UM12H + W_LFC1-UM13H.
ELSEIF S_RPAMAX-LOW = 15.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S + W_LFC1-UM11S + W_LFC1-UM12S + W_LFC1-UM13S + W_LFC1-UM14S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H + W_LFC1-UM11H + W_LFC1-UM12H + W_LFC1-UM13H + W_LFC1-UM14H.
ELSEIF S_RPAMAX-LOW = 16.
UMS = W_LFC1-UM01S + W_LFC1-UM02S + W_LFC1-UM03S + W_LFC1-UM04S + W_LFC1-UM05S + W_LFC1-UM06S + W_LFC1-UM07S + W_LFC1-UM08S + W_LFC1-UM09S + W_LFC1-UM10S + W_LFC1-UM11S + W_LFC1-UM12S + W_LFC1-UM13S + W_LFC1-UM14S + W_LFC1-UM15S.
UMH = W_LFC1-UM01H + W_LFC1-UM02H + W_LFC1-UM03H + W_LFC1-UM04H + W_LFC1-UM05H + W_LFC1-UM06H + W_LFC1-UM07H + W_LFC1-UM08H + W_LFC1-UM09H + W_LFC1-UM10H + W_LFC1-UM11H + W_LFC1-UM12H + W_LFC1-UM13H + W_LFC1-UM14H + W_LFC1-UM15H.
ENDIF.
W_DATAOUT2-AKONT = W_LFB1-AKONT.
W_DATAOUT2-LIFNR = W_LFC1-LIFNR.
W_DATAOUT2-UMSAV = W_LFC1-UMSAV.
W_DATAOUT2-UMS = UMS.
W_DATAOUT2-UMH = UMH.
W_DATAOUT2-UML = W_LFC1-UMSAV + UMS - UMH.
APPEND W_DATAOUT2 TO I_DATAOUT2.
ENDLOOP.
LOOP AT I_LFC3 INTO W_LFC3.
READ TABLE I_LFB1 INTO W_LFB1 WITH KEY LIFNR = W_LFC3-LIFNR .
W_DATAOUT21-AKONT = W_LFB1-AKONT.
W_DATAOUT21-LIFNR = W_LFC3-LIFNR.
W_DATAOUT21-UMSAV = W_LFC3-SALDV.
W_DATAOUT21-UMS = 0.
W_DATAOUT21-UMH = 0.
W_DATAOUT21-UML = W_LFC3-SALDV.
APPEND W_DATAOUT21 TO I_DATAOUT21.
ENDLOOP.
LOOP AT I_DATAOUT21 INTO W_DATAOUT21.
READ TABLE I_T074 INTO W_T074 WITH KEY HKONT = W_DATAOUT21-AKONT.
W_DATAOUT2-AKONT = W_T074-HKONT.
W_DATAOUT2-LIFNR = W_DATAOUT21-LIFNR.
W_DATAOUT2-UMSAV = W_DATAOUT21-UMSAV .
W_DATAOUT2-UMS = 0.
W_DATAOUT2-UMH = 0.
W_DATAOUT2-UML = W_LFC3-SALDV.
APPEND W_DATAOUT2 TO I_DATAOUT2.
ENDLOOP.
LOOP AT I_BSIK INTO W_BSIK.
IF W_BSIK-SHKZG = ‘S‘.
UMS = W_BSIK-DMBTR.
ELSEIF
UMH = W_BSIK-DMBTR.
ENDIF.
W_DATAOUT2-AKONT = W_BSIK-HKONT.
W_DATAOUT2-LIFNR = W_BSIK-LIFNR.
W_DATAOUT2-UMSAV = W_BSIK-DMBTR .
W_DATAOUT2-UMS = UMS.
W_DATAOUT2-UMS = UMH.
W_DATAOUT2-UMS = UMS + UMH.
APPEND W_DATAOUT2 TO I_DATAOUT2.
ENDLOOP.
LOOP AT I_BSAK INTO W_BSAK.
IF W_BSAK-SHKZG = ‘S‘.
UMS = W_BSAK-DMBTR.
ELSEIF
UMH = W_BSAK-DMBTR.
ENDIF.
W_DATAOUT2-AKONT = W_BSAK-HKONT.
W_DATAOUT2-LIFNR = W_BSAK-LIFNR.
W_DATAOUT2-UMSAV = W_BSAK-DMBTR .
W_DATAOUT2-UMS = UMS.
W_DATAOUT2-UMS = UMH.
W_DATAOUT2-UMS = UMS + UMH.
APPEND W_DATAOUT2 TO I_DATAOUT2.
ENDLOOP.
SORT I_DATAOUT2.
DELETE ADJACENT DUPLICATES FROM I_DATAOUT2.
ENDFORM. " GETDATA2
*&---------------------------------------------------------------------*
*& FORM GETADATA3
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GETADATA3 .
*得意データ取得
*通常の統制鑑定残高の取得
SELECT KUNNR
UMSAV
*? UM01S~UM16S
*? UM01H~UM16H
INTO TABLE I_KNC1
FROM KNC1
WHERE
*? KUNNR IN RB_ROTE3 AND
BUKRS = P_BUKRS
AND GJAHR = P_RYEAR.
*特仕訳取引き金額の取得
SELECT KUNNR
SHBKZ
SALDV
INTO TABLE I_KNC3
FROM KNC3
WHERE
"? KUNNR IN RB_ROTE3 AND
BUKRS = P_BUKRS
AND GJAHR = P_RYEAR.
*統制鑑定取得
SELECT AKONT
INTO TABLE I_KNB1
FROM KNB1
WHERE
"? KUNNR IN RB_ROTE3 AND
BUKRS = P_BUKRS.
*鑑定コード取得
SELECT SKONT
INTO TABLE I_T074
FROM T074
WHERE KTOPL = W_T001-KTOPL
AND KOART = ‘K‘
AND UMSKZ = I_KNC3-SHBKZ
AND HKONT = I_KNC1-UMSAV.
*BSIDデータ取得
SELECT HKONT
KUNNR AS 取引先コード
SHKZG
GJAHR
MONAT
DMBTR
WAERS
INTO TABLE I_BSID
FROM BSID
WHERE BUKRS = P_BUKRS
AND GJAHR = P_RYEAR
AND MONAT <= S_RPAMAX
AND UMSKZ <> SPACE
AND HKONT IN S_SAKNR
AND KUNNR IN RB_NOTE3.
*BSADデータ取得
SELECT HKONT
KUNNR AS 取引先コード
SHKZG
GJAHR
MONAT
DMBTR
WAERS
INTO TABLE I_BSAD
FROM BSAD
WHERE BUKRS = P_BUKRS
AND GJAHR = P_RYEAR
AND MONAT <= S_RPAMAX
AND UMSKZ <> SPACE
AND HKONT IN S_SAKNR
AND KUNNR IN RB_NOTE3.
ENDFORM. " GETADATA3
*&---------------------------------------------------------------------*
*& FORM GETDATA1
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GETDATA1 .
* 会計期間数を取り得
*SELECT ANZAP
* INTO TABLE I_
* FROM Z_TR00005
* WHERE BUKRS = P_BUKRS.
*管理領域の取り得
SELECT KOKRS
INTO TABLE I_TKA02
FROM TKA02
WHERE BUKRS = P_BUKRS.
* AND BSBER = SPACE.
* 利益センタの取り得
* SELECT ET_SETVAL
* INTO TABLE I_K_GROUP_REMOTE_READ
* FROM K_GROUP_REMOTE_READ
* WHERE SETCLASS = ‘0106‘
* AND CO_AREA = 2-1-2
* AND CHAT_ACCTS = 1-1
* AND GROUPNAME IN RB_NOTE1
* AND LANGUAGE = SY-LANGU.
*利益センターグループデータ取得
SELECT RACCT DRCRK HSLVT RTCUR "全期間
INTO TABLE I_FAGLFLEXT
FROM FAGLFLEXT
WHERE RYEAR = P_RYEAR
* AND RPMAX = 2-1-1
* AND RLANR = 0L
AND RRCTY = 0
* AND BUKRS = P_BUKRS
AND RBUSA LIKE P_RBUSA
AND RACCT IN S_SAKNR
AND PRCTR = I_TKA02-KOKRS.
"4特別データ取り得
"決算ヘッドデータ取得
SELECT BELNR
STBLG
XREVERSAL
INTO TABLE I_BKPF
FROM BKPF
WHERE
" MONAT = (3,6,9,12,...)AND
BLART = ‘YA‘
AND GJAHR = P_RYEAR
AND BUKRS = P_BUKRS.
"反対ヘッドデータ取り得
SELECT BELNR
STBLG
XREVERSAL
INTO TABLE I_BKPF
FROM BKPF
WHERE MONAT IN S_RPAMAX
"AND XREVER = 1 AND 2
AND GJAHR = P_RYEAR
AND BUKRS = P_BUKRS.
"特別仕訳金額取り得
"利益センターグループの特別仕訳
SELECT BELNR
HKONT
PRCTR
SHKZG
DMBTR
BUZEI
INTO TABLE I_BSEG
FROM BSEG
WHERE
" BELNR = BKPF "会計伝票番号 AND
GJAHR = P_RYEAR
AND BUKRS = P_BUKRS
AND GSBER LIKE P_RBUSA
AND PRCTR = I_TKA02-KOKRS.
"AND RACCT IN S_SAKNR.
"仕入れ先データ(未決算)
SELECT BELNR
HKONT
LIFNR
SHKZG
DMBTR
INTO TABLE I_BSIK
FROM BSIK
WHERE
"BELNR = BKPF会計伝票番号 AND
GJAHR = P_RYEAR
AND LIFNR = RB_NOTE2
AND BUKRS = P_BUKRS
AND HKONT IN S_SAKNR.
"仕入れ先データ(決算済み)
SELECT BELNR
HKONT
LIFNR
SHKZG
DMBTR
INTO TABLE I_BSAK
FROM BSAK
WHERE
" BELNR = BKPF会計伝票番号 AND
GJAHR = P_RYEAR
AND LIFNR = RB_NOTE2
AND BUKRS = P_BUKRS
AND HKONT IN S_SAKNR.
" 得意先データ(未決算)
SELECT BELNR
HKONT
KUNNR
SHKZG
DMBTR
INTO TABLE I_BSID
FROM BSID
WHERE
" BELNR = BKPF会計伝票番号 AND
GJAHR = P_RYEAR
AND KUNNR = RB_NOTE3
AND BUKRS = P_BUKRS
AND HKONT IN S_SAKNR.
"得意データ(決算済み)
SELECT BELNR
HKONT
KUNNR
SHKZG
DMBTR
INTO TABLE I_BSAD
FROM BSAD
WHERE
" BELNR = BKPF会計伝票番号 AND
GJAHR = P_RYEAR
AND KUNNR = RB_NOTE3
AND BUKRS = P_BUKRS
AND HKONT IN S_SAKNR.
"5データ処理
"5-1特別仕訳データ除く
"5-2鑑定コードテキストを取り得する
*SELELCT 鑑定コードテキスト
*INTO TABLE I_SKAT
*FROM SKAT
*WHERE SPRAS = SY-LANGU
*AND KTOPL = I_SKA1-SAKNR
*AND SAKNR =
"利益センタグループテキストを取り得する
SELECT DESCRIPT
INTO TABLE I_SETHEADERT
FROM SETHEADERT
WHERE SETCLASS = ‘0106‘
AND SUBCLASS = I_TKA02-KOKRS.
*AND SETNAME IN
*AND LANGU = SY-LANGU.
"仕入先テキストを取り得する
ENDFORM. " GETDATA1
*&---------------------------------------------------------------------*
*& FORM DISPLAYBYALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_I_DATAOUT2 TEXT
* -->P_I_FIELDCAT TEXT
*----------------------------------------------------------------------*
FORM DISPLAYBYALV USING I_DATAOUT2 TYPE IT_DATAOUT2
I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
GS_LAYOUT-COLWIDTH_OPTIMIZE = ‘X‘.
GS_LAYOUT-ZEBRA = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_CALLBACK_PF_STATUS_SET = CNS_PF_STATUS "设置ALV的自定义按钮 GUI
I_CALLBACK_USER_COMMAND = CNS_USER_COMMAND "设置ALV自定义按钮响应事件
IT_FIELDCAT = I_FIELDCAT
IS_LAYOUT = GS_LAYOUT
TABLES
T_OUTTAB = I_DATAOUT2
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " DISPLAYBYALV
*&---------------------------------------------------------------------*
*& FORM SETFIELDCAT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SETFIELDCAT .
CLEAR W_FIELD.
DEFINE ADDFIELDCAT.
W_FIELD-COL_POS = &1.
W_FIELD-FIELDNAME = &2.
W_FIELD-SELTEXT_L = &3.
W_FIELD-JUST = &4.
APPEND W_FIELD TO I_FIELDCAT.
END-OF-DEFINITION.
ADDFIELDCAT 1 ‘AKONT‘ ‘統制鑑定‘ ‘L‘.
ADDFIELDCAT 2 ‘ LIFNR‘ ‘仕入先‘ ‘L‘.
ADDFIELDCAT 3 ‘UMSAV‘ ‘前期残高‘ ‘L‘.
ADDFIELDCAT 4 ‘UMS‘ ‘J方‘ ‘L‘.
ADDFIELDCAT 5 ‘UMH‘ ‘貸方‘ ‘L‘.
ADDFIELDCAT 6 ‘UML‘ ‘当期残高‘ ‘L‘.
ENDFORM. " SETFIELDCAT
FORM ALV_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN‘EXPORT‘.
PERFORM EXPORT_FORM."调用导出程序
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM EXPORT_FORM
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM EXPORT_FORM .
PERFORM PROCESS_OUTDATA USING i_dataout2.
PERFORM CALLGUI.
ENDFORM. " EXPORT_FORM
DATA: BEGIN OF GT_OUT OCCURS 0,
STR TYPE STRING,
END OF GT_OUT.
FORM PROCESS_OUTDATA USING i_dataout2 TYPE IT_DATAOUT2.
REFRESH GT_OUT.
CLEAR GT_OUT.
DATA:WA_OUT LIKE GT_OUT.
DATA:L_STR TYPE STRING.
DATA:L_TIMES TYPE I.
DATA: " I_DATAOUT2 TYPE IT_DATAOUT2,
W_DATAOUT2 TYPE IT_DATAOUT2.
* data: fieldnames type TABLE OF I_FIELDCAT.
FIELD-SYMBOLS: <DYN_WA> TYPE ANY,
< DYN_FIELD> TYPE ANY.
LOOP AT I_FIELDCAT.
CONCATENATE WA_OUT-STR I_FIELDCAT-SELTEXT_L CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO WA_OUT-STR.
IF SY-TABIX LE 6.
CONCATENATE GT_OUT-STR CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO GT_OUT-STR.
CONTINUE.
ENDIF.
ENDLOOP.
APPEND GT_OUT.
APPEND WA_OUT TO GT_OUT.
CLEAR WA_OUT.
L_TIMES = 6.
LOOP AT I_DATAOUT2 ASSIGNING <DYN_WA>.
DO L_TIMES TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
L_STR = <DYN_FIELD>.
CONCATENATE WA_OUT-STR L_STR CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO WA_OUT-STR.
ENDDO.
APPEND WA_OUT TO GT_OUT.
CLEAR WA_OUT.
ENDLOOP.
ENDFORM.
FORM CALLGUI.
CALL FUNCTION ‘GUI_DOWNLOAD‘
EXPORTING
FILENAME = ‘C:\Users\i060729\Desktop\BBB.XLS‘
FILETYPE = ‘DAT‘
CODEPAGE = ‘4110‘
TABLES
DATA_TAB = GT_OUT[].
" fieldnames = i_fieldcat.
*** 设置excel为可见
" set property of v_excel ‘Visible‘ = 1.
ENDFORM.
excel-call function,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/xjm123/p/3756096.html