F4 help for a column in tableview
Hi all,
I have achieved F4 help using java script for input field, but i want to use it to fill each value of a column, i am using iterator for the column properties. Is the method of displaying help same as used for input field. I want to do it without using the concept of MVC.
Any pointers are welcome...
Regards,
Rohit Khetarpal
Rohit,
Here you go. Using Flowlogic..used Flight example to narrate this..
Just i added pieces which is mandatory so that you can develope the full code..
In Iterator of Main Tableview:
IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START
DATA col_inputField TYPE REF TO CL_HTMLB_INPUTFIELD.
CREATE OBJECT col8_inputField.
col_inputField->id = p_cell_id.
col_inputField->width = '100%'.
col_inputField->maxlength = 40.
col_inputField->showHelp = 'X'.
row_index = p_row_index.
condense row_index.
concatenate `openF4Window('` row_index `','` p_cell_id `');` into javascript.
col_inputField->onValueHelp = javascript.
_value = p_row_index.
condense _value.
concatenate 'flights[' _value '].connid' into attribute_path.
col_inputField->_value = p_cell_binding.
p_replacement_bee = col_inputField.
<b>Main page Layout:</b>
<htmlb:page>
<script language="JavaScript" type="text/javascript">
function openF4Window(row_index,p_cell_id)
document.getElementById("row_index").value=row_index;
document.getElementById("p_cell_id").value=p_cell_id;
var s=0;
var r=1;
var w=260;
var h=100;
var x=screen.width/2;
x=x-w/2;
var y=screen.height/2;
y=y-h/2;
popUp=window.open('f4.htm', '_blank', 'Emp Details','width=100,height=300');
</script>
<htmlb:tableView id = "main"
width = "200"
headerVisible = "true"
design = "alternating"
visibleRowCount = "10"
fillUpEmptyRows = "true"
selectionMode = "SINGLESELECT"
selectedRowIndex = "<%= row_index %>"
onRowSelection = "MyEventRowSelection"
showNoMatchText = "true"
filter = "server"
sort = "server"
onHeaderClick = "MyEventHeaderClick"
table = "<%= it_sflight %>"
iterator = "<%= iterator %>" >
<b>f4.htm page Layout:</b>
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
<htmlb:page title="Test" >
<htmlb:form id="my_window" >
<%
data TV_ITERATOR Type Ref To zcl_itr." - Iterator Function
data iterator type ref to IF_HTMLB_TABLEVIEW_ITERATOR.
create object tv_iterator exporting appl_cons = application.
iterator = tv_iterator.
%>
<htmlb:tableView id = "pop"
width = "200"
headerVisible = "true"
design = "alternating"
visibleRowCount = "10"
fillUpEmptyRows = "true"
selectionMode = "SINGLESELECT"
selectedRowIndex = "<%= row_index %>"
onRowSelection = "MyEventRowSelection"
showNoMatchText = "true"
filter = "server"
sort = "server"
onHeaderClick = "MyEventHeaderClick"
table = "<%= it_help %>"
iterator = "<%= iterator2 %>" >
</htmlb:tableView>
<%
if connid is not initial.
%>
<htmlb:inputField id = "checked"
visible = "FALSE"
value = "<%= lv_checked %>" />
<script for="checked" language="javascript" even="onLoad()">
var row_index=opener.document.getElementById("row_index").value;
var p_cell_id=opener.document.getElementById("p_cell_id").value;
opener.document.forms[0][p_cell_id].value=document.getElementById("connid").value;
window.self.close();
</script>
<%
endif.
%>
</htmlb:form>
</htmlb:page>
</htmlb:content>
<b>Oninputprocessing of F4.htm</b>
DATA: IND TYPE I.
DATA: TV TYPE REF TO CL_HTMLB_TABLEVIEW.
DATA: EVENT1 TYPE REF TO CL_HTMLB_EVENT.
EVENT1 = CL_HTMLB_MANAGER=>GET_EVENT( RUNTIME->SERVER->REQUEST ).
TV ?= CL_HTMLB_MANAGER=>GET_DATA(
REQUEST = RUNTIME->SERVER->REQUEST
NAME = 'tableView'
ID = 'pop' ).
IF TV IS NOT INITIAL.
DATA: TV_DATA TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.
TV_DATA = TV->DATA.
IF TV_DATA->SELECTEDROWINDEX IS NOT INITIAL.
DATA: ROW LIKE LINE OF APPL->ITAB.
READ TABLE APPL->ITAB INDEX TV_DATA->SELECTEDROWINDEX INTO ROW.
DATA VALUE TYPE STRING.
APPL->CONNID = ROW-CONNID.
ENDIF.
ENDIF.
Hope this will solve your problem.
Raja T
Similar Messages
-
How to get the F4 help for table columns ..
Dear All,
Here I have created table with cell editors of INPUT FIELD .
And I would like to provide the f4 help for those columns .
Here I have checked the node , which i have binded to the table, there input help mode is set to Automatic and search helps are also attached for that node .
But in the table I am not getting the F4 help . Where as if i create the input fields invidually i am able to see the F4 help .
But for table column I am unable to find..
Help me regard this...
Thanks & regards,
Veerednra NathHi,
In debugging , the I have seen the node info attributes list ( VALUE_HELP_ID and VALUE_HELP_MODE ) .
For you understanding, Here I am giving the values which contains ,
VALUE_HELP_ID contains the AUTO:VBUK
AUTO:VBUP
AUTO:MAT1
AUTO:H_T023
and
VALUE_HELP_MODE contains the all Zeros for all the four attributes .
Hope I have given correct inputs .
Thanks & Regards,
Veerendra Nath -
Help for adjusting columns of a JTAble in a Table Model
Hello community,
In order to have a good display of by DataBase in a JTable, I've wrote some code to adjust columns in function of datas. Those datas are displayed with a TableModel ( which I've declared in a class JDBCAdapter ).
When I start my application, I call adjustColumns(), and all is great but when I add information to my DB and display it, the columns of my JTable return to default width...
So I want to incorporate my function adjustColumns in my TableModel, and I need help...
void adjustColumns()
// Ajuste les colonnes aux donnes pour que tout soit visible
int nbRow,nbCol;
nbRow = JTable1.getRowCount();
nbCol = test.getColumnCount();
for ( int i = 0; i < nbCol; i++ )
com.sun.java.swing.table.TableColumn column = null;
column = JTable1.getColumnModel().getColumn(i);
int dataLength = 0;
for ( int j = 0; j< nbRow; j++ )
FontMetrics fm;
int dataLengthTmp;
String valueTable;
fm = JTable1.getFontMetrics(JTable1.getFont());
if ( test.getValueAt(j, i) == null )
System.out.println("Valeur nulle...");
dataLengthTmp = 0;
else
valueTable = test.getValueAt(j, i).toString();
dataLengthTmp = fm.stringWidth(valueTable);
System.out.println(valueTable + " = " + dataLengthTmp);
if ( dataLengthTmp > dataLength )
dataLength = dataLengthTmp;
if ( dataLength != 0 )
column.setWidth(dataLength + 5);
else
column.sizeWidthToFit();
JTable1.setModel(test);
JTable1.repaint();
import java.util.Vector;
import java.sql.*;
import com.sun.java.swing.table.AbstractTableModel;
import com.sun.java.swing.event.TableModelEvent;
public class JDBCAdapter extends AbstractTableModel {
Connection connection;
Statement statement;
ResultSet resultSet;
String[] columnNames = {};
Vector rows = new Vector();
ResultSetMetaData metaData;
public JDBCAdapter(String url, String driverName,
String user, String passwd) {
try {
Class.forName(driverName);
System.out.println("Ouverture de la connexion a la base de donnee...");
connection = DriverManager.getConnection(url, user, passwd);
statement = connection.createStatement();
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
public void executeQuery(String query) {
if (connection == null || statement == null) {
System.err.println("There is no database to execute the query.");
return;
try {
resultSet = statement.executeQuery(query);
metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
columnNames = new String[numberOfColumns];
// Get the column names and cache them.
// Then we can close the connection.
for(int column = 0; column < numberOfColumns; column++) {
columnNames[column] = metaData.getColumnLabel(column+1);
// Get all rows.
rows = new Vector();
while (resultSet.next()) {
Vector newRow = new Vector();
for (int i = 1; i <= getColumnCount(); i++) {
newRow.addElement(resultSet.getObject(i));
rows.addElement(newRow);
// close(); Need to copy the metaData, bug in jdbc:odbc driver.
fireTableChanged(null); // Tell the listeners a new table has arrived.
catch (SQLException ex) {
System.err.println(ex+" query = "+query);
public void executeUpdate(String query) {
if (connection == null || statement == null) {
System.err.println("There is no database to execute the query.");
return;
try {
statement.executeUpdate(query);
// close(); Need to copy the metaData, bug in jdbc:odbc driver.
fireTableChanged(null); // Tell the listeners a new table has arrived.
catch (SQLException ex) {
System.err.println(ex+" query = "+query);
public void close() throws SQLException {
System.out.println("Fermeture de la connection a la base de donnee... Bye !");
resultSet.close();
statement.close();
connection.close();
protected void finalize() throws Throwable {
close();
super.finalize();
// Implementation of the TableModel Interface
// MetaData
public String getColumnName(int column) {
if (columnNames[column] != null) {
return columnNames[column];
} else {
return "";
public Class getColumnClass(int column) {
int type;
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return super.getColumnClass(column);
switch(type) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
return String.class;
case Types.BIT:
return Boolean.class;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
return Integer.class;
case Types.BIGINT:
return Long.class;
case Types.FLOAT:
case Types.DOUBLE:
return Double.class;
case Types.DATE:
return java.sql.Date.class;
default:
return Object.class;
public boolean isCellEditable(int row, int column) {
try {
return metaData.isWritable(column+1);
catch (SQLException e) {
return false;
public int getColumnCount() {
return columnNames.length;
// Data methods
public int getRowCount() {
return rows.size();
public Object getValueAt(int aRow, int aColumn) {
Vector row = (Vector)rows.elementAt(aRow);
return row.elementAt(aColumn);
public String dbRepresentation(int column, Object value) {
int type;
if (value == null) {
return "null";
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return value.toString();
switch(type) {
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
return value.toString();
case Types.BIT:
return ((Boolean)value).booleanValue() ? "1" : "0";
case Types.DATE:
return value.toString(); // This will need some conversion.
default:
return "\""+value.toString()+"\"";
public void setValueAt(Object value, int row, int column) {
try {
String tableName = metaData.getTableName(column+1);
// Some of the drivers seem buggy, tableName should not be null.
if (tableName == null) {
System.out.println("Table name returned null.");
String columnName = getColumnName(column);
String query =
"update "+tableName+
" set "+columnName+" = "+dbRepresentation(column, value)+
" where ";
// We don't have a model of the schema so we don't know the
// primary keys or which columns to lock on. To demonstrate
// that editing is possible, we'll just lock on everything.
for(int col = 0; col<getColumnCount(); col++) {
String colName = getColumnName(col);
if (colName.equals("")) {
continue;
if (col != 0) {
query = query + " and ";
query = query + colName +" = "+
dbRepresentation(col, getValueAt(row, col));
System.out.println(query);
System.out.println("Not sending update to database");
// statement.executeQuery(query);
catch (SQLException e) {
// e.printStackTrace();
System.err.println("Update failed");
Vector dataRow = (Vector)rows.elementAt(row);
dataRow.setElementAt(value, column);
Thanks to help me.Hi,
OK. I have read your code sample again. It looks like the JDBCAdapter class is reloading table data in the executeQuery method. Why not call adjustColumns at the end of this method after the new rows and columns are loaded? Perhaps it also should be called at the end of executeUpdate. Have you tried doing that?
I would still set
JTable1.setAutoCreateColumnsFromModel (false); to prevent Java from readjusting the size automatically at some other time.
regards,
Terry -
ALV: F4 help for a column wanted, but without any check
Hello,
I have an ALV and I use a DDIC structure for the field catalog. My requirement is that for all columns in ALV, the F4 should appear normally (using the DDIC information), but I do not want an automatic check for the value entered by user.
So .e.g. if in F4, possible values are 1, 2, 3 then the ALV throws an error if user leaves the field blank (because blank was not a possible value for the domain of the field). How, can I by-pass this automatic check by ALV (while still keeping the F4 help)?
Regards,
MohitHi hope u know the difference between value table and check table.
In this case you have to give value table as F4 reference but not check table.
I mean consider the field Plant. if you are defining plane with reference to master table T001w and u r entering a value not in T001W it will give error. because here it is check table. where as define the plant with refence to MARC. then MARC will be value table. and dont give error if you enter any plane value not there in MARC.
Try to find out value tables for your fields and use. Then it will work. -
ALV: Search help for editable column using OVS/Input Help Component Usage?
Hi all,
Is is possible to assign a value help like OVS or "Input Help Component Usage" to a editable ALV column using Web Dynpro?
Thanks and regards,
UlrichHi Madhu,
Than I must have made something wrong because this is exactly what I've tried.
I'll check my freely prgrammed value and the assigning again.
Thanks a lot for your quick reply.
Ulrich -
Help for fixed columns in web layout
Hi all,
I'm facing the problem of Fixing the column of web layout,I know there's a post of solving this,
Fixed Rows/Columns in Web Interfaces
but all the download links in this post are expired,could any one send me the file or the how to documents to [email protected]? thank you very much!
thank you all.Denny,
The easiest way is to use the Microsoft OWC (office Web component) and you can have Excel on the web where you have to publish the layouts for the web.
If not, and you use pure web, Olaf Fisher's paper might be published as a how to guide by now. I would suggest a search on SDN. I have downloaded the file a long time ago but I think it is on the server in the office. -
Need Help for Pivoting Columns in table
I have a data like below in the table
col1 col2 col3 col4
a b 10 jan-11
aa b 20 feb-11
aab b 30 mar-11
Need desire o/p like
col1 col2 jan-11 feb-11 mar-11
a b 10
aa b 20
aab b 30
Can anyone help me on this? decode is not the option here because my table gets dynamic data and rows count can vary too(eg. 2000).
Thanks,
-KPPlease try searching the forum BEFORE you ask a question.. There are NUMEROUS posting son the subject:
http://forums.oracle.com/forums/search.jspa?objID=f75&q=pivot
Thank you,
Tony Miller
Webster, TX
Never Surrender Dreams!
JMS
If this question is answered, please mark the thread as closed and assign points where earned.. -
Change search help for each line of a web dynpro table
Hi all i have got the following code to dynamically change the search help of a single field on a web dynpro app and was just wondering if anyone could show me the code for implementing it onto a table so that the same field on each row has a different search help assigned to it!
CALL METHOD node_info->set_attribute_value_help
EXPORTING
name = 'DEPT'
value_help_mode = '121'
value_help = 'PREMN'.
Regards
MartHi,
it is possible to have different search help for same table column for different context elements i.e. table lines. the way to acheive this is by using cell variants in table column.
Steps to follow:
1. In your table column insert cell variant. Depending upon number of variations for search help, insert that number of cell variants in table column
2. Enter the value of variant key property of each cell variant for ex. 01 for first cell variant and 02 for second cell variant
3. Insert cell editor for each of cell variant. for ex. if you have 2 different search helps for single column then insert two cell variant in table column and for each cell variant insert cell editor, let say input field in this case
4. Bind the value property of each input field to different context attribute of the node. for ex: you have table with two columns i.e. Dynamic and fldate
. First column is Dynamic. It will have two cell variants and each cell variant have cell editor of type input field i.e. depending upon the value of second column i.e. fldate, the search help of first column will be decided.
5. Create context node from structure "SFLIGHT" and select 3 components from structure i.e. Carrid, connid, fldate. Add another context attribute to same context node i.e. selected_cell_variant of type string
6. Bind each of context attribute carrid and coonid to value property of cell editor i.e. input field of cell vairaints from column Dynamic
7. Bind value property of cell editor i.e. input field of fldate column to context attribute fldate
8.. Bind selectedCellVariant property of table column Dynamic to context attribute selected_cell_variant
9. Now, Write method at the wddoinit of view to fill up the context node from table sflight table
10. Write event handler for event OnEnter of cell editor from table column FLDATE. in this event handler depnding upon the date set the value of context attribute "selected_cell_variant" to 01 or 02
DATA lv_date TYPE S_DATE.
ASSERT CONDITION context_element IS NOT INITIAL. " context_element is default paramter for event handler
context_element->get_attribute(
EXPORTING
name = 'FLDATE' " NAME
IMPORTING
value = lv_date " DATA
IF lv_date > '20101016'.
context_element->set_attribute(
EXPORTING
value = '01' " Attribute Value
name = 'SELECTED_CELL_VARIANT' " Web Dynpro: Name of Context Element
ELSE.
context_element->set_attribute(
EXPORTING
value = '02' " Attribute Value
name = 'SELECTED_CELL_VARIANT' " Web Dynpro: Name of Context Element
ENDIF.
11. Depending upon the value of selectedCellVariant the corresponding search help will show up in table column. So change the value of column fldate for each table row and see how search help gets changed.
Thanks,
Rahul
Edited by: Rahul Yadav on Oct 17, 2010 12:09 AM -
F4 Help for Classical ALV Grid ( REUSE_ALV_GRID_DISPLAY_LVC)
Hi All,
We have an ABAP program that displays data using REUSE_ALV_GRID_DISPLAY_LVC. There is an editable column in the report for which we need to display F4 help. The functionality of the F4 help will completely user-defined.
Please let me know how to provide custom F4 help for editable column in ALV.
Thanks,
sathish.Hi satish,
Use ' F4IF_INT_TABLE_VALUE_REQUEST' function module after PROCESS ON VALUE-REQUEST event.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'LAND1'
* PVALKEY = ' '
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'T_LCDETAILS-DEST_COUNTRY'
callback_program = sy-repid
value_org = 'S'
TABLES
value_tab = t_country
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Regards,
Venkat. -
Search Help for Domain in Table View
Hi,
I have to give a search help for one column in a table view, and the values in the search help should come from a domain. I wrote this code, but it doesn't seem to work:
lv_str_index = iv_index.
CONDENSE lv_str_index.
CONCATENATE 'table[' lv_str_index '].OP1A' INTO ls_map-context_attr.
ls_map-f4_attr = 'OPERATOR'.
APPEND ls_map TO lt_inmap.
CREATE OBJECT rv_valuehelp_descriptor
TYPE
cl_bsp_wd_valuehelp_f4descr
EXPORTING
iv_help_id = 'ZOPERATOR'
iv_help_id_kind = if_bsp_wd_valuehelp_f4descr=>help_id_kind_dtel
iv_input_mapping = lt_inmap
iv_output_mapping = lt_outmap.
the ZOPERATOR is my domain. OP1A is the context attribute. I am actually not sure what to give for F4_ATTR.
Please help...
Thanks....Hi
Instead of the Domain , use the Data Element which uses that particular Domain ZOPERATOR.
For Example ZDE_OPERATOR is the data element which uses the Domain ZOPERATOR.
then
lv_str_index = iv_index.
CONDENSE lv_str_index.
CONCATENATE 'table[' lv_str_index '].OP1A' INTO ls_map-context_attr.
ls_map-f4_attr = 'OPERATOR'.
APPEND ls_map TO lt_inmap.
CREATE OBJECT rv_valuehelp_descriptor
TYPE
cl_bsp_wd_valuehelp_f4descr
EXPORTING
iv_help_id = 'ZDE_OPERATOR'
iv_help_id_kind = if_bsp_wd_valuehelp_f4descr=>help_id_kind_dtel
iv_input_mapping = lt_inmap
iv_output_mapping = lt_outmap. -
Is there a way to have tooltips for every column in a TableView?
Hi there!
I found in documentation that any node and control can show a tooltip ( http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tooltip.html ) but I can't get tooltips to work for TableColumn (a column from TableView).
Do you have any idea how could I have tooltips for each column of the table view?TableColumn's are neither controls nor nodes, so you can neither set nor install tooltips on them.
You can use cellfactories to set tooltips on cells generated from the factories.
You can use css style lookups (node.lookup function) to get access to table nodes (such as the headers) after the tableview has been displayed on a stage and then manipulate the displayed nodes to add tooltips. It's not a great approach, but it is the only approach I know at the moment that would work. -
Set filter for only one column in tableview
Hi
i am using in MVC a htmlb:tableview with filter in only one column of 8.
This is all working fine, except that the user can enter a searchsting in the filterfield for all columns, but in handle_event (of the controller) ; i only react to a text in the filterfield of column 4 and ignore all other filtertext , which were maybe entered in the other columns.
My question:
how can i enter the filter only for one column, in a way that the user cannot enter any text in the filterfield of the other columns, only in column 4 ?
my view:
<htmlb:tableView id = "requirements"
table = "//model/pdst_reqs"
filter = "APPLICATION"
keyColumn = "EXTID"
iterator = "<%=model%>"
footerVisible = "FALSE"
encode = "TRUE"
visibleRowCount = "<%=model->rowcount%>"
width = "100%"/>
Best Regards
BrittaYou can disbale the Filter for the particular column by setting the DISABLE_FILTER in the Iterator method IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS. Here is the sample code
method IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS .
CLEAR p_column_definitions.
CLEAR p_overwrites.
data tv_column TYPE TABLEVIEWCONTROL.
tv_column-COLUMNNAME = 'FLDATE'.
tv_column-SORT = 'X'.
tv_column-EDIT = 'X'.
tv_column-ONCELLCLICK = 'MyCellClick1'.
tv_column-title = 'Date '.
APPEND tv_column TO p_column_definitions.
CLEAR tv_column.
tv_column-COLUMNNAME = 'PRICE'.
tv_column-horizontalAlignment = 'right'.
tv_column-verticalAlignment = 'middle'.
tv_column-ONCELLCLICK = 'MyCellClick2'.
tv_column-title = 'Currency'.
tv_column-EDIT = 'X'.
tv_column-DISABLE_FILTER = 'X'. " <-------Like this
APPEND tv_column TO p_column_definitions.
endmethod.
Hope this will solve your problem.
Raja -
Web dynpro for abap how to create a customize search help in alv column
hi:
Web dynpro for abap how to create a customize search help in alv column and put search help value into alv column?
Are there specific examples ?
thanks!!HI:
I want to created a freely programed help which include date&time,and put help value to alv column.
I have created a freely programed help in web dynpro for abpa application,I refer:
**************** - WebDynpro for ABAP
but have a problem!
If you focus on the the input field in the first row, you get the value help
However if I go to the second row and focus on the same input field in this column, I don't get the value help:
What is a good way to solve similar problems?
thanks -
Possibly a very basic question but I am going nowhere without a solution. I have set up a spreadsheet in Numbers but it won't give me sums for chosen columns. I have viewed the run through videos and used the formula but nothing happens apart from giving a figure of zero or a red arrow. The sum icon in the bottom left hand section of the window does not highlight or show any total as I understand from the video that you can drag whatever total is here onto the relevent position on your spreadsheet. I have Numbers 09 version 2.3 (554). Can anyone advise. Thanks.
Hi Sohojools,
To sum a column, use a formula such as this one in Cell A6
Type this in a cell below your data:
=SUM(A2:A4) or whatever range of cells you want to sum. The easy way is to type:
=SUM(
and then drag or shift-click to select the range of cells. Close the formula with a final bracket ")".
The sum icon in the bottom left hand section of the window does not highlight or show any total
To see the sum (and other simple statistics) in the bottom left, select a range of cells. That tells Numbers which cells you are refering to.
The videos are good, but the Numbers'09 User guide, and the Formulas and Functions User Guide are better. Download them from the Help Menu in Numbers.
Regards,
Ian. -
Help for a query to add columns
Hi,
I need for a query where I should add each TableC value as an additional column.
Please suggest...
I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
Considering Id of TableA.
Sample data
TableA :
ID NAME TABLENAME ETYPE
23 Name1 TABLE NAMEA Etype A
TableB :
ID A_ID RTYPE RNAME
26 23 RTYPEA RNAMEA
61 23 RTYPEB RNAMEB
TableC :
ID B_ID COMPNAME CONC
83 26 Comp Name AA 1.5
46 26 Comp Name BB 2.2
101 61 Comp Name CC 4.2
Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
Output required: Put each TABLEC value as an additional column
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME TableC_1_CONC TableC_2_COMPNAME TableC_2_CONC
Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2 so on..
Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL
Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
Output:
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
TableC_1_CONCvalue value value value valueHi,
Welcome to the forum!
Do you want the data from TableC presented
(1) in one column, or
(2) in several columns (a different column of results for each row in the original TableC)?
(1) Is called String Aggregation and is easier than (2).
The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
Ignoring TableA for now, you could get what you want by saying
SELECT b.rtype
, STRAGG ( c.compname
|| ' '
|| c.conc
) AS c_data
FROM TableB b
JOIN TableC c ON b.id = c.b_id
GROUP BY b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
(a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
(b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
The two scripts below contain basic information on pivots.
This first script is similar to what you would do for case (a):
-- How to Pivot a Result Set (Display Rows as Columns)
-- For Oracle 10, and earlier
-- Actually, this works in any version of Oracle, but the
-- "SELECT ... PIVOT" feature introduced in Oracle 11
-- is better. (See Query 2, below.)
-- This example uses the scott.emp table.
-- Given a query that produces three rows for every department,
-- how can we show the same data in a query that has one row
-- per department, and three separate columns?
-- For example, the query below counts the number of employess
-- in each departent that have one of three given jobs:
PROMPT ========== 0. Simple COUNT ... GROUP BY ==========
SELECT deptno
, job
, COUNT (*) AS cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
, job;
Output:
DEPTNO JOB CNT
20 CLERK 2
20 MANAGER 1
30 CLERK 1
30 MANAGER 1
10 CLERK 1
10 MANAGER 1
20 ANALYST 2
PROMPT ========== 1. Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno;
-- Output:
DEPTNO ANALYST_CNT CLERK_CNT MANAGER_CNT
30 0 1 1
20 2 2 1
10 0 1 1
-- Explanation
(1) Decide what you want the output to look like.
(E.g. "I want a row for each department,
and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
(2) Get a result set where every row identifies which row
and which column of the output will be affected.
In the example above, deptno identifies the row, and
job identifies the column.
Both deptno and job happened to be in the original table.
That is not always the case; sometimes you have to
compute new columns based on the original data.
(3) Use aggregate functions and CASE (or DECODE) to produce
the pivoted columns.
The CASE statement will pick
only the rows of raw data that belong in the column.
If each cell in the output corresponds to (at most)
one row of input, then you can use MIN or MAX as the
aggregate function.
If many rows of input can be reflected in a single cell
of output, then use SUM, COUNT, AVG, STRAGG, or some other
aggregate function.
GROUP BY the column that identifies rows.
PROMPT ========== 2. Oracle 11 PIVOT ==========
WITH e AS
( -- Begin sub-query e to SELECT columns for PIVOT
SELECT deptno
, job
FROM scott.emp
) -- End sub-query e to SELECT columns for PIVOT
SELECT *
FROM e
PIVOT ( COUNT (*)
FOR job IN ( 'ANALYST' AS analyst
, 'CLERK' AS clerk
, 'MANAGER' AS manager
NOTES ON ORACLE 11 PIVOT:
(1) You must use a sub-query to select the raw columns.
An in-line view (not shown) is an example of a sub-query.
(2) GROUP BY is implied for all columns not in the PIVOT clause.
(3) Column aliases are optional.
If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
{code}
The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
{code}
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus.
(This can be easily adapted to PL/SQL or other tools.)
PROMPT ========== 0. Basic Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
ORDER BY deptno
PROMPT ========== 1. Dynamic Pivot ==========
-- ***** Start of dynamic_pivot.sql *****
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT DISTINCT
', COUNT (CASE WHEN job = '''
|| job
|| ''' ' AS txt1
, 'THEN 1 END) AS '
|| job
|| '_CNT' AS txt2
FROM scott.emp
ORDER BY txt1;
SPOOL OFF
-- Restore SQL*Plus features suppressed earlier
SET FEEDBACK ON
SET PAGESIZE 50
SPOOL p:\sql\cookbook\dynamic_pivot.lst
SELECT deptno
@@dynamic_pivot_subscript
FROM scott.emp
GROUP BY deptno
ORDER BY deptno
SPOOL OFF
-- ***** End of dynamic_pivot.sql *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one. If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one. That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
{code}
Maybe you are looking for
-
SAP Tables for Open Customer Orders and Sales History
Dear Experts. I am looking to get SAP SD related tables for the following, 1) SAP tables for Open Customer Orders From SAP, I need to get all tables that Contain all open customer orders for products. 2) Sales History From SAP, I need to get all
-
Apex no respond 400 bad request
My computer suddenly had a blue screen of death and restarted, I am trying to log into the apex installed on my laptop and I am getting a 400 bad request, The HTTP client sent a request that this server could not understand. Any ideas on what might b
-
Select Path gets me the 'inverse' selection
i'm in Photoshop CS4 for Mac lately, when I create a path that is some sort of closed shape, and click the 'select path' icon on the Paths palette, I get the inverse selection. Of course i can fix this with 'Invert Selection'. But how can I fix it so
-
RF / SAPConsole screen logon size
Hi everybody! I've installed SAPConsole in my client and had developed some ABAP transactions on it, in the last months, with no big problems. However, when I connect the RF device to SAPConsole, the fields on the logon screen extend the device scree
-
Switching from Entourage back to Mail...any suggestions
I downloaded Entourage and I am not happy with it, I want to go back to mail but I'm worried about the switch, anyone have any suggestions on keeping the previous emails?