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

Getting material changes list using change document



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



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 29, 2007 4:51 pm    Post subject: Getting material changes list using change document Reply with quote

Code:

REPORT ZQA_MATERIAL_CHANGE_LIST no standard page heading line-size 132.

tables: bdcp, mara, makt.

data: i_cdhdr like cdhdr occurs 0 with header line,
i_cdshw like cdshw occurs 0 with header line.

* SELECTION SCREEN ELEMENTS ------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK one
WITH FRAME TITLE text-001.
Select-options: s_datum for sy-datum obligatory.
select-options : s_time for sy-uzeit.
* Start of change Seshu 02/19/2007
* Reason - Added Material Number as Range Option
*select-options : p_matnr for mara-matnr.
select-options s_matnr for mara-matnr.
select-options: S_usernm for sy-uname.
SELECTION-SCREEN END OF BLOCK one.

SELECTION-SCREEN BEGIN OF BLOCK two
WITH FRAME TITLE text-002.
parameters: r_all radiobutton group one default 'X',
r_erps radiobutton group one,
r_select radiobutton group one.
SELECTION-SCREEN: BEGIN OF LINE, POSITION 5.
parameter p_fname like bdcp-fldname.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK two.

ranges r_objectid for cdhdr-objectid.

* List of fields transmitted to ERPsy-Daisy
select-options so_fname for i_cdshw-fname no-display.

* START OF SELECTION --------------------------------------------------*
START-OF-SELECTION.

if r_select is initial.
clear p_fname.
endif.

perform set_erpsy_daisy_fields.
perform get_data.
perform write_report.

* SUBROUTINES ---------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data.

* data: v_objectid like cdhdr-objectid.
*
** move p_matnr to v_objectid.
*
loop at s_matnr.
move : s_matnr-low to r_objectid-low,
s_matnr-high to r_objectid-high,
s_matnr-option to r_objectid-option,
s_matnr-sign to r_objectid-sign.
append r_objectid.
endloop.

**if v_objectid is initial.
*select * from cdhdr into table i_cdhdr
* where USERNAME in s_usernm
* and OBJECTCLAS = 'MATERIAL'
* and UDATE in s_datum
* and utime in s_time.
*
*
*else.
select * from cdhdr into table i_cdhdr
where OBJECTID in r_objectid
and USERNAME in s_usernm
and OBJECTCLAS = 'MATERIAL'
and UDATE in s_datum
and utime in s_time.
*endif.

if sy-subrc ne 0.
message e000(zwave) with 'No Data Found for given Selection'.
endif.

ENDFORM. " get_data

*&---------------------------------------------------------------------*
*& Form write_report
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_report.
data: v_fname(60) type c,
v_changenr like i_cdhdr-changenr,
v_count type i value 0.

sort i_cdhdr by tcode changenr.

* list materials created ---------------------------------------

if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials created since',
25 s_datum-low ,39 'to',43 s_datum-high,
132 sy-vline.
format color off.
uline.

else.

uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials created since',
s_datum-low ,
132 sy-vline.
format color off.
ULINE.
endif.

loop at i_cdhdr where tcode = 'MM01' or
tcode = 'MM11'.
perform write_header_line using i_cdhdr.
endloop.
uline.

* list materials deleted ---------------------------------------

if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials flagged for deletion since',
43 s_datum-low ,55 'to',59 s_datum-high,
132 sy-vline.
format color off.
uline.
else.

uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials flagged for deletion since',
s_datum-low,
132 sy-vline.
format color off.
uline.

endif.

loop at i_cdhdr where tcode = 'MM06' or
tcode = 'MM16'.
perform write_header_line using i_cdhdr.
endloop.
uline.

* display detail for material changes ---------------------------
skip.
if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials changed since',
28 s_datum-low ,39 'to',43 s_datum-high,
132 sy-vline.
format color off.
else.

uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials changed since',
s_datum-low ,
132 sy-vline.
format color off.

endif.

* display material change transactions (immediate and change)
loop at i_cdhdr where tcode = 'MM02' or
tcode = 'MM12'.
* retrieve change document line items
perform get_change_positions using i_cdhdr-changenr.
* display each item matching field on parameter screen, only
* ERPsy-Daisy materials, or all fields if both paramters blank
v_count = 0.
loop at i_cdshw.
if ( p_fname is initial or
i_cdshw-fname = p_fname ) and
i_cdshw-fname in so_fname.
* write header line if this is the first line item from change
* order to meet above criteria
add 1 to v_count.
if v_count = 1.
if i_cdhdr-changenr <> v_changenr.
if sy-index <> 1.
uline.
endif.
perform write_header_line using i_cdhdr.
endif.
endif.
v_changenr = i_cdhdr-changenr.
* write change line
concatenate '(' i_cdshw-fname ')'
into v_fname.
concatenate i_cdshw-ftext v_fname
into v_fname separated by space.
write: / sy-vline.
if i_cdshw-chngind = 'U'. "update
write 12 'Change >'.
elseif i_cdshw-chngind = 'D' or
i_cdshw-chngind = 'I'.
write 12 'Deleted >'.
elseif i_cdshw-chngind = 'I'.
write 12 'Inserted >'.
endif.
write: v_fname,
132 sy-vline.
write: / sy-vline,
16 'Old Value:',
(40) i_cdshw-f_old,
132 sy-vline,
/ sy-vline,
16 'New Value:',
(40) i_cdshw-f_new,
132 sy-vline.
endif.
endloop.
endloop.
uline.

ENDFORM. " write_report

*&---------------------------------------------------------------------*
*& Form write_header_line
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_header_line using x_cdhdr like cdhdr.

data: v_date(10) type c,
v_time(8) type c.

* get material description
select single maktx
from makt
into makt-maktx
where matnr = x_cdhdr-objectid.

format color col_heading intensified off.
write: / sy-vline,
x_cdhdr-objectid+8(10) no-zero,
(40) makt-maktx,
x_cdhdr-tcode,
x_cdhdr-username,
x_cdhdr-udate,
x_cdhdr-utime,
132 sy-vline.
format color off.

ENDFORM. " write_header_line

*&---------------------------------------------------------------------*
*& Form get_change_positions
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_change_positions using x_chgnbr.

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING
* ARCHIVE_HANDLE = 0
CHANGENUMBER = x_chgnbr
* TABLEKEY = ' '
* TABLENAME = ' '
* IMPORTING
* HEADER =
TABLES
EDITPOS = i_cdshw
* EDITPOS_WITH_HEADER =
* EXCEPTIONS
* NO_POSITION_FOUND = 1
* WRONG_ACCESS_TO_ARCHIVE = 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. " get_change_positions

*&---------------------------------------------------------------------*
*& Form set_erpsy_daisy_fields
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_erpsy_daisy_fields.

if r_erps = 'X'.
move: 'I' to so_fname-sign,
'EQ' to so_fname-option,
'BISMT' to so_fname-low.
append so_fname.
move 'MATNR' to so_fname-low.
append so_fname.
move 'MAKTX' to so_fname-low.
append so_fname.
* MVKE fields
move 'VKORG' to so_fname-low.
append so_fname.
move 'VTWEG' to so_fname-low.
append so_fname.
move 'VMSTA' to so_fname-low.
append so_fname.
move 'VMSTA' to so_fname-low.
append so_fname.
move 'VRKME' to so_fname-low.
append so_fname.
move 'MSTAV' to so_fname-low.
append so_fname.
* MARA fields
move 'MTART' to so_fname-low.
append so_fname.
move 'MATKL' to so_fname-low.
append so_fname.
move 'MEINS' to so_fname-low.
append so_fname.
move 'EAN11' to so_fname-low.
append so_fname.
* MARC fields
move 'MTVFP' to so_fname-low.
append so_fname.
move 'MSTDV' to so_fname-low.
append so_fname.
move 'PLIFZ' to so_fname-low.
append so_fname.
move 'WERKS' to so_fname-low.
append so_fname.
move 'ZZDEPT' to so_fname-low.
append so_fname.
move 'ZZATP1' to so_fname-low.
append so_fname.
move 'ZZATP2' to so_fname-low.
append so_fname.
move 'ZZATP3' to so_fname-low.
append so_fname.
move 'ZZATP4' to so_fname-low.
append so_fname.
move 'ZZATP5' to so_fname-low.
append so_fname.
move 'ZZATP6' to so_fname-low.
append so_fname.
move 'ZZATP7' to so_fname-low.
append so_fname.
* MARM fields
move 'UMREN' to so_fname-low.
append so_fname.
move 'UMRES' to so_fname-low.
append so_fname.

endif.

ENDFORM. " set_erpsy_daisy_fields

text elements :

P_FNAME Field name
R_ALL All Fields
R_ERPS Only ERPsy-Daisy Fields
R_SELECT Field:
S_DATUM Changes from Date
S_MATNR Material
S_TIME Changes from Time
S_USERNM User
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 -> ММ 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.