Vous êtes sur la page 1sur 6

*&---------------------------------------------------------------------*

*& Report ZALV_COMPARITIVE_SALES_ORDER1


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZALV_COMPARITIVE_SALES_ORDER1.
*&---------------------------------------------------------------------*
*& Report ZSD_COMPARTIVE_REPOT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
type-pools: slis.
Types: begin of ty_vbap,
matnr type matnr,
arktx type arktx,
erdat type erdat,
netwr type NETWR_AP,
nt currency
end of ty_vbap,
begin of ty_final,
matnr type matnr,
arktx type arktx,
Cur_mon type netwr_ap,
last_mon type netwr_ap,
ly_cur_mon type netwr_ap,
end of ty_final.

"Material Number
"Short text for sales order item
"Date on Which Record Was Created
"Net value of the order item in docume

"Material Number
"Short text for sales order item

Data: t_vbap type STANDARD TABLE OF ty_vbap INITIAL SIZE 0,


t_vbap1 type STANDARD TABLE OF ty_vbap initial size 0,
t_final type STANDARD TABLE OF ty_final initial size 0,
w_vbap TYPE ty_vbap,
w_final type ty_final,
t_fcat type slis_t_fieldcat_alv,
w_fcat type slis_fieldcat_alv,
w_layout type slis_layout_alv,
cur_m_Fdate type sy-datum,
cur_m_ldate type sy-datum,
Last_m_fdate type sy-datum,
last_m_ldate type sy-datum,
Ly_cur_m_fdate type sydatum,

"
"
"
"
"

Current Month first date


Current Month Last date
Last Month First Date
Last Month last Date
Last Year current Month first

date
ly_cur_m_ldate type sy-datum,

" Last year current Month last d

ate
cur_m_name type string,
last_m_name type string,
ly_cur_m_name type string,
ame

" Current Month Name


" Last Month Name
" Last year current Month n

g_matnr type matnr,


g_erdat type erdat,
g_l_erdat type erdat.
SELECTION-SCREEN: begin of block b1 with frame.
select-options: s_matnr for g_matnr OBLIGATORY,
s_erdat for g_erdat NO-DISPLAY,
s_lerdat for g_l_erdat NO-DISPLAY.
parameters: p_month type numc2,
p_year type numc4.
SELECTION-SCREEN: end OF block b1.
INITIALIZATION.
Clear: w_vbap,
w_fcat.
refresh: t_vbap,
t_fcat.
AT SELECTION-SCREEN.
Perform sub_validate_matnr.
Start-OF-SELECTION.
Perform sub_get_date.
perform sub_get_vbap.
perform sub_pop.
perform sub_display.
*&---------------------------------------------------------------------*
*&
Form SUB_VALIDATE_MATNR
*&---------------------------------------------------------------------*
*
This is to validate Matnr (Material)
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_MATNR .
data: l_matnr type matnr.
select single matnr from mara into l_matnr WHERE matnr in s_matnr.
If sy-subrc <> 0.
Message E003(Zmsg_fa) with S_matnr.
endif.
ENDFORM.
" SUB_VALIDATE_MATNR
*&---------------------------------------------------------------------*
*&
Form SUB_GET_DATE
*&---------------------------------------------------------------------*
*
This is to fetch dates and its Months name
*----------------------------------------------------------------------*
FORM SUB_GET_DATE .

CALL FUNCTION 'ZTEST_DATE'


EXPORTING
P_MONTH
= p_month
P_YEAR
= p_year
IMPORTING
Current_mon
= cur_m_name
Last_mon
= last_m_name
LY_Cur_mon
= ly_cur_m_name
DATE4
= cur_m_fdate
DATE1
= cur_m_ldate
DATE
= last_m_fdate
DATE5
= last_m_ldate
DATE3
= ly_cur_m_fdate
DATE2
= ly_cur_m_ldate
.
s_erdat-low = last_m_fdate.
s_erdat-high = cur_m_ldate.
s_erdat-sign = 'I'.
s_erdat-option = 'BT'.
append s_erdat.
s_lerdat-low = ly_cur_m_fdate.
s_lerdat-high = ly_cur_m_ldate.
s_lerdat-sign = 'I'.
s_lerdat-option = 'BT'.
append s_lerdat.
ENDFORM.
" SUB_GET_DATE
*&---------------------------------------------------------------------*
*&
Form SUB_GET_VBAP
*&---------------------------------------------------------------------*
*
This is to fetch data from vbap
*----------------------------------------------------------------------*
FORM SUB_GET_VBAP .
select matnr
arktx
erdat
netwr from vbap into table t_vbap
where ( ( ( erdat in s_erdat ) or ( erdat in s_lerdat ) ) and matnr in s_
matnr ).
if sy-subrc <> 0.
MESSAGE e004(zmsg_fa) with s_matnr p_month p_year.
leave LIST-PROCESSING.
endif.
sort t_vbap by matnr erdat.
loop at t_vbap into w_vbap.
collect w_vbap into t_vbap1.
endloop.
clear w_vbap.
ENDFORM.
" SUB_GET_VBAP
*&---------------------------------------------------------------------*
*&
Form SUB_POP
*&---------------------------------------------------------------------*
*
This is to populate the final internal table
*----------------------------------------------------------------------*

FORM SUB_POP .
data: lw_vbap type ty_vbap.
sort t_vbap1 by matnr erdat.
loop at t_vbap1 into w_vbap.
w_final-matnr = w_vbap-matnr.
w_final-arktx = w_vbap-arktx.
lw_vbap = w_vbap.
at new erdat.
w_vbap = lw_vbap.
if ( w_vbap-erdat >= cur_m_fdate and w_vbap-erdat <= cur_m_ldate ).
w_final-cur_mon = w_vbap-netwr.
elseif ( w_vbap-erdat >= ly_cur_m_fdate and w_vbap-erdat <= ly_cur_m_ldate
).
w_final-ly_cur_mon = w_vbap-netwr.
else.
w_final-last_mon = w_vbap-netwr.
endif.
endat.
at end of matnr.
append w_final to t_final.
clear : w_final,
w_vbap.
endat.
endloop.
ENDFORM.
" SUB_POP
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY
*&---------------------------------------------------------------------*
*
This is to display the final internal table
*----------------------------------------------------------------------*
FORM SUB_DISPLAY .
perform sub_fieldcat using : '1'
'2'
'3'
'4'
'5'

'MATNR' 'Material no',


'ARKTX' 'Item Description',
'CUR_MON' Cur_m_name,
'LAST_MON' Last_m_name,
'LY_CUR_MON' Ly_cur_m_name.

perform sub_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK
= ' '
* I_BYPASSING_BUFFER
= ' '
* I_BUFFER_ACTIVE
= ' '
I_CALLBACK_PROGRAM
= Sy-cprog
* I_CALLBACK_PF_STATUS_SET
= ' '
* I_CALLBACK_USER_COMMAND
= ' '

*
*
*
*
*
*
*

I_CALLBACK_TOP_OF_PAGE
= ' '
I_CALLBACK_HTML_TOP_OF_PAGE
= ' '
I_CALLBACK_HTML_END_OF_LIST
= ' '
I_STRUCTURE_NAME
=
I_BACKGROUND_ID
= ' '
I_GRID_TITLE
=
I_GRID_SETTINGS
=
IS_LAYOUT
= w_layout
IT_FIELDCAT
= t_fcat
* IT_EXCLUDING
=
* IT_SPECIAL_GROUPS
=
* IT_SORT
=
* IT_FILTER
=
* IS_SEL_HIDE
=
* I_DEFAULT
= 'X'
* I_SAVE
= ' '
* IS_VARIANT
=
* IT_EVENTS
=
* IT_EVENT_EXIT
=
* IS_PRINT
=
* IS_REPREP_ID
=
* I_SCREEN_START_COLUMN
= 0
* I_SCREEN_START_LINE
= 0
* I_SCREEN_END_COLUMN
= 0
* I_SCREEN_END_LINE
= 0
* I_HTML_HEIGHT_TOP
= 0
* I_HTML_HEIGHT_END
= 0
* IT_ALV_GRAPHICS
=
* IT_HYPERLINK
=
* IT_ADD_FIELDCAT
=
* IT_EXCEPT_QINFO
=
* IR_SALV_FULLSCREEN_ADAPTER
=
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
=
* ES_EXIT_CAUSED_BY_USER
=
TABLES
T_OUTTAB
= t_final
* EXCEPTIONS
* PROGRAM_ERROR
= 1
* OTHERS
= 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.
" SUB_DISPLAY
*&---------------------------------------------------------------------*
*&
Form SUB_FIELDCAT
*&---------------------------------------------------------------------*
*
This is to fill the fieldcat
*----------------------------------------------------------------------*
FORM SUB_FIELDCAT USING
w_fcat-col_pos =
w_fcat-fieldname
w_fcat-seltext_m
append w_fcat to

col.
= fname.
= seltxt.
t_fcat.

Col fname seltxt.

clear w_fcat.
ENDFORM.
" SUB_FIELDCAT
*&---------------------------------------------------------------------*
*&
Form SUB_LAYOUT
*&---------------------------------------------------------------------*
*
This is to fill layout
*----------------------------------------------------------------------*
FORM SUB_LAYOUT .
w_layout-colwidth_optimize = 'X'.
ENDFORM.
" SUB_LAYOUT

Vous aimerez peut-être aussi