02-15-2007 5:17 PM
Hi all,
how can we populate a field catalog using REUSE_ALV_FIELDCATALOG_MERGE.
Thanks and regards.
bharath.
02-15-2007 6:27 PM
hi
good
Data to be displayed in ALV
Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
----
Other data needed
field to store report name
data i_repid like sy-repid.
field to check table length
data i_lines like sy-tabix.
----
Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
----
select-options:
s_matnr for marav-matnr matchcode object MAT1.
----
start-of-selection.
read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
----
*
Now, we start with ALV
*
----
*
*
To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
The fieldcatalouge can be generated by FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
report source, including this report.
The only problem one might have is that the report and table names
need to be in capital letters. (I had it )
*
*
----
Store report name
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
I_PROGRAM_NAME is the program which calls this function
*
I_INTERNAL_TABNAME is the name of the internal table which you want
to display in ALV
*
I_INCLNAME is the ABAP-source where the internal table is defined
(DATA....)
CT_FIELDCAT contains the Fieldcatalouge that we need later for
ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
----
*
And now, we are ready to display our list
Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
I_CALLBACK_PROGRAM is the program which calls this function
*
IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
now the data definition needed for display
*
I_SAVE allows the user to save his own layouts
*
T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
thanks
mrutyun^
02-15-2007 5:29 PM
There are examples all over the place.
http://www.sap-img.com/fu015.htm
http://www.sap-img.com/abap/reincarnation-of-reuse-alv-fieldcatalog-merge.htm
http://www.erpgenie.com/abap/code/abap28.htm
http://www.sapdevelopment.co.uk/reporting/alv/alv_variousfcat.htm
Here are just a few.....
Regards,
Rich Heilman
02-15-2007 6:27 PM
hi
good
Data to be displayed in ALV
Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.
----
Other data needed
field to store report name
data i_repid like sy-repid.
field to check table length
data i_lines like sy-tabix.
----
Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.
----
select-options:
s_matnr for marav-matnr matchcode object MAT1.
----
start-of-selection.
read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.
Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.
end-of-selection.
----
*
Now, we start with ALV
*
----
*
*
To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
The fieldcatalouge can be generated by FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
report source, including this report.
The only problem one might have is that the report and table names
need to be in capital letters. (I had it )
*
*
----
Store report name
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
I_PROGRAM_NAME is the program which calls this function
*
I_INTERNAL_TABNAME is the name of the internal table which you want
to display in ALV
*
I_INCLNAME is the ABAP-source where the internal table is defined
(DATA....)
CT_FIELDCAT contains the Fieldcatalouge that we need later for
ALV display
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*This was the fieldcatlogue
----
*
And now, we are ready to display our list
Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
I_CALLBACK_PROGRAM is the program which calls this function
*
IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
now the data definition needed for display
*
I_SAVE allows the user to save his own layouts
*
T_OUTTAB contains the data to be displayed in ALV
IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
thanks
mrutyun^
02-15-2007 7:12 PM
HI,
u can add fields to fieldcatalog manually...
<b>**************************
DATA: BEGIN OF gt_final_outtab OCCURS 0,
matnr LIKE mara-matnr,
mtart like mara-mtart,
maktx LIKE makt-maktx,
menge LIKE mseg-menge,
meins LIKE mseg-meins,
per_val TYPE p DECIMALS 4,
werks like mseg-werks,
END OF gt_final_outtab.
FORM get_fieldcat.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
DATA: pos TYPE i VALUE 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-datatype = 'CHAR'.
ls_fieldcat-outputlen = 18.
ls_fieldcat-seltext_l = 'Material Number'.
ls_fieldcat-checkbox = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
pos = pos + 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MAKTX'.
ls_fieldcat-datatype = 'CHAR'.
ls_fieldcat-outputlen = 20.
ls_fieldcat-seltext_l = 'Product Description'.
ls_fieldcat-checkbox = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
pos = pos + 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MENGE'.
ls_fieldcat-outputlen = 15.
ls_fieldcat-seltext_l = 'Lbs Shipped'.
ls_fieldcat-checkbox = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
pos = pos + 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = pos.
ls_fieldcat-fieldname = 'MEINS'.
ls_fieldcat-outputlen = 4.
ls_fieldcat-seltext_l = 'QTY'.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ENDFORM. " get_fieldcat
----
FORM show_report.
PERFORM get_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
it_fieldcat = gt_fieldcat[]
i_save = 'A'
TABLES
t_outtab = gt_final_outtab.
ENDFORM. " Show_report</b>
Regards
SAB
02-15-2007 7:17 PM
HI,
Please note that structure ZSTOCK is a custom table and iline looks as follow :-
data: iline type table of zstock with header line.
data: gt_fieldcat type slis_t_fieldcat_alv.
perform setup-fieldcatalog using gt_fieldcat[].
form setup-fieldcatalog using _fieldcat type slis_t_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_internal_tabname = 'ILINE'
i_structure_name = 'ZSTOCK'
changing
ct_fieldcat = _fieldcat.
loop at _fieldcat into ls_fieldcat.
case ls_fieldcat-fieldname.
when 'DEPT'.
ls_fieldcat-no_out = 'X'.
when 'DESCR'.
ls_fieldcat-no_out = 'X'.
when 'GOOD_PRD'.
ls_fieldcat-do_sum = 'X'.
endcase.
modify _fieldcat from ls_fieldcat.
endloop.
endform. " FIELDCATALOG
See the below link for an example program, it is well explained
http://www.erpgenie.com/abap/code/abap28.htm
Regards
Sudheer