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

Change Document Report [ Property Sector in Real Estate ]



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



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Oct 14, 2007 9:25 pm    Post subject: Change Document Report [ Property Sector in Real Estate ] Reply with quote

Requirement:
In SAP Real Estate, Properties, Buildings and Rental Units are grouped using пїЅBusiness EntityпїЅ . But the problem is that since пїЅBusiness EntityпїЅ is one of the Primary Key Fields in Master Data tables, once assigned with a particular пїЅBusiness EntityпїЅ, Property / Buldings / Rental Unit can't be moved to a different пїЅBusiness EntityпїЅ directly. If at all it has to be done, Master data needs to be deleted entirely and then it can be recreated with new Entity Group.

To avoid this deletion & recreation, a new user field called 'Propery Sector' needs to be added to all the master data tables and related transaction screens. Also, Business event FMs will be modifed to populate this field through Master Data Xns. The 'Propery Sector' will replace the functionality of SAP's пїЅBusiness EntityпїЅ field with added advantage that it can be changed to move Properties / Buildings / Rental Units to a different group.

After this is achieved, the requirement is to have the ability to display ( a Report ) the master data which was moved betwen the property sectors. Basically, a change document report is required for this field 'Property Sector', displaying all the records between a given date range when a Property / Bulding / Rental Unit was moved from one Propery Sector to other.

Processing:
Change documents are already getting generated for Real Estate Master Data [ Property / Buldings / Rental Unit ]. Further, this new user field can be activated for change document record creation by setting the 'change document' indicator on the related Data Element.

Now, a ALV report will be created to get the change document details for the given Date & Time range and change document object 'GRUNDSTK'[ Property ]. Changes relevant to any other field except Property Sector will be filtered-out.

Further, selected and filtered data will be displayed using ALV FM 'REUSE_ALV_GRID_DISPLAY'.

Code:

report z_property_sector_change_rep .

*-----------------------------------------------------------------------
* Change Document Report for Property Sectors ( Real Estate )
*-----------------------------------------------------------------------
* Program        : Z_PROPERTY_SECTOR_CHANGE_REP
* Presented By   : www.rmtiwari.com
*-----------------------------------------------------------------------

tables: cdhdr, cdpos, viob02, zentitygroup.
DATA : GT_SECTOR_DESC TYPE SORTED TABLE OF ZENTITYGROUP
                           with unique key zentity_group
                                    with header line.
data: lt_cdhdr type table of cdhdr with header line.

data: begin of gt_change_property_report occurs 0,
      bukrs      type viob02-bukrs,
      swenr      type viob02-swenr,
      sgrnr      type viob02-sgrnr,
      sector_old type viob02-zentity_group,
      old_desc   type zentitygroup-zentity_gr_desc,
      sector_new type viob02-zentity_group,
      new_desc   type zentitygroup-zentity_gr_desc,
      udate      type cdhdr-udate,
      utime      type cdhdr-utime,
      uname      type cdhdr-username,

      end of gt_change_property_report.
data : gt_change_sector_list type standard table of cdred
                                  with header line.
data : gt_change_sector      type standard table of cdred
                                  with header line.
data : begin of lv_objectid,
       bukrs      type viob02-bukrs,
       swenr      type viob02-swenr,
       sgrnr      type viob02-sgrnr,
       end of lv_objectid.

* ALV stuff
type-pools: slis.
data: gt_fieldcat type slis_t_fieldcat_alv,
      gs_layout   type slis_layout_alv,
      gt_sort     type slis_t_sortinfo_alv,
      gt_list_top_of_page type slis_t_listheader,
      gt_events   type slis_t_event.


*------------------PARAMETER------------------------------------------*

selection-screen begin of block user with frame title text-s01.
SELECT-OPTIONS: UDATE FOR  CDHDR-UDATE
                      default sy-datum no-extension ,    "Changed On
                utime for  cdhdr-utime no-extension .    "Changed Time
select-options: uname for cdhdr-username  default sy-uname."Changed By
selection-screen end   of block user.

selection-screen begin of block property with frame title text-s02.
SELECT-OPTIONS: SECTOR FOR VIOB02-ZENTITY_GROUP, "PROPERTY SECTOR
                sgrnr for  viob02-sgrnr.               "Property No.

selection-screen end   of block property.


*----------------------------------------------------------------------*

at selection-screen.

* Check if user is authorised to run this report.
  PERFORM AUTHORIZATION_CHECK.

initialization.
  PERFORM FIELDCAT_INIT.
  PERFORM LAYOUT_INIT.
  PERFORM SORT_INIT.
  PERFORM EVENTTAB_BUILD USING GT_EVENTS[].

start-of-selection.

* Get Change documents
  PERFORM GET_CHANGE_DOCUMENTS.

end-of-selection.

* Show report in ALV
  PERFORM DISPLAY_REPORT.

*&---------------------------------------------------------------------*
*&      Form  get_change_documents
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form get_change_documents.
  data: lr_objectid   type range of cdobjectv,
        lr_objectid_line   like line of lr_objectid.

  if not sgrnr is initial.
*   select properties from viob02
    SELECT BUKRS SWENR SGRNR
      INTO LV_OBJECTID
      FROM VIOB02
     where sgrnr in sgrnr.

*     Fill property range.
      lr_objectid_line-sign = 'I'.
      lr_objectid_line-option = 'EQ'.

      lr_objectid_line-low = lv_objectid.
      collect lr_objectid_line into lr_objectid.

    endselect.
  endif.

* Fill date & Time
* time_until (up to time)
  if utime-high = space.
    utime-high = '235959'.
  endif.
* time_of_change (from time)
  if utime-low = space.
    utime-low = '000000'.
  endif.

* date_until (up to date)
  if udate-high is initial or udate-high = space.
    udate-high = '99991231'.
  endif.
* date_of_change (from date)
  if udate-low = space.
    udate-low = '00000101'.
  endif.

* select header from cdhdr
  SELECT * FROM CDHDR INTO TABLE LT_CDHDR
           where objectclas eq 'GRUNDSTK'
           AND OBJECTID IN LR_OBJECTID
           AND   USERNAME   IN UNAME
           and (
                (
                  udate =  udate-low
                  and
                  utime > = utime-low
                 )
                 or
                  udate >   udate-low
                )
           and (
                (
                  udate =  udate-high
                  and
                  utime < = utime-high
                 )
                 or
                  udate <   udate-high
                ).

  loop at lt_cdhdr.
    refresh gt_change_sector.

    call function 'CHANGEDOCUMENT_READ'
      exporting
*   ARCHIVE_HANDLE                   = 0
        CHANGENUMBER                     = lt_cdhdr-CHANGENR
        date_of_change                   = lt_cdhdr-udate
        objectclass                      = 'GRUNDSTK'
        objectid                         = lt_cdhdr-objectid
*   TABLEKEY                         = ' '
*   TABLENAME                        = ' '
        time_of_change                   = lt_cdhdr-utime
        username                         = lt_cdhdr-username
*   LOCAL_TIME                       = ' '
*        date_until                       = udate-high
*        time_until                       = utime-high
      tables
        EDITPOS                          = GT_CHANGE_SECTOR
     exceptions
       no_position_found                = 1
       wrong_access_to_archive          = 2
       time_zone_conversion_error       = 3
       others                           = 4
              .
    append lines of gt_change_sector to gt_change_sector_list.

  endloop.
* We only need changes to property sector field.
  delete gt_change_sector_list where fname < >  'ZENTITY_GROUP'.
  delete gt_change_sector_list where chngind eq 'I'.

  check  not gt_change_sector_list[] is initial.

* Get Sector Description.
  SELECT * INTO TABLE GT_SECTOR_DESC
    from zentitygroup.

  loop at gt_change_sector_list.

*   Filter on the basis of Property sector.
    if not ( gt_change_sector_list-f_old in sector or
           gt_change_sector_list-f_new in sector ).
      continue.
    endif.

    gt_change_property_report-bukrs = gt_change_sector_list-objectid(4)
.
    gt_change_property_report-swenr =
 gt_change_sector_list-objectid+4(8).
    gt_change_property_report-sgrnr =
                                  gt_change_sector_list-objectid+12(8).


    gt_change_property_report-sector_old = gt_change_sector_list-f_old.
    gt_change_property_report-sector_new = gt_change_sector_list-f_new.
    gt_change_property_report-udate = gt_change_sector_list-udate.
    gt_change_property_report-utime = gt_change_sector_list-utime.
    gt_change_property_report-uname = gt_change_sector_list-username.

    clear : gt_sector_desc.
    read table gt_sector_desc with key zentity_group =
                                 gt_change_property_report-sector_old.
    gt_change_property_report-old_desc = gt_sector_desc-zentity_gr_desc.

    clear : gt_sector_desc.
    read table gt_sector_desc with key zentity_group =
                                 gt_change_property_report-sector_new.
    gt_change_property_report-new_desc = gt_sector_desc-zentity_gr_desc.

    append  gt_change_property_report.

  endloop.

endform.                    "get_change_documents
*&---------------------------------------------------------------------*
*&      Form  display_report
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form display_report.

  PERFORM GRID_DISPLAY.

endform.                    "display_report
*&---------------------------------------------------------------------*
*&      Form  layout_init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form layout_init.
  gs_layout-zebra             = 'X'.
  gs_layout-cell_merge        = 'X'.
  gs_layout-colwidth_optimize = 'X'.
  gs_layout-no_vline          = ' '.
  gs_layout-totals_before_items = ' '.
  gs_layout-key_hotspot         = 'X'.

endform.                    " layout_init
*&---------------------------------------------------------------------*
*&      Form  COMMENT_BUILD
*&---------------------------------------------------------------------*
*       Processing of listheader
*----------------------------------------------------------------------*
form comment_build using p_fk_list_top_of_page type slis_t_listheader.

  data: ls_line type slis_listheader.
  refresh p_fk_list_top_of_page.
* List Heading : Typ H
  clear ls_line.
  ls_line-typ  = 'H'.
  ls_line-info  = 'Property Sector Change Report for Properties'.
  append ls_line to p_fk_list_top_of_page.

* List : Typ S
  clear ls_line.
  ls_line-typ  = 'S'.
  ls_line-key  = 'Date Range:'.
  ls_line-info  = udate-low.
  if not udate-high is initial.
    write ' To ' to  ls_line-info+30.
    ls_line-info+36 = udate-high.
  endif.
  append ls_line to p_fk_list_top_of_page.

* List : Typ S
  clear ls_line.
  ls_line-typ  = 'S'.
  ls_line-key  = 'Time Range:'.
  ls_line-info  = utime-low.
  if not utime-high is initial.
    write ' To ' to  ls_line-info+30.
    ls_line-info+36 = utime-high.
  endif.
  append ls_line to p_fk_list_top_of_page.


endform.                               " COMMENT_BUILD

*&---------------------------------------------------------------------*
*&      Form  fieldcat_init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form fieldcat_init.
  data: ls_fieldcat type slis_fieldcat_alv.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'BUKRS'.
*  ls_fieldcat-key          = 'X'.
  ls_fieldcat-reptext_ddic = 'Company'.
  ls_fieldcat-outputlen    = 4.
  ls_fieldcat-hotspot      = ' '.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'SWENR'.
*  ls_fieldcat-key          = 'X'.
  ls_fieldcat-reptext_ddic = 'Business entity'.
  ls_fieldcat-outputlen    = 8.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'SGRNR'.
*  ls_fieldcat-key          = 'X'.
  ls_fieldcat-reptext_ddic = 'Property'.
  ls_fieldcat-outputlen    = 8.
  ls_fieldcat-hotspot      = 'X'.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'SECTOR_OLD'.
  ls_fieldcat-reptext_ddic = 'Old B.Sector'.
  ls_fieldcat-outputlen    = 2.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'OLD_DESC'.
  ls_fieldcat-reptext_ddic = 'Old Sector Description'.
  ls_fieldcat-outputlen    = 20.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'SECTOR_NEW'.
  ls_fieldcat-reptext_ddic = 'New B.Sector'.
  ls_fieldcat-outputlen    = 2.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'NEW_DESC'.
  ls_fieldcat-reptext_ddic = 'New Sector Description'.
  ls_fieldcat-outputlen    = 20.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'UDATE'.
  ls_fieldcat-reptext_ddic = 'Changed Date'.
  ls_fieldcat-outputlen    = 10.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'UTIME'.
  ls_fieldcat-reptext_ddic = 'Changed Time'.
  ls_fieldcat-outputlen    = 10.
  append ls_fieldcat to gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'UNAME'.
  ls_fieldcat-reptext_ddic = 'Changed By'.
  ls_fieldcat-outputlen    = 10.
  append ls_fieldcat to gt_fieldcat.




endform.                    "fieldcat_init

*&---------------------------------------------------------------------*
*&      Form  sort_init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form sort_init.
  data: ls_sort type slis_sortinfo_alv.

* Default sorting by PO item and Invoice block code.

  clear ls_sort.
  ls_sort-fieldname = 'UDATE'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.

  clear ls_sort.
  ls_sort-fieldname = 'UTIME'.
  ls_sort-spos      = 2.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.

  clear ls_sort.
  ls_sort-fieldname = 'UNAME'.
  ls_sort-spos      = 3.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.

  clear ls_sort.
  ls_sort-fieldname = 'BUKRS'.
  ls_sort-spos      = 4.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.

  clear ls_sort.
  ls_sort-fieldname = 'SWENR'.
  ls_sort-spos      = 5.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.

  clear ls_sort.
  ls_sort-fieldname = 'SGRNR'.
  ls_sort-spos      = 6.
  ls_sort-up        = 'X'.
  append ls_sort to gt_sort.


endform.                    "sort_init

*&---------------------------------------------------------------------*
*&      Form  EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*      Ereignistabelle Bilden
*      EVENTS TABLE BUILD
*----------------------------------------------------------------------*
 
form eventtab_build using  p_fk_events  type slis_t_event.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = p_fk_events.
  READ TABLE P_FK_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
                           into ls_event.
  if sy-subrc = 0.
    move 'TOP_OF_PAGE' to ls_event-form.
    append ls_event to p_fk_events.
  endif.
  READ TABLE P_FK_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND
                           into ls_event.
  if sy-subrc = 0.
    move 'USER_COMMAND' to ls_event-form.
    append ls_event to p_fk_events.
  endif.

endform.                               " EVENTTAB_BUILD

*&---------------------------------------------------------------------*
*&      Form  grid_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form grid_display.
  data : lv_report type sy-repid.

  lv_report = sy-repid.

* Show Invoice Block Report in ALV.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            IS_LAYOUT          = GS_LAYOUT
            IT_FIELDCAT        = GT_FIELDCAT
            IT_SORT            = GT_SORT
            i_default          = ' '
            i_save             = 'X'
            I_CALLBACK_PROGRAM = LV_REPORT
            it_events          = gt_events[]
       tables
            T_OUTTAB           = GT_CHANGE_PROPERTY_REPORT
       exceptions
            program_error      = 1
            others             = 2.
  if sy-subrc < >  0.
    message id sy-msgid type sy-msgty number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    "grid_display
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       User commands for ALV Function
*----------------------------------------------------------------------*
form user_command using r_ucomm     type syucomm
                        rs_selfield type slis_selfield.

  if r_ucomm eq '&IC1'.
*   Drilldown by user.
    read table gt_change_sector_list index rs_selfield-tabindex.

    case rs_selfield-fieldname.

*     For Purchase Order
      when 'SGRNR'.
*       Call transaction ME23N to display the PO
        set parameter id 'BUK' field gt_change_property_report-bukrs.
        set parameter id 'WEH' field gt_change_property_report-swenr.
        set parameter id 'GRS' field gt_change_property_report-sgrnr.
        call transaction 'FO32' and skip first screen.
    endcase.

  endif.

endform.                    "user_command
*---------------------------------------------------------------------*
*       FORM TOP_OF_PAGE                                              *
*---------------------------------------------------------------------*
*       Ereigniss TOP_OF_PAGE                                       *
*       event     TOP_OF_PAGE
*---------------------------------------------------------------------*
form top_of_page.

  PERFORM COMMENT_BUILD  USING GT_LIST_TOP_OF_PAGE[].
  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = gt_list_top_of_page.

endform.                    "TOP_OF_PAGE


*&---------------------------------------------------------------------*
*&      Form  authorization_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->   p1        text
*  < --  p2        text
*----------------------------------------------------------------------*
 
form authorization_check.

*                 CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
*                   EXPORTING
*                     TCODE         = 'ZPRCD'
*                   EXCEPTIONS
*                     OK            = 1
*                     NOT_OK        = 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.

endform.                    " authorization_check
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 -> PP 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.