‎2011 Aug 09 6:20 AM
Hello,
My requirement is to compare a table having two different versions ( version is a primary key in the table ). So I have called a method passing two internal tables containing data from both the tables and do the comparision. I want to know through RTTI how can I find the number of fields of that table. I don't want to use 'DDIF_FIELDINFO_GET' to know the number of fields. Though my requirement is met and I am able to do things properly. I want to use RTTI to find the number of fields of the structure. My code is given below:
METHOD SIGNATURE: IM_CNDITEM_FIRST (importing ) type ZSD_TT_CND_ITEM,
IM_CNDITEM_SECOND(importing) type ZSD_TT_CND_ITEM.
FIELD-SYMBOLS: <fs> TYPE ZSD_CND_ITEM,
<fs1> TYPE ZSD_CND_ITEM,
<fs3> TYPE ANY,
<fs4> TYPE ANY.
TYPE-POOLS: abap.
types: BEGIN OF ty_mesg,
field type name_feld,
mesg type char255,
end of ty_mesg.
DATA: ls_mesg type ty_mesg.
DATA: lt_mesg type table of ty_mesg.
DATA: LS_TAB_FIELDS TYPE DFIES.
DATA: LT_TAB_FIELDS TYPE TABLE OF DFIES.
DATA: lv_line type i.
data: lv_type type abap_typekind.
DATA: LV_TYPEDESCR TYPE REF TO CL_ABAP_TYPEDESCR.
data: funcname type rs38l_fnam.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = GC_TABNAME "GC_TABNAME a constant with table name 'ZSD_CND_ITEM'
FIELDNAME = ' '
LANGU = SY-LANGU
LFIELDNAME = ' '
ALL_TYPES = ' '
GROUP_NAMES = ' '
UCLEN =
IMPORTING
X030L_WA =
DDOBJTYPE =
DFIES_WA =
LINES_DESCR =
TABLES
DFIES_TAB = LT_TAB_FIELDS
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.
ENDIF.
DESCRIBE TABLE LT_TAB_FIELDS LINES LV_LINE.
LOOP AT im_cnditem_first assigning <fs>.
READ TABLE im_cnditem_second assigning <fs1> with key artnr = <fs>-artnr.
if ( sy-subrc = 0 and <fs1> is assigned ).
do lv_line times.
READ TABLE LT_TAB_FIELDS INTO LS_TAB_FIELDS INDEX SY-INDEX.
assign component sy-index of structure <fs> to <fs3>.
ASSIGN COMPONENT sy-index of STRUCTURE <fs1> to <fs4>.
if ls_tab_fields-convexit <> ' '.
concatenate 'CONVERSION_EXIT_' ls_tab_fields-convexit '_INPUT' into funcname.
CALL FUNCTION funcname
EXPORTING
INPUT = <fs3>
IMPORTING
OUTPUT = <fs3>.
CALL FUNCTION funcname
EXPORTING
INPUT = <fs4>
IMPORTING
OUTPUT = <fs4>.
endif.
if <fs3> <> <fs4>.
ls_mesg-field = ls_tab_fields-fieldname.
concatenate 'value changed from' <fs3> 'to' <fs4> into ls_mesg-mesg.
append ls_mesg to lt_mesg.
clear: ls_mesg.
endif.
enddo.
else.
ls_mesg-field = 'ARTNR'.
ls_mesg-mesg = 'Does not exist'.
append ls_mesg to lt_mesg.
endif.
ENDLOOP.
‎2011 Aug 09 7:29 AM
Hi,
Try using the RTTI classes CL_ABAP_STRUCTDESCR, CL_ABAP_TABLEDESCR.
Sample code is as below
DATA LT_SFLIGHT TYPE TABLE OF SFLIGHT.
DATA LO_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR.
data lo_structdescr type ref to cl_abap_structdescr.
data lt_components type CL_ABAP_STRUCTDESCR=>component_table.
LO_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_DATA( P_DATA = LT_SFLIGHT ).
lo_structdescr ?= lo_tabledescr->GET_TABLE_LINE_TYPE( ).
lt_components = lo_structdescr->get_components( ).
or try using FM 'GET_COMPONENT_LIST'
Thanks,
Ravi Aswani
‎2011 Aug 09 7:29 AM
Hi,
Try using the RTTI classes CL_ABAP_STRUCTDESCR, CL_ABAP_TABLEDESCR.
Sample code is as below
DATA LT_SFLIGHT TYPE TABLE OF SFLIGHT.
DATA LO_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR.
data lo_structdescr type ref to cl_abap_structdescr.
data lt_components type CL_ABAP_STRUCTDESCR=>component_table.
LO_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_DATA( P_DATA = LT_SFLIGHT ).
lo_structdescr ?= lo_tabledescr->GET_TABLE_LINE_TYPE( ).
lt_components = lo_structdescr->get_components( ).
or try using FM 'GET_COMPONENT_LIST'
Thanks,
Ravi Aswani
‎2011 Aug 09 8:04 AM
Thanks Ravi. It solved my problem. Can I get field attributes using RTTI. From get_component , i get the field names and number of fields. Can I get other attributes without using FM like whether the field has conversion exit.
Debopriyo
‎2011 Aug 09 8:04 AM