Sample of Simple ALV Report
---------------------------------------------------------------------*
*& Report ZAASHISH_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZAASHISH_ALV.
type-pools: slis.
data: wa_num type matnr,
wa_werks type werks_d.
types: begin of ty_mara,
matnr type matnr, "Material Number field of Mara Table
meins type meins, "Unit field of Mara Table
mtart type mtart, "Material Type field of Mara Table
matkl type matkl, "Unit of Issue field of Mara Table
prdha type prodh_d, "Product Hierarchy field of Mara Table
end of ty_mara,
ty_t_mara type standard table of ty_mara.
*Creating Structure for makt
types: begin of ty_makt,
matnr type matnr, "Material Number field of Makt Table
maktx type maktx, "Material Description field of Makt Table
end of ty_makt,
ty_t_makt type standard table of ty_makt.
*Creating Structure for marc
types: begin of ty_marc,
matnr type matnr, "Material Number field of Marc Table
werks type werks, "Plant field of Marc
ekgrp type ekgrp, "Purchasing group field of Marc Table
ausme type ausme, "Unit of Issue field of Marc Table
end of ty_marc,
ty_t_marc type standard table of ty_marc.
*Creating Structure for mard
types: begin of ty_mard,
matnr type matnr, "Material Number field of Mard Table
werks type werks_d, "Plants field in Mard Table
lgort type lgort_d, "Storage Location field of Mard Table
end of ty_mard,
ty_t_mard type standard table of ty_mard.
*Creating output structure
types: begin of ty_list,
matnr type matnr,
meins type meins,
mtart type mtart,
matkl type matkl,
pradh type prodh_d,
maktx type maktx,
werks type werks_d,
ekgrp type ekgrp,
ausme type ausme,
lgort type lgort_d,
end of ty_list,
ty_t_list type standard table of ty_list.
*Declaring Wprk area
data: w_mara type ty_mara,
w_marc type ty_marc,
w_makt type ty_makt,
w_mard type ty_mard,
w_list type ty_list,
w_fieldcatalog type slis_fieldcat_alv.
data: i_mara type ty_t_mara,
i_marc type ty_t_marc,
i_makt type ty_t_makt,
i_mard type ty_t_mard,
i_list type ty_t_list,
i_fieldcatalog type slis_t_fieldcat_alv.
*Creates Selection Screen for werks & matnr
select-options gv_werks for wa_werks .
select-options gv_matnr for wa_num.
*Fetching records from mara and placing into i_mara
select
matnr
meins
mtart
matkl
prdha
into table i_mara
from mara
where matnr in gv_matnr.
if sy-subrc = 0 and i_mara is not initial.
sort i_mara by matnr.
*Fetching records from marc and placing into i_marc
select
matnr
werks
ekgrp
ausme
into table
i_marc
from marc
for all entries in i_mara
where matnr = i_mara-matnr.
if sy-subrc = 0 and i_marc is not initial.
sort i_marc by matnr.
*Fetching records from mard and placing into i_mard
select
matnr
werks
lgort
into table
i_mard
from
mard
for all entries in
i_marc
where matnr = i_marc-matnr.
if sy-subrc = 0 and i_mard is not initial.
sort i_mard by matnr.
endif.
*Fetching records from makt and placing into i_makt
endif.
select
matnr
maktx
into table
i_makt
from
makt
for all entries in
i_mara
where matnr = i_mara-matnr.
if sy-subrc = 0 and i_makt is not initial.
sort i_makt by matnr.
endif.
endif.
*Creating loop to fetch one by one record from i_mara and placing into w_mara
loop at i_mara into w_mara.
w_list-matnr = w_mara-matnr.
w_list-meins = w_mara-meins.
w_list-mtart = w_mara-mtart.
w_list-matkl = w_mara-matkl.
w_list-pradh = w_mara-prdha.
read table i_marc into w_marc with key matnr = w_mara-matnr.
w_list-werks = w_marc-werks.
w_list-ekgrp = w_marc-ekgrp.
read table i_mard into w_mard with key matnr = w_mara-matnr.
w_list-werks = w_mard-werks.
w_list-lgort = w_mard-lgort.
read table i_makt into w_makt with key matnr = w_mara-matnr.
w_list-maktx = w_makt-maktx.
append w_list to i_list.
endloop.
w_fieldcatalog-col_pos = 1.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MATNR'.
w_fieldcatalog-seltext_m = 'material number'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 2.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MEINS'.
w_fieldcatalog-seltext_m = 'Unit of Measure'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 3.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MTART'.
w_fieldcatalog-seltext_m = 'Material Type'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 4.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'AUSME'.
w_fieldcatalog-seltext_m = 'Unit of Issue'.
*append w_fieldcatalog to i_fieldcatalog.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 5.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MATKL'.
w_fieldcatalog-seltext_m = 'Material Group'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 6.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'PRADH'.
w_fieldcatalog-seltext_m = 'Product Hierarchy'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 7.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'WERKS'.
w_fieldcatalog-seltext_m = 'plant'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 8.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'EKGRP'.
w_fieldcatalog-seltext_m = 'Purchasing Group'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 9.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'LGORT'.
w_fieldcatalog-seltext_m = 'Storage Location'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 10.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MAKTX'.
w_fieldcatalog-seltext_m = 'Material Description'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
id_lines type i,
id_linesc(10) type c.
*title
wa_header-typ = 'H'.
wa_header-info = 'Material Table Report'.
append wa_header to t_header.
clear wa_header.
*Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = 'SUB_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 =
IT_FIELDCAT = i_fieldcatalog
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'X'
* 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 = i_list
* 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.
perform sub_top_of_page.
form SUB_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = t_header
I_LOGO = 'AASHISH'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
endform.
*& Report ZAASHISH_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZAASHISH_ALV.
type-pools: slis.
data: wa_num type matnr,
wa_werks type werks_d.
types: begin of ty_mara,
matnr type matnr, "Material Number field of Mara Table
meins type meins, "Unit field of Mara Table
mtart type mtart, "Material Type field of Mara Table
matkl type matkl, "Unit of Issue field of Mara Table
prdha type prodh_d, "Product Hierarchy field of Mara Table
end of ty_mara,
ty_t_mara type standard table of ty_mara.
*Creating Structure for makt
types: begin of ty_makt,
matnr type matnr, "Material Number field of Makt Table
maktx type maktx, "Material Description field of Makt Table
end of ty_makt,
ty_t_makt type standard table of ty_makt.
*Creating Structure for marc
types: begin of ty_marc,
matnr type matnr, "Material Number field of Marc Table
werks type werks, "Plant field of Marc
ekgrp type ekgrp, "Purchasing group field of Marc Table
ausme type ausme, "Unit of Issue field of Marc Table
end of ty_marc,
ty_t_marc type standard table of ty_marc.
*Creating Structure for mard
types: begin of ty_mard,
matnr type matnr, "Material Number field of Mard Table
werks type werks_d, "Plants field in Mard Table
lgort type lgort_d, "Storage Location field of Mard Table
end of ty_mard,
ty_t_mard type standard table of ty_mard.
*Creating output structure
types: begin of ty_list,
matnr type matnr,
meins type meins,
mtart type mtart,
matkl type matkl,
pradh type prodh_d,
maktx type maktx,
werks type werks_d,
ekgrp type ekgrp,
ausme type ausme,
lgort type lgort_d,
end of ty_list,
ty_t_list type standard table of ty_list.
*Declaring Wprk area
data: w_mara type ty_mara,
w_marc type ty_marc,
w_makt type ty_makt,
w_mard type ty_mard,
w_list type ty_list,
w_fieldcatalog type slis_fieldcat_alv.
data: i_mara type ty_t_mara,
i_marc type ty_t_marc,
i_makt type ty_t_makt,
i_mard type ty_t_mard,
i_list type ty_t_list,
i_fieldcatalog type slis_t_fieldcat_alv.
*Creates Selection Screen for werks & matnr
select-options gv_werks for wa_werks .
select-options gv_matnr for wa_num.
*Fetching records from mara and placing into i_mara
select
matnr
meins
mtart
matkl
prdha
into table i_mara
from mara
where matnr in gv_matnr.
if sy-subrc = 0 and i_mara is not initial.
sort i_mara by matnr.
*Fetching records from marc and placing into i_marc
select
matnr
werks
ekgrp
ausme
into table
i_marc
from marc
for all entries in i_mara
where matnr = i_mara-matnr.
if sy-subrc = 0 and i_marc is not initial.
sort i_marc by matnr.
*Fetching records from mard and placing into i_mard
select
matnr
werks
lgort
into table
i_mard
from
mard
for all entries in
i_marc
where matnr = i_marc-matnr.
if sy-subrc = 0 and i_mard is not initial.
sort i_mard by matnr.
endif.
*Fetching records from makt and placing into i_makt
endif.
select
matnr
maktx
into table
i_makt
from
makt
for all entries in
i_mara
where matnr = i_mara-matnr.
if sy-subrc = 0 and i_makt is not initial.
sort i_makt by matnr.
endif.
endif.
*Creating loop to fetch one by one record from i_mara and placing into w_mara
loop at i_mara into w_mara.
w_list-matnr = w_mara-matnr.
w_list-meins = w_mara-meins.
w_list-mtart = w_mara-mtart.
w_list-matkl = w_mara-matkl.
w_list-pradh = w_mara-prdha.
read table i_marc into w_marc with key matnr = w_mara-matnr.
w_list-werks = w_marc-werks.
w_list-ekgrp = w_marc-ekgrp.
read table i_mard into w_mard with key matnr = w_mara-matnr.
w_list-werks = w_mard-werks.
w_list-lgort = w_mard-lgort.
read table i_makt into w_makt with key matnr = w_mara-matnr.
w_list-maktx = w_makt-maktx.
append w_list to i_list.
endloop.
w_fieldcatalog-col_pos = 1.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MATNR'.
w_fieldcatalog-seltext_m = 'material number'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 2.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MEINS'.
w_fieldcatalog-seltext_m = 'Unit of Measure'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 3.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MTART'.
w_fieldcatalog-seltext_m = 'Material Type'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 4.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'AUSME'.
w_fieldcatalog-seltext_m = 'Unit of Issue'.
*append w_fieldcatalog to i_fieldcatalog.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 5.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MATKL'.
w_fieldcatalog-seltext_m = 'Material Group'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 6.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'PRADH'.
w_fieldcatalog-seltext_m = 'Product Hierarchy'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 7.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'WERKS'.
w_fieldcatalog-seltext_m = 'plant'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 8.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'EKGRP'.
w_fieldcatalog-seltext_m = 'Purchasing Group'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 9.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'LGORT'.
w_fieldcatalog-seltext_m = 'Storage Location'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
w_fieldcatalog-col_pos = 10.
w_fieldcatalog-tabname = 'ty_t_list'.
w_fieldcatalog-fieldname = 'MAKTX'.
w_fieldcatalog-seltext_m = 'Material Description'.
append w_fieldcatalog to i_fieldcatalog.
clear w_fieldcatalog.
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
id_lines type i,
id_linesc(10) type c.
*title
wa_header-typ = 'H'.
wa_header-info = 'Material Table Report'.
append wa_header to t_header.
clear wa_header.
*Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = 'SUB_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 =
IT_FIELDCAT = i_fieldcatalog
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'X'
* 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 = i_list
* 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.
perform sub_top_of_page.
form SUB_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = t_header
I_LOGO = 'AASHISH'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
endform.
No comments:
Post a Comment