Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

need a function module for profit center

former_member810660
Participant
0 Likes
2,702

Hi all experts,

can some one give me some suggestions regarding the below given issue.

some function modules or bapi's if any

For the profit center master data we need to pull only level 4, 6, 7 and profit center descriptions for 4 specific nodes. I wanted to find out if there was any function module available which can be used to extract these levels for specific profit centers. Also if there was any function module available which would pull all the profit centers below a given node all the way through the hierarchy. For example if given a level 4 node is there something available which would get all the profit centers under this node, instead of having to use tables SETNODE and SETLEAF which gets pretty complicated once you reach level 7, 8, 9.

points will be awarded for all.

Thanks & Regards,

Poorna

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,721

Hi,

Check these BAPIs

BAPI_PROFITCENTER_CREATE - Create Profit Center

BAPI_PROFITCENTER_CHANGE - Change Profit Center

<b>BAPI_PROFITCENTERGRP_ADDNODE - Add Node to a Profit Center Group

BAPI_PROFITCENTERGRP_CREATE - Create Profit Center Group</b>

Let me know if you need any other information.

Regards,

Rs

3 REPLIES 3
Read only

Former Member
0 Likes
1,722

Hi,

Check these BAPIs

BAPI_PROFITCENTER_CREATE - Create Profit Center

BAPI_PROFITCENTER_CHANGE - Change Profit Center

<b>BAPI_PROFITCENTERGRP_ADDNODE - Add Node to a Profit Center Group

BAPI_PROFITCENTERGRP_CREATE - Create Profit Center Group</b>

Let me know if you need any other information.

Regards,

Rs

Read only

0 Likes
1,721

Hi all,

Here is the solution for this Problem:


**------------------------ Data ---------------------------------*
DATA: i_cepct  LIKE cepct OCCURS 0 WITH HEADER LINE,
      wa_cepct LIKE cepct,
      i_cepc   LIKE cepc OCCURS 0 WITH HEADER LINE,
      wa_cepc  LIKE cepc.
*Variable declaration
DATA: w_ctr1(2) TYPE c,
      w_inc1 TYPE i.

DATA: w_level_code(30) TYPE c,
      w_level_name(50) TYPE c,
      w_level_code1(30) TYPE c,
      w_level_name1(50) TYPE c.

*Field symbols.
FIELD-SYMBOLS: <cd1>,
               <nm1>.

* External level table will be using the following structure
DATA: BEGIN OF data_tab OCCURS 0,
        level(4)      TYPE n,          "level in hierarchy
        groupname     LIKE grpdynp-name_coall, "name of node
        fromvalue     LIKE setvalues-from,  "From-Value of interval
        tovalue       LIKE setvalues-to,    "To-Value of interval
        descript      LIKE sethier-descript,"description of this entry
      END OF data_tab.

* Tables to read sets
DATA: sethier   LIKE sethier OCCURS 0 WITH HEADER LINE, "hier-nodes
      setvalues LIKE setvalues OCCURS 0 WITH HEADER LINE, "hier-values
      g_setval_index LIKE sy-tabix,    "index for setvalues,
      g_int     TYPE i.

DATA: BEGIN OF i_profit OCCURS 10,
  id(15)                TYPE c,
  code(10)                 TYPE c,
  name(20)                 TYPE c,
  desc(40)                 TYPE c,
  hier_lvl1_code(30)       TYPE c,
  hier_lvl1_name(50)       TYPE c,
  hier_lvl2_code(30)       TYPE c,
  hier_lvl2_name(50)       TYPE c,
  hier_lvl3_code(30)       TYPE c,
  hier_lvl3_name(50)       TYPE c,
  hier_lvl4_code(30)       TYPE c,
  hier_lvl4_name(50)       TYPE c,
  hier_lvl5_code(30)       TYPE c,
  hier_lvl5_name(50)       TYPE c,
  hier_lvl6_code(30)       TYPE c,
  hier_lvl6_name(50)       TYPE c,
  hier_lvl7_code(30)       TYPE c,
  hier_lvl7_name(50)       TYPE c,
  hier_lvl8_code(30)       TYPE c,
  hier_lvl8_name(50)       TYPE c,
  hier_lvl9_code(30)       TYPE c,
  hier_lvl9_name(50)       TYPE c,
  hier_lvl10_code(30)      TYPE c,
  hier_lvl10_name(50)      TYPE c,
  hier_lvl11_code(30)      TYPE c,
  hier_lvl11_name(50)      TYPE c,
  created_by(15)                         TYPE c,
  created_date(10)                       TYPE c,
  last_updated_by(15)                    TYPE c,
  last_updated_date(10)                  TYPE c,
  batch_id(15)                           TYPE c,
  stage2_dim_id(15)        TYPE c,
  source_system_id(20)                   TYPE c,
  alt_account_set_hierarchy_ind(1)       TYPE c,
END OF i_profit.

DATA: BEGIN OF i_str_pc2 OCCURS 10,
        code(10)                 TYPE c,
        desc(50)                 TYPE c,
        hier_lvl1_name(50)       TYPE c,
        hier_lvl3_name(50)       TYPE c,
        hier_lvl4_name(50)       TYPE c,
        extradatetime(20)        TYPE c,
      END OF i_str_pc2,

      BEGIN OF i_setid OCCURS 4,
        g_setid   LIKE sethier-setid,
        v_kokrs LIKE sethier-kokrs,
      END OF i_setid.

DATA : wa_str_pc2 LIKE i_str_pc2,
       wa_setid LIKE i_setid,
       v_datetim(20) TYPE c,
       v_tim(8) TYPE c,
       v_level_dec(50) TYPE c,
       v_profit_desc(50) TYPE c.

*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      IPROFIT STRUCTURE  ZPCT
*"----------------------------------------------------------------------

* Append all the major nodes to I_setid
* SOI7CR0326 – Profit Center node1( under this Hier will be available, and the end you will have profit centers),
* SOI7FU0763 – Profit Center node2,
* SOI7FU0764 – Profit Center node3,
* SOI7FU0765 – Profit Center node4.

  wa_setid-g_setid = text-009.
  wa_setid-v_kokrs = text-004.

  APPEND wa_setid TO i_setid.

  wa_setid-g_setid = text-010.
  wa_setid-v_kokrs = text-004.

  APPEND wa_setid TO i_setid.

  wa_setid-g_setid = text-011.
  wa_setid-v_kokrs = text-004.

  APPEND wa_setid TO i_setid.

  wa_setid-g_setid = text-012.
  wa_setid-v_kokrs = text-004.

  APPEND wa_setid TO i_setid.

* Loop at earch major nodes from i_setid.

  LOOP AT i_setid INTO wa_setid.
    REFRESH: i_profit.
* Preparations: check authority to read sets
    CALL FUNCTION 'G_SET_OR_GROUP_AUTHORITY'
         EXPORTING
              i_setid = wa_setid-g_setid
              i_actvt = '03'.

* Funtion module to import the set hierarchy and nodes values.
    REFRESH: sethier, setvalues.
    CALL FUNCTION 'G_SET_TREE_IMPORT'
         EXPORTING
              no_rw_info    = 'X'
              setid         = wa_setid-g_setid
         TABLES
              set_hierarchy = sethier
              set_values    = setvalues.

* Copy set into DATA_TAB
    REFRESH data_tab.
    g_setval_index = 1.
    LOOP AT sethier.
      CLEAR data_tab.
      data_tab-level = sethier-level.
      data_tab-groupname = sethier-shortname.
      data_tab-descript = sethier-descript.
      APPEND data_tab.
      CHECK sethier-vcount > 0.
      CLEAR data_tab.
      data_tab-level = sethier-level + 1.
      g_int = g_setval_index + sethier-vcount - 1.
      LOOP AT setvalues FROM g_setval_index TO g_int.
        data_tab-fromvalue = setvalues-from.
        data_tab-tovalue = setvalues-to.
        data_tab-descript = setvalues-descript.
        APPEND data_tab.
      ENDLOOP.
      g_setval_index = g_int + 1.
    ENDLOOP.

* Loop at the data_tab to move all the Profit center nodes to i_profit.
    LOOP AT data_tab.

      w_inc1 = data_tab-level.
      w_ctr1 = w_inc1.

      IF data_tab-level = text-002 .
        v_level_dec = data_tab-descript.  "Description of level 4 node
        CONTINUE.
      ENDIF.

      IF NOT data_tab-groupname IS INITIAL.
        CONCATENATE text-001 w_ctr1 text-007 INTO w_level_code1.
        ASSIGN  (w_level_code1) TO <cd1>.
        <cd1> = data_tab-groupname.

        CONCATENATE text-001 w_ctr1 text-008 INTO w_level_name1.
        ASSIGN (w_level_name1) TO <nm1>.
        <nm1> = data_tab-descript.

      ELSEIF NOT ( data_tab-fromvalue IS INITIAL OR
                        data_tab-tovalue IS INITIAL ) AND
                         data_tab-level NE text-003 .
        MOVE data_tab-fromvalue TO i_profit-code.
        PERFORM clear_above_level USING w_ctr1.
        APPEND i_profit.
        CONTINUE.
      ENDIF.
    ENDLOOP.

*Select description from CEPCT table

    SELECT * FROM cepct
             INTO TABLE i_cepct
             WHERE spras EQ text-006.

    SELECT * FROM cepc
             INTO  TABLE i_cepc.

    SORT i_cepc DESCENDING BY prctr datbi.
    DELETE ADJACENT DUPLICATES FROM i_cepc COMPARING prctr.

    SORT i_cepc.
    SORT i_profit BY code.

* Date and Times for each record.

    CONCATENATE sy-uzeit+0(2) text-005 sy-uzeit+2(2) text-005
      sy-uzeit+4(2) INTO v_tim.

    CONCATENATE sy-datum v_tim INTO v_datetim SEPARATED BY space.

    LOOP AT i_profit .
      CLEAR: wa_cepc,
             wa_cepct.

      IF   ( i_profit-code <> space
        AND i_profit-hier_lvl2_name <> space
        AND i_profit-hier_lvl3_name <> space ).

        READ TABLE i_cepc INTO wa_cepc WITH KEY prctr = i_profit-code.

        IF sy-subrc = 0.

        READ TABLE i_cepct INTO wa_cepct WITH KEY prctr = wa_cepc-prctr
                                                  datbi = wa_cepc-datbi.
          IF sy-subrc = 0.

*v_level_dec               ( Description of level 4 node )
*i_profit-hier_lvl2_name   ( Descri Level 6 )
*i_profit-hier_lvl3_name   ( Descri Level 6 )
*i_profit-code             ( Profit Center code )
*v_profit_desc             ( Profit Center description )

   CONCATENATE wa_cepct-ltext text-013 i_profit-code INTO v_profit_desc.

            wa_str_pc2-hier_lvl1_name = v_level_dec.
            wa_str_pc2-hier_lvl3_name = i_profit-hier_lvl2_name.
            wa_str_pc2-hier_lvl4_name = i_profit-hier_lvl3_name.
            wa_str_pc2-code           = i_profit-code.
            wa_str_pc2-desc           = v_profit_desc.
            wa_str_pc2-extradatetime  = v_datetim.
            APPEND wa_str_pc2 TO iprofit.

          ENDIF.
        ENDIF.
      ENDIF.
    ENDLOOP.

    CLEAR: v_level_dec.

  ENDLOOP.
  CLEAR: wa_setid.

ENDFUNCTION.

Read only

Former Member
0 Likes
1,721

Hi,

Please check this FM K_HIERARCHY_TABLES_READ.

Regards,

Ferry Lianto