cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the preprocess BADI for user defined dimension.

Former Member
0 Kudos

Hi All,

        I want to plan on the node level because there is a requirement from the user. Standard pre process BADI code working for all the dimensions by changing the code based on the requirement (dimension name). It is not working for the User defined dimension. Let me know how to change the code for User defined dimension.  I have changed the code for my requirement. I am trying to add the one user defined (Project) component, It prompts for the Access code. Could you please suggest me on this.I need your valuable suggestion to solve this issue at the earliest.

BADI CODE:

   method if_ujr_wb_pre_process~pre_process.
  data: ls_user type ujr_s_dim_handler,
lt_user_members type uja_t_dim_member, " dimension members of Entity
lo_user type ref to if_uja_dim_data, " Object Reference to Dimension
lt_hier_info type uja_t_hier, " Hierachies Infos
ls_hier_info type uja_s_hier,
lt_hier_name type uja_t_hier_name, " Hierachies name list
lt_attr_list type uja_t_attr, " Attributes Infos
ls_attr_list type uja_s_attr,
lt_attr_name type uja_t_attr_name, " Attributes name list
lf_non_base type uj_flg, " 'X'=non base member; ' '=base member
lt_user_mbr type uja_t_dim_member, " childen entity members
l_num_base type i, " number of children entity members
lr_data type ref to data.

  field-symbols: <ls_dim_obj> type ujr_s_dim_handler,
  <ls_record> type any,
  <l_user> type uj_dim_member, " Entity member of current records
  <lt_user_mbr> type hashed table, " All entity members
  <ls_user_mbr> type any,
  <lf_calc> type uj_flg, " 'Y'=non base member
  <lf_storedcalc> type any, " 'Y'=non base member
  <l_base_mbr> type uj_dim_member,
  <l_keyfigure> type any. " Keyfigure
  " Find the Entity dimension by its type
  loop at it_dim_obj assigning <ls_dim_obj> where dim_type = uj00_cs_dim_type-user.
    lo_user ?= <ls_dim_obj>-dim_obj.
    ls_user = <ls_dim_obj>.
  endloop.
  " Get hierachy (PARENTH1, PARENTH2 ...)
  lo_user->get_hier_list( importing et_hier_info = lt_hier_info ).
  loop at lt_hier_info into ls_hier_info.
    append ls_hier_info-hier_name to lt_hier_name.
  endloop.
  " Get necessary attributes (CALC and STORED_CALC)
  lo_user->get_attr_list( importing et_attr_list = lt_attr_list ).
  loop at lt_attr_list into ls_attr_list
  where attribute_name = ujr0_c_attr_calc or attribute_name = ujr0_c_attr_storedcalc.
    append ls_attr_list-attribute_name to lt_attr_name.
  endloop.
  " Get Members
  call method lo_user->read_mbr_data
    exporting
      if_ret_hashtab = abap_true
      it_attr_list   = lt_attr_name " columns:attributes name list
      it_hier_list   = lt_hier_name " columns:hieracies name list
    importing
      er_data        = lr_data.
  assign lr_data->* to <lt_user_mbr>.
  " preparation: create data structure and assign fields
  create data lr_data like line of ct_array.
  assign lr_data->* to <ls_record>.
  assign component ls_user-dimension of structure <ls_record> to <l_user>.
  assign component ujr0_c_keyfigure of structure <ls_record> to <l_keyfigure>.
  loop at ct_array into <ls_record>.
    read table <lt_user_mbr>
    with table key (ujr0_c_member_id) = <l_user>
    assigning <ls_user_mbr>.
    if sy-subrc = 0.
      " lf_non_base = <lf_calc>=Y OR <lf_storedcalc>=Y.
      assign component ujr0_c_attr_calc of structure <ls_user_mbr> to <lf_calc>.
      lf_non_base = <lf_calc>.
      assign component ujr0_c_attr_storedcalc of structure <ls_user_mbr> to <lf_storedcalc>.
      if sy-subrc = 0 and <lf_storedcalc> = ujr0_cs_calc-calculated_member.
        lf_non_base = ujr0_cs_calc-calculated_member.
      endif.
      " Disaggregate non base member
      if lf_non_base = ujr0_cs_calc-calculated_member.
        " A more precise version is to retrieve only accessible member of IS_USER
        call method lo_user->get_children_mbr
          exporting
            i_parent_mbr     = <l_user> " Parent
            i_level          = -99 " -99 = All children in any level; -1 = direct child
            if_only_base_mbr = abap_true " Only base member
          importing
            et_member        = lt_user_mbr.
        " Re-calculate the keyfigure, divide by N = number of base members
        " Usually it doesn't matter with IF_CALC_DELTA = false,
        " if the operation is linear mathematical.
        describe table lt_user_mbr lines l_num_base.
        " Avoid divide by zero
        if l_num_base > 0.
          <l_keyfigure> = <l_keyfigure> / l_num_base.
          " Copy N times with new base members
          loop at lt_user_mbr assigning <l_base_mbr>.
            <l_user> = <l_base_mbr>.
            " When IF_CALC_DELTA = true, appending means the latest records take effects,
            " previous records with same dimension member will be overwritten.
            " The newly appended records will also be looped and processed.
            append <ls_record> to ct_array.
          endloop.
        endif. " divide by zero
        " Remove the old one
        delete ct_array.
      endif.
    endif.
  endloop.
endmethod.

Accepted Solutions (0)

Answers (1)

Answers (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You are attempting to change an SAP delivered example implementation which is why it is asking for an access code.  You should not do this.  You should create your own implementation instead.  Here is a how to guide showing how to do this.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0309226-814f-2d10-61a6-ef8da29e3...

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rich,

           The BADI what I implemented by following your link,It is working for the APSHELL dimensions to plan on the NODE level members not for user defined Dimension based on project requirement. Could you please guide me how can I use this for my requirement. I have observed one thing that is there are some components like account,entity,user. My intention is there is a componnet like USER. I thought that is for the user defined dimension. Advise me on this.

Best Regards,

Krishna.