‎2007 Jul 10 12:28 PM
Hi All,
I have to declare an internal table referring to a standard structure, but excluding some fields in the structure.
For Example, note in the below declaration:
DATA: lv_dtab type p0002.
my requirement is that, lv_dtab should have the same structure as of p0002, but ommitting 2 or 3 fields. ..
i.e.if the structure p0002 has 20 fields of type 'c' and 10 fields of type 'p' , lv_dtab should be declared such a way that it has only 20 fields ( type 'c' fields only).
Is there a way to declare the lv_dtab , to match my requirement.
Or is there any other way to achieve this.
Thanks in Advance,
Vijay Raghavendra S
‎2007 Jul 10 12:32 PM
‎2007 Jul 10 12:50 PM
Hi,
This is technically not feasiable, but if you just want to ommit only 2 or 3 fields then you can as well use p0002 itself.
This will not cause much performance problem.
Regards,
Sesh
‎2007 Jul 10 1:11 PM
Hi,
it is not possible to creation of iinternal table as per your requirement, you must go with creation of internal table manually.
while creating internal table, perfomance point of view you declare internal table with all the required fields in SE11 by using LINE TYPE and ROW TYPE.
LINE TYPE -
> behaves like work area
ROW TYPE-----> behaves like internal table body.
regards,
Ashok Reddy
‎2007 Jul 10 1:54 PM
Hello Vijay
Assuming that you have the <b>RTTI </b>classes available in your SAP system you can use the following sample coding. You may also have a look at thread:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_RTTI_CREATE_ITAB
*&
*&---------------------------------------------------------------------*
*& NOTE: create specific itab based on given structure/table
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_rtti_create_itab.
TYPE-POOLS: abap.
DATA:
gd_tabnam TYPE string,
gd_tabfield TYPE string,
go_table TYPE REF TO cl_salv_table,
go_sdescr TYPE REF TO cl_abap_structdescr,
go_sdescr_new TYPE REF TO cl_abap_structdescr,
go_tdescr TYPE REF TO cl_abap_tabledescr,
go_typedescr TYPE REF TO cl_abap_typedescr,
gdo_handle TYPE REF TO data,
gs_component TYPE abap_compdescr,
gt_components TYPE abap_compdescr_tab,
*
gs_comp TYPE abap_componentdescr,
gt_comp TYPE abap_component_tab.
*
FIELD-SYMBOLS:
<gt_p0002x> TYPE STANDARD TABLE.
PARAMETER:
p_tabnam TYPE tabname DEFAULT 'P0002'.
START-OF-SELECTION.
" Describe structure
go_sdescr ?= cl_abap_structdescr=>describe_by_name( p_tabnam ).
gt_components = go_sdescr->components.
DELETE gt_components
WHERE ( type_kind = cl_abap_typedescr=>typekind_packed
OR type_kind = cl_abap_typedescr=>typekind_hex
OR type_kind = cl_abap_typedescr=>typekind_float ).
" OR:
DELETE gt_components
WHERE NOT ( type_kind = cl_abap_typedescr=>typekind_num OR
type_kind = cl_abap_typedescr=>typekind_char OR
type_kind = cl_abap_typedescr=>typekind_date ).
REFRESH: gt_comp.
LOOP AT gt_components INTO gs_component.
" Build fieldname
CONCATENATE p_tabnam gs_component-name INTO gd_tabfield
SEPARATED BY '-'.
CLEAR: gs_comp.
gs_comp-type ?= cl_abap_datadescr=>describe_by_name( gd_tabfield ).
gs_comp-name = gs_component-name.
APPEND gs_comp TO gt_comp.
ENDLOOP.
go_sdescr_new = cl_abap_structdescr=>create( gt_comp ).
go_tdescr = cl_abap_tabledescr=>create( go_sdescr_new ).
" Create data refence followed by table creation
CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
ASSIGN gdo_handle->* TO <gt_p0002x>.
* Dynamic select
" P0002 -> PA0002
CONCATENATE p_tabnam+0(1) 'A' p_tabnam+1 INTO gd_tabnam.
CONDENSE gd_tabnam NO-GAPS.
SELECT * FROM (gd_tabnam) UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE <gt_p0002x>.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = go_table
CHANGING
t_table = <gt_p0002x>.
go_table->display( ).
CATCH cx_salv_msg .
ENDTRY.
" Display component list in order to prove that indeed the field names
" are used (instead of the data element names)
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = go_table
CHANGING
t_table = gt_comp.
go_table->display( ).
CATCH cx_salv_msg .
ENDTRY.
END-OF-SELECTION.Regards
Uwe