Dynamic table type generation at runtime
Hi,
Is there any way by which I can generate the table types at runtime.
I am fetching table_name from all_tables and according to the table_name fetched from all_tables, I want to generate a table type for the same (eg. some thing like mentioned below) :
TYPE v_tablename(int_tablecounter)||'_typ' IS TABLE OF v_tablename(int_tablecounter)%ROWTYPE INDEX BY BINARY_INTEGER
thanks,
aks
Hello aks,
did you try
1 Declare
2 v_CNT NUMBER := 1;
3 v_TABLE VARCHAR2(30) := 'TEST';
4 v_STMT VARCHAR2(500);
5 Begin
6 v_STMT := ' DECLARE '||
7 ' TYPE TAB'||v_CNT||' IS TABLE OF '||v_TABLE||'%ROWTYPE INDEX BY PLS_INTEGER;'||
8 ' v_TAB'||v_CNT||' TAB'||v_CNT||';'||
9 ' BEGIN'||
10 ' v_TAB'||v_CNT||'(1).ID := 1;'||
11 ' v_TAB'||v_CNT||'(1).COL := ''TEST'';'||
12 ' P.L ( v_TAB'||v_CNT||'(1).COL );'||
13 ' END;';
14 EXECUTE IMMEDIATE v_STMT;
15* End;
bprechtl@DEV01>
bprechtl@DEV01> /
TEST
PL/SQL-Prozedur wurde erfolgreich abgeschlossen.
bprechtl@DEV01>And did you like it? ;-)
Bernd
Similar Messages
-
Create Structure with dynamical Table-Type
Hi experts,
is there a possibility, to create a structure via SE11 and including there a field which referes to a dynamic table-type.
So that I can append to this structure-field all different table-types?
for example: ones I append MARA[] and ones AFKO[]
Thx for helpHi Christian,
There's not predefined generic type to do that, but you could create your own field type (deep structure) which would be able to keep table lines after transposition (90 degree flip) where in example it would have four columns: Table type, row id(index) field name, value. That way you could store ANY table row you need... This will not come cheap and will involve some work of course.
You may want have a look at standard ABAP services RRTS and RTTI (see classes and structures used in attributes an parameters) - these are two services for handling data types and metadata related operations during runtime. You may want to use them for flipping your table entries to the tabular form and so on. You may also find some ideas there on how to compose your own data type for your purposes.
Good luck!
Marcin -
Dynamic ALV: but with globally available dynamic table type
Hello,
I would like to create a dynamic node for a ALV and dynamic table types to fill and the ALV.
The ALV data can be changed so I need to read it again.
I have read all the threads about dynamic node create and i have no problem with it. I can create a structure and a table dynamically. thats also no issue for me.
But. I fill the ALV data in a method and read it in another method to save the changes in a data base table.
Thats also no problem
So where i need your help? I currently create the dynamic table and structure in both methods. That works, but why do the same thing twice?
I cant figure out by myself how to create a dynamic table/structure in a global way, so the dynamic table/structure is created once and then available in the whole WD4A view.
I tried is with a class type in se24 with reference to CL_ABAP_STRUCTDESCR but I cant make that run, because to access the type I created an attribute in se24 with reference to the class type that I now try in instance and fill in the method. But ABAP thinks that my attribute is not compatible anymore.
Any idea how to make a dynamic table globally available? That must be an ABAP god who can answer this question, hehe. So imagin me falling on my knees for the one who has an answer that really works
Kind regards,
HendrikThis doesn't seem too difficult really. For a dynamic table you just need to declare the internal table as TYPE REF TO DATA.
Just more this declaration to the attributes of your Component Controller. So for instance in my component controller I have an attribute called i_data with the RefTo column checked and the associated type = DATA.
So now I could do the following:
create data wd_this->idata type table of (tablename).
Or however you are dynamically creating the table - maybe with TYPE HANDLE instead.
The point is that your dynamic table is now global to your entire component and you can read and write to it from different methods.
Is this what you were looking for? Without knowing more about your existing coding, it is difficult to say more. -
RTTS - Dynamic Structure/Type Generation
Hi,
my apologies if this question has been asked before and in the wrong forum.
Is it possible to dynamically create a structure/type of variable length without using a fixed type? e.g. I want to create a structure with 4 'fixed' fields followed by a number of variable entries dependent upon an external source. I would normally do something like ..
types : begin of ty_data,
matnr type matnr,
werks type werks,
lifnr type lifnr,
menge_01 type menge_d,
menge_02 type menge_d,
end of ty_data.
data : it_data type sorted table of ty_data with unique key ...
I want to define he whole structure dynamically at runtime.
Could someone point me to a blog/bar/exit or better still give me an answer?
Thanks in advanceHello Terry
Of course you can create all kinds of structures / table types dynamically, e.g.:
[Creating Flat and Complex Internal Tables Dynamically using RTTI|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI]
Your external source must provide you with the meta-data about the structure. This you can use as input for RTTI in order to create your dynamic data objects.
Regards
Uwe -
Hi folks,
Is there any generic data type for table declaration, beside :
data: lt_generic type table of data
I know that field-symbols can have the generic table type any
field-symbols: <lft_generic> type any table.
I basically want to be able to read from generic tables.
READ TABLE lt_generic ....
Thanks
AndreasHi Neil,
actually i want to execute a read on the dynamic created tabel.
Maybe this repot explains my purpose.
REPORT ztc_dqm_dynamic.
* Step 1: << local definitions >>
" << variables >>
" << error string >>
DATA: lv_error TYPE string.
" << struc >>
" << holds one component >>
DATA: ls_component TYPE
cl_abap_structdescr=>component.
" << table >>
DATA: lt_component TYPE cl_abap_structdescr=>component_table.
DATA: lt_db_indexfields TYPE TABLE OF ztcc_dqm_indices.
" << dynamic >>
" << generated struc >>
DATA: ls_dystruc TYPE REF TO data.
" << generated table >>
DATA: lt_dytable TYPE REF TO data.
" << field symbols >>
FIELD-SYMBOLS: <lfs_indexfields> TYPE ANY TABLE.
FIELD-SYMBOLS: <lfs_indexfield> TYPE ANY.
FIELD-SYMBOLS: <lfs_db_indexfields> TYPE ztcc_dqm_indices.
" << objects >>
DATA: lr_struc_type TYPE REF TO cl_abap_structdescr.
DATA: lr_table_type TYPE REF TO cl_abap_tabledescr.
" << exception >>
DATA: lr_ex TYPE REF TO cx_sy_type_creation.
* Step 2: << dynamic struc >>
" << set struc fields >>
SELECT *
FROM ztcc_dqm_indices
INTO TABLE lt_db_indexfields
WHERE addr_type EQ 1
ORDER BY index_order.
" << get types >>
LOOP AT lt_db_indexfields ASSIGNING <lfs_db_indexfields>.
ls_component-name =
<lfs_db_indexfields>-fieldname.
ls_component-type ?=
cl_abap_datadescr=>describe_by_name( <lfs_db_indexfields>-fieldtype ).
APPEND ls_component TO lt_component.
ENDLOOP.
" << create struc >>
TRY.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = lt_component
p_strict = abap_true
RECEIVING
p_result = lr_struc_type.
CATCH cx_sy_struct_creation INTO lr_ex.
CALL METHOD lr_ex->if_message~get_text
RECEIVING
result = lv_error.
WRITE: / lv_error.
ENDTRY.
" << create table >>
TRY.
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = lr_struc_type
* p_table_kind = tablekind_std
* p_unique = abap_false
* p_key = p_key_kind
* keydefkind_default =
RECEIVING
p_result = lr_table_type.
CATCH cx_sy_table_creation INTO lr_ex.
CALL METHOD lr_ex->if_message~get_text
RECEIVING
result = lv_error.
WRITE: / lv_error.
ENDTRY.
" << create attributs >>
CREATE DATA: ls_dystruc TYPE HANDLE lr_struc_type.
CREATE DATA: lt_dytable TYPE HANDLE lr_table_type.
* Step 3: << dynamic assignment >>
ASSIGN lt_dytable->* TO <lfs_indexfields>.
ASSIGN ls_dystruc->* TO <lfs_indexfield>.
" << this works >>
LOOP AT <lfs_indexfields> ASSIGNING <lfs_indexfield>.
ENDLOOP.
" << i want >>
READ TABLE lt_dytable
INTO ls_dystruc
WITH KEY ..... -
Hi everyone.
We are working on upgrading from 4.6c to ECC 6.0 and I've run into a programming problem.
I have a class that I use to convert any internal table based on a dictionary structure to a comma-separated text file. For the most part, I use the dynamic table techniques that are easy to find here and in other code forums.
In 6.0 I can not get it to work. The value assignment of the input table to the field-symbol for the dynamic table causes a "OBJECTS_TABLES_NOT_COMPATIBLE" runtime error. So far what I can find on this error specific to dynamic tables is related to BW and/or PI. And I can't seem to find any alternative ways of dealing with dynamic tables. In debug I can see that decimal number fields in the dynamic table have a different length than what's in the dictionary.
Any help or ideas would be greately appreciated.
Here is part of the method that converts the itab to an dynamic internal table, then creates a csv record for each record (I've hilighted the line that causes the dump) :
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( i_structure ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
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.
endloop.
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>.
put data into the dynamic table
<dyn_table> = it_data[]. "<<==the runtime error happens on this line
loop at <dyn_table> into <dyn_wa>.
clear: l_fdata, l_data.
do.
l_index = sy-index.
assign component l_index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
read table ifc into xfc index l_index.
if xfc-inttype = 'D'.
*etc...
Thank you,
- GeorgeHi,
For Dynamic internal table.u check SM30 Transaction.ther is one simple way to find the code in debugging.
if not possible i will send code which is relatd to dynamic table .
*& Form get_table_structure
* Get structure of an SAP table
form get_table_structure.
data : it_tabdescr type abap_compdescr_tab,
wa_tabdescr type abap_compdescr.
data : ref_table_descr type ref to cl_abap_structdescr.
* Return structure of the table.
ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_tabdescr[] = ref_table_descr->components[].
loop at it_tabdescr into wa_tabdescr.
clear wa_fieldcat.
wa_fieldcat-fieldname = wa_tabdescr-name .
wa_fieldcat-datatype = wa_tabdescr-type_kind.
wa_fieldcat-inttype = wa_tabdescr-type_kind.
wa_fieldcat-intlen = wa_tabdescr-length.
wa_fieldcat-decimals = wa_tabdescr-decimals.
append wa_fieldcat to it_fieldcat.
endloop.
endform. "get_table_structure
*& Form create_itab_dynamically
* Create internal table dynamically
form create_itab_dynamically.
* Create dynamic internal table and assign to Field-Symbol
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = dyn_table.
assign dyn_table->* to <fs_table>.
* Create dynamic work area and assign to Field Symbol
create data dyn_line like line of <fs_table>.
assign dyn_line->* to <fs_wa>.
endform. "create_itab_dynamically
Edited by: subrahmanyam24 on Nov 18, 2010 5:12 AM
Edited by: subrahmanyam24 on Nov 18, 2010 5:15 AM -
How to pass values in dynamic structure and then dynamic table
Hi,
we have a Z structure in se11 holding 10 fields. But at run time i need to create a dynamic table with more than 10 records.
I am able to create the structure and corresponding internal table. Now the issue is i have to populate this dynamic structure with some values and then append it to dynamic internal table. Since the dynamic table type is any its not allowing an index operation like modify etc etc.
Could anyone help me in passing the values . I have searched in SDN . everyone created a dynamic table and then populated it values from some standard or custom tables.Then assigning the component of structure and displaying the output. but in my situation i have no such values stored in any tables. i populate values based on certain calculation.Hi Friends,
This is the piece of code.After creating dynamic work area and dynamic table what i should do?
TYPES: BEGIN OF STR,
ID TYPE I,
NAME(30) TYPE C,
END OF STR.
data: v_lines type i.
STR_TYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'STR' ).
STR_COMP = STR_TYPE->GET_COMPONENTS( ).
APPEND LINES OF STR_COMP TO COMP_TAB.
COMP-NAME = 'NAME1'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
COMP-NAME = 'VALUE1'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
COMP-NAME = 'NAME2'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
COMP-NAME = 'VALUE2'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
COMP-NAME = 'NAME3'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
COMP-NAME = 'VALUE3'.
COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_STRING( ).
APPEND COMP TO COMP_TAB.
NEW_STR = CL_ABAP_STRUCTDESCR=>CREATE( COMP_TAB ).
NEW_TAB = CL_ABAP_TABLEDESCR=>CREATE(
P_LINE_TYPE = NEW_STR
P_TABLE_KIND = CL_ABAP_TABLEDESCR=>TABLEKIND_STD
P_UNIQUE = ABAP_FALSE ).
CREATE DATA DREF TYPE HANDLE NEW_TAB.
CREATE DATA DREF1 TYPE HANDLE NEW_str. -
Define table type on runtime...Getting Error..
My requirement is to
I am trying to define table type on runtime. i.e. ortf_in_table_tbl{noformat}({noformat}i).field_position_rec.ortf_segment_field_name in below code.
But when I am executing below code and getting below error:
DECLARE
CURSOR field_position_cur (p_table_name VARCHAR2)
IS
SELECT xosf.field_name, xosf.starting_position, xosf.field_length
FROM record_types xort, record_segments xors, segment_fields xosf
WHERE xort.record_type_id = xors.record_type_id
AND xors.record_segment_id = xosf.record_segment_id
AND xosf.table_name = p_table_name;
CURSOR raw_data_cur
IS
SELECT *
FROM raw_data;
TYPE raw_data_typ IS TABLE OF raw_data_cur%ROWTYPE
INDEX BY BINARY_INTEGER;
TYPE table_typ IS TABLE OF emp%ROWTYPE
INDEX BY BINARY_INTEGER;
table_tbl table_typ;
raw_data_tbl raw_data_typ;
BEGIN
OPEN raw_data_cur;
LOOP
FETCH raw_data_cur
BULK COLLECT INTO raw_data_tbl;
EXIT WHEN raw_data_tbl.COUNT = 0;
FOR i IN raw_data_tbl.FIRST .. raw_data_tbl.LAST
LOOP
FOR field_position_rec IN field_position_cur ('EMP')
LOOP
table_tbl (i).field_position_rec.field_name :=
SUBSTR (raw_data_tbl (i).raw_line_text,
field_position_rec.starting_position,
field_position_rec.field_length
DBMS_OUTPUT.put_line
( 'table_tbl (i).field_position_rec.field_name '
|| table_tbl (i).field_position_rec.field_name
END LOOP;
END LOOP;
END LOOP;
CLOSE raw_data_cur;
FORALL i IN table_tbl.FIRST .. table_tbl.LAST
INSERT INTO emp
VALUES (table_tbl (i)
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('OTHERS ' || SQLERRM);
END;
**ORA-06550: line 61, column 52:**
**PLS-00302: component 'FIELD_POSITION_REC' must be declared**
**ORA-06550: line 54, column 13:**
**PL/SQL: Statement ignored**Here field_position_cur is giving me column name for the EMP table (i.e. field_position_rec.field_name) and field_position_cur is giving start and length to derive value of the that column
i.e.
SUBSTR (raw_data_tbl (i).raw_line_text,
field_position_rec.starting_position,
field_position_rec.field_length
)But it is giving me error. We are on 10g database.
Please suggest the solution to it.
Edited by: BluShadow on 12-Jan-2012 08:21
added {noformat}{noformat} and other tags to make it readable. Please read {message:id=9360002} and learn to do this yourself.piyushgupta wrote:
My requirement is to
I am trying to define table type on runtime. Please explain - it is not clear from the code what you are attempting.
Also note that PL/SQL is strong typed language. This mean that you cannot define a variable using a weak type and at runtime change that into a formal data type.
In Oracle, the abstract AnyData data type can be used for unknown data types - and methods exist that allows different data types to be stored and retrieved as AnyData types. Of course, there are overheads involved in using an abstract data type (implemented as an object class) like this.
Another method is to use DBMS_SQL to create dynamic code (SQL or PL/SQL) - and perform dynamic binding (the bind determines the data type of the bind variable in the code). If the dynamic code is a SQL select, the describe interface enables you to determine the content (columns and data types) of the SQL projection.
The final method that comes to mind is using a RTTI (Run Time Type Information) interface - something that is also supported by Oracle (and basically the backend implementation of answering a describe interface call). This is however a bit more complex and quite specialised and needs a very unique problem to justify it being used. -
How to know or check the type of a field when processing a dynamic table?
Dear all,
When processing a dynamic table i have a short dump because of a convert_of_type incorrect, so i would like to check the type of field-symbol <f> before moving the data (type char) to this field-symbol <f>.
Could you please help me how to check or get the type of field-symbol <f> (because field-symbol <f> is assigned dynamic, so this <f> can be type char, unit, or quantity, ...)?
The source code same as below:
ASSIGN COMPONENT lc_field OF STRUCTURE ls_data TO <f>.
MOVE lv_field TO <f>. (Dump is here when lv_field is char type and <f> is quantity type => could i check the type of <f> if it's char type before using this instruction "MOVE ..."?)
Thanks a lot in advance,
Vinh VoTry to use this way
WRITE lv_field TO <f>.
Instead of
MOVE lv_field TO <f>.
a® -
Dynamic Table UI Element with different data type for each cell
Hi Experts,
I have a problem with a dynamic Table UI Element in Web Dynpro ABAP. I have the following coding:
METHOD set_col_row .
TYPE-POOLS: icon.
DATA:
lv_node TYPE REF TO if_wd_context_node,
lv_node_info TYPE REF TO if_wd_context_node_info,
lv_element TYPE REF TO if_wd_context_element,
lt_attributes TYPE wdr_context_attr_info_map,
lv_table TYPE REF TO cl_wd_table,
lv_table_column TYPE REF TO cl_wd_table_column,
lv_text_view TYPE REF TO cl_wd_text_view,
lv_image TYPE REF TO cl_wd_image,
lv_text_edit TYPE REF TO cl_wd_text_edit,
lv_header TYPE REF TO cl_wd_caption,
attribute LIKE LINE OF lt_attributes,
lv_index TYPE string,
lv_cur_row TYPE i,
path TYPE string,
lv_value TYPE string,
attr_name TYPE string,
l_trc_point_id TYPE string,
l_num_cols TYPE string,
l_num_rows TYPE string,
lv_text TYPE string,
lv_index2 TYPE i,
lr_ress_selections TYPE REF TO /its/di_2_cpr_ress_selections,
lt_comp_tab TYPE cl_abap_structdescr=>component_table,
ls_comp_tab LIKE LINE OF lt_comp_tab,
lv_count TYPE i,
lv_col_count TYPE i,
lv_col_count_read TYPE i,
lv_index_read TYPE i,
lv_num_cols_minus_1 TYPE i,
lv_bind_lv_value TYPE string,
wd_standard_cell TYPE REF TO cl_wd_table_standard_cell,
lv_data_count TYPE i,
lv_data_count_str TYPE string,
wd_table_column TYPE REF TO cl_wd_table_column,
lv_column_id TYPE string.
FIELD-SYMBOLS:
TYPE ANY.
Instanz der Klasse /ITS/DI_2_CPR_RESS_SELECTIONS
lr_ress_selections = /its/di_2_cpr_ress_selections=>factory( ).
ASSIGN lr_ress_selections->gr_table->* TO gt_comp_tab.
ls_comp_tab-name = 'SUMME'.
APPEND ls_comp_tab TO lt_comp_tab.
ls_comp_tab-name = 'CELL_VARIANT'.
APPEND ls_comp_tab TO lt_comp_tab.
CLEAR ls_comp_tab.
l_num_rows = num_rows + 1.
CONDENSE l_num_rows.
l_num_cols = num_columns + 1.
CONDENSE l_num_cols.
UI-Element 'TABLE'
lv_table ?= wd_this->m_view->get_element( 'TBL_TABLE' ).
lv_table->remove_all_columns( ).
Kontext-Knoten 'TABLE'
lv_node = wd_context->get_child_node( 'TABLE' ).
lv_node_info = lv_node->get_node_info( ).
lv_node_info->remove_dynamic_attributes( ).
attribute-type_name = 'STRING'.
lv_num_cols_minus_1 = num_columns - 1.
Für jede Spalte einmal tun
DO lv_num_cols_minus_1 TIMES.
lv_index = sy-index + 1.
CONDENSE lv_index.
lv_table_column = cl_wd_table_column=>new_table_column( ).
lv_column_id = lv_table_column->id.
Spaltenüberschriften setzen
IF lv_index EQ 1. "Beim ersten Durchlauf --> erste Spalte = "Ressourcen"
lv_text = text-010.
sy-index = 0.
ELSE. "Danach für jede weitere Spalte eine Zeile aus der gt_comp_tab nehmen
lv_index_read = lv_index - 1.
READ TABLE lt_comp_tab INDEX lv_index_read INTO ls_comp_tab.
lv_text = ls_comp_tab-name.
lv_header = cl_wd_caption=>new_caption( text = lv_text ).
lv_table_column->set_header( lv_header ).
ENDIF.
CONCATENATE 'TABLE.A' lv_index INTO path.
lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path ).
lv_table_column->set_table_cell_editor( lv_text_view ).
lv_table_column->bind_selected_cell_variant( 'TABLE.CELL_VARIANT' ).
lv_table->add_column( lv_table_column ).
wd_table_column ?= wd_this->m_view->get_element( lv_column_id ).
*****************Test Cell Variant*************************************************
IF lv_index GT 1.
LOOP AT .
IF sy-tabix EQ lv_cur_row.
Name zuweisen
ASSIGN COMPONENT 'NAME' OF STRUCTURE .
Zuweisen ob Blatt oder nicht
lv_element->set_attribute( name = 'NAME' value = lv_value ).
ASSIGN COMPONENT 'IS_LEAF' OF STRUCTURE set_attribute( name = attr_name value = lv_value ).
ENDIF.
ENDLOOP.
Now my problem is, that I need for every ROW of my table UI Element a different cell editor. I know how to change it for the column. But is not my issue. I want to have images (traffic lights red and green) in some rows. The other rows should have numbers. The coding works, so that I have all the data at the right place in my table, only the images are shown as a string, because the cells of these rows have the cell editor Text_View. I tried something with cell variants (with cl_wd_table_standard_cell), but it was not possible for me to get a cell variant "image" in these cells/rows were I need it.
I hope you understand my problem and now what to do here.
Thanks a lot in advance.
Best Regards,
IngmarHi Experts, I have a problem with a dynamic Table UI Element in Web Dynpro ABAP. I have the following coding: METHOD set_col_row . TYPE-POOLS: icon. DATA: lv_node TYPE REF TO if_wd_context_node, lv_node_info TYPE REF TO if_wd_context_node_info, lv_element TYPE REF TO if_wd_context_element, lt_attributes TYPE wdr_context_attr_info_map, lv_table TYPE REF TO cl_wd_table, lv_table_column TYPE REF TO cl_wd_table_column, lv_text_view TYPE REF TO cl_wd_text_view, lv_image TYPE REF TO cl_wd_image, lv_text_edit TYPE REF TO cl_wd_text_edit, lv_header TYPE REF TO cl_wd_caption, attribute LIKE LINE OF lt_attributes, lv_index TYPE string, lv_cur_row TYPE i, path TYPE string, lv_value TYPE string, attr_name TYPE string, l_trc_point_id TYPE string, l_num_cols TYPE string, l_num_rows TYPE string, lv_text TYPE string, lv_index2 TYPE i, lr_ress_selections TYPE REF TO /its/di_2_cpr_ress_selections, lt_comp_tab TYPE cl_abap_structdescr=>component_table, ls_comp_tab LIKE LINE OF lt_comp_tab, lv_count TYPE i, lv_col_count TYPE i, lv_col_count_read TYPE i, lv_index_read TYPE i, lv_num_cols_minus_1 TYPE i, lv_bind_lv_value TYPE string, wd_standard_cell TYPE REF TO cl_wd_table_standard_cell, lv_data_count TYPE i, lv_data_count_str TYPE string, wd_table_column TYPE REF TO cl_wd_table_column, lv_column_id TYPE string. FIELD-SYMBOLS: LIKE LINE OF lt_attributes, TYPE ANY TABLE, TYPE ANY, TYPE ANY, TYPE ANY. * Instanz der Klasse /ITS/DI_2_CPR_RESS_SELECTIONS lr_ress_selections = /its/di_2_cpr_ress_selections=>factory( ). ASSIGN lr_ress_selections->gr_table->* TO . lt_comp_tab = lr_ress_selections->gt_comp_tab. ls_comp_tab-name = 'SUMME'. * APPEND ls_comp_tab TO lt_comp_tab. * ls_comp_tab-name = 'CELL_VARIANT'. APPEND ls_comp_tab TO lt_comp_tab. CLEAR ls_comp_tab. l_num_rows = num_rows + 1. CONDENSE l_num_rows. l_num_cols = num_columns + 1. CONDENSE l_num_cols. * UI-Element 'TABLE' lv_table ?= wd_this->m_view->get_element( 'TBL_TABLE' ). lv_table->remove_all_columns( ). * Kontext-Knoten 'TABLE' lv_node = wd_context->get_child_node( 'TABLE' ). lv_node_info = lv_node->get_node_info( ). lv_node_info->remove_dynamic_attributes( ). attribute-type_name = 'STRING'. lv_num_cols_minus_1 = num_columns - 1. * Für jede Spalte einmal tun DO lv_num_cols_minus_1 TIMES. lv_index = sy-index + 1. CONDENSE lv_index. lv_table_column = cl_wd_table_column=>new_table_column( ). lv_column_id = lv_table_column->id. * Spaltenüberschriften setzen IF lv_index EQ 1. "Beim ersten Durchlauf --> erste Spalte = "Ressourcen" lv_text = text-010. sy-index = 0. ELSE. "Danach für jede weitere Spalte eine Zeile aus der gt_comp_tab nehmen lv_index_read = lv_index - 1. READ TABLE lt_comp_tab INDEX lv_index_read INTO ls_comp_tab. lv_text = ls_comp_tab-name. lv_header = cl_wd_caption=>new_caption( text = lv_text ). lv_table_column->set_header( lv_header ). ENDIF. CONCATENATE 'TABLE.A' lv_index INTO path. lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path ). lv_table_column->set_table_cell_editor( lv_text_view ). lv_table_column->bind_selected_cell_variant( 'TABLE.CELL_VARIANT' ). lv_table->add_column( lv_table_column ). wd_table_column ?= wd_this->m_view->get_element( lv_column_id ). ******************Test Cell Variant************************************************** IF lv_index GT 1. LOOP AT ASSIGNING . ASSIGN COMPONENT 'TYPE' OF STRUCTURE TO . ADD 1 TO lv_data_count. lv_data_count_str = lv_data_count. CONCATENATE 'A' lv_index lv_data_count_str INTO path. wd_standard_cell = cl_wd_table_standard_cell=>new_table_standard_cell( view = wd_this->m_view variant_key = 'FLDATE' ). IF = '01' OR = '04'. lv_image = cl_wd_image=>new_image( bind_source = path view = wd_this->m_view ). wd_standard_cell->set_editor( lv_image ). wd_standard_cell->set_cell_design( '01' ). ELSE. lv_text_view = cl_wd_text_view=>new_text_view( bind_text = path view = wd_this->m_view ). wd_standard_cell->set_editor( lv_text_view ). wd_standard_cell->set_cell_design( '02' ). ENDIF. wd_table_column->add_cell_variant( wd_standard_cell ). ENDLOOP. ENDIF. ************************************************************************************* CONCATENATE 'A' lv_index INTO attribute-name. lv_node_info->add_attribute( attribute ). ENDDO. DO num_rows TIMES." Für jede Zeile einmal tun lv_cur_row = sy-index. lv_element = lv_node->create_element( ). lv_node->bind_element( new_item = lv_element set_initial_elements = abap_false ). DO l_num_cols TIMES. ADD 1 TO lv_col_count. IF lv_count LT 1. LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. * Name zuweisen ASSIGN COMPONENT 'NAME' OF STRUCTURE TO . "NAME lv_value = . * Zuweisen ob Blatt oder nicht lv_element->set_attribute( name = 'NAME' value = lv_value ). ASSIGN COMPONENT 'IS_LEAF' OF STRUCTURE TO . "NAME lv_value = . lv_element->set_attribute( name = 'IS_LEAF' value = lv_value ). ENDIF. ENDLOOP. ENDIF. IF lv_count GT 0. lv_col_count_read = lv_col_count - 1. lv_index = sy-index. LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. CLEAR ls_comp_tab. READ TABLE lt_comp_tab INDEX lv_col_count_read INTO ls_comp_tab. ASSIGN COMPONENT ls_comp_tab-name OF STRUCTURE TO . lv_value = . CONDENSE lv_index. CONCATENATE 'A' lv_index INTO attr_name. lv_element->set_attribute( name = attr_name value = lv_value ). ENDIF. ENDLOOP. ENDIF. lv_count = lv_count + 1. ENDDO. CLEAR lv_col_count. CLEAR lv_count. ENDDO. ENDMETHOD. I definied my table in Layout Tab of the View and create here in thos method dynamicly my columns. lv_table_column = cl_wd_table_column=>new_table_column( ). . . lv_table->add_column( lv_table_column ). In I have my data that should be shown later in my table. So I create for each row in this fieldsymbol in a loop: lv_element = lv_node->create_element( ). lv_node->bind_element( new_item = lv_element set_initial_elements = abap_false ). Later I fill every cell in my table with a different value with this loop: LOOP AT ASSIGNING . IF sy-tabix EQ lv_cur_row. CLEAR ls_comp_tab. READ TABLE lt_comp_tab INDEX lv_col_count_read INTO ls_comp_tab. ASSIGN COMPONENT ls_comp_tab-name OF STRUCTURE TO . lv_value = . CONDENSE lv_index. CONCATENATE 'A' lv_index INTO attr_name. lv_element->set_attribute( name = attr_name value = lv_value ). ENDIF. ENDLOOP. Now my problem is, that I need for every ROW of my table UI Element a different cell editor. I know how to change it for the column. But is not my issue. I want to have images (traffic lights red and green) in some rows. The other rows should have numbers. The coding works, so that I have all the data at the right place in my table, only the images are shown as a string, because the cells of these rows have the cell editor Text_View. I tried something with cell variants (with cl_wd_table_standard_cell), but it was not possible for me to get a cell variant "image" in these cells/rows were I need it. I hope you understand my problem and now what to do here. Thanks a lot in advance. Best Regards, Ingmar
-
How to create bindings at runtime for Dynamic Tables ?
We have lot of Dynamic tables, In ADF, we need to try out the Dynamic EO, Dynamic VO, Dynamic DataControl and Dynamic binding for UI
Ex:
We need to load the data to the ADF table where database table name is dynamic, the columns in the tables are also dynamic. At runtime , we need to create VO, Dynamic binding and display to UI? We also should be able to add, delete,update records in the dynamic tables.
Does anyone done this before? Please shared your thoughts on thisHi,
for a table you can declaratively build a tree binding. Then you remove all the attribute items in the tree definition so that the number of attributes is dynamic. See: https://blogs.oracle.com/groundside/entry/towards_ultra_reusability_for_adf
Frank -
Dynamic table generation for Employee Schedule Project
Hi,
I am new to Jave programming and attempting to teach myself Java using the Sun tutorials & these forums. As a first step of learning, I want to do a Automated Employee Schedule Project in Java. (JSP)
There are two main parts of the project. The first part will be a table with the employees listed down the left, the days of the week across the top, and with each cell being that employee's shift for the day. There are four different types of shift in a day ( M- Morning, R- Regular, A- Afternoon and N- Night).
The second part will allows the user to enter in a new employee or display/edit an existing employee's information, including a list of scheduling constraints, like can?t work in Morning shift / Night shift. Apart from that number of employee in a shift may vary based on situation.
Could you please help me to understand the flow for creating this Automated Employee Schedule project?
Thanks in advance.
AmitavaI need the logic as to how to generate the shift plan. Could you tell me how to get about creating this dynamic table and any idea what i should take as baseline? I was thinking to read the employees from the database and take them as input for the first column. and the number of days as the column list. Can you tell me if this is the correct approach?
-
Dynamic table with field type table
Hi,
I´m using "cl_alv_table_create=>create_dynamic_table" to create a dynamic table for ALV Grid.
But...I need to use colors in ALV, then I need to declare a field type LVC_S_SCOL in dynamic table from "cl_alv_table_create=>create_dynamic_table".
How can I declare this in fieldcat?
The code:
Creating dynamic table
DATA: table_agrup TYPE REF TO data,
line_agrup TYPE REF TO data.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fieldcat
IMPORTING
ep_table = table_agrup
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN table_agrup->* TO .
Printing ALV
CALL METHOD obj_grid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = 'A'
is_layout = w_layout
CHANGING
it_outtab =
it_fieldcatalog = t_fieldcat
it_sort = t_sort
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
Thanks.It is not possible with the METHOD cl_alv_table_create=>create_dynamic_table to include another table inside that newly generated table.
I have tried to do it with the code and I got the dynamic table created after at the end of the program.
In the code,
<DYN_TABLE> has same effect as your <table> variable
<DYN_WA> has same effect as your <HEADER>
REPORT ZTEST_NP_DYNAMIC.
DATA: DY_TABLE TYPE REF TO DATA,
DY_LINE TYPE REF TO DATA.
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>,
<DYN_FIELD>.
FIELD-SYMBOLS: <FS> TYPE ANY.
* To generate the Dyanmic table with the COLOR
DATA: LS_SOURCE TYPE STRING.
DATA: LT_SOURCE LIKE STANDARD TABLE OF LS_SOURCE WITH HEADER LINE.
DATA: L_NAME LIKE SY-REPID.
DATA: L_MESSAGE(240) TYPE C,
L_LINE TYPE I,
L_WORD(72) TYPE C.
DATA: L_FORM(30) TYPE C VALUE 'TABLE_CREATE'.
LT_SOURCE = 'REPORT ZTEST_SUBROUTINE_POOL.'.
APPEND LT_SOURCE.
LT_SOURCE = 'FORM TABLE_CREATE USING I_FS TYPE ANY.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BEGIN OF LT_GENTAB OCCURS 0.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BUKRS TYPE BUKRS. '.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: BKTXT TYPE BKTXT. '.
APPEND LT_SOURCE.
* you can add your fields here.....
LT_SOURCE = 'DATA: COLOR TYPE lvc_t_scol. '.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: END OF LT_GENTAB.'.
APPEND LT_SOURCE.
LT_SOURCE = 'DATA: POINTER TYPE REF TO DATA.'.
APPEND LT_SOURCE.
LT_SOURCE = 'CREATE DATA POINTER LIKE STANDARD TABLE OF LT_GENTAB.'.
APPEND LT_SOURCE.
LT_SOURCE = 'I_FS = POINTER.'.
APPEND LT_SOURCE.
LT_SOURCE = 'ENDFORM. '.
APPEND LT_SOURCE.
L_NAME = 'ZTEST_SUBROUTINE_POOL'.
CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 9.
GENERATE SUBROUTINE POOL LT_SOURCE NAME L_NAME
MESSAGE L_MESSAGE LINE L_LINE WORD L_WORD. "#EC CI_GENERATE
ENDCATCH.
IF NOT L_MESSAGE IS INITIAL.
MESSAGE E000(0K) WITH L_MESSAGE L_LINE L_WORD.
ENDIF.
ASSIGN DY_TABLE TO <FS>.
PERFORM (L_FORM) IN PROGRAM (L_NAME) USING <FS>.
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>.
Write: 'bye'.
Regards,
Naimesh Patel -
Data type doubled on dynamic table
Hello Everyone,
I'm creating a Z program to insert data to any Z table created, for that, the user must put the name of the Z table and the path of the file with all data to be inserted.
The problem is that on dynamic table creation the datatype of the fields are doubled, I.E.: if the datatype is N length 3, it's coming as N length 6.
Does anyone know to solve this issue?
Thanks in Advance!Hi
Just as I said, if u need to create a table like a dictionary table u can use the standard fm DDIF_FIELDINFO_GET in order to get the informations, so it doesn't need to calculate the real size.
My system is unicode too, and I used the fm above to create dynamically a structure based on dictionary definition:
LOOP AT VAKE_DFIES_TAB INTO DFIES WHERE FIELDNAME <> 'KFRST' AND
FIELDNAME <> 'KBSTAT'.
COMPONENT-NAME = DFIES-FIELDNAME.
MOVE DFIES-LENG TO _LEN.
MOVE DFIES-DECIMALS TO _DEC.
CASE DFIES-DATATYPE.
WHEN 'CHAR' OR 'LANG' OR 'CUKY'.
MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = _LEN )
TO LR_VALUE_DESCR.
WHEN 'NUMC'.
MOVE CL_ABAP_ELEMDESCR=>GET_N( P_LENGTH = _LEN )
TO LR_VALUE_DESCR.
WHEN 'INT1' OR 'INT2' OR 'INT4'.
MOVE CL_ABAP_ELEMDESCR=>GET_I( ) TO LR_VALUE_DESCR.
WHEN 'DATE'.
MOVE CL_ABAP_ELEMDESCR=>GET_D( ) TO LR_VALUE_DESCR.
WHEN 'DEC' OR 'CURR'.
MOVE CL_ABAP_ELEMDESCR=>GET_P( P_LENGTH = _LEN
P_DECIMALS = _DEC )
TO LR_VALUE_DESCR.
WHEN 'TIME'.
MOVE CL_ABAP_ELEMDESCR=>GET_T( ) TO LR_VALUE_DESCR.
WHEN 'UDEF'.
ENDCASE.
COMPONENT-TYPE = LR_VALUE_DESCR.
INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDLOOP.
IF SY-SUBRC <> 0.
PERFORM RAISE_ERROR USING 'C'.
ENDIF.
* Creazione struttura chiave
LR_STRUCT_DESCR
= CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
P_STRICT = 'X' ).
CREATE DATA DYN_VAKEY TYPE HANDLE LR_STRUCT_DESCR.
ASSIGN DYN_VAKEY->* TO <FS_VAKEY>.
Max -
GenIL model generation and Table types
When we run the GenIL model generation program, it generates ZMDL* structures for each Z* structures generated previously by SPROXY. But each element that is a Table type is skipped. So the GenIL model is incomplete and does not contain table elements.
For exemaple, assuming the existing Z_QUERY_ELMTS structure generated by SPROXY:
CONTROLLER Types PRXCTRLTAB
W_SYSTEM Types CHAR
SELECTION_BY_NIIN Types ZMATERIAL_BY_EL_QU_S_SEL_N_TAB
SELECTION_BY_PART_NUM Types ZMATERIAL_BY_EL_QU_S_SEL_P_TAB
DESCRIPTION Types ZSEARCH_TEXT STRING
EIAC Types ZEIACCODE STRING
the corresponding ZMDL structure is
WEAPON_SYSTEM Types CHAR2 CHAR
DESCRIPTION Types ZMDLSEARCH_TEXT STRING
EIAC Types ZMDLEIACCODE STRING
So every table type is skipped.
Is it a limitation of the product? Or a missing functionanliy?
Thanks in advance for your helpBy the way in the developer guide, it's also confusing:
- Creation of root object, p.47
Type Name: This is the data type which you retrieved above (ZSALES_ORDER_HEADER_DETAILS) u2013 the root attribute structure of the business object will be based on this structure. This structure has to completely define the attributes (payload) of your business object and typically matches with the response of the Read operation. Make sure this structure is u201Cflatu201D and does not contain any complex types or tables
- But p.51
Take a look at the attribute structure. It contains the list of all attributes of your business object derived from the structures of the server proxy. Also take a look a folder Relations, which contains relationships to dependent objects if your data structure is of a complex nature. In our example this folder is empty since the data structure is a flat one and therefore no relationship and no dependent object are required.
Maybe you are looking for
-
Question concerning java Serialization of a complex internal field variable.
Not everything in the J2SE implements serializable by default. Say BufferedImage. I have learned from an online artical that absolutely all fields to be serialized must implement Serializable, including internal ("global") class fields, a la http://
-
Play Count / Last Played inconsistencies
I have a smart playlist that simply shows all music that I've never played. I set this up to simply show music where Plays=0. I've noticed recently that music I know I've listened to is still in the playlist, looking at the screenshot below you can s
-
Human Task form deployment issue
Dear Experts, How to deploy Human Task form WAR file to the BPEL OC4J container through SOA em console. I have viewed through em console but i cant see any option for (war or ear ) work flow deployment. Please suggest. Thanks Rajesh A
-
Anyone got anything for me?
-
DTP reinitialize re-initialize
Is it possible to re-initialize the delta on a DTP? If so, how? Example: I'm using DTP 1 with delta to load data target 2. If I delete data from data target 2, how do I reload the data from DTP 1 and start with a new delta?