FUNCTION Z02FI_SUN_INF_BUDGET
.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_ZZBUDGET) LIKE BSEG-ZZBUDGET
*" REFERENCE(I_ZZBUKRS) LIKE Z02FITSSDOC_H-ZZBUKRS
*" REFERENCE(I_ZZGJAHR) LIKE Z02FITSSDOC_H-ZZGJAHR
*" REFERENCE(I_ZZBELNR) LIKE Z02FITSSDOC_H-ZZBELNR
*" REFERENCE(I_ZZBUZEI) TYPE BUZEI OPTIONAL
*" VALUE(I_FUNDCTR) TYPE CHAR100 DEFAULT 'petrochinahalfaya'
*" TABLES
*" ZZMSGT STRUCTURE ZZMSGT OPTIONAL
*"----------------------------------------------------------------------
DATA
: LS_HEADERINFO
TYPE BAPIPLNHDR
,
LT_INDEXSTRUCTURE
TYPE
TABLE
OF BAPIACPSTRU
WITH
HEADER
LINE
,
LT_COOBJECT
TYPE
TABLE
OF BAPIPCPOBJ
WITH
HEADER
LINE
,
LT_PERVALUE
TYPE
TABLE
OF BAPIPCPVAL
WITH
HEADER
LINE
,
LT_RETURN
TYPE
TABLE
OF BAPIRET2
WITH
HEADER
LINE
.
DATA
:LS_Z02FITSSBUDG
TYPE Z02FITSSBUDG
.
DATA
: L_BFLAG
.
DATA
: L_PSPNR
LIKE PRPS
-PSPNR
.
DATA
: L_UP
LIKE PRHI
-
UP
.
DATA
: L_MSG
LIKE Z02FITSSLOG
-ZZMSG
.
DATA
: LS_ZZMSGT
TYPE ZZMSGT
.
DATA
:N
(
2
)
TYPE N
VALUE
12
.
FIELD-SYMBOLS
: <F_FIELD1>
,
<F_FIELD2>
.
DATA
:L_STR1
TYPE STRING
,
L_STR2
TYPE STRING
.
CLEAR
:LS_HEADERINFO
,LT_INDEXSTRUCTURE
,LT_INDEXSTRUCTURE[]
,LT_COOBJECT
,LT_COOBJECT[]
,LT_PERVALUE
,LT_PERVALUE[]
,LT_RETURN
,LT_RETURN[]
,
L_BFLAG
,L_STR1
,L_STR2
,LS_Z02FITSSBUDG
,L_UP
,L_PSPNR
.
LS_HEADERINFO
-CO_AREA
=
'1000'
.
LS_HEADERINFO
-FISC_YEAR
= I_ZZBUDGET+0
(
4
)
.
LS_HEADERINFO
-PERIOD_FROM
=
'001'
.
LS_HEADERINFO
-PERIOD_TO
=
'012'
.
LS_HEADERINFO
-VERSION
=
'0'
.
LS_HEADERINFO
-PLAN_CURRTYPE
=
'C'
.
LT_INDEXSTRUCTURE
-OBJECT_INDEX
=
'000001'
.
LT_INDEXSTRUCTURE
-VALUE_INDEX
=
'000001'
.
APPEND LT_INDEXSTRUCTURE
.
LT_COOBJECT
-OBJECT_INDEX
=
'000001'
.
LT_COOBJECT
-WBS_ELEMENT
= I_ZZBUDGET
.
APPEND LT_COOBJECT
.
LT_PERVALUE
-VALUE_INDEX
=
'000001'
.
LT_PERVALUE
-COST_ELEM
=
'9999999999'
.
APPEND LT_PERVALUE
.
CALL
FUNCTION
'BAPI_COSTACTPLN_READPRIMCOST'
EXPORTING
HEADERINFO
= LS_HEADERINFO
TABLES
INDEXSTRUCTURE
= LT_INDEXSTRUCTURE
COOBJECT
= LT_COOBJECT
PERVALUE
= LT_PERVALUE
RETURN
= LT_RETURN
.
READ
TABLE LT_RETURN
WITH
KEY
TYPE
=
'E'
.
IF SY
-SUBRC
EQ
0
.
"读取Budget information有错误
L_BFLAG
=
'X'
.
LOOP
AT LT_RETURN
.
CLEAR L_MSG
.
CALL
FUNCTION
'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID
= LT_RETURN
-
ID
MSGNR
= LT_RETURN
-
NUMBER
MSGV1
= LT_RETURN
-MESSAGE_V1
MSGV2
= LT_RETURN
-MESSAGE_V2
MSGV3
= LT_RETURN
-MESSAGE_V3
MSGV4
= LT_RETURN
-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT
= L_MSG
.
CONCATENATE
'Read the information of document' I_ZZBELNR
'item' I_ZZBUZEI
'occured error'
INTO L_MSG
SEPARATED
BY SPACE
.
CALL
FUNCTION
'Z02FI_SUN_INF_SSLOG'
EXPORTING
I_ZZBUKRS
= I_ZZBUKRS
I_ZZGJAHR
= I_ZZGJAHR
I_ZZBELNR
= I_ZZBELNR
I_ZZBUZEI
= I_ZZBUZEI
I_ZZMSG
= L_MSG
TABLES
ZZMSGT
= ZZMSGT
.
ENDLOOP
.
ELSE
.
"读取Budget information没 有错误
READ
TABLE LT_PERVALUE
INDEX
1
.
IF SY
-SUBRC
EQ
0
.
DO
12
TIMES
.
N
= SY
-
INDEX
.
CLEAR
: L_STR1
,L_STR2
.
CONCATENATE
'LS_Z02FITSSBUDG-ZZBUDGET_M' N
INTO L_STR1
.
ASSIGN
(L_STR1
)
TO <F_FIELD1>
.
CONCATENATE
'LT_PERVALUE-VAR_VAL_PER' N
INTO L_STR2
.
ASSIGN
(L_STR2
)
TO <F_FIELD2>
.
<F_FIELD1>
= <F_FIELD2>
.
ENDDO
.
LS_Z02FITSSBUDG
-ZZBUDGET
= I_ZZBUDGET
.
LS_Z02FITSSBUDG
-ZZFUNDCTR
= I_FUNDCTR
.
LS_Z02FITSSBUDG
-ZZYEAR
= I_ZZBUDGET+0
(
4
)
.
LS_Z02FITSSBUDG
-ZZBUDGST
=
'Y'
.
SELECT
SINGLE PSPNR POST1
INTO
(L_PSPNR
,LS_Z02FITSSBUDG
-ZZBUDGET_DESP
)
FROM PRPS
WHERE POSID
= I_ZZBUDGET
.
SELECT
SINGLE
UP
INTO L_UP
FROM PRHI
WHERE POSNR
= L_PSPNR
.
IF L_UP
IS
NOT
INITIAL
.
LS_Z02FITSSBUDG
-ZZBUDGET_PARENT
= L_UP
.
ENDIF
.
LS_Z02FITSSBUDG
-ZZBUDGET_CURR
=
'USD'
.
LS_Z02FITSSBUDG
-ZZBUDGET_MAX
=
0
.
MODIFY Z02FITSSBUDG
FROM LS_Z02FITSSBUDG
.
"更新数据库
IF SY
-SUBRC
EQ
0
.
LS_ZZMSGT
-ZZMSGTYPE
=
'S'
.
CONCATENATE
'The Budget' I_ZZBUDGET
' was synchronized successfully'
INTO LS_ZZMSGT
-ZZMSG
SEPARATED
BY SPACE
.
APPEND LS_ZZMSGT
TO ZZMSGT
.
COMMIT
WORK
AND
WAIT
.
ELSE
.
ROLLBACK
WORK
.
ENDIF
.
ENDIF
.
ENDIF
.
ENDFUNCTION
.