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

Budgetary adjustment



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Thu Feb 19, 2009 3:27 pm    Post subject: Budgetary adjustment Reply with quote

Code:
report  z_wfm_budgetory_adjust.

** Data Declaration

tables: zwfd_live_store.

data:   begin of itab occurs 10,

         zz_object_id type zwfd_live_store-zz_object_id,

         end of itab.

* User Input parameters

select-options: istore for zwfd_live_store-zz_store_id.
parameters:     idate type sy-datum,
                ilevel  type int1 default 1.



start-of-selection.


  select zz_object_id into table itab from zwfd_live_store
  where zz_store_id in istore.

  check sy-subrc = 0.


  loop at itab.


*    CALL FUNCTION 'ZWFM_AUTO_WORKLOAD_ADJUSTMENT'
*      EXPORTING
*        iv_org_id               =  itab-zz_object_id
*        iv_effective_date       = idate
*       IV_ADJ_LEVEL             = ilevel
* IMPORTING
*   ET_RETURN               =
    .


*FUNCTION ZWFM_AUTO_WORKLOAD_ADJUSTMENT.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(IV_ORG_ID) TYPE  HROBJID
*"     REFERENCE(IV_EFFECTIVE_DATE) TYPE  BEGDATUM
*"     REFERENCE(IV_ADJ_LEVEL) TYPE  INT1 DEFAULT 1
*"  EXPORTING
*"     REFERENCE(ET_RETURN) TYPE  WFMCAST_RETURN
*"----------------------------------------------------------------------

    data: lo_org           type ref to  cl_wfm_organization.
    data: lv_end_date      type         begdatum,
          lv_start_date    type         begdatum,
          lt_departments   type         wfmcast_org_composite,
          ls_departments   type         wfmcass_org_composite,
          lo_cfg           type ref to  cl_wfm_cfg,
          wa_ids           type         wfmt_id_type,
          errstr           type         string,
          ls_return        type         bapiret2.

    data: iv_org_id type  hrobjid,
       iv_effective_date type  begdatum,
       iv_adj_level type  int1,
       et_return type  wfmcast_return.

    data: ls_mod_inandout  type         wfmfcs_budget_constraint,
          lt_wa_guids      type         wfmcast_name_id_list,
          ls_wa_guid       type         wfmcass_name_id_list,
          lv_planned_hrs   type         f.


    iv_org_id               =  itab-zz_object_id.
    iv_effective_date       = idate.
    iv_adj_level             = ilevel.


*create the org object. this will also verify if the org is valid
    create object lo_org
        exporting
          p_org_objid            = iv_org_id
          p_start_date           = iv_effective_date
          p_end_date             = iv_effective_date
        exceptions
          invalid_org_objid      = 1
          no_active_plan_version = 2
          location_is_not_active = 3
          others                 = 4.

    if sy-subrc <> 0.
      ls_return-type = 'E'.
      message e163(crm_wfm_cas) with iv_org_id iv_effective_date
      into ls_return-message.
      append ls_return to et_return.
*      RETURN.
      continue.
    endif.

*get the week breaker date in case the start date passing in is wrong
    try.
        lv_start_date =
                  lo_org->get_start_date_of_week( iv_effective_date ).
        lv_end_date = lv_start_date + 6.
      catch cx_wfm_organization.
        data:  lv_error_org_name type wfm_cas_ltext.
        lv_error_org_name = lo_org->get_lname( ).
        ls_return-type = 'E'.
        message e365(crm_wfm_cas) with lv_error_org_name
        into ls_return-message.
        append ls_return to et_return.
*        RETURN.
        continue.

    endtry.


*get the correct configuration
    if iv_adj_level = 1.        "adjust on org unit level
    elseif iv_adj_level = 2.   "adjust on department level
      call function 'WFM_ORG_SUBORGS_GETLIST'
        exporting
          iv_org_objid  = iv_org_id
          iv_start_date = lv_start_date
          iv_end_date   = lv_end_date
        importing
          et_org        = lt_departments
          es_return     = ls_return.

      if ls_return-type = 'E'.
        append ls_return to et_return.
*        RETURN.
        continue.
      endif.

    else.                       "adjust on workarea level

      lo_cfg = lo_org->get_config( ).
      call method lo_cfg->get_toppar_ontype
          exporting
            par_type     = 201
          importing
            parameters   = wa_ids
*            PARMAP       =
*          EXCEPTIONS
*            NO_PARAMETER = 1
*            others       = 2
                .
      if wa_ids is not initial.
        select wrkarea_id as id
               wrkarea_code as sname
            into corresponding fields of table lt_wa_guids
            from wfmcas_wrkarea
            for all entries in wa_ids
            where wrkarea_code = wa_ids-profile_id.
      endif.


    endif.

*get the correct forecasted value and planned value by calling
*'WFM_BUDGETARY_CONSTRAINTS_GET'

    if iv_adj_level = 1.        "adjust on org unit level
      call function 'WFM_BUDGETARY_CONSTRAINTS_GET'
        exporting
          iv_org_id                     = iv_org_id
*     IV_WORKAREA_ID                = ''
          iv_start_date                 = lv_start_date
       importing
         et_budgetary_collection       = ls_mod_inandout
*     EV_LABEL_NAME                 =
         es_return                     = ls_return
                .
      concatenate iv_org_id lv_start_date into errstr separated by '-'.

      if ls_return-type = 'E'.
        if ls_return-message is initial.
          message e008(wfm_multi_cfg) with errstr
          into ls_return-message.
        endif.
        append ls_return to et_return.
*        RETURN.
        continue.
      endif.

      perform convert_to_hours
                  using
                     ls_mod_inandout
                  changing
                     lv_planned_hrs
                     ls_return.

      if ls_return-type = 'E'.
        message e008(wfm_multi_cfg) with errstr
        into ls_return-message.
        append ls_return to et_return.
*        RETURN.
        continue.
      endif.

*force the planned hours be adjust hours
      ls_mod_inandout-adj_hours = lv_planned_hrs.

      call function 'WFM_BUDGETARY_CONSTRAINTS_MOD'
        exporting
          iv_org_id               = iv_org_id
          iv_start_date           = lv_start_date
          et_budgetary_collection = ls_mod_inandout
        importing
          es_return               = ls_return.

      if ls_return-type = 'E'.
        if ls_return-message is initial.
          message e008(wfm_multi_cfg) with errstr
          into ls_return-message.
        endif.
        append ls_return to et_return.
*        return.
        continue.

      endif.


    elseif iv_adj_level = 2.  "adjust on department level
      loop at lt_departments into ls_departments.
*    "ignore the root org when dealing with department
        if ls_departments-org_objid = iv_org_id.
          continue.
        endif.
        clear errstr.
        concatenate iv_org_id ls_departments-org_objid
  lv_start_date into errstr separated by '-'.

        call function 'WFM_BUDGETARY_CONSTRAINTS_GET'
          exporting
            iv_org_id                     = ls_departments-org_objid
*     IV_WORKAREA_ID                = ''
            iv_start_date                 = lv_start_date
         importing
           et_budgetary_collection       = ls_mod_inandout
*     EV_LABEL_NAME                 =
           es_return                     = ls_return
                  .
        if ls_return-type = 'E'.
          if ls_return-message is initial.
            message e008(wfm_multi_cfg) with errstr
            into ls_return-message.
          endif.
          append ls_return to et_return.
          continue.
        endif.


        perform convert_to_hours
                    using
                       ls_mod_inandout
                    changing
                       lv_planned_hrs
                       ls_return.

        if ls_return-type = 'E'.
          message e008(wfm_multi_cfg) with errstr
        into ls_return-message.
          append ls_return to et_return.
          continue.
        endif.

*force the planned hours be adjust hours
        ls_mod_inandout-adj_hours = lv_planned_hrs.
        ls_mod_inandout-unit_id = ls_departments-org_objid.

        call function 'WFM_BUDGETARY_CONSTRAINTS_MOD'
          exporting
            iv_org_id               = ls_departments-org_objid
            iv_start_date           = lv_start_date
            et_budgetary_collection = ls_mod_inandout
          importing
            es_return               = ls_return.

        if ls_return-type = 'E'.
          if ls_return-message is initial.
            message e008(wfm_multi_cfg) with errstr
            into ls_return-message.
          endif.
          append ls_return to et_return.
          continue.
        endif.


      endloop.
    else.                     "adjust on workarea level

      loop at lt_wa_guids into ls_wa_guid.

        clear errstr.
        concatenate iv_org_id ls_wa_guid-sname lv_start_date  into errstr
  separated by '-'.


        call function 'WFM_BUDGETARY_CONSTRAINTS_GET'
          exporting
            iv_org_id                     = iv_org_id
            iv_workarea_id                = ls_wa_guid-id
            iv_start_date                 = lv_start_date
         importing
           et_budgetary_collection       = ls_mod_inandout
*     EV_LABEL_NAME                 =
           es_return                     = ls_return
                  .
        if ls_return-type = 'E'.
          if ls_return-message is initial.
            message e008(wfm_multi_cfg) with errstr
            into ls_return-message.
          endif.
          append ls_return to et_return.
          continue.
        endif.

        perform convert_to_hours
                    using
                       ls_mod_inandout
                    changing
                       lv_planned_hrs
                       ls_return.

        if ls_return-type = 'E'.
          message e008(wfm_multi_cfg) with errstr
          into ls_return-message.
          append ls_return to et_return.
          continue.
        endif.

*force the planned hours be adjust hours
        ls_mod_inandout-adj_hours = lv_planned_hrs.
        ls_mod_inandout-unit_id = ls_wa_guid-id.

        call function 'WFM_BUDGETARY_CONSTRAINTS_MOD'
          exporting
            iv_org_id               = iv_org_id
            iv_start_date           = lv_start_date
            et_budgetary_collection = ls_mod_inandout
          importing
            es_return               = ls_return.

        if ls_return-type = 'E'.
          if ls_return-message is initial.
            message e008(wfm_multi_cfg) with errstr
            into ls_return-message.
          endif.
          append ls_return to et_return.
          continue.
        endif.

      endloop.

    endif.

  endloop.
*  ENDFUNCTION.

*&--------------------------------------------------------------------*
*&      Form  convert_to_hours
*&--------------------------------------------------------------------*
form convert_to_hours
  using
    ls_planned type wfmfcs_budget_constraint
  changing
    lv_planned_hrs type f
    ls_return type bapiret2.

  if ls_planned-fcst_hours <= 0.
    ls_return-number = '444'.  "missing forecasted value
    ls_return-type = 'E'.
    return.
  endif.

  if ls_planned-planned_values <= 0.
    ls_return-number = '111'.  "missing planned value
    ls_return-type = 'E'.
    return.
  endif.

  if ls_planned-constraint_type = '0'. "payroll
    if ls_planned-ahr = 0.
      ls_return-number = '222'.  "missing ahr
      ls_return-type = 'E'.
      return.
    endif.

    lv_planned_hrs = ls_planned-planned_values / ls_planned-ahr.

  elseif ls_planned-constraint_type = '1'. "hours
    lv_planned_hrs = ls_planned-planned_values.

  elseif ls_planned-constraint_type = '2'. "payroll percent
    if ls_planned-ahr = 0.
      ls_return-number = '222'.  "missing ahr
      ls_return-type = 'E'.
      return.
    elseif ls_planned-sales = 0.
      ls_return-number = '333'.  "missing sales
      ls_return-type = 'E'.
      return.
    endif.

    lv_planned_hrs =
ls_planned-planned_values * ls_planned-sales / ls_planned-ahr.

  else.  "sales per hour
    if ls_planned-sales = 0.
      ls_return-number = '333'.  "missing sales
      ls_return-type = 'E'.
      return.
    endif.

    lv_planned_hrs = ls_planned-sales / ls_planned-planned_values.

  endif.

endform.                    "convert_to_hours
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 -> SAP Business Workflow 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 can 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.