Dynamic Columns in PLSQL Table
All,
Is it possible to build the columns of a PLSQL table dynamically at run time? I got a requirement wherein the number of columns are known only during the program execution.
Thanks,
Offhand, I cannot see how it can be done - or even if hacked somehow, of how it can be of any use.
One need to use the right tool for the job - and PL/SQL "tables" is always the wrong tool as Oracle tables (fixed or temp) is better.
Now if you need to use associative array (and not a so-called PL/SQL "table"), then that is something very different than a so-called table.
To explain - an associative array is nothing like an Oracle table. Thus calling such an array a "table" in PL/SQL leads the developer to make gross design mistakes as the developer attempts to treat that array as he/she would an Oracle table. Even use the SQL engine on a PL/SQL data structure in the PGA.
The best place for data is in Oracle. That is why we buy and use Oracle. As soon as you want to do that in PL/SQL instead, using an array, you need to ensure that you reasons are valid. (e.g. bulk collect, etc)
Similar Messages
-
Multiple dynamic column in cross table
Hi all,
I have a cross table which stored the sale's quantity and amount.
The layout in view result likes below:
saler quantity1 quantity2 quantity3 quantitysummary amount1 amount2 amount3 amount4 amountsummary
S3 100 20
S2 50 30
S1 300 40
The layout in view structure likes below:
saler quantity quantitysummary amount amountsummary
S3 100 20
S2 50 30
S1 300 40
the quantity1...n and amount1...n columns is not fixed.the 2 columns is dynamic.
It's easy that only one column is dynamic,but now there are two columns is dynamic,I don't know how to achieve it.
Has anyone an idea how to accomplish this?
Thank you trying to help me!You cant do this on BO , you can add static columns but if you put some dynamic column in the left or right i turns dynamic...
Regards -
Dynamic Column Header On Table Control
Dear Friend
How I can set Dynamic Column Header Text On Table Control
Regards
SupperkornJust set it to a global variable name, and then set the value of that global variable as needed, e.g. in your TOP include define "g_my_header(20) type c" and then use g_my_header in the "Table column header" definition in the Dynpro... and in your PBO code put a value in g_my_header.
Jonathan -
Dynamical columns in internal table
Hi all.
I need to make an internal table with dynamical columns(i have 3 static columns and the rest depends on the number of clients that i have in a month). If it's possible, how can i do it?
Can anyone please help.
Thanks & RegardsHi,
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. <b> *Creates a dyanamic internal table **</b>
perform get_data.
perform write_out.
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.
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.
endform.
form create_dynamic_itab.
<b>* Create dynamic internal table and assign to FS</b>
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.
form get_data.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
Regards
Sudheer -
Dynamically Access a plsql table
If I have 2 plsql tables :
vt1_games and vt2_games that I usuallly update with the
following:
vt1_games(vt1_count) := ......
or
vt2_games(vt2(count) := ......
How can I use a variable for the plsql table name and pointer?
Thanks,
PaulI've moved this question to the correct forum.
-
How to bind dynamic columns in ADF table to view object
In the below piece of code i am trying to bind a dynamically added column to my newly added attribute in view object, but the value expression does not set the value of this attibute in the view object please help on what is wrong in this code ??
<af:table value="#{bindings.ViewObj1.collectionModel}" var="row"
rows="#{bindings.ViewObj1.rangeSize}"
emptyText="#{bindings.ViewObj1.viewable ? 'No rows yet.' : 'Access Denied.'}"
fetchSize="#{bindings.ViewObj1.rangeSize}"
filterModel="#{bindings.ViewObj1Query.queryDescriptor}"
queryListener="#{bindings.ViewObj1Query.processQuery}" varStatus="vs"
selectedRowKeys="#{bindings.ViewObj1.collectionModel.selectedRow}"
rowSelection="single"
binding="#{backingBeanScope.backing_createDTpg1.table1}"
id="table1"
columnSelection="single"
partialTriggers="::addCol ::addColAfter ::addColBefore ::removeCol ::addRow ::addRowAfter ::addRowBefore ::removeRow ::addAction ::addActionAfter ::addActionBefore ::deleteAction :::dialog1 :::d1"
allDetailsEnabled="true" verticalGridVisible="false"
horizontalGridVisible="true" width="100%" disableColumnReordering="true"
selectionListener="#{bindings.ViewObj1.collectionModel.makeCurrent}"
immediate="true" contentDelivery="immediate"
editingMode="clickToEdit" autoHeightRows="-1">
<af:column sortProperty="Sno" filterable="false" sortable="false"
headerText="Sno"
align="center" width="28" rowHeader="true"
inlineStyle="font-style:italic;" frozen="true"
id="sno" selected="true" headerNoWrap="true"
displayIndex="0">
<af:outputText id="ot0" value="#{vs.index+1}"/>
</af:column>
<af:column id="separatorColumn" align="center"
width="15" frozen="true" displayIndex="1"
rowHeader="unstyled" sortable="false"
filterable="false" selected="false"
inlineStyle='background-image:url("jheadstart/images/jsp_forward.png"); background-repeat:no-repeat; outline-color:InactiveCaption; outline-style:solid; outline-width:thin;'
headerText=""/>
</af:table>
DCBindingContainer dcBindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind =
(DCIteratorBinding)dcBindings.get("ViewObj1Iterator");
ViewObject decisionTableView1 = iterBind.getViewObject();
System.out.println("before getAttributeCount :"+decisionTableView1.getAttributeCount());
int counter = decisionTableView1.getAttributeCount() + 1;
AttributeDef attribute =
decisionTableView1.addDynamicAttribute("condition_" + counter);
RichColumn column = new RichColumn();
column.setId("condition_" + counter);
column.setHeaderText("condition_" + counter);
column.setNoWrap(true);
RichInputText inputtext = new RichInputText();
inputtext.setId("condition_"+counter);
inputtext.setAutoSubmit(true);
inputtext.setValueExpression("condition_"+counter,
getValueBinding("#{row.bindings.condition_" +
counter +
".inputValue}"));
column.getChildren().add(inputtext);
RichCommandImageLink headerLink = new RichCommandImageLink();
headerLink.setText("<<Select Fact>>");
headerLink.setId("conditionLink_" + counter);
column.setHeader(headerLink);
List columnList = this.table1.getChildren();
int separatorColumnIndex =
findColumnIndex(columnList, "separatorColumn");
if (columnIndex == -1 || columnIndex > separatorColumnIndex) {
columnIndex = separatorColumnIndex;
System.out.println("Column Index :" + columnIndex);
column.setDisplayIndex(columnIndex);
this.table1.getChildren().add(columnIndex, column);Sorry Frank i could not figure out what u rtrying to say.
In my case i have ADF table with two predefined coulmns :
1 : a serial number read only column
2 : a separator coumn
I need help to bind the newly created dynamic attribute in the VO with my newly created column in the ADF table which has a input text as child.
My problem is binding the is not working properly as values entered in the Table are not reflected in the VO.
And when i insert a new column in between two columns which has already filled values the data in the rows does not shift coreespondingly..
Edited by: user10281080 on Jul 27, 2009 12:22 AM -
Dynamic insertion of data in a Dynamic Column in a table
Hi EveryBody ,
I have a table where i am increasing the column dynamically . I need to insert data through PreparedStatement Like
pst = con.prepareStatement(CBBsqlConstants.addOrderItem);
pst.setString(1,ein);
pst.setString(2,insert_date);
pst.setString(3,checkList);
pst.setString(4,Quantities);
pst.setDate(5,pick_date);
pst.setDate(6,completed_date);
pst.setString(7,comment);
pst.setInt(8,status);
pst.setString(9,agent_ein);
i = pst.executeUpdate();
But here my column is increasing dynamically, so the above cant be constant as column is incresing . how do i handle the insertion part dynamically.
Thanks So much . Please help with this .Server_java wrote:
Ya you are right ,
Take i am ordering some Items and quantity from checkbox and inserting that to the table , each item and quantity is going to consume a row , but when i am going have column for each item , all the items i am going to select is going to appear in a single row . so i am consuming .But only 256 column is allowed for a table ,but my item is not going to excced that . That maximum number of columns is the least of the problems here.
The problem is that you are taking data that should be in another table and turning it into metadata instead. That's a mistake because it makes your entire application brittle and it doesn't need to be. It also will make querying your table a nightmare.
Let's take a look at your solution and then the correct solution.
Your solution (condensed)
tblOrder
id
customername
apples
oranges
bananas
cherries
Sample data (CSV format for the forum)
1,"John Smith",0,0,0,1
2,"Jane Smith",1,0,0,3
3,"Kate Smith",0,2,1,0
The correct solution
tblOrder
id
customername
Sample data
1,"John Smith"
2,"Jane Smith"
3,"Kate Smith"
tblProduct
id
name
Sample data
1, "Apples"
2,"Oranges"
3, "Bananas"
4, "Cherries"
tblOrderItem
orderid
productid
quantity
Sample data
1,4,1
2,1,1
2,4,3
3,2,2
3,3,1
So what's the difference?
With your design what happens when you want to add a new fruit? Your schema changes and all your code breaks. With my design you simply insert one row and that's it.
And what happens if you do happen to eventually need more than 250 odd fruits? With your design you are screwed. With my correct design it's never going to be a problem.
And consider that with my design you can populate user inteface components using actual data and not table meta data.
And the list goes on... the point is the only correct solution is to use a proper relational design. -
Dynamic Column Heading in Table Control
Hi
I have a table Control which needs dynamic heading for the first column. So i dragged a label and placed it on the Column 1 header. I gave the corresponding declaration and assignment in TOP include for that screen field. I also tried assigning values in the PBO of the screen also. I even tried replacing the Label with an I/O field. It is not allowing.
Nothing is working. Any suggestions.Instead of the text field for your column heading, put an input/output field there, and specify the field for output only. Then assign the field with the header that you want on your PBO.
-
Show dynamic columns in ALV table
I have a question that i need to create report in ALV
like this ...
i need to select doc date e.g. from 03.11.2007 to 05.02.2008
and the report is expected to show like this
SO# | cust | sales gp | 2007-11 order amt | 2007-12 order amt | 2008-01 order amt | 2008-02 order amt
____ |_____|________|________________|________________|________________|_________________
| | | | | |
something like that ....
the no. of period column which is depend on the range of selected doc date....
so how to do that ?!?!?hi sky ,
use dynamic table as:-
Declaration for Dynamic Table:-
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_table1> TYPE STANDARD TABLE,
<dyn_wa1>,
<dyn_wa>.
FIELD-SYMBOLS: <l_fs_dyn> TYPE ANY,
<l_fs_bom> TYPE ANY.
*---Dynamic Internal Table
DATA: dy_table TYPE REF TO data,
dy_table1 TYPE REF TO data,
dy_line TYPE REF TO data.
Creation of Dynamic Internal Table:-
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fcat (for which internal table needs to be built)
IMPORTING
ep_table = dy_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF.
Population of Dynamic Internal Table:-
CLEAR: l_tabix,
w_tabix.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ASSIGN dy_table->* TO <dyn_table1>.
CREATE DATA dy_line LIKE LINE OF <dyn_table1>.
ASSIGN dy_line->* TO <dyn_wa1>.
LOOP AT it_parent.
l_tabix = sy-tabix.
LOOP AT fcat INTO ls_fcat TO 23."WHERE col_pos <= '19'.
ASSIGN COMPONENT ls_fcat-fieldname
OF STRUCTURE <dyn_wa> TO <l_fs_dyn>.
ASSIGN COMPONENT ls_fcat-fieldname
OF STRUCTURE it_parent TO <l_fs_bom>.
<l_fs_dyn> = <l_fs_bom>.
ENDIF.
ENDLOOP
Thanks & Regards,
Ruchi Tiwari -
Dynamic columns in ADF Table don't work as they do in dataTable
Hello!
I've tried the sample from http://forum.java.sun.com/thread.jspa?forumID=427&threadID=560252 and all is working perfectly fine.
Since my company has decided to go with ADF I've tried to port this sample to ADF. However I am experiencing one major problem. The dynamically created columns all have the same ID in different rows. That's why only the last row displays the correct values. Has anyone tried to port the sample from the JSF Forum to the ADF Table and succeeded? Is there a way to manipulate the IDs manually and if so, where do we do it?
Any help would be greatly appreciated.The Develop the JSF/Tiles Application section explains the procedure to dynamically bind column values to a JSF data table. ADF JSF table column binding is similar to the JSF datatable.
http://www.oracle.com/technology/pub/articles/vohra_tiles.html -
Stored Procedure for updating dynamic columns in a table
I have a table with a lot of columns around 30ish
Now I want to create a stored procedure that will update a specific column to a new value.
I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.
here's my Stored Procedure
USE [db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_UpdateData]
@itemID int,
@ColumnName varchar(50),
@newValue nvarchar(50)
AS
BEGIN
Update dbo.ProjectAllocation
Set @ColumnName = @newValue
Where itemID = @itemID END
When I pass the following
@ColumnName: UserName
@newValue: NewUserName
@itemID: 1
it doesnt update row with itemID = 1.
How can I do this?
----------------------- Sharepoint NewbieDid you try my last post method. Its better to use parameterized approach.
Anyway, if you want to change your code,you may need to change as below.....
SET @sql = 'UPDATE dbo.table SET ' + @ColumnName + '=''' + @newValue + ''' WHERE [itemID] = ' + cast(@itemID as varchar(50)); -
Dynamic columns in Internal Table
Hi Experts,
We have client requirments where clients want to see the report of certain no of wage types.
The no. of wage types is variable, they can select any no. of wage type (30-50). Is there any way of dynamically declaring the no of fields in internal table?
Thanks & Regards
Manas NayakHi,
use this..
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_month.
ASSIGN dy_month->* TO <dyn_month>.
CREATE DATA dy_wa LIKE LINE OF <dyn_month>.
ASSIGN dy_wa->* TO <wa_month>.
use this in one loop.....in every loop passing you just create the field catalog ifc... i think your prob will be solved.
Arunima -
Dynamic creation of column in database table
Can I create columns in a database table dynamically?
Let's say I have two columns in a table. Users requested to have dynamic columns in the table. They wanted to create any no. of fields in the table dynamically. We can't alter the table every now and then. Is there any solution for this. Please let me.
Your early response is highly appreciated.
ThanksI can't use "Alter" statement every time. User may need to insert any no.of columns dynamically. There is no fixed columns. Right now there are two columns which are static. Somebody said it is durable through XML. Can you please let me know in detail. I haven't not done anything using XML.
Thanks for the response. -
Adding dynamic columns in Table Control
Hi All,
Can we add dynamic columns in a table control? The requirement is something like this. When the user clicks a button it should add a column to the table. Also is it possible for the same column to refer to different fields of the Internal Table of the Database table. Example. The first row in the table control must refer to MARA-MATNR and the second row must refer to MAKT-MAKTX.
Regards,
SudhindraHello Sudhindra,
If you know all the columns that the table control will ever contain, then I suppose it is possible to add and delete the columns dynamically.
What cannot be dynamic, is the determination of which coulmn would be displayed in the table control.
To elaborate, In SE51, you have to define the table control with all the possible columns. In the program, during the PBO, you can choose to hide some of these columns. When the user performs certain action (PAI), you can determine which opf the hidden columns would be displayed in the table control after the next PBO.
Coming to your second requirement, I don't think it is directly possible in case of table conrols. You will have to do some manipulation to achieve it. But even if you can I think you should not. Because, It is not elegant from a good-UI design perspective. ANd during the course of the necessary manipulations, we might have to forgo some of the features like Automatic Field Validation, Automatic Input Help etc. You can use ALV for the same.
Please be judicious in deciding which approach to consider and if you run into some more problems, please do get back with some more details like how many columns you have, how many different row-types do you want, what are the features for the fields that you wish to provide (eg. F4 help) an so on...
Regards,
Anand Mandalika. -
How to compare two PLSQL tables dynamically.
Hi,
Can you any body help for the following scenario,
I have two PLSQLtables with same structure ,Each PLSQL table contains more than 100 columns.
Now I want to compare content of the two PLSQL tables column wise.
I Knew allready one method like below
FOR I IN 1..100
LOOP
IF PLSQL_1_TAB(I).ACCT_NO = PLSQL_2_TAB(I).ACCT_NO THEN
INSERT INTO …....
END IF;
END LOOP;
is there any method to compare two PLSQL tables dynamically
Edited by: RAVI KUMAR.T.V. on May 5, 2011 11:51 PMHi Saubhik,
Thanks for your reply..
See the below code..
DECLARE
CURSOR cur_emp IS
SELECT *
FROM emp
WHERE job = 'MANAGER';
TYPE typ1 IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER;
v_pl_old typ1;
v_pl_new typ1;
BEGIN
OPEN cur_emp;
FETCH cur_emp INTO v_pl_old(1);
CLOSE cur_emp;
UPDATE emp SET comm = comm+1000 WHERE hiredate < '01-MAY-1981' AND job = 'MANAGER';
COMMIT;
OPEN cur_emp;
FETCH cur_emp INTO v_pl_new(1);
CLOSE cur_emp;
IF v_pl_old(1) = v_pl_new(1) THEN
DBMS_OUTPUT.PUT_LINE('Latest comm not yet Updated');
ELSE
DBMS_OUTPUT.PUT_LINE('Latest comm Updated');
END IF;
END;
When the above code is executed iam getting the following error :
ORA-06550: line 19, column 19: PLS-00306: wrong number or types of arguments in call to '='
ORA-06550: line 19, column 4: PL/SQL: Statement ignored
Here in the example I have taken the standard EMP table, but
actually, Iam having a bigger table with 90 columns of different datatypes,
in which some of the columns gets updated after some UPDATE statements executed based on some conditions.
Now, my requirement is to compare the values of each and every column in the table before and after the execution of the UPDATE statements,
and to insert the modified values only along with the primary key column value into in a new table of similar structure.
If I write the code (to compare the values of each and every column in the table, and if the value is modified then insert that value along with the primary key value into a different talbe) then as the table is having many columns (90), the code becomes lengthy..
Is there any alternative method which does the same with shorter code.
Can you please give me an idea/sol. to meet my requirement.
Thanks..
Edited by: RAVI KUMAR.T.V. on May 9, 2011 2:43 AM
Maybe you are looking for
-
After updating my IPad2 and IPhone 4s to IOS6 I can not use the Music function on the IPone to play songs. The IPad 2 is okay. Help!
-
Law 12741/ 2012 - "Lei de Transparência Fiscal"
Dears, In Brazil, we have got a law 12741/ 2012 -> "Lei de Transparência Fiscal" and need to upload an excell from IBPT site to table z. For that, has SAP note? Thanks,
-
Hai I am new to Jdeveloper. I have a task to display images dynamically. <img src="file:///Z:/Image/sample.bmp " alt="images" /> i am using mysql database.i am getting the path from database. Now i want to pass the path of the image file.how can i do
-
How can I buy music for my Ipod? all I do is adding to my wish list it is fustraiting
-
Can anyone help with this? I've searched the help databases and can't seem to find an answer to this anywhere.