10-30-2007 8:44 AM
Hi.
I need to create an internal table based on a database table (ZTAB1).
However, I only want columns 3, 4 and 5 from ZTAB1. How do I do that?
****************************************************
DATA BEGIN OF ITAB_LINE.
INCLUDE STRUCTURE ZTAB1.
DATA END OF ITAB_LINE.
DATA ITAB LIKE TABLE OF ITAB_LINE.
****************************************************
In this case, ITAB will have the same columns as ZTAB1.
But I do not want ZTAB1-Field1, ZTAB1-Field2. I only want ZTAB1-Field3, Field4, Field5 in ITAB. Is there any way I can drop ZTAB1-Field1, ZTAB1-Field2 from ITAB, using the codes above? Thanks.
10-30-2007 8:46 AM
Hi,
try this:
data: begin of itab1 occurs 0,
field3 type zitab1-field3,
field4 type zitab1-field4,
field5 type zitab1-field5,
end of itab1.
regards
Kannaiah
10-30-2007 8:47 AM
Define as
DATA BEGIN OF ITAB_LINE.
Field3 like ZTAB1-Field3,
Field4 like ZTAB1-Field4,
Field5 like ZTAB1-Field5,
DATA END OF ITAB_LINE.
regards,
GURU
10-30-2007 8:47 AM
You can declare your own type:
types : begin of ty_ztab,
field3 type ztab1-field3,
field4 type ztab1-field4,
field5 type ztab1-field5,
end of ty_ztab1.
data : it_ztab1 type table of ty_ztab1.
this resolve your query
reward points if helpful
10-30-2007 8:51 AM
Hi All.
Thanks for the reply. The example I gave was a simplified one.
ZTAB1 can actually have many columns, and it can have different columns at different time (dynamic table). Only the first two columns are fixed.
Hence, I could not manually declare the other ZTAB1 columns.
Any idea how to drop the column from the ITAB using some SAP commands?
10-30-2007 8:59 AM
Hi Kian ,
If you are creating a dynamic internal table than you can call LVC_FIELDCAT_MERGE and you can delete your coloumns as you want depending on your needs.
Hope this helps.
Regards
Caglar
10-30-2007 9:00 AM
Hi,
Try like this:
DATA: d_ref TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat,
fname TYPE fieldname.
DATA: g_itab1 TYPE STANDARD TABLE OF itab1.
DATA: wa_itab1 TYPE itab1.
TYPES: tabname LIKE dcobjdef-name,
fieldname LIKE dcobjdef-name.
PARAMETER: p_tablen TYPE tabname. "Input table field
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE dntab.
DATA: END OF itab.
FIELD-SYMBOLS : <f_fs> TYPE table,
<f_fs2> TYPE ANY,
<f_fs3> TYPE ANY,
<f_fs4> TYPE ANY.
REFRESH itab.
" Hard code the table name "ZTAB1"
CALL FUNCTION 'NAMETAB_GET' "Fetches the fields
EXPORTING
langu = sy-langu
tabname = p_tablen
TABLES
nametab = itab
EXCEPTIONS
no_texts_found = 1.
" Get the fields excluding field1 and field2
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
ls_alv_cat-seltext = itab-fieldtext.
ls_alv_cat-reptext = itab-fieldtext.
APPEND ls_alv_cat TO i_alv_cat.
fcount = fcount + 1.
ENDLOOP.
"Build Catolog
Dynamic internal table build
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = d_ref.
" Assign this to field symbol
ASSIGN d_ref->* TO <f_fs>. " Dynamic table creation with fields of the
*table
Regards
Kannaiah