BAPI_COSTCENTER_CREATEMULTIPLE

Hello Guru's,
I am facing a problem in BAPI_COSTCENTER_CREATEMULTIPLE while processing... that BAPI is executing fine, but data was not getting updated in D/B table, the program i have enclosed below, please have a look and kindly suggest me what is wrong in that...
Helpful Answeres will be Rewarded,
*& Report  ZKCZ005R                                                    *
REPORT  ZKCZ005R NO STANDARD PAGE HEADING LINE-SIZE 255 LINE-COUNT 64
MESSAGE-ID ZFA.
*&  Tables Declaration
TABLES:T001.
*&  Global Types Declaration
TYPES: BEGIN OF TY_DATA,
        KOSTL TYPE KOSTL,             " Cost center
        VALID_FROM TYPE DATAB,        " From date
        VALID_TO TYPE DATBI,          " To date
        PERSON_IN_CHARGE TYPE VERAK,  " Person
        DEPARTMENT TYPE ABTEI,        " Dept
        COSTCENTER_TYPE TYPE KOSAR,   " cost center type
        COSTCTR_HIER_GRP TYPE KHINR,  " cost center hier
        COMP_CODE TYPE BUKRS,         " company code
        BUS_AREA TYPE GSBER,          " Business area
        PROFIT_CTR TYPE PRCTR,        " Profit center
        LOCK_UPDATE TYPE BKZOB,       " Lock Commit
        CSTG_SHEET TYPE AUFKALSM,     " Costing Sheet
        TITLE TYPE ANRED,             " Addr.title
        TELCO_LANGU TYPE SPRAS,       " Language
        NAME TYPE KTEXT,              " Name
        DESC TYPE KLTXT,              " Description
        MSG(55) TYPE C,               " Message
       END OF TY_DATA.
*&  Work area Declaration
DATA:
     WA_DATA TYPE TY_DATA.
*&  Internal tables Declaration
DATA: T_DATA TYPE STANDARD TABLE OF TY_DATA INITIAL SIZE 0,
      t_write_list TYPE TABLE OF abaplist.
*Global Variables
CONSTANTS: c_yes TYPE xfeld VALUE 'X'.
data: v_subrc TYPE sy-subrc,
      v_error_exist TYPE xfeld.
*&  Selection Screen Declaration
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_test TYPE checkbox DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: rb_file RADIOBUTTON GROUP r1.
SELECTION-SCREEN COMMENT 3(29) FOR FIELD p_file.
PARAMETERS: p_file LIKE rlgrap-filename.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 3.
SELECTION-SCREEN COMMENT 3(29) FOR FIELD p_header.
PARAMETERS: p_header(3) TYPE n DEFAULT 1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: rb_clbd RADIOBUTTON GROUP r1.
SELECTION-SCREEN COMMENT (28) text-003.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.
PARAMETERS: p_intca TYPE c NO-DISPLAY.  " Internal call
Screen Validations
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM get_filename USING  p_file.
AT SELECTION-SCREEN ON p_file.
  PERFORM validate_filename.
Start Of Selection
START-OF-SELECTION.
IF p_intca IS INITIAL.
Do this because we do not want to lock the material items
when using BAPI_GOODSMVT_CREATE. With SUBMIT, the locks
on materials will be released
    SUBMIT ZKCZ005R
      WITH p_test = p_test
      WITH rb_file = rb_file
      WITH p_file = p_file
      WITH p_header = p_header
      WITH rb_clbd = rb_clbd
      WITH p_intca = 'X'
      EXPORTING LIST TO MEMORY AND RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = t_write_list
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc <> 0.
    ENDIF.
    IF NOT t_write_list[] IS INITIAL.
      CALL FUNCTION 'WRITE_LIST'
        TABLES
          listobject = t_write_list.
    ENDIF.
  ELSE.
    CHECK v_subrc IS INITIAL.
    PERFORM upload_data CHANGING v_subrc.
    IF v_subrc IS INITIAL.
      PERFORM CREATE_DATA.
    ENDIF.
   PERFORM display_data.
ENDIF.
End Of Selection
END-OF-SELECTION.
SUBROUTINES
*&      Form  get_filename
FORM get_filename  USING pi_file TYPE rlgrap-filename.
  DATA: lv_file  TYPE string,
        li_files TYPE filetable,
        lv_subrc TYPE i,
        lv_title TYPE string VALUE 'File System for Pres. Server'.
  lv_file = pi_file.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = lv_title
      default_filename        = lv_file
    CHANGING
      file_table              = li_files
      rc                      = lv_subrc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      OTHERS                  = 4.
  READ TABLE li_files INDEX 1 INTO pi_file.
ENDFORM.                    " get_filename
*&      Form  validate_filename
FORM validate_filename .
  CHECK rb_file = c_yes.
  IF p_file IS INITIAL.
    MESSAGE e318 WITH 'Enter file path name'.
  ENDIF.
ENDFORM.                    " validate_filename
*&      Form  upload_data
FORM upload_data CHANGING pc_v_subrc TYPE sy-subrc.
  DATA: lv_file TYPE string,
        lv_subrc LIKE sy-subrc,
        lv_tabix TYPE sy-tabix,
        lwa_data TYPE TY_data,
        lt_clip(1024) OCCURS 0 WITH HEADER LINE.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = 'Uploading data'(t01).
  CLEAR pc_v_subrc.
  REFRESH T_data.
  IF rb_clbd = 'X'.
    CALL FUNCTION 'CLPB_IMPORT'
      TABLES
        data_tab = lt_clip.
    LOOP AT lt_clip.
      CHECK lt_clip NE space.
      CLEAR lwa_data.
      PERFORM asc2dat_konvert
          IN PROGRAM saplgrap USING lt_clip lwa_data lv_subrc.
      APPEND lwa_data TO T_data.
      CLEAR:Lwa_DATA.
    ENDLOOP.
  ELSEIF rb_file = 'X'.
    lv_file = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename            = lv_file
        filetype            = 'ASC'
        has_field_separator = 'X'
        dat_mode            = 'X'
      TABLES
        data_tab            = t_data
      EXCEPTIONS
        OTHERS              = 4.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
endif.
  IF t_data[] IS INITIAL.
    pc_v_subrc = 4.
  ENDIF.
ENDFORM.                    " upload_data
*&      Form  CREATE_data
FORM CREATE_DATA .
  DATA: lv_tabix TYPE sy-tabix,
        lv_tot_records TYPE i.
For BAPI
  DATA : lt_data TYPE TABLE OF BAPI0012_CCINPUTLIST,
         lT_return TYPE TABLE OF bapiret2,
         lv_test TYPE bapi2017_gm_gen-testrun,
         LWA_DATA TYPE BAPI0012_CCINPUTLIST,
         LV_HEADER TYPE BAPI0012_GEN-CO_AREA.
  IF p_test IS INITIAL.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        text = 'Posting data'(t02).
  ELSE.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        text = 'Simulate posting'(t03).
  ENDIF.
  lv_test = p_test.
LOOP AT T_DATA INTO WA_DATA.
LWA_DATA-COSTCENTER =  WA_DATA-KOSTL.
LWA_DATA-VALID_FROM =  WA_DATA-VALID_FROM.
LWA_DATA-COMP_CODE = WA_DATA-COMP_CODE.
LWA_DATA-VALID_TO = WA_DATA-VALID_TO.
LWA_DATA-PERSON_IN_CHARGE = WA_DATA-PERSON_IN_CHARGE.
LWA_DATA-DEPARTMENT = WA_DATA-DEPARTMENT.
LWA_DATA-COSTCENTER_TYPE = WA_DATA-COSTCENTER_TYPE.
LWA_DATA-COSTCTR_HIER_GRP = WA_DATA-COSTCTR_HIER_GRP.
LWA_DATA-BUS_AREA = WA_DATA-BUS_AREA.
LWA_DATA-PROFIT_CTR = WA_DATA-PROFIT_CTR.
LWA_DATA-LOCK_IND_COMMITMENT_UPDATE = WA_DATA-LOCK_UPDATE.
LWA_DATA-CSTG_SHEET = WA_DATA-CSTG_SHEET.
LWA_DATA-ADDR_TITLE = WA_DATA-TITLE.
LWA_DATA-TELCO_LANGU = WA_DATA-TELCO_LANGU.
LWA_DATA-NAME = WA_DATA-NAME.
LWA_DATA-DESCRIPT = WA_DATA-DESC.
APPEND: LWA_DATA TO LT_DATA.
CLEAR: LWA_DATA,WA_DATA.
ENDLOOP.
LV_HEADER = 'SG01'.
CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'
  EXPORTING
    CONTROLLINGAREA           = LV_HEADER
   TESTRUN                    = ' '
   MASTER_DATA_INACTIVE       = ' '
  TABLES
    COSTCENTERLIST            = LT_DATA
    RETURN                    = LT_RETURN
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     WAIT   = 'X'.
ELSE.
   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFORM.                    " CREATE_data
.Thanks,
Murali

Hi Devi,
After call BAPI 'BAPI_COSTCENTER_CREATEMULTIPLE' "SY" structure has:
MSGID                                     KS
MSGTY                                     E
MSGNO                                     002
MSGV1                                     1000
MSGV2                                     COST CENTER
Try next code after call the BAPI.
  READ TABLE et_return WITH KEY type = 'E'
  TRANSPORTING NO FIELDS.
  IF sy-subrc NE 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = abap_true
      IMPORTING
        return = lw_bapiret2.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = lw_bapiret2.
  ENDIF.

Similar Messages

  • Extensionin parameter in BAPI_COSTCENTER_CREATEMULTIPLE

    Hi,
      I  have created a BAPI "BAPI_COSTCENTER_CREATEMULTIPLE" and cost centers are created successfully but Custom fields are not updated. the below is the codePlease, help me.
      DATA: t_cclist TYPE STANDARD TABLE OF bapi0012_ccinputlist,
            wa_cclist TYPE bapi0012_ccinputlist,
            t_extin TYPE STANDARD TABLE OF bapiparex,
            wa_extin TYPE bapiparex,
            t_ret TYPE STANDARD TABLE OF bapiret2,
            wa_ret TYPE bapiret2.
      wa_cclist-costcenter = 'TST413'.
      wa_cclist-valid_from = sy-datum.
      wa_cclist-valid_to = '99991231'.
      wa_cclist-person_in_charge = 'DEVON'.
      wa_cclist-department = '000000032328'.
      wa_cclist-costcenter_type = 'O'.
      wa_cclist-costctr_hier_grp = 'FLD0000006'.
      wa_cclist-comp_code ='0132'.
      wa_cclist-profit_ctr = 'P0000016'.
      wa_cclist-addr_title = 'TITLE'.
      wa_cclist-addr_name1 = 'NAME 1'.
      wa_cclist-addr_city = 'NAME 2'.
      wa_cclist-addr_district = ' '.
      wa_cclist-addr_country = 'CA'.
      wa_cclist-addr_region = 'BC'.
      wa_cclist-jv_venture = '100000'.
      wa_cclist-jv_rec_ind = 'BI'.
      wa_cclist-jv_equity_typ = 'E01'.
      wa_cclist-jv_otype = 'C001'.
      wa_cclist-name = 'MANATOKAN HOL 100/06'.
      wa_cclist-descript = 'MANATOKAN HOL 100/06C-14-62-6W4M SL5-14'.
      APPEND wa_cclist TO t_cclist.
      CLEAR wa_cclist.
    Move custom fields to BAPI strcture
      CLEAR wa_extin.
      wa_extin-structure = 'BAPI_TE_CSKS'.
    wa_extin-valuepart1+0(10) = 'TST413'. "Cost Center
      wa_extin-valuepart1+10(4) = '100'.  "Acquisition
      wa_extin-valuepart1+14(4) = ''.   "Divestiture
      wa_extin-valuepart1+16(4) = ''. "Company Prior to Rollup
      wa_extin-valuepart1+20(20) = ''.  "Cost Center Groupings
      wa_extin-valuepart1+40(2) = ''.     "Business Segment
      wa_extin-valuepart1+42(6) = ''.   "Exploratory Play
      wa_extin-valuepart1+48(38) = ''.    "Peep GUID
      wa_extin-valuepart1+86(3) = ''.   "Surface Location Unique Well Identifier Survey System
      wa_extin-valuepart1+89(16) = ''.  "Surface Location Unique Well Identifier UWI
      wa_extin-valuepart1+105(25) = 'DEVON ENERGY CORPORATION'.    "Acquisition Description
      wa_extin-valuepart1+135(25) = ''.   "Divestiture Description
      wa_extin-valuepart1+160(30) = ''.   "Cost Center Groupings Description
      wa_extin-valuepart1+190(15) = ''.   "Business Segment Description
      wa_extin-valuepart1+205(25) = ''.   "Company Prior to Rollup Description
      wa_extin-valuepart2+0(30) = ''. "Exploratory Play Description
      wa_extin-valuepart2+30(10) = '20110607'. "Effective Date of Sale
      wa_extin-valuepart2+40(10) = '20110607'. "Closing Date
      wa_extin-valuepart2+50(10) = '20110607'. "Post Close/Binding Date
      wa_extin-valuepart2+60(8) = '25'.   "Location :Latitude
      wa_extin-valuepart2+68(1) = 'N'.   "Location:Latitude Direction
      wa_extin-valuepart2+69(9) = '36'.   "Location:Longitude
      wa_extin-valuepart2+77(1) = 'S'.   "Location:Longitude Direction
      wa_extin-valuepart2+78(3) = 'DLS'. "Unique Well Identifier: Survey System
      wa_extin-valuepart2+81(16) = '100052006908600'.    "Unique Well Identifier: UWI
      wa_extin-valuepart2+97(10) = ''.  "Service Provider
      wa_extin-valuepart2+107(6) = 'PROD'.    "Status
      wa_extin-valuepart2+113(10) = 'ARL SUCC'. "Tax Successor Code
      wa_extin-valuepart2+123(10) = 'DEV01OCT14'.   "Tax Stream Pool
      wa_extin-valuepart2+133(14) = '100'.   "Percent
      wa_extin-valuepart2+147(35) = ''. "Service Provider Description
      wa_extin-valuepart2+182(20) = 'PRODUCING'. "Status Description
      wa_extin-valuepart2+202(15) = 'ARL SUCCESOR'. "Tax Successor Description
      wa_extin-valuepart3+0(40) ='DEVON ACQD AFTER 2001-10-14'.  "Tax Stream Pool Description
      APPEND wa_extin TO t_extin.
      CLEAR wa_extin.
      CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'
        EXPORTING
          controllingarea      = 'D001'
        TESTRUN              = ' '
        MASTER_DATA_INACTIVE = ' '
        LANGUAGE             =
        TABLES
          costcenterlist       = t_cclist
          return               = t_ret
          extensionin          = t_extin.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    Thanks,
    Deepthi.

    Custom fields are updated now. I have  created one BADI and moved into strctures.

  • Create Cost center using Bapi_costcenter_createmultiple

    Hi All,
    This is the first time that i am working on BAPI.
    I have to upload an xcel sheet which has the data of required filds that are needed to create the cost center in tcode KS01.
    So my flat file is ready to be used.
    I am unable to use the bapi to upload this data and i am also getting a runtime error.
    I am posting my code. Please help me out to finish the requirement.
    DATA: T_COST     TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE,
          T_CONT     TYPE BAPI0012_GEN-CO_AREA,
          T_LIST     LIKE BAPI0012_CCINPUTLIST OCCURS 0 WITH HEADER LINE,
          T_RETN     LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
    DATA: V_FILE like IBIPPARMS-PATH,
          v_field like DYNPREAD-FIELDNAME,
          v_file1 like RLGRAP-FILENAME.
    CALL FUNCTION 'F4_FILENAME'
       EXPORTING
         PROGRAM_NAME        = SYST-CPROG
         DYNPRO_NUMBER       = SYST-DYNNR
         FIELD_NAME          = v_field
       IMPORTING
         FILE_NAME           = v_FILE
    v_file1 = v_file.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                      = V_FILE1
          i_begin_col                   = 1
          i_begin_row                   = 2
          i_end_col                     = 8
          i_end_row                     = 3
        tables
          intern                        = T_COST
       EXCEPTIONS
         INCONSISTENT_PARAMETERS       = 1
         UPLOAD_OLE                    = 2
         OTHERS                        = 3 .
      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 'BAPI_COSTCENTER_CREATEMULTIPLE'
            EXPORTING
              controllingarea            = T_CONT
             TESTRUN                    = ' '
            MASTER_DATA_INACTIVE       = ' '
             LANGUAGE                    = sy-langu
            tables
              costcenterlist             = T_LIST
              return                     = T_RETN
            EXTENSIONIN                =
            EXTENSIONOUT               =
       LOOP AT T_RETN.
         WRITE:/ T_RETN-MESSAGE.
       ENDLOOP.
    Regards,
    Darpana

    Hi,
    In Bapi  parameter TESTRUN pass 'X' 
    CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'
    EXPORTING
    controllingarea = T_CONT
    TESTRUN = ' '
    MASTER_DATA_INACTIVE = ' '
    or after 'BAPI_COSTCENTER_CREATEMULTIPLE'
    use BAPI_TRANSACTION_COMMIT.
    Thanks,
    Krishna..

  • How to use the next 'initial' cost center in infotype 0027

    Hello experts!
    I need some help in posting in infotype 0027 which should be fairly easy to most of you. As you guys know, there are a total of 25 cost centers available (KST01-KST25) for this infotype. What I want to do is check from KST01 if it exists with a valid entry at a specific date (BEGDA and ENDDA will be provided as well) all the way up to KST25 and choose the first cost center field that is INITIAL. This is used before 'BAPI_COSTCENTER_CREATEMULTIPLE' so that if KST01 up to KST05 all have values on the same BEGDA & ENDDA, how can I have KST06 chosen? Thanks in advance for your help!

    Hi,
       Write as below.
    data : p_0027 like pa0027 occurs 0 with header line.
    data : lv_KOSTL type KOSTL.
    data : lv_index(2) type n.
    data : lv_cost(12).
    field-symbols : <lv_kostl> type any.
    select single * from pa0027 into p_0027.
    do 25 times
          varying lv_KOSTL from p_0027-KST01 next p_0027-KST02.
      lv_index = lv_index + 1.
      IF lv_KOSTL is initial.
        concatenate 'KST' lv_index into lv_cost.
        exit.
      endif.
    enddo.
    assign  component lv_cost of structure p_0027 to <lv_kostl>.
    IF sy-subrc = 0.
    <lv_kostl> = '100'.    " <-- Assign any value here
    ENDIF.
    Regards,
    Srini.

  • WF_Batch id deletes cost center from euipment master data - IE02

    hi guys,
    how to trace this.. we have checked some of our equipment master data that wf_batch id has deleted its cost center..how can we work from this..how to trace which programs/function did it.. is it purely coming from workflow ?

    there is an error, should be:
    Loop at it_tab.
    refresh it_cost.
    or:
    'BAPI_COSTCENTER_CREATEMULTIPLE'
    should be outside loop it_tab....
    greetings,darek
    Edited by: dariusz sobczak on Apr 30, 2008 4:23 PM

  • Is it possible with out BPM- update transaction from flat file - XI -RFC

    Hi
    my requirment is:  i need to update 2 values transaction(ks01)
    Required data we get in flat file(Val1,Val2), that data needs to be updated in transaction KS01 in r/3 system.
    Scenario is: Flat file - XI - Rfc -KS01.
    im have come across couple of doubts while thinking this way:
    ->is it possible using fie -to- rfc scenario to update KS01 transaction in R/3 system through RFC, if possible some body please explain the complete process to implement this scenario.
    ->is it possible file -to- rfc without BPM in XI 
    can somebody please help out me, how can i approach for the above requirment
    -> help would be appriciated and thanks in advance
    Regards
    Rajesh

    The BAPI / RFC corresponding to your requirement is :
    BAPI_COSTCENTER_CREATEMULTIPLE
    You scenario on  a high level would be FILE-XI-RFC
    in your IR, map the corresponding fields of the fiel to the fields in the BAPI's interface.
    As BAPI is synchronous , you may have to use  BPM to implement the Asynch-Sync bridge.
    Regards,
    Ravi

  • Asset and cost centre

    hi,how can i create my own asset and cost centres?

    Hi Lakshmi,
    Use BAPI_FIXEDASSET_CREATE to create assets and BAPI_COSTCENTER_CREATEMULTIPLE to create cost centers.
    Regds,
    Younus
    <b>Reward Helpful Answers!!!</b>

  • Cost Center and Profit Center Planning

    Hi,
    I have one  Co issue.  Pls Suggest me the wiseful solution.
    Cost Center and Profit Center Planning.
    For F-2008 Planning  data they have updated in the month of Aug, 07 for Profit and Loss Items and they have revised the plan data of some cost elements in the month of oct, 2007 (say 5% Increas).  when comparing the cost center report to profit center report, both are not matching.  the reason when i see and reconcile the document nos and values in between cost center and profit center reports  i found out that there are some documents are missing in the profit center report. 
    wherever plan data had revised e.g for cost element Salaries they have updated 100000 Planning cost in the month of Aug, 07.  In the month of Oct, 07 increased 5% i.e.5000. In cost center line items details i found 2 documents for Rs.100000/- and Rs.5000/-  But in Profit Center Line Items i am getting only Rs.5000/- Value Document.
    Note.  As and when KP06 Plan data has been updated Profit Center line items are generating.  It is not necessary to run any programme inorder to transfer Plan Data from cost center to profit center.
    Observations From My Side:-
    I tried to run the transaction code 1ke0. i have selected the cost object is Cost Center, version and had given Cost Center Parameter in development and quality clients and executed the same.By this time already existing data either deleting/ riversing and creating new documents fully except manually changed data in profit center through 7ke1.
    My Question is
    1.Upto what extent it will work.
    2.will it be possible to transfer data from cost center to profit center only missing documents which are available in cost center, without disturbing of existing data in profit center.
    3.suppose if i done this activity, there are some data which was already transferred from other cost objects like internatl orders & wbs elements to Profit Center. will the data get disturbed (deleted/riversed).
    Pls suggest me the wiseful way to solve the

    Hi
    Try This
    BAPI_COSTCENTER_CREATEMULTIPLE
    BAPI_COSTCENTERGROUP_CREATE
    BAPI_PROFITCENTER_CREATE
    BAPI_PROFITCENTERGRP_CREATE.
    Regards,
    V.balaji
    Reward if usefull

  • COst center planning upload

    Hi ,
    My question is more specific to FI (functional).
    Watz the best way to upload the COst center planning?(KP06)?
    this is done for every quarter at my client.
    BDC pgm is looking more complicated.(table control, there are few disabled fields which need to validated)
    but i am able to find an option UPLOAD under menu.
    If i am not wrong there is one more method to this upload using so called Generic files.
    I am technical guy, never worked in FI area. I am having little support form Functional side.( i guess he has not done earlier).
    So completely left to technical .
    can anyone give the method of tips in doing so.
    Regards
    satheesh.

    Hi Parag,
    Thank you for ur response.
    I would like to have some more info regarding the table parameter used in BAPI_COSTCENTER_CREATEMULTIPLE.
    Can you tell me exactly how do we map .
    for eg:
    I have the 5000-300 cost center.
    under this cost center if we have the cost element matches to the file provided.
    the it should  update the planning data(cost center plan) periodically, i mean For JAN FEB MAR (individually).
    Can this happen with the mentioned Func.Modu.
    Let  me know if u have info.
    Regards
    Sathesh

  • FM to create a cost center

    Hello All,
    I need an FM to create a cost center in back ground referring another cost center
    I checked the FM K_COSTCTR_BAPI_CREATEMULTIPLE, does not have an option to create referring another cost center.
    Any help would be greatly appreciated.
    Thank you
    Best Regards
    Amar

    Check BUS object BUS0012 for CostCenter.
    - CostCenter.GetDetail1 to get information from original cost center (BAPI_COSTCENTER_GETDETAIL1)
    - CostCenter.CreateMultiple to create the new one (BAPI_COSTCENTER_CREATEMULTIPLE)
    Regards,
    Raymond

  • Budgeting for Cost center in KPZ2 tcode

    Hi Friends,
    I have a requirement stating to create the cost center and do the budgeting for that cost center.
    This has to be done using BAPI / FM.
    Can anyone help me out in finding out the BAPI / FM .

    Try those BAPI
    - BAPI_COSTCENTER_CREATEMULTIPLE Create One or More Cost Centers
    - BAPI_COSTACTPLN_POSTPRIMCOST Primary Cost Planning: Postings (sample report RK_BAPI_POSTPRIMCOST)
    Regards,
    Raymond

  • BAPI for cost centre create/change

    Hi,
    Is there a BAPI for Cost centre create and change?
    Thanks in advance.
    Regards,
    Arun Mohan

    Hi Ravi,
    My system is 4.6B.
    I found BAPI_COSTCENTER_CREATEMULTIPLE,
    but the BAPI for CC change is not present.
    Is there any other BAPI for CC change?
    Arun

  • Budget and Planning KP06 and CJR2

    Does anybody know about function/BAPI that inputs the budget for cost center (trans. KP06) and projects/WBS (trans. CJR2). I want to stop using BDC and use the function instead.
    I looked at function BAPI_COSTACTPLN_POSTACTINPUT and its group; they don’t work for me because they require the usage of Cost Center/Activity type while we are not using Activity type in here.
    Thanks,
    Naji.
    Message was edited by:
            Naji Aboutanos

    Hi,
    <b>Bapis for cost center(BUS0012):</b>
    BAPI_COSTCENTER_CREATEMULTIPLE Create One or More Cost Centers
    BAPI_COSTCENTER_GETDETAIL Detailed Information About Cost Center For Key Date
    BAPI_COSTCENTER_GETDETAIL1 Detail Information for Cost Center on Key Date (1)
    BAPI_COSTCENTER_GETLIST List of Cost Centers Using Selection Criteria
    BAPI_COSTCENTER_GETLIST1 List of Cost Centers for Selection Criteria (1)
    BAPI_CTR_GETACTALLOCATIONTYPES Checks Which IST-ILV Types are Possible According to Activity Type Categ.
    BAPI_CTR_GETACTIVITYPRICES Read prices for cost center/activity type according to selection
    BAPI_CTR_GETACTIVITYQUANTITIES Rad plan activity/capacity/scheduled activity for cost center/acty type
    BAPI_CTR_GETACTIVITYTYPES List of cost centers / activity types with control information
    <b>Bapi for WBS:</b>
    BAPI_CC1_DNLOAD_WBSELEMENT HR-PDC: Download Work Breakdown Structure Element
    Pls reward points.
    Regards,
    Ameet

  • Bapi to get Cost center group

    Hi,
       Is there any standard bapi that takes cost center as input and displays its corresponding cost center group.
    Thanks,
    Divya.

    hii,
                     just have a luk.
    BAPI_COSTCENTER_CREATEMULTIPLE Create One or More Cost Centers
    BAPI_COSTCENTER_GETDETAIL Detailed Information About Cost Center For Key Date
    BAPI_COSTCENTER_GETDETAIL1 Detail Information for Cost Center on Key Date (1)
    BAPI_COSTCENTER_GETLIST List of Cost Centers Using Selection Criteria
    BAPI_COSTCENTER_GETLIST1 List of Cost Centers for Selection Criteria (1)
    BAPI_CTR_GETACTALLOCATIONTYPES Checks Which IST-ILV Types are Possible According to Activity Type Categ.
    BAPI_CTR_GETACTIVITYPRICES Read prices for cost center/activity type according to selection
    BAPI_CTR_GETACTIVITYQUANTITIES Rad plan activity/capacity/scheduled activity for cost center/acty type
    BAPI_CTR_GETACTIVITYTYPES List of cost centers / activity types with control information
    regards,
    Shweta

  • How can i create orgnsiation structure in sap

    Hi Guys
        Can anybody tell me how to craete an organsation strucuture first when first implimenting the sap in your company...step by step answer
    thankx
    Edited by: madhubabu rao on Jun 12, 2008 1:10 PM

    Hi,
    I have some code which I developed.
    *&      Form  Create_operation_unit
    *       This subroutine is for creation of Operating Unit
    FORM create_operation_unit .
    *  DATA:lv_valto TYPE datab.
      DATA:
    *  lv_desc TYPE bapiset_hier-descript,
           lv_gpname TYPE bapiset_hier-groupname,
          lv_legno TYPE cepc-zzleg_no.
      TYPES : BEGIN OF st_dept,
              ww007 TYPE t25f4-ww007,
              bezek TYPE t25f4-bezek,
              END OF st_dept.
      DATA: lt_dept TYPE TABLE OF st_dept.
      DATA: wa_dept LIKE LINE OF lt_dept,
            lv_lock_ind type cepc-lock_ind,
            lv_segment  type cepc-segment.
      DATA: lv_index TYPE sy-tabix.
      DATA: lv_index1 TYPE sy-tabix,
            lv_prctr  TYPE cepc-prctr,
            lv_zsgid TYPE zfpasgid,
            lv_zsgid_prev TYPE zfpasgid.
      DATA: lv_indicators TYPE bapi0015_8.
      IF p_sd_pct IS NOT INITIAL.                                           "For Profit Center Group.
        CLEAR: gt_hierarchy,gt_hierarchy[].
        CLEAR: gt_hierarchy1,gt_hierarchy1[].
        CLEAR: gt_value,gt_value[].
        CLEAR: gt_value1,gt_value1[].
        GET PARAMETER ID 'CAC' FIELD gv_p_kokrs.
        IF gv_p_kokrs IS INITIAL.
          CALL TRANSACTION 'OKKS'.
          GET PARAMETER ID 'CAC' FIELD gv_p_kokrs.
        ENDIF.
        lv_index = 1.
        lv_index1 = 2.
    * Get deatils of lower levels group from target.
        CALL FUNCTION 'BAPI_PROFITCENTERGRP_GETDETAIL'
          EXPORTING
            controllingarea = gv_p_kokrs
            groupname       = p_sd_pct
          TABLES
            hierarchynodes  = gt_hierarchy
            hierarchyvalues = gt_value.
    ***Get company code for profit center.
        IF gt_value[] IS NOT INITIAL.
          SELECT bukrs
                   FROM csks INTO TABLE gt_csks1
                   FOR ALL ENTRIES IN gt_value
                   WHERE prctr = gt_value-valfrom.
        ENDIF.
        LOOP AT gt_csks1 INTO wa_csks1.
          wa_co_code-comp_code = wa_csks1-bukrs.
          wa_co_code-assign_to_prctr = 'X'.
          APPEND wa_co_code TO gt_co_code.
        ENDLOOP.
        SELECT ww007 bezek FROM t25f4 INTO TABLE lt_dept
                          WHERE spras = sy-langu.
        LOOP AT lt_dept INTO wa_dept.
          READ TABLE gt_hierarchy INTO wa_hierarchy WITH KEY groupname+7(3) = wa_dept-ww007+5(3).
          IF ( wa_dept-ww007(4) = p_sd_pct AND wa_dept-ww007+5(3) = wa_hierarchy-groupname+7(3) ).
            lv_gpname = wa_hierarchy-groupname.
            wa_hierarchy-descript = wa_dept-bezek.
            MODIFY gt_hierarchy FROM wa_hierarchy
                   TRANSPORTING descript
                 WHERE groupname = lv_gpname.
          ENDIF.
        ENDLOOP.
    *   Get the Lock indicator and segmant from source Operting unit.
          SELECT lock_ind
                 segment
            FROM cepc
            INTO (lv_lock_ind,
                   lv_segment)
            BYPASSING BUFFER
            WHERE datbi GE sy-datum
              AND kokrs = gv_p_kokrs
              AND KHINR = p_sd_pct.   "cepc values for source group
          endselect.
        READ TABLE gt_hierarchy INTO wa_hierarchy WITH KEY groupname = p_sd_pct.
    *  gv_tgt_level = wa_hierarchy-hierlevel - 1.                           "chain level
        gv_src_level = wa_hierarchy-hierlevel.                              "Operating unit level
        gv_dep_level = wa_hierarchy-hierlevel + 1.                          "department level.
        LOOP AT gt_hierarchy INTO wa_hierarchy.
          IF wa_hierarchy-hierlevel = gv_src_level.                         "Opearing Unit node
            wa_hierarchy1-groupname = p_dsno.
    *        wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-descript = p_name.
            wa_hierarchy1-hierlevel = wa_hierarchy-hierlevel.
            APPEND wa_hierarchy1 TO gt_hierarchy1.
          ENDIF.
          IF wa_hierarchy-hierlevel = gv_dep_level.                         "Department node
            CONCATENATE p_dsno wa_hierarchy-groupname+7(3) INTO gv_ngrname.
            wa_hierarchy1-groupname = gv_ngrname.
    *        wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-hierlevel = wa_hierarchy-hierlevel.
            APPEND wa_hierarchy1 TO gt_hierarchy1.
          ENDIF.
          CLEAR wa_hierarchy1.
        ENDLOOP.
        DELETE ADJACENT DUPLICATES FROM gt_hierarchy1
                     COMPARING groupname.
    *---BEGIN Create profit center group
        CALL FUNCTION 'BAPI_PROFITCENTERGRP_CREATE'
          EXPORTING
            controllingareaimp = gv_p_kokrs
          IMPORTING
            return             = wa_message
          TABLES
            hierarchynodes     = gt_hierarchy1
            hierarchyvalues    = gt_value1.
        IF wa_message IS INITIAL.
          CONCATENATE p_dsno text-020
                      INTO wa_message-message
                      SEPARATED BY space.
          APPEND wa_message TO gt_message.
    * Add node only if PCGroup is created successfully
    *---BEGIN Add node to profit center group
          CALL FUNCTION 'BAPI_PROFITCENTERGRP_ADDNODE'
            EXPORTING
              controllingarea = gv_p_kokrs
              groupname       = p_tg_pct
              subgroupname    = p_dsno
            IMPORTING
              return          = wa_message.
          IF wa_message IS INITIAL.
            CONCATENATE p_dsno text-021 p_tg_pct
                        INTO wa_message-message
                        SEPARATED BY space.
            APPEND wa_message TO gt_message.
    *---Create Profit Center ONLY if PCgroup and ADD node created.
            gv_pcgroup_created = 'X'.                                       "flag used while Creating Profit Centers
    *---Cost center group cration based on successful PC group creation.
          ELSE.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
            APPEND wa_message TO gt_message.
          ENDIF.
          PERFORM output CHANGING gt_message.
          CLEAR: gt_message,gt_message[],wa_message.
    *---END Add node
        ELSE.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          APPEND wa_message TO gt_message.
        ENDIF.
        PERFORM output CHANGING gt_message.
        CLEAR: gt_message,gt_message[].
    *---END PC Group Create
      ENDIF.                                                                "end For Profit Center Group.
      IF p_sd_cct IS NOT INITIAL AND gv_pcgroup_created EQ 'X'.             "For Cost Center Group.ONLY when PC group creation is successful
        CLEAR: gt_hierarchy,gt_hierarchy[].
        CLEAR: gt_hierarchy1,gt_hierarchy1[].
        CLEAR: gt_value,gt_value[].
        CLEAR: gt_value1,gt_value1[].
    * Get deatils of lower levels group from target.
        CALL FUNCTION 'BAPI_COSTCENTERGROUP_GETDETAIL'
          EXPORTING
            controllingarea = gv_p_kokrs
            groupname       = p_sd_cct
          TABLES
            hierarchynodes  = gt_hierarchy
            hierarchyvalues = gt_value.
        READ TABLE gt_value INTO wa_value INDEX 1.
        IF sy-subrc = 0.
          SELECT SINGLE kokrs khinr bukrs kosar
                      FROM csks
                      INTO (gv_c_kokrs, gv_c_grpname, gv_c_bukrs, gv_kosar)
                      WHERE kokrs = gv_p_kokrs
                      AND   kostl = wa_value-valfrom
                      AND   datbi GE sy-datum.
        ENDIF.
        LOOP AT lt_dept INTO wa_dept.
          READ TABLE gt_hierarchy INTO wa_hierarchy WITH KEY groupname+7(3) = wa_dept-ww007+5(3).
          IF ( wa_dept-ww007(4) = p_sd_cct AND wa_dept-ww007+5(3) = wa_hierarchy-groupname+7(3) ).
            lv_gpname = wa_hierarchy-groupname.
            wa_hierarchy-descript = wa_dept-bezek.
            MODIFY gt_hierarchy FROM wa_hierarchy
                   TRANSPORTING descript
                 WHERE groupname = lv_gpname.
          ENDIF.
        ENDLOOP.
        READ TABLE gt_hierarchy INTO wa_hierarchy WITH KEY groupname = p_sd_cct.
    *  gv_tgt_level = wa_hierarchy-hierlevel - 1.                           "chain level
        gv_src_level = wa_hierarchy-hierlevel.                              "Operating unit level
        gv_dep_level = wa_hierarchy-hierlevel + 1.                          "department level.
        LOOP AT gt_hierarchy INTO wa_hierarchy.
          IF wa_hierarchy-hierlevel = gv_src_level.                         "Operating Unit node
            wa_hierarchy1-groupname = p_dsno.
    *        wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-descript = p_name.
            wa_hierarchy1-hierlevel = wa_hierarchy-hierlevel.
            APPEND wa_hierarchy1 TO gt_hierarchy1.
          ENDIF.
          IF wa_hierarchy-hierlevel = gv_dep_level.                         "Department node
            CONCATENATE p_dsno wa_hierarchy-groupname+7(3) INTO gv_ngrname.
            wa_hierarchy1-groupname = gv_ngrname.
    *        wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-descript = wa_hierarchy-descript.
            wa_hierarchy1-hierlevel = wa_hierarchy-hierlevel.
            APPEND wa_hierarchy1 TO gt_hierarchy1.
          ENDIF.
          CLEAR wa_hierarchy1.
        ENDLOOP.
    *Create Cost Center Group
    *---BEGIN of COSTCENTER Group CREATE
        CALL FUNCTION 'BAPI_COSTCENTERGROUP_CREATE'
          EXPORTING
    *dinesh
            controllingareaimp = gv_p_kokrs
          IMPORTING
            return             = wa_message
          TABLES
            hierarchynodes     = gt_hierarchy1
            hierarchyvalues    = gt_value1.
        IF wa_message IS INITIAL.
          CONCATENATE p_dsno text-022
                      INTO wa_message-message
                      SEPARATED BY space.
          APPEND wa_message TO gt_message.
    *Add node to cost center group ONLY if Cost Center Group creation is successful
    *---BEGIN of ADDNODE
          CALL FUNCTION 'BAPI_COSTCENTERGROUP_ADDNODE'
            EXPORTING
    *dinesh
              controllingarea = gv_p_kokrs
              groupname       = p_tg_cct
              subgroupname    = p_dsno
            IMPORTING
              return          = wa_message.
          IF wa_message IS INITIAL.
            CONCATENATE p_dsno text-023 p_tg_cct
                        INTO wa_message-message
                        SEPARATED BY space.
            APPEND wa_message TO gt_message.
    * Cost Center is created ONLY if Cost Center group and add node is successful
            gv_ccgroup_created = 'X'.                                       "flag used while crateing cost center
          ELSE.
    *Rollback if BAPI fails in Adding Node
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
            APPEND wa_message TO gt_message.
          ENDIF.
          PERFORM output CHANGING gt_message.
          CLEAR: gt_message,gt_message[],wa_message.
    *---END of ADDNODE
        ELSE.
    *Rollback if BAPI fails in creating group
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          APPEND wa_message TO gt_message.
        ENDIF.
        PERFORM output CHANGING gt_message.
        CLEAR: gt_message,gt_message[],wa_message.
    *---END of COSTCENTER CREATE
      ENDIF.                                                                "End of Cost Center Group
      LOOP AT gt_hierarchy1 INTO wa_hierarchy1.
        CLEAR: wa_profitcenterid,wa_basicdata,wa_address.
        CLEAR: wa_costcenterlist,gt_costcenterlist,gt_costcenterlist[].
    ***Call function get_next_numbers to generate profit center no.
        CALL FUNCTION 'NUMBER_GET_NEXT'
          EXPORTING
            nr_range_nr             = '02'
            object                  = 'COPCA_OBJ'
          IMPORTING
            number                  = gv_number
          EXCEPTIONS
            interval_not_found      = 1
            number_range_not_intern = 2
            object_not_found        = 3
            quantity_is_0           = 4
            quantity_is_not_1       = 5
            interval_overflow       = 6
            buffer_overflow         = 7
            OTHERS                  = 8.
        IF sy-subrc <> 0.
          IF sy-subrc = 8.
            wa_message-id = sy-msgid.
            wa_message-type = sy-msgty.
            wa_message-number = sy-msgno.
            wa_message-message_v1 = sy-msgv1.
            wa_message-message_v2 = sy-msgv2.
            wa_message-message_v3 = sy-msgv3.
            wa_message-message_v4 = sy-msgv4.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 1.
            wa_message-message_v1 = text-043.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 2.
            wa_message-message_v1 = text-044.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 3.
            wa_message-message_v1 = text-045.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 4.
            wa_message-message_v1 = text-046.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 5.
            wa_message-message_v1 = text-047.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 6.
            wa_message-message_v1 = text-048.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[].
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ELSEIF sy-subrc = 7.
            wa_message-message_v1 = text-049.
            APPEND wa_message TO gt_message.
            PERFORM output CHANGING gt_message.
            CLEAR: gt_message,gt_message[],wa_message.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ENDIF.
        ELSE.
          IF p_sd_pct IS NOT INITIAL.                                       "For Profit Center create.
    *Create Profit Center only when Profit center group creation and add node is successful
            IF gv_pcgroup_created = 'X'.                                    "PCG flag check
              clear: wa_profitcenterid,
                     wa_basicdata,
                     wa_address,
                     lv_indicators.
              wa_profitcenterid-co_area = gv_p_kokrs.
              wa_profitcenterid-profit_ctr = gv_number.
              wa_basicdata-prctr_name = wa_hierarchy1-groupname.
              wa_basicdata-long_text = wa_hierarchy1-descript.
              wa_basicdata-in_charge = sy-uname.
              wa_basicdata-prctr_hier_grp = wa_hierarchy1-groupname.
              wa_basicdata-segment        = lv_segment.
              IF wa_hierarchy1-hierlevel = gv_src_level.                    "Address and locking only in Op.Unit
                lv_indicators-LOCK_IND = lv_lock_ind.
                wa_address-name       = p_name.
                wa_address-street     = p_strt.
                wa_address-city       = p_city.
                wa_address-postl_code = p_pcod.
                wa_address-country    = p_cont.
                wa_address-region     = p_reg.
              ENDIF.
    * Create Profit Center
    *          WAIT UP TO 2 SECONDS.
              CALL FUNCTION 'BAPI_PROFITCENTER_CREATE'
                EXPORTING
                  profitcenterid = wa_profitcenterid
                  validfrom      = p_date
                  validto        = c_validto
                  basicdata      = wa_basicdata
                  address        = wa_address
                  indicators     = lv_indicators
                IMPORTING
                  return         = wa_message
                TABLES
                  companycodes   = gt_co_code.
    *          WAIT UP TO 2 SECONDS.
              IF wa_message-type NE 'E' OR wa_message-type NE 'A'.
                CONCATENATE wa_profitcenterid-profit_ctr text-024
                            INTO wa_message-message
                            SEPARATED BY space.
                APPEND wa_message TO gt_message.
              ELSE.
                CLEAR gv_pcgroup_created.                                    "CEPC updation is based on this
                CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
                APPEND wa_message TO gt_message.
              ENDIF.
              PERFORM output CHANGING gt_message.
              CLEAR: gt_message,gt_message[],wa_message.
            ENDIF .                                                         "end of flag check
          ENDIF.                                                            "end of profitcenter create
          IF p_sd_cct IS NOT INITIAL.                                       "For Cost Center Create.
    *Create Cost Center only when Cost center group creation and add node is successful
            IF gv_ccgroup_created = 'X'.                                    "CCG flag check
              IF wa_hierarchy1-hierlevel = gv_dep_level.                    "Cost Center only in Dept level
                READ TABLE gt_value INTO wa_value INDEX lv_index1.
                SELECT kostl kosar FROM csks
                        INTO TABLE gt_csks_cat
                        WHERE kostl = wa_value-valfrom.
                lv_index1 =  lv_index1 + 1.
                READ TABLE gt_csks_cat INTO wa_csks_cat WITH KEY kostl = wa_value-valfrom.
                wa_costcenterlist-costcenter       = gv_number.
                wa_costcenterlist-valid_from       = p_date.
                wa_costcenterlist-valid_to         = c_validto. "31.12.9999
                wa_costcenterlist-person_in_charge = sy-uname.
                wa_costcenterlist-comp_code        = gv_c_bukrs .
                wa_costcenterlist-costcenter_type  = wa_csks_cat-kosar.
                wa_costcenterlist-costctr_hier_grp = wa_hierarchy1-groupname.
                wa_costcenterlist-descript         = wa_hierarchy1-descript.
                wa_costcenterlist-name             = wa_hierarchy1-groupname.
                wa_costcenterlist-profit_ctr       = gv_number.
                APPEND wa_costcenterlist TO gt_costcenterlist.
    *---BEGIN Create Cost Center
                CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'
                  EXPORTING
                    controllingarea = gv_p_kokrs
                  TABLES
                    costcenterlist  = gt_costcenterlist
                    return          = gt_message.
                READ TABLE gt_message INTO wa_message INDEX 1.
                CLEAR gt_message[].
                IF wa_message-type = 'E' OR wa_message-type = 'A'.
                  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
                  CONCATENATE wa_message-message wa_message-message_v1 text-050 p_dsno text-051
                      INTO wa_message-message
                      SEPARATED BY space.
                  APPEND wa_message TO gt_message.
                  CLEAR: gt_message,gt_message[],wa_message.
                ELSE.
    * Activate only if Cost center is created successfully
    *---BEGIN of ACTIVATION
                  CLEAR : wa_costcenterlist_act,gt_costcenterlist_act[].
                  wa_costcenterlist_act-co_area     = gv_p_kokrs.
                  wa_costcenterlist_act-costcenter     = gv_number.
                  wa_costcenterlist_act-name            = p_name.
                  wa_costcenterlist_act-descript     = wa_hierarchy1-descript.
                  wa_costcenterlist_act-act_state     = 'X'.
                  APPEND wa_costcenterlist_act TO gt_costcenterlist_act.
                  CALL FUNCTION 'BAPI_CTR_ACTIVATE_MULTIPLE'
                    EXPORTING
                      controllingarea = gv_p_kokrs
                    TABLES
                      costcenterlist  = gt_costcenterlist_act
                      return          = gt_message.
                  READ TABLE gt_message INTO wa_message INDEX 1.
                  IF wa_message-type = 'E' OR wa_message-type = 'A'.
                    CLEAR gv_ccgroup_created.                                 "CEPC updation is based on this condition
                    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
                    CONCATENATE p_dsno text-050
                                INTO wa_message-message
                                SEPARATED BY space.
                    APPEND wa_message TO gt_message.
                  ELSE.
                    CONCATENATE wa_profitcenterid-profit_ctr text-025 text-026
                                INTO wa_message-message
                                SEPARATED BY space.
                    APPEND wa_message TO gt_message.
                    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.                "COMMIT CC activation
                  ENDIF.
                  PERFORM output CHANGING gt_message.
                  CLEAR: gt_message,gt_message[],wa_message.
    *---END of ACTIVATION
                ENDIF.
                PERFORM output CHANGING gt_message.
                CLEAR: gt_message,gt_message[],wa_message.
    *---END Create Cost Center
              ENDIF.
            ENDIF.                                                          "end of CCG flag check
          ENDIF.                                                            "end of cost center create
    *--Updating CEPC Append Structure ZDSG_DATA and sales group table ZFPASALESGROUP
          IF gv_ccgroup_created = 'X' AND gv_pcgroup_created = 'X'.
            READ TABLE gt_hierarchy
                       INTO wa_hierarchy
                       WITH KEY hierlevel = wa_hierarchy1-hierlevel.          "source group
            IF sy-subrc = 0.
    *CEPC values for source group
              READ TABLE gt_value INTO wa_value INDEX lv_index.
              SELECT SINGLE * FROM cepc
                        INTO wa_cepc BYPASSING BUFFER
                        WHERE  kokrs   = gv_p_kokrs
                        AND datbi      GE sy-datum
                        AND prctr      = wa_value-valfrom.
    * For updating CEPC
              IF sy-subrc = 0.
                READ TABLE gt_hierarchy INDEX lv_index
                         INTO wa_hierarchy.
                lv_index = lv_index + 1.
                IF wa_hierarchy-hierlevel = 1.
                  CONCATENATE p_legacy wa_hierarchy-groupname+7(3) INTO lv_legno.
                  p_ztype = '05'.
                  p_zstype = ' '.
                ELSE.
                  lv_legno = p_legacy.
                ENDIF.
                wa_cepc-prctr        = gv_number.
                wa_cepc-datbi        = c_validto.
                wa_cepc-kokrs        = gv_p_kokrs.
                wa_cepc-zzleg_no  = lv_legno.
                wa_cepc-zztype        = p_ztype.
                wa_cepc-zzstype   = p_zstype.
                wa_cepc-zzfsdate  = p_sal_da.
                wa_cepc-zzdist        = p_zdist.
                wa_cepc-zzsvat    = p_zsvat.
                APPEND wa_cepc TO gt_cepc.
                PERFORM update_append_cepc TABLES gt_cepc.
                CLEAR:wa_cepc,gt_cepc[],gt_cepc,lv_prctr.
    * For updating ZFPASALESGROUP
                SELECT SINGLE prctr
                  INTO lv_prctr
                  FROM cepc
                 WHERE khinr = wa_hierarchy-groupname.
                IF sy-subrc = 0.
                  SELECT  * FROM zfpasalesgroup
                            INTO TABLE gt_salesgrp
                           WHERE zvalid_from GE p_date
                             AND zvalid_to LE c_validto
                             AND prctr = lv_prctr
                             AND zdeactive = ''.
                  IF sy-subrc = 0.
                    SELECT MAX( zsgid ) INTO lv_zsgid FROM  zfpasalesgroup.
                    IF lv_zsgid IS INITIAL.
                      lv_zsgid = '1000000000'.
                    ENDIF.
                    SORT gt_salesgrp BY zsgid zvalid_from.
                    LOOP AT gt_salesgrp INTO wa_salesgrp.
                      IF lv_zsgid_prev NE wa_salesgrp-zsgid OR lv_zsgid_prev IS INITIAL.
    *                      wa_salesgrp-zsgid = lv_zsgid.
    *                  else.
                        lv_zsgid = lv_zsgid + 1.
                        lv_zsgid_prev = wa_salesgrp-zsgid.
                        wa_salesgrp-zsgid = lv_zsgid.
                      ELSE.
    *                  lv_zsgid_prev = lv_zsgid.
                        wa_salesgrp-zsgid = lv_zsgid.
                      ENDIF.
                      wa_salesgrp-prctr = gv_number.
                      IF wa_salesgrp-zvalid_from LT p_date.
                        wa_salesgrp-zvalid_from = p_date.
                      ENDIF.
    *              wa_salesgrp-zvalid_to = c_validto.
    *                insert new entry in zfpasalesgroup for data entered on screen.
                      INSERT into zfpasalesgroup values wa_salesgrp.
    *                MODIFY zfpasalesgroup FROM TABLE gt_salesgrp .
    *                Message for output
                      IF sy-subrc = 0.
                        CONCATENATE  wa_salesgrp-zsgid text-102 'ZFPASALESGROUP'
                                    INTO wa_message-message
                                    SEPARATED BY space.
                        wa_message-type = 'S'.
                        APPEND wa_message TO gt_message.
                        PERFORM output CHANGING gt_message.
                        CLEAR: gt_message,gt_message[],wa_message.
                      ELSE.
    *                Message for output if its not successful
                        CONCATENATE text-103 'ZFPASALESGROUP'
                                    INTO wa_message-message
                                    SEPARATED BY space.
                        wa_message-type = 'E'.
                        APPEND wa_message TO gt_message.
                        PERFORM output CHANGING gt_message.
                        CLEAR: gt_message,gt_message[],wa_message.
                      ENDIF.
                      CLEAR wa_salesgrp.
                    ENDLOOP.
                    CLEAR: wa_salesgrp, gt_salesgrp[], gt_salesgrp,lv_zsgid_prev .
                  ENDIF.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
      PERFORM display_log CHANGING gt_log.
      PERFORM clear_variables.
      gv_active_tab = 'SOS_TAB1'.
    ENDFORM.                    " Create_operation_unit
    <REMOVED BY MODERATOR>
    Regards
    Susheel
    Code Formatted by: Alvaro Tejada Galindo on Jun 12, 2008 4:31 PM

Maybe you are looking for