2007 Sep 29 8:47 AM
RESPECTED SIR I WANT TO USE ALV WITH CALL FUNCTION REUSE_ALV_GRID_DISPLAY, MAINTAINING FIELD CATALOG SPECIFICALLY HOW TO CREATE FIELD CATALOG?,AND USE IT TO DISPLAY ALV-GRID.
PLEASE PRESENT THE MOVEMENT OF CONTROL STEP BY STEP.
THANKS
2007 Sep 29 8:55 AM
Saurabh,
Check these links out... u will get to know how ALV works
http://www.sap-img.com/abap/example-of-a-simple-alv-grid-report.htm
http://69.89.31.134/~geniehol/erpgenie/sap/abap/code/abap28.htm
reward if helpful,
Karthik
Saurabh,
Check these links out... u will get to know how ALV works
http://www.sap-img.com/abap/example-of-a-simple-alv-grid-report.htm
http://69.89.31.134/~geniehol/erpgenie/sap/abap/code/abap28.htm
reward if helpful,
Karthik
2007 Sep 29 8:55 AM
Saurabh,
Check these links out... u will get to know how ALV works
http://www.sap-img.com/abap/example-of-a-simple-alv-grid-report.htm
http://69.89.31.134/~geniehol/erpgenie/sap/abap/code/abap28.htm
reward if helpful,
Karthik
2007 Sep 29 9:01 AM
Hi saurabh,
This is a simple example.
<code>
&----
*& Report ZSAMPLEALV12
*&
&----
*&
*&
&----
*REPORT ZSAMPLEALV12.
&----
*& Report ZSAMPLEALV2 *
*& *
&----
*& *
*& *
&----
report zsamplealv12
message-id z00.
tables: mara.
data: v_flag,
v_data(50).
data: begin of it_final occurs 1,
matnr like mara-matnr,
maktx like makt-maktx,
werks like mard-werks,
lgort like mard-lgort,
labst like mard-labst,
dummy like icon-id,
end of it_final.
*-- Declaration of Type Groups
type-pools : slis.
data : i_fldcat_head type slis_t_fieldcat_alv,
wa_fldcat_head type slis_fieldcat_alv.
data : i_events type slis_t_event,
wa_event like line of i_events.
data : i_events_f type slis_t_event,
wa_event_f like line of i_events.
data : wa_layout type slis_layout_alv.
data: it_sort type slis_sortinfo_alv occurs 0 with header line.
data : i_comment type slis_t_listheader,
wa_comment type slis_listheader.
data : i_comment_f type slis_t_listheader,
wa_comment_f type slis_listheader.
data : wa_group type slis_sp_group_alv,
i_group type slis_t_sp_group_alv.
selection-screen begin of block b1 with frame title text-h01.
select-options: s_matnr for mara-matnr.
selection-screen end of block b1.
initialization.
concatenate 'User :' sy-uname into v_data.
it_final-dummy = '@&@&'.
at selection-screen on s_matnr.
if not s_matnr[] is initial.
perform validate_matnr.
endif.
start-of-selection.
perform get_data.
perform generate_fldcat.
perform generate_events.
perform generate_layout.
perform do_sort.
perform do_group.
end-of-selection.
if v_flag = 'X'.
perform display_report.
else.
message i010 with 'NO DATA TO DISPLAY'.
endif.
&----
*& Form VALIDATE_MATNR
&----
text
----
--> p1 text
<-- p2 text
----
form validate_matnr .
select matnr up to 1 rows
into (mara-matnr)
from mara
where matnr in s_matnr.
endselect.
if sy-subrc ne 0.
message i010 with 'INVALID RANGE OF MATERIAL' s_matnr-low 'To'
s_matnr-high.
endif.
endform. " VALIDATE_MATNR
&----
*& Form GET_DATA
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
select a~matnr
b~maktx
c~werks
c~lgort
c~labst
into corresponding fields of table it_final
from mara as a
inner join makt as b
on amatnr eq bmatnr
inner join mard as c
on amatnr eq cmatnr
where a~matnr in s_matnr
and b~spras = sy-langu.
if sy-subrc eq 0.
v_flag = 'X'.
else.
v_flag = space.
endif.
endform. " GET_DATA
&----
*& Form DISPLAY_REPORT
&----
text
----
--> p1 text
<-- p2 text
----
form display_report .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
i_callback_program = 'ZSAMPLEALV12'
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 = wa_layout
it_fieldcat = i_fldcat_head
IT_EXCLUDING =
it_special_groups = i_group
IT_SORT = IT_SORT
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
it_events = i_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
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = it_final
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. " DISPLAY_REPORT
&----
*& Form GENERATE_FLDCAT
&----
Generating the field catalog
----
form generate_fldcat.
wa_fldcat_head-fieldname = 'MATNR'.
wa_fldcat_head-col_pos = '1'.
wa_fldcat_head-just = 'C'.
wa_fldcat_head-outputlen = '18'.
wa_fldcat_head-seltext_m = 'Material Code'. "middle key word
wa_fldcat_head-ddictxt = 'M'.
wa_fldcat_head-ref_tabname = ' '.
append wa_fldcat_head to i_fldcat_head.
wa_fldcat_head-fieldname = 'MAKTX'.
wa_fldcat_head-col_pos = '2'.
wa_fldcat_head-outputlen = '40'.
wa_fldcat_head-seltext_m = 'Item Name'.
wa_fldcat_head-ddictxt = 'M'.
append wa_fldcat_head to i_fldcat_head.
wa_fldcat_head-fieldname = 'WERKS'.
wa_fldcat_head-col_pos = '3'.
wa_fldcat_head-outputlen = '10'.
wa_fldcat_head-seltext_m = 'Plant'.
wa_fldcat_head-ddictxt = 'M'.
append wa_fldcat_head to i_fldcat_head.
wa_fldcat_head-fieldname = 'LGORT'.
wa_fldcat_head-col_pos = '4'.
wa_fldcat_head-outputlen = '20'.
wa_fldcat_head-seltext_m = 'Location'.
wa_fldcat_head-ddictxt = 'M'.
append wa_fldcat_head to i_fldcat_head.
wa_fldcat_head-fieldname = 'LABST'.
wa_fldcat_head-col_pos = '5'.
wa_fldcat_head-outputlen = '20'.
wa_fldcat_head-seltext_m = 'Unrestricted Qty'.
wa_fldcat_head-ddictxt = 'M'.
wa_fldcat_head-do_sum = 'X'.
append wa_fldcat_head to i_fldcat_head.
endform. " GENERATE_FLDCAT
&----
*& Form GENERATE_LAYOUT
&----
Generating the Layout
----
form generate_layout .
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
wa_layout-totals_text = 'Totals'.
wa_layout-subtotals_text = 'Sub Totals'.
endform. " GENERATE_LAYOUT
&----
*& Form DO_SORT
&----
Sorting the ALV List
----
form do_sort .
*-- Populating the sort table
it_sort-fieldname = 'WERKS'.
it_sort-tabname = 'IT_FINAL'.
it_sort-up = 'X'.
it_sort-subtot = 'X'.
append it_sort.
endform. " DO_SORT
&----
*& Form GENERATE_EVENTS
&----
Generating the ALV Events
----
form generate_events .
call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
importing
et_events = i_events
exceptions
list_type_wrong = 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.
if not i_events[] is initial.
read table i_events into wa_event with key name = 'TOP_OF_PAGE'.
wa_event-form = 'GENERATE_USERCOMMAND'.
modify i_events from wa_event index sy-tabix.
read table i_events into wa_event with key name = 'END_OF_LIST'.
wa_event-form = 'GENERATE_USERCOMMAND_FOOTER'.
modify i_events from wa_event index sy-tabix.
endif.
endform. " GENERATE_EVENTS
&----
*& Form GENERATE_USERCOMMAND
&----
Displaying Header Text and Logo on Page Header
----
form generate_usercommand .
clear i_comment[].
wa_comment-typ = 'H'.
wa_comment-info = 'Material Information Report'.
append wa_comment to i_comment.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_comment
i_logo = 'ENJOYSAP_LOGO'
i_end_of_list_grid = 'X'.
endform. " GENERATE_USERCOMMAND
&----
*& Form GENERATE_USERCOMMAND_FOOTER
&----
text
----
--> p1 text
<-- p2 text
----
form generate_usercommand_footer .
clear i_comment[].
wa_comment-typ = 'A'.
wa_comment-info = v_data.
append wa_comment to i_comment.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_comment
I_LOGO = 'ZSAT_LOGO'
i_end_of_list_grid = 'X'.
endform. " GENERATE_USERCOMMAND_FOOTER
&----
*& Form DO_GROUP
&----
Grouping the data
----
form do_group .
clear i_group.
wa_group-sp_group = 'A'.
wa_group-text = 'WERKS'.
append wa_group to i_group.
endform. " DO_GROUP
</code>
If you have any further query do get back to me.
Reward points if u find it helpful.
Thanks & regards,
rajesh
2007 Sep 29 9:56 AM
Hi Saurabh,
See the below code where i have created fieldcatalog manually and passes to grid and list as well. Just uncoment the one which you need.
*&---------------------------------------------------------------------*
*& Report ZGS_ALV_MANUAL_LISTGRID
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZGS_ALV_MANUAL_LISTGRID.
TABLES: vbap.
SELECT-OPTIONS s_vbeln FOR vbap-vbeln.
TYPE-POOLS slis.
DATA fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA layout TYPE slis_layout_alv.
DATA: BEGIN OF itab OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
ernam LIKE vbap-ernam,
netwr LIKE vbap-netwr,
END OF itab.
START-OF-SELECTION.
SELECT vbeln
posnr
ernam
netwr
INTO TABLE itab
FROM vbap
WHERE vbeln IN s_vbeln.
fcat-seltext_l = 'Sales Doc No.'.
fcat-col_pos = '1'.
fcat-fieldname = 'VBELN'.
fcat-tabname = 'ITAB'.
fcat-outputlen = '15'.
APPEND fcat.
CLEAR fcat.
fcat-seltext_l = 'Item No.'.
fcat-col_pos = '2'.
fcat-fieldname = 'POSNR'.
fcat-tabname = 'ITAB'.
fcat-outputlen = '12'.
APPEND fcat.
CLEAR fcat.
fcat-seltext_l = 'Name of Person'.
fcat-col_pos = '3'.
fcat-fieldname = 'ERNAM'.
fcat-tabname = 'ITAB'.
fcat-outputlen = '25'.
APPEND fcat.
CLEAR fcat.
fcat-seltext_l = 'Net Value of Order'.
fcat-col_pos = '4'.
fcat-fieldname = 'NETWR'.
fcat-tabname = 'ITAB'.
fcat-outputlen = '20'.
APPEND fcat.
CLEAR fcat.
* abc-no_vline = 'X'.
* abc-no_hline = 'X'.
* layout-zebra = 'X'.
* CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
* EXPORTING
** I_INTERFACE_CHECK = ' '
** I_BYPASSING_BUFFER =
** I_BUFFER_ACTIVE = ' '
** I_CALLBACK_PROGRAM = ' '
** I_CALLBACK_PF_STATUS_SET = ' '
** I_CALLBACK_USER_COMMAND = ' '
** I_STRUCTURE_NAME =
** is_layout = layout
* it_fieldcat = 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
** IMPORTING
** E_EXIT_CAUSED_BY_CALLER =
** ES_EXIT_CAUSED_BY_USER =
* TABLES
* t_outtab = itab
* 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.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* 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 = 'Sales Document:Item Data'
* I_GRID_SETTINGS =
IS_LAYOUT = layout
IT_FIELDCAT = 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
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = ITAB
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.
Reward points if useful else getbk,
Aleem.
2007 Sep 29 10:50 AM
hi,
here is the code.
TYPE-POOLS:slis.
TABLES:mara,
makt,
marc.
DATA:BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
werks LIKE marc-werks,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
meins LIKE mara-meins,
ntgew LIKE mara-ntgew,
END OF itab.
DATA:t_fcat TYPE slis_t_fieldcat_alv,
t_eve TYPE slis_t_event.
DATA : st_layout TYPE slis_layout_alv.
SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:mat FOR mara-matnr. " no intervals no-extension.
SELECTION-SCREEN:END OF BLOCK blk1.
INITIALIZATION.
PERFORM build_cata USING t_fcat.
PERFORM build_event.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM display_data.
&----
*& Form build_cata
&----
text
----
-->TEMP_FCAT text
----
FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.
sy-tvar0 = sy-uname.
WRITE sy-datum TO sy-tvar1.
DATA:wa_fcat TYPE slis_fieldcat_alv.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MAKTX'.
wa_fcat-seltext_m = 'Description'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-seltext_m = 'Plant'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MTART'.
wa_fcat-seltext_m = 'Type'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MATKL'.
wa_fcat-seltext_m = 'Group'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MEINS'.
wa_fcat-seltext_m = 'Measurement Unit'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'NTGEW'.
wa_fcat-seltext_m = 'Net Value'.
APPEND wa_fcat TO temp_fcat.
ENDFORM. "build_cata
&----
*& Form build_event
&----
text
----
FORM build_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = t_eve
EXCEPTIONS
list_type_wrong = 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. "build_event
&----
*& Form data_retrieval
&----
text
----
FORM data_retrieval.
SELECT maramatnr maramtart maramatkl marameins mara~ntgew
maktmaktx marcwerks
INTO CORRESPONDING FIELDS OF TABLE itab
FROM mara INNER JOIN makt ON
maramatnr = maktmatnr
INNER JOIN marc ON
maramatnr = marcmatnr
WHERE mara~matnr IN mat.
SORT itab BY matnr.
DELETE ADJACENT DUPLICATES FROM itab.
ENDFORM. "data_retrieval
&----
*& Form display_data
&----
text
----
FORM display_data.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'ZALV_DS'
it_fieldcat = t_fcat
it_events = t_eve
I_GRID_TITLE = 'DATA'
TABLES
t_outtab = itab
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. "display_data
Hope it will b useful to u.
Here in this report form <b>build_event.</b> doent make any difference as i havent use any event but it is useful when u want to create header, footer or want to make interactive report.
Reward if useful.
2007 Sep 29 11:57 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |