‎2007 Mar 20 10:09 AM
Hi ,
Is there a way to create Create Fieldcatalog based on internal table (dynamic).
while creating fieldcat we usually many give the fields "fieldname" and "tabname".
is there a way to get the fieldname from the main table ?
Eg ..
I have i_tab as the output table. It has 3 fields "a", "b" and "c"
Now when i created fieldcat manually ( in case i cannot use fieldcat_merge FM) , i have to append 3 throws in fieldcat table.
These rows would have "a", "b" and "c".
Now i want to know if there is a way in which i can find "a" "b" and "c" fieldnames from the createdd internal tables.
i can then append the same to fieldcat.
‎2007 Mar 20 10:12 AM
Hi anuj,
Yes u can do that
chk this
**DYNAMIC CREATION OF FIELDCATALOG***************
*FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
*LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
LOOP AT it_mandt WHERE mandt IN s_mandt.
CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
wa_fieldcatalog-inttype = 'NUMC'.
wa_fieldcatalog-outputlen = '14'.
wa_fieldcatalog-reptext = it_mandt.
wa_fieldcatalog-seltext = it_mandt.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR :wa_fieldcatalog ,it_mandt.
ENDLOOP.
‎2007 Mar 20 10:17 AM
‎2007 Mar 20 10:28 AM
Hello Anuj ,
You can get the field names in the intenal table by using FM
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = u_con_name_ldb_struc
TABLES
dd03p_tab = lt_dd03p
EXCEPTIONS
illegal_input = 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.
You can use the internal table lt_dd03p to create field catalog ..
Is this wht u r lloking for ?
‎2007 Mar 20 11:28 AM
Hi Anuj,
I created a FORM routine for this 4 or 5 years ago and made a couple of refinements. Meanwhile it has prooved as very useful.
The disadvantag is that it creates the oldfashioned field catalog for the function calls. But I already used it for OO fieldcatalog of LVC type - there is a function module for this but I do not have the name here.
You need the two forms (second called in first) to build the field catalog from any internal table that can be used for ALV display.
*&---------------------------------------------------------------------*
*& Form ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------*
* Feldkatalog from (arbitrary) internal Table (c) Clemens Li
* * build field catalog from type description
*----------------------------------------------------------------------*
form alv_fieldcat_for_itab "#EC *
tables pt_outtab type table "#EC *
changing pt_alv_fieldcat type slis_t_fieldcat_alv."#EC *
data:
lv_desc type sydes_desc,
ls_alv_fieldcat type slis_fieldcat_alv,
lv_longfield type text80."CRM<=R/3 fname.
field-symbols:
<typeinfo> type sydes_typeinfo,
<nameinfo> type sydes_nameinfo.
describe field pt_outtab into lv_desc. "#EC *
loop at lv_desc-types
assigning <typeinfo>
where not idx_name is initial
and table_kind is initial "no entries for deep table like color
and back = 1. "top-level-entries only.
read table lv_desc-names index <typeinfo>-idx_name
assigning <nameinfo>.
check <nameinfo>-name <> 'INCLUDE'.
ls_alv_fieldcat-fieldname = <nameinfo>-name.
while not <nameinfo>-continue is initial.
add 1 to <typeinfo>-idx_name.
read table lv_desc-names index <typeinfo>-idx_name
assigning <nameinfo>.
concatenate
ls_alv_fieldcat-fieldname
<nameinfo>-name
into ls_alv_fieldcat-fieldname.
endwhile." not <nameinfo>-continue IS INITIAL.
read table lv_desc-names index <typeinfo>-idx_help_id
assigning <nameinfo>.
if sy-subrc = 0.
* Caution: Help-ID may be Tablename-Fieldname and thus longer
* than 30 Chars; ls_alv_fieldcat-rollname is 30 Chars only
ls_alv_fieldcat-rollname = <nameinfo>-name.
lv_longfield = <nameinfo>-name.
while not <nameinfo>-continue is initial.
add 1 to <typeinfo>-idx_help_id.
read table lv_desc-names index <typeinfo>-idx_help_id
assigning <nameinfo>.
concatenate
lv_longfield
<nameinfo>-name
into lv_longfield.
endwhile." not lv_desc-continue is initial.
* help id may be data element or <table>-<field>
if lv_longfield ca '-'.
* get data type for table field
perform get_rollname_4_tabfield
using lv_longfield changing ls_alv_fieldcat.
endif." lv_longfield ca '-'.
else.
* No Help-ID: Use Fieldname as text
ls_alv_fieldcat-seltext_s =
ls_alv_fieldcat-seltext_m =
ls_alv_fieldcat-seltext_l =
ls_alv_fieldcat-reptext_ddic =
<nameinfo>-name.
endif." sy-subrc = 0.
* Starting 4.7: get edit mask
if not <typeinfo>-idx_edit_mask is initial.
read table lv_desc-names index <typeinfo>-idx_edit_mask
assigning <nameinfo>.
ls_alv_fieldcat-edit_mask = <nameinfo>-name.
if not <nameinfo>-continue is initial.
add 1 to <typeinfo>-idx_edit_mask.
read table lv_desc-names index <typeinfo>-idx_edit_mask
assigning <nameinfo>.
concatenate
ls_alv_fieldcat-edit_mask
<nameinfo>-name
into ls_alv_fieldcat-edit_mask.
endif." not <nameinfo>-continue IS INITIAL.
endif." not <typeinfo>-IDX_EDIT_MASK is initial.
* assign length, output length and decimals
ls_alv_fieldcat-intlen = <typeinfo>-length.
ls_alv_fieldcat-outputlen = <typeinfo>-output_length.
ls_alv_fieldcat-decimals_out = <typeinfo>-decimals.
ls_alv_fieldcat-inttype = <typeinfo>-type.
append ls_alv_fieldcat to pt_alv_fieldcat.
clear: "prevent anything 2 B taken for subsequent fields
ls_alv_fieldcat.
endloop." at lv_desc-types where not IDX_NAME is in initial.
endform. " ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------
*& Form get_rollname_4_tabfield
*&---------------------------------------------------------------------
* Get Data type for Table field
*----------------------------------------------------------------------
form get_rollname_4_tabfield
using p_fname type text80 ""CRM<=R/3 fname
changing p_alv_fieldcat type slis_fieldcat_alv.
field-symbols:
<dfies> type dfies.
data:
lv_tabname type tabname,
lt_dfies type table of dfies,
lv_fieldname type fieldname.
split p_fname at '-'
into lv_tabname lv_fieldname.
clear p_alv_fieldcat-rollname.
call function 'DDIF_FIELDINFO_GET'
exporting
tabname = lv_tabname
fieldname = lv_fieldname
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
tables
dfies_tab = lt_dfies
* FIXED_VALUES =
exceptions
not_found = 1
internal_error = 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.
else.
read table lt_dfies assigning <dfies> index 1.
p_alv_fieldcat-rollname = <dfies>-rollname.
* Und wenn keinerlei Twexte gepflegt sind?
if <dfies>-reptext is initial and
<dfies>-scrtext_s is initial and
<dfies>-scrtext_m is initial and
<dfies>-scrtext_l is initial.
* No Text: Use Fieldname as text
p_alv_fieldcat-seltext_s =
p_alv_fieldcat-seltext_m =
p_alv_fieldcat-seltext_l =
p_alv_fieldcat-reptext_ddic =
p_alv_fieldcat-fieldname.
endif." <dfies>-reptext IS INITIAL AND
endif.
endform. " get_rollname_4_tabfield
Regards,
Clemens