2007 Apr 02 9:25 AM
Hi all,
i have an internal table that was generated based on an ddic structure - now i want to add a column to that table. how can i do that ?
thank you!
clemens
2007 Apr 02 9:35 AM
data : begin of itab occurs 0.
include structure <DDIC Structure>.
data : field definition,
end of itab.
itab-fieldname=value.
append itab.
Hope it helps.
Regards,
Kalai
Hi all,
i have an internal table that was generated based on an ddic structure - now i want to add a column to that table. how can i do that ?
thank you!
clemens
2007 Apr 02 9:27 AM
Hi ,
I am not sure how to add a new column to an IT having entries , what i can suggest is use another IT which has this additional column.
Regards
Arun
2007 Apr 02 9:28 AM
just add in the declaration part
data : begin of itab1 occurs 0.
include structure mara.
data : werks like marc-werks.
data : end of itab1.
regards
shiba dutta
2007 Apr 02 9:28 AM
Hi,
types : begin of ty.
include structure mara.
types : new_field type c,
end of ty.
data : itab type standard table of ty,
wa type ty.
2007 Apr 02 9:28 AM
Hi,
U can define ur Internal table as :
data : begin of itab occurs 0.
include structure <DDIC Structure>.
data : field definition,
end of itab.
Regards,
Himanshu
2007 Apr 02 9:35 AM
data : begin of itab occurs 0.
include structure <DDIC Structure>.
data : field definition,
end of itab.
itab-fieldname=value.
append itab.
Hope it helps.
Regards,
Kalai
2007 Apr 02 10:08 AM
Best Method is
DATA: BEGIN OF <Internal Table Name> OCCURS 0.
INCLUDE STRUCTURE <DDIC Strucuture Name>.
DATA: <Filed Name you want to add> LIKE <Reference Field>
DATA: END OF <Internal Table Name>.
2007 Apr 02 10:48 AM
Hi to all, thank you for your help! here is the code that i have:
REPORT *************_4 .
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>.
TYPE-POOLS: slis.
TABLES: dd03l, dd04t.
TYPES:
BEGIN OF ty_table_struct,
fieldname TYPE dd03l-fieldname, " Tabellenname
ddtext TYPE dd04t-ddtext, " Kurztext
checkbox,
END OF ty_table_struct.
DATA:t_fieldcat TYPE slis_t_fieldcat_alv,
w_fieldcat TYPE slis_fieldcat_main.
DATA:
gt_table_struct TYPE TABLE OF ty_table_struct.
DATA: v_repid TYPE sy-repid.
DATA:
dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat,
l_tab_fields TYPE STANDARD TABLE OF ty_table_struct,
w_tab_fields LIKE LINE OF l_tab_fields.
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(28) v_1 FOR FIELD p_table.
PARAMETERS p_table TYPE dd03l-tabname OBLIGATORY VALUE CHECK.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
v_1 = 'Tabelle für Dublettenprüfung'.
v_repid = sy-repid.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
*&---------------------------------------------------------------------*
*& Form get_structure
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
READ TABLE l_tab_fields INTO w_tab_fields
WITH KEY fieldname = xdetails-name.
IF sy-subrc = 0.
CLEAR xfc.
xfc-fieldname = xdetails-name.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDIF.
ENDLOOP.
ENDFORM. "get_structure
*&---------------------------------------------------------------------*
*& Form create_dynamic_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. "create_dynamic_itab
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data.
* Select Data from table.
SELECT (l_tab_fields) INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
FROM (p_table).
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form write_out
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM write_out.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_structure_name = p_table
CHANGING
ct_fieldcat = t_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_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.
* Show only fields that are needed
LOOP AT t_fieldcat INTO w_fieldcat.
READ TABLE l_tab_fields INTO w_tab_fields
WITH KEY fieldname = w_fieldcat-fieldname.
IF sy-subrc <> 0.
DELETE t_fieldcat.
ENDIF.
ENDLOOP.
w_fieldcat-tabname = '<dyn_table>'.
w_fieldcat-fieldname = 'NETPR'.
w_fieldcat-seltext_m = 'Net Price'.
w_fieldcat-outputlen = 15.
w_fieldcat-col_pos = 10.
* w_fieldcat-do_sum = 'X'. "Display column total
w_fieldcat-datatype = 'CURR'.
append w_fieldcat to t_fieldcat.
* Write out data from table.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = t_fieldcat
I_BYPASSING_BUFFER = 'X'
TABLES
t_outtab = <dyn_table>
EXCEPTIONS
program_error = 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.
ENDFORM. "write_out
*&---------------------------------------------------------------------*
*& Form f_read_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_read_data.
SELECT * FROM ( dd03l
INNER JOIN dd04t
ON dd03l~rollname = dd04t~rollname
AND dd04t~ddlanguage = syst-langu
AND dd04t~as4local = 'A' ) INTO CORRESPONDING FIELDS OF
TABLE
gt_table_struct WHERE dd03l~tabname = p_table .
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-rollname = &3.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
DATA:
l_exit,
ls_private TYPE slis_data_caller_exit,
ls_field TYPE ty_table_struct,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'FIELDNAME' 'ty_table_struct' 'FIELDNAME'.
m_fieldcat 'DDTEXT' 'ty_table_struct' 'DDTEXT'.
* Optimize column width
ls_private-columnopt = 'X'.
* Display data in a popup
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_selection = 'X'
i_zebra = 'X'
it_fieldcat = lt_fieldcat
i_tabname = 'gt_table_struct'
i_checkbox_fieldname = 'CHECKBOX'
is_private = ls_private
IMPORTING
e_exit = l_exit
TABLES
t_outtab = gt_table_struct.
CHECK l_exit = space.
* write selected columns to the internal table for inclusion
* into fieldcat
LOOP AT gt_table_struct INTO ls_field WHERE checkbox = 'X'.
APPEND ls_field-fieldname TO l_tab_fields.
ENDLOOP.
ENDFORM.What
i want it to
do is,have the alvgrid displaying the fields from t_fieldcat
,plus
somefields
( that should be appended to the internal table before, i think ? ). What went wrong ?Clemens
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |