FUNCTION ZFCO_SET_PLAN_ADMIN.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_KOKRS) TYPE KOKRS
*" VALUE(I_VERSN) TYPE VERSN_COBK
*" VALUE(I_GJAHR) TYPE GJAHR
*" VALUE(I_COMMIT_WORK) TYPE COMMIT_WORK OPTIONAL
*" VALUE(I_KOSTL_F) TYPE KOSTL
*" VALUE(I_KSTAR_F) TYPE KSTAR
*" VALUE(I_YRNMN_F) TYPE ZEYRNMN_F
*" REFERENCE(I_KOSTL_T) TYPE KOSTL
*" REFERENCE(I_KSTAR_T) TYPE KSTAR
*" VALUE(I_YRNMN_T) TYPE ZEYRNMN_T
*" VALUE(I_BLTXT) TYPE BLTXT OPTIONAL
*" VALUE(I_WTGRT_F) TYPE ZWTRGT
*" VALUE(I_WTGRT_T) TYPE ZWTRGT
*" VALUE(I_TWAER) TYPE TWAER
*" EXPORTING
*" VALUE(E_TYPE) TYPE BAPI_MTYPE
*" VALUE(E_MESSAGE) TYPE BAPI_MSG
*"----------------------------------------------------------------------
DATA: BEGIN OF LT_COBK OCCURS 1.
INCLUDE STRUCTURE COBK.
DATA: END OF LT_COBK.
DATA: BEGIN OF LT_COEJA OCCURS 1.
INCLUDE STRUCTURE COEJA.
DATA: END OF LT_COEJA.
DATA: LS_COBK TYPE COBK.
CLEAR: LT_COBK, LT_COBK[], LS_COBK, LT_COEJA, LT_COEJA[],
E_TYPE, E_MESSAGE.
* 전용될 계획 데이터 헤더(From)
PERFORM FILL_COBK_ADMIN
TABLES LT_COBK
USING I_KOKRS I_VERSN I_GJAHR '001' 'RKP1' I_BLTXT I_TWAER
CHANGING LS_COBK.
* 전용될 코스트 센터 계정에 대한 월 계획 금액 입력(From)
PERFORM FILL_COEJ_ADMIN
TABLES LT_COEJA
USING LS_COBK I_KOKRS I_VERSN I_GJAHR I_YRNMN_F
I_KOSTL_F I_KSTAR_F I_WTGRT_F I_TWAER LS_COBK-BELNR.
* 전용할 계획 데이터 헤더(To)
PERFORM FILL_COBK_ADMIN
TABLES LT_COBK
USING I_KOKRS I_VERSN I_GJAHR '001' 'RKP1' I_BLTXT I_TWAER
CHANGING LS_COBK.
* 전용할 코스트 센터 계정에 대한 월 계획 금액 입력(To)
PERFORM FILL_COEJ_ADMIN
TABLES LT_COEJA
USING LS_COBK I_KOKRS I_VERSN I_GJAHR I_YRNMN_T
I_KOSTL_T I_KSTAR_T I_WTGRT_T I_TWAER LS_COBK-BELNR.
* 제어 통화 및 통화 유형
CALL FUNCTION 'K_COBK_TAB_CURRENCY_FILL'
TABLES
ITCOBK = LT_COBK
EXCEPTIONS
KOKRS_GJAHR_NOT_FOUND = 1
KOKRS_NOT_FOUND = 2
KOKRS_WRONG_CUSTOMIZED = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
* 전표 처리
CALL FUNCTION 'K_COEJA_INSERT'
EXPORTING
* EPSKZ = 'X'
* TOTALS_UPDATE = 'X'
VRGNG = 'RKP1'
TABLES
COBK_TAB = LT_COBK
COEJA_TAB = LT_COEJA.
IF SY-SUBRC = 0.
E_TYPE = 'S'.
MESSAGE S030 INTO E_MESSAGE.
COMMIT WORK AND WAIT.
ELSE.
E_TYPE = 'E'.
MESSAGE S031 INTO E_MESSAGE.
ROLLBACK WORK .
ENDIF.
ENDFUNCTION.
FORM FILL_COEJ_ADMIN TABLES PT_COEJA STRUCTURE COEJA
USING PS_COBK STRUCTURE COBK
P_KOKRS
P_VERSN
P_GJAHR
P_YRNMN
P_KOSTL
P_KSTAR
P_WKGRT
P_TWAER
P_BELNR.
CLEAR PT_COEJA.
DATA: LV_WTG0(30),
LV_WOG0(30),
LV_WKG0(30),
LV_WKF0(30).
MOVE-CORRESPONDING PS_COBK TO PT_COEJA.
PT_COEJA-BUZEI = '001'.
PT_COEJA-ZLENR = '001'.
PT_COEJA-WRTTP = '01'.
PT_COEJA-LEDNR = '00'.
PT_COEJA-BEKNZ = 'S'.
PT_COEJA-BELTP = '1'.
LV_WTG0 = 'PT_COEJA-WTG0' && P_YRNMN.
LV_WOG0 = 'PT_COEJA-WOG0' && P_YRNMN.
LV_WKG0 = 'PT_COEJA-WKG0' && P_YRNMN.
LV_WKF0 = 'PT_COEJA-WKF0' && P_YRNMN.
ASSIGN (LV_WTG0) TO FIELD-SYMBOL(<FS_WTG0_T>).
ASSIGN (LV_WOG0) TO FIELD-SYMBOL(<FS_WOG0_T>).
ASSIGN (LV_WKG0) TO FIELD-SYMBOL(<FS_WKG0_T>).
ASSIGN (LV_WKF0) TO FIELD-SYMBOL(<FS_WKF0_T>).
<FS_WTG0_T> = P_WKGRT.
<FS_WOG0_T> = P_WKGRT.
<FS_WKG0_T> = P_WKGRT.
<FS_WKF0_T> = P_WKGRT.
PT_COEJA-TWAER = P_TWAER.
PT_COEJA-OBJNR = 'KS' && P_KOKRS && P_KOSTL.
PT_COEJA-KSTAR = P_KSTAR.
APPEND PT_COEJA.
ENDFORM. "FILL_COEJ
FORM FILL_COBK_ADMIN TABLES PT_COBK STRUCTURE COBK
USING P_KOKRS P_VERSN P_GJAHR P_SUMBZ P_VRGNG P_BLTXT P_TWAER
CHANGING PS_COBK TYPE COBK.
DATA: LS_TKA04 TYPE TKA04,
LS_TKA07 TYPE TKA07.
DATA: LS_COBK TYPE COBK.
CLEAR: LS_COBK, LS_TKA04, LS_TKA07.
* Nummernkreis lesen
SELECT SINGLE *
INTO LS_TKA04
FROM TKA04
WHERE KOKRS = P_KOKRS
AND ACTIVITY = P_VRGNG.
IF SY-SUBRC > 0.
ENDIF.
SELECT SINGLE *
INTO LS_TKA07
FROM TKA07
WHERE KOKRS = P_KOKRS
AND VERSN = P_VERSN
AND GJAHR = P_GJAHR.
*
* Belegnummer holen
PERFORM NUMBER_GET_NEXT
USING P_KOKRS LS_TKA04-INUMKR LS_COBK-BELNR.
* restlichen Belegkopffelder füllen
LS_COBK-MANDT = SY-MANDT. "Mandant
LS_COBK-KOKRS = P_KOKRS. "Kostenrechnungskreis
* LS_COBK-BELNR = P_BELNR.
LS_COBK-GJAHR = P_GJAHR. "Geschäftsjahr
LS_COBK-PERAB = '001'. "Ab-Periode
LS_COBK-PERBI = '012'. "Bis-Periode
LS_COBK-VERSN = P_VERSN. "Version
LS_COBK-VRGNG = P_VRGNG. "Vorgang CO
LS_COBK-BLDAT = SY-DATLO. "Belegdatum "P30K068665
CLEAR LS_COBK-BUDAT. "Buchungsdatum
LS_COBK-CPUDT = SY-DATUM. "Erfassungsdatum des Beleges
LS_COBK-USNAM = SY-UNAME. "Name des Benutzers
LS_COBK-BLTXT = P_BLTXT.
LS_COBK-STFLG = SPACE. "Kennzeichen 'Beleg ist Storno
LS_COBK-STOKZ = SPACE. "Kennzeichen 'Beleg wurde stor
CLEAR:
LS_COBK-REFBT, "Belegtyp des Referenzbeleges
LS_COBK-REFBN, "Belegnummer des Referenbelege
LS_COBK-REFBK, "Buchungskreis des FI-Belegs
LS_COBK-REFGJ, "Geschäftsjahr des Referenzbel
LS_COBK-BLART, "Belegart des FI-Referenzbeleg
LS_COBK-ORGVG. "Orginal-Vorgang CO
LS_COBK-SUMBZ = P_SUMBZ. "Anzahl der Buchungszeilen
CLEAR:
LS_COBK-DELBZ. "Anzahl bereits gelöschter Buc
LS_COBK-WSDAT = LS_TKA07-PLDAT. "Wertstellungsdatum für Währun
LS_COBK-KURST = LS_TKA07-KURST. "Kurstyp
* LS_COBK-KWAER = 'KRW'.
PT_COBK = LS_COBK.
PS_COBK = LS_COBK.
APPEND PT_COBK.
CLEAR: PT_COBK.
ENDFORM.