2007 Sep 17 9:27 AM
In the following Subroutine signature, P_SOURCE and P_DEST strutures can be any type.
FORM uc_move USING P_SOURCE TYPE ANY
CHANGING P_DEST TYPE ANY.
My requirement is to find if some field exists in P_DEST .
Example, I want to check if ROUTE is part of P_DEST structure.
Please help!!
2007 Sep 17 9:34 AM
you can do it like this:
FIELD-SYMBOLS: <fld> TYPE ANY.
ASSIGN COMPONENT 'ROUTE' OF STRUCTURE 'PDEST' TO <fld>.
IF sy-subrc = 0.
your field is present
ENDIF.
you can check it later in the code with
IF <fld> IS ASSIGNED.
your field is present
ENDIF.
In the following Subroutine signature, P_SOURCE and P_DEST strutures can be any type.
FORM uc_move USING P_SOURCE TYPE ANY
CHANGING P_DEST TYPE ANY.
My requirement is to find if some field exists in P_DEST .
Example, I want to check if ROUTE is part of P_DEST structure.
Please help!!
2007 Sep 17 9:34 AM
Hello
Assign your p_dest to a field symbol..
Use "assign component 'ROUTE' of structure ..." statement..
if field symbol is assigned it means field exists else it implies field does not exist...
Regards,
Arun
2007 Sep 17 9:34 AM
you can do it like this:
FIELD-SYMBOLS: <fld> TYPE ANY.
ASSIGN COMPONENT 'ROUTE' OF STRUCTURE 'PDEST' TO <fld>.
IF sy-subrc = 0.
your field is present
ENDIF.
you can check it later in the code with
IF <fld> IS ASSIGNED.
your field is present
ENDIF.
2007 Sep 17 9:34 AM
HI,
use the class.
CL_ABAP_TYPEDESCR and the method describe_by_data.
Here is the example.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE cl_abap_structdescr=>component_table.
DATA: ls_comp LIKE LINE OF lt_comp.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( data_incoming ).
lt_comp = lr_rtti_struc->get_components( ).
READ TABLE lt_comp INTO ls_comp with key name = 'FIELD1'.
if sy-subrc = 0.
" field exists
endif.
Regards,
Sesh
2007 Sep 17 9:35 AM
Hi Raja..
This is the way to find whether a COMPONENT exists using the FIELD SYMBOLS.
FORM uc_move USING P_SOURCE TYPE ANY
CHANGING P_DEST TYPE ANY.
FIELD-SYMBOLS: <FS_COMP> TYPE ANY.
ASSIGN-COMPONENT ROUTE OF STRUCTURE P_DEST TO <FS>.
if SY-SUBRC = 0.
<<<<COMPONENT EXISTS>>>
ENDIF.
<b>
reward if Helpful.</b>
2007 Sep 17 9:36 AM
Hi,
Check if this code helps
It can find the field names of any table / structure
data: begin of myitab,
number type i,
name(30),
end of myitab.
data: INT_TABNAME(40).
INT_TABNAME = 'MYITAB'.
* Insert internal table fieldname into itab
DATA : IRSTRUCINFO LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = sy-repid
FIELDNAME = INT_TABNAME
TABLES
COMPONENTS = IRSTRUCINFO.
loop at IRSTRUCINFO.
write:/ IRSTRUCINFO-COMPNAME.
endloop.
2007 Sep 17 9:36 AM
Hi,
You can use Function modules DDIF_NAMETAB_GET or RPY_TABLE_READ
and get the list of fields in that structure,
Then check if the field you want is in it or not.
Regards,
Samson Rodrigues.
2007 Sep 17 9:53 AM
2007 Sep 17 9:56 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |