Posted: Sun Oct 14, 2007 9:25 pm Post subject: Change Document Report [ Property Sector in Real Estate ]
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.
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.
* 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
).
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.
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
*----------------------------------------------------------------------*
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.
*&---------------------------------------------------------------------*
*& 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.
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.
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.