SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Cost center Group



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CO
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Oct 27, 2007 3:44 pm    Post subject: Cost center Group Reply with quote

Code:
* TABLES
TABLES : COEP,
PRPS,
BAPISET_HIER ,
ZFI_BURDEN.
* TYPES
TYPES: BEGIN OF YT_TEMPLATE,
KSTAR LIKE COEP-KSTAR,
WOGBTR LIKE COEP-WOGBTR,
END OF YT_TEMPLATE.

* DATA VARIABLES
DATA: W_FI LIKE COEP-WOGBTR,
W_PROJECT LIKE COEP-WOGBTR,
W_ABSORPTION LIKE COEP-WOGBTR,
W_TNAME LIKE TSTC-TCODE VALUE 'ZFP1',
W_SUBRC LIKE SY-SUBRC.

*CONSTANTS
CONSTANTS: C_X TYPE C VALUE 'X',
C_ABB LIKE BAPICO_GROUP-CHRT_ACCTS VALUE 'ABB',
C_GROUPNAME LIKE BAPICO_GROUP-GROUPNAME VALUE 'FI_'.

* INTERNAL TABLES
DATA: T_FI TYPE STANDARD TABLE OF YT_TEMPLATE WITH HEADER LINE,
T_PROJECTS TYPE STANDARD TABLE OF YT_TEMPLATE WITH HEADER LINE,
T_TEMP TYPE STANDARD TABLE OF YT_TEMPLATE WITH HEADER LINE,
T_COEP TYPE STANDARD TABLE OF COEP WITH HEADER LINE,
T_CSKU TYPE STANDARD TABLE OF CSKU WITH HEADER LINE.

DATA : BEGIN OF T_NODES_MAIN OCCURS 0.
INCLUDE STRUCTURE BAPISET_HIER.
DATA END OF T_NODES_MAIN .

DATA : BEGIN OF T_VALUES_MAIN OCCURS 0.
INCLUDE STRUCTURE BAPI1113_VALUES.
DATA : END OF T_VALUES_MAIN.

DATA : BEGIN OF T_NODES OCCURS 0.
INCLUDE STRUCTURE BAPISET_HIER.
DATA END OF T_NODES .

DATA : BEGIN OF T_VALUES OCCURS 0.
INCLUDE STRUCTURE BAPI1113_VALUES.
DATA : END OF T_VALUES.

DATA : BEGIN OF T_GROUP OCCURS 0,
GROUPNAME LIKE BAPISET_HIER-GROUPNAME,
DESCRIPT LIKE BAPISET_HIER-DESCRIPT,
VALFROM LIKE BAPI1113_VALUES-VALFROM,
END OF T_GROUP .

DATA: BEGIN OF T_FINAL OCCURS 0,
KSTAR LIKE COEP-KSTAR,
KTEXT LIKE CSKU-KTEXT,
KAGRU LIKE CSKU-KTEXT, "TYPE KAGRU,
FI_WOGBTR LIKE COEP-WOGBTR,
PR_WOGBTR LIKE COEP-WOGBTR,
DF_WOGBTR LIKE COEP-WOGBTR,
END OF T_FINAL.

*SELECTION SCREEN
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_GJAHR FOR COEP-GJAHR OBLIGATORY NO INTERVALS NO-EXTENSION,
S_PERIO FOR COEP-PERIO OBLIGATORY NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN : END OF BLOCK B1.

SELECTION-SCREEN : BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS : P_SUM RADIOBUTTON GROUP SUM user-command SUM DEFAULT 'X',
P_DETAIL RADIOBUTTON GROUP SUM.
SELECTION-SCREEN : END OF BLOCK B2.

*START-OF-SELECTION.
START-OF-SELECTION.

*Authorization check for this transaction.
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
tcode = W_Tname
EXCEPTIONS
ok = 1
not_ok = 2.
IF sy-subrc = 2.
MESSAGE e172(00) WITH W_Tname.
ENDIF.
CALL FUNCTION 'SUSR_AUTHORITY_CHECK_S_TCODE'
EXPORTING
tcode = W_Tname
IMPORTING
rc = W_subrc.
IF W_subrc <> 0.
MESSAGE e172(00) WITH W_Tname.
ENDIF.


*SELECT KSTAR WOGBTR FROM COEP INTO TABLE T_FI
* WHERE PERIO EQ S_PERIO-LOW
* AND GJAHR EQ S_GJAHR-LOW
* AND KOKRS EQ '0300'
* AND BUKRS EQ '0300'
* AND WRTTP EQ '04'
* AND VERSN EQ '000'
* AND GSBER EQ '9950'.
*
*SELECT KSTAR WOGBTR FROM COEP INTO TABLE T_PROJECTS
* WHERE PERIO EQ S_PERIO-LOW
* AND GJAHR EQ S_GJAHR-LOW
* AND KOKRS EQ '0300'
* AND BUKRS EQ '0300'
* AND WRTTP EQ '04'
* AND VERSN EQ '000'
* AND GSBER EQ '9950'
* AND ( OBJNR LIKE 'PR%' OR OBJNR LIKE 'NV%' ).

SELECT * FROM CSKU INTO TABLE T_CSKU.

****TEST SCENARIO
SELECT KSTAR WOGBTR FROM COEP INTO TABLE T_FI
WHERE KOKRS EQ '0100'
AND BUKRS EQ '0310'
AND WRTTP EQ '04'
AND VERSN EQ '000'
AND GSBER EQ '3410'.

SELECT KSTAR WOGBTR FROM COEP INTO TABLE T_PROJECTS
WHERE KOKRS EQ '0100'
AND BUKRS EQ '0310'
AND WRTTP EQ '04'
AND VERSN EQ '000'
AND GSBER EQ '3410'
AND ( OBJNR LIKE 'VB%' OR OBJNR LIKE 'AO%' ).
****TEST SCENARIO

REFRESH T_TEMP.
LOOP AT T_FI INTO T_TEMP.
COLLECT T_TEMP.
ENDLOOP.
REFRESH T_FI.
APPEND LINES OF T_TEMP TO T_FI.

REFRESH T_TEMP.
LOOP AT T_PROJECTS INTO T_TEMP.
COLLECT T_TEMP.
ENDLOOP.
REFRESH T_PROJECTS.
APPEND LINES OF T_TEMP TO T_PROJECTS.

CLEAR T_PROJECTS.
CLEAR: W_FI, W_PROJECT, W_ABSORPTION.
LOOP AT T_FI.
READ TABLE T_PROJECTS WITH KEY KSTAR = T_FI-KSTAR.
MOVE: T_FI-KSTAR TO T_FINAL-KSTAR,
T_FI-WOGBTR TO T_FINAL-FI_WOGBTR,
T_PROJECTS-WOGBTR TO T_FINAL-PR_WOGBTR.
T_FINAL-DF_WOGBTR = T_FINAL-FI_WOGBTR - T_FINAL-PR_WOGBTR.
IF T_FINAL-DF_WOGBTR IS NOT INITIAL.
APPEND T_FINAL.
W_FI = W_FI + T_FINAL-FI_WOGBTR.
W_PROJECT = W_PROJECT + T_FINAL-PR_WOGBTR.
W_ABSORPTION = W_ABSORPTION + T_FINAL-DF_WOGBTR.
ENDIF.
ENDLOOP.

****One of the method to get cost group name
DATA: it_buffer LIKE cskb_ex OCCURS 0 WITH HEADER LINE.

LOOP AT T_FINAL.
CALL FUNCTION 'K_COSTELEM_SELECT'
EXPORTING
KOKRS = '0100'
CE_FROM = T_FINAL-KSTAR
* CE_TO =
* CE_GROUP =
* DATE_FROM =
* DATE_TO =
* LANGU = SY-LANGU
* ONLY_COMPLETE = ' '
* WITH_TEXT = 'X'
* BYPASSING_BUFFER = ' '
* FILL_BUFFER = 'X'
* TABNAME = 'CSKB_EX'
TABLES
IT_RESULT = IT_BUFFER
EXCEPTIONS
NO_RECORD_FOUND = 1
GROUP_NOT_FOUND = 2
OTHERS = 3
.
IF SY-SUBRC <0> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_GROUPS .

*This routine get Cost elements for cost element group " BURDENRATE" .

CALL FUNCTION 'BAPI_COSTELEMENTGRP_GETDETAIL'
EXPORTING
CHARTOFACCOUNTS = C_ABB
GROUPNAME = C_GROUPNAME
* IMPORTING
* RETURN =
TABLES
HIERARCHYNODES = T_NODES_MAIN
HIERARCHYVALUES = T_VALUES_MAIN
.
* T_NODES_MAIN index 1 has heading for cost element group which needs to
* be deleted
DELETE T_NODES_MAIN INDEX 1 .

* looping Cost element groups for corresponding cost elements.
LOOP AT T_NODES_MAIN.

CALL FUNCTION 'BAPI_COSTELEMENTGRP_GETDETAIL'
EXPORTING
CHARTOFACCOUNTS = C_ABB
GROUPNAME = T_NODES_MAIN-GROUPNAME
* IMPORTING
* RETURN =
TABLES
HIERARCHYNODES = T_NODES
HIERARCHYVALUES = T_VALUES.

LOOP AT T_VALUES.
MOVE T_NODES-GROUPNAME TO T_GROUP-GROUPNAME.
MOVE T_NODES-DESCRIPT TO T_GROUP-DESCRIPT.
MOVE T_VALUES-VALFROM TO T_GROUP-VALFROM.
APPEND T_GROUP.
CLEAR T_GROUP.
ENDLOOP.
ENDLOOP.

ENDFORM. " GET_GROUPS

*&---------------------------------------------------------------------*
*& Form DISPLAY_SUMMARY
*&---------------------------------------------------------------------*
* This subroutine displays summary information
*----------------------------------------------------------------------*
FORM DISPLAY_SUMMARY .

DATA: T_TEMP_FINAL LIKE STANDARD TABLE OF T_FINAL WITH HEADER LINE,
WV_TEMP TYPE I.

LOOP AT T_FINAL INTO T_TEMP_FINAL.
CLEAR: T_TEMP_FINAL-KSTAR,
T_TEMP_FINAL-KTEXT.
COLLECT T_TEMP_FINAL.
ENDLOOP.

REFRESH T_FINAL.
APPEND LINES OF T_TEMP_FINAL TO T_FINAL.
REFRESH T_TEMP_FINAL.

WRITE: 1(21) TEXT-003, W_FI,
/1(21) TEXT-004, W_PROJECT,
/1(21) TEXT-005, W_ABSORPTION.

FORMAT COLOR COL_HEADING INTENSIFIED ON.
SKIP 3.
WRITE: (96) SY-ULINE.
WRITE: / SY-VLINE, (20) TEXT-006, SY-VLINE, (21) TEXT-007 CENTERED, SY-VLINE,
(21) TEXT-008 CENTERED, SY-VLINE, (21) TEXT-009 CENTERED, SY-VLINE.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: (96) SY-ULINE.

LOOP AT T_FINAL.
WV_TEMP = SY-TABIX MOD 2.
IF WV_TEMP EQ 0.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
ENDIF.
WRITE:/ SY-VLINE, (20) T_FINAL-KAGRU,
SY-VLINE, (21) T_FINAL-FI_WOGBTR , SY-VLINE, (21) T_FINAL-PR_WOGBTR,
SY-VLINE, (21) T_FINAL-DF_WOGBTR, SY-VLINE.
ENDLOOP.

IF T_FINAL IS INITIAL.
WRITE: / SY-VLINE, TEXT-013,96 SY-VLINE.
ELSE.
WRITE: (96) SY-ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ SY-VLINE, (20) TEXT-012,
SY-VLINE, (21) W_FI , SY-VLINE, (21) W_PROJECT,
SY-VLINE, (21) W_ABSORPTION, SY-VLINE.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
ENDIF.
WRITE: (96) SY-ULINE.
ENDFORM. " DISPLAY_SUMMARY

*&---------------------------------------------------------------------*
*& Form DISPLAY_DETAIL
*&---------------------------------------------------------------------*
* This subroutine displays Detail information
*----------------------------------------------------------------------*
FORM DISPLAY_DETAIL .
DATA: WV_TEMP TYPE I.

WRITE: 1(21) TEXT-003, W_FI,
/1(21) TEXT-004, W_PROJECT,
/1(21) TEXT-005, W_ABSORPTION.

FORMAT COLOR COL_HEADING INTENSIFIED ON.
SKIP 3.
WRITE: (138) SY-ULINE.
WRITE:/ SY-VLINE, (16) TEXT-010,
SY-VLINE, (20) TEXT-011,
SY-VLINE, (20) TEXT-006,
SY-VLINE, (21) TEXT-007 CENTERED, SY-VLINE, (21) TEXT-008 CENTERED,
SY-VLINE, (21) TEXT-009 CENTERED, SY-VLINE.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: (138) SY-ULINE.


LOOP AT T_FINAL.
WV_TEMP = SY-TABIX MOD 2.
IF WV_TEMP EQ 0.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
ENDIF.
WRITE: / SY-VLINE, (16) T_FINAL-KSTAR,
SY-VLINE, (20) T_FINAL-KTEXT,
SY-VLINE, (20) T_FINAL-KAGRU,
SY-VLINE, (21) T_FINAL-FI_WOGBTR, SY-VLINE, (21) T_FINAL-PR_WOGBTR,
SY-VLINE, (21) T_FINAL-DF_WOGBTR, SY-VLINE.
ENDLOOP.

IF T_FINAL IS INITIAL.
WRITE: / SY-VLINE, TEXT-013,138 SY-VLINE.
ELSE.
WRITE: (138) SY-ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE: / SY-VLINE, (16) TEXT-012,
SY-VLINE, (20) SPACE,
SY-VLINE, (20) SPACE,
SY-VLINE, (21) W_FI, SY-VLINE, (21) W_PROJECT,
SY-VLINE, (21) W_ABSORPTION, SY-VLINE.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
ENDIF.
WRITE: (138) SY-ULINE.
ENDFORM. " DISPLAY_DETAIL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CO All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.