Update with a select statement
hi experts,
I need some help again.. :)
I have an insert query here with a select statement.. Juz wondering how to do it in update?
insert into newsmail_recipient
(IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
select newsmail_recipientid_seq.nextval
, liste
, 1
, sysdate
, sysdate
, null
, null
, ru.nf_userid
, null
from roleuser ru, unit u, userinfo ui
where u.ip_unitid = ru.nf_unitid
and u.ip_unitid = unit_id
and ui.ip_userid = ru.nf_userid
and ui.nf_statusid = 1
and n_internal = 0
and ui.ip_userid not in (select user_id
from newsmail_recipient
where user_id = ui.ip_userid
and nf_listid = liste
and nf_statusid = 1);let me know your thoughts.
Regards,
jp
Hi,
924864 wrote:
... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Similar Messages
-
Smart scan not working with Insert Select statements
We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
Can you please help us to explain this behavior?There is a specific exadata forum - you would do better to post the question there: Exadata
I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
Regards
Jonathan Lewis -
Quick help with a select statement...
Hello all,
I will try to lay this out as simply as possible. I have the following table in my code:
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table.
I then run through a select statement as follows:
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
That works fine. The next statement, in the report, is the following select. When this next select runs it clears all of the fields except for vbeln and erdat. I want c~vbeln to go into it_table-so_vbeln. Now it is going into it_table-vbeln.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table? Also, is there a way to combine the two selects into one join?
Regards,
DavisFollowing is the entire report, if that makes it easier:
*& Report Z_TRANS_EVAL
REPORT z_trans_eval.
TABLES: likp, lips, adrc, vbpa.
TYPE-POOLS: truxs.
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table,
wa_table LIKE LINE OF it_table,
it_table_csv TYPE truxs_t_text_data.
DATA : lv_tabix LIKE sy-tabix.
DATA temp_string TYPE string.
DATA w_adrnr TYPE vbpa-adrnr.
DATA: w_adrnr_sp TYPE vbpa-adrnr.
* Selction criteria
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
SELECT-OPTIONS: so_vstel FOR likp-vstel,
so_wadat FOR likp-wadat_ist,
so_mtart FOR lips-mtart.
SELECTION-SCREEN END OF BLOCK b2.
* CSV output filename
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
PARAMETERS: p_file(30) TYPE c.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
START-OF-SELECTION.
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
* Get internal address number for ship to party
LOOP AT it_table INTO wa_table.
lv_tabix = sy-tabix. "update counter.
SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
vbeln = wa_table-vgbel
AND parvw = 'WE'.
SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
vbeln = wa_table-vbeln
AND parvw = 'SP'
AND posnr = '000000'.
SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
lifnr = wa_table-lifnr.
* Get address data from VBPA
SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
FROM adrc WHERE
addrnumber = w_adrnr.
ENDSELECT.
* Update the internal table
MODIFY it_table INDEX lv_tabix FROM wa_table.
ENDLOOP.
END-OF-SELECTION.
* Call correct display procedure(s).
IF p_file <> ''.
* Save a CSV file
PERFORM display_csv.
ELSE.
*Display in ALV
PERFORM display_alv.
ENDIF.
*& Form display_alv
* text
* --> p1 text
* <-- p2 text
FORM display_alv .
DATA: gr_alv TYPE REF TO cl_salv_table,
gr_func TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_error TYPE REF TO cx_salv_error.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = it_table.
CATCH cx_salv_msg INTO gr_error.
ENDTRY.
gr_func = gr_alv->get_functions( ).
gr_func->set_all( abap_true ).
gr_alv->display( ).
ENDFORM. " display_alv
*& Form display_csv
* text
* --> p1 text
* <-- p2 text
FORM display_csv .
DATA: w_filename TYPE string.
CONCATENATE p_file temp_string INTO w_filename.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = it_table
CHANGING
i_tab_converted_data = it_table_csv
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_filename
TABLES
data_tab = it_table_csv
EXCEPTIONS
OTHERS = 1.
PERFORM display_alv.
ENDFORM. " display_csv -
Batch updates with callable/prepared statement?
The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797 states
that "Using Batch updates with the callableStatement or preparedStatement is
not supported". What does that actually mean? We have used both callable and prepared
statements with the batch update in our current project (with the Oracle 817 db).
It seems to run ok anyway.So the documentation should state that batch updates do not work ok in old versions
of JDriver for Oracle, BUT work correctly with newer version. Additionally, batch
updates work ok when used with Oracle supplied jdbc-drivers?
"Stephen Felts" <[email protected]> wrote:
Support for addBatch and executeBatch in the WLS Jdriver for Oracle was
added in 7.0SP2.
It was not available in 6.X or 7.0 or 7.0SP1.
"Janne" <[email protected]> wrote in message news:3edb0cdc$[email protected]..
The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797
states
that "Using Batch updates with the callableStatement or preparedStatementis
not supported". What does that actually mean? We have used both callableand prepared
statements with the batch update in our current project (with the Oracle817 db).
It seems to run ok anyway. -
Short dump with a select statement
I have the following select statement (I have also inluded my data statement(s)) and I get a short dump. The error is as follows:
<b>What happened?
Error in ABAP application program.
The current ABAP program "ZPARTNER" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
Following a SELECT statement, the data read could not be placed in AN
the output area.
A conversion may have been intended that is not supported by the
system, or the output area may be too small.
Error analysis
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
caught, which
led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the
target field.
Either conversion is not supported for the target field's type or the
target field is too short to accept the value or the data are not in a
form that the target field can accept </b>
it_adrc TYPE TABLE OF adrc,
wa_adrc LIKE LINE OF it_adrc,
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
Regards,
DavisIf you only need the fields mentioned in the select query, then follow this:
TYPES: BEGIN OF ADRC_TYPE,
ADDRNUMBER LIKE ADRC-ADDRNUMBER,
NAME1 LIKE ADRC-NAME1,
STREET LIKE ADRC-STREET,
CITY LIKE ADRC-CITY,
REGION LIKE ADRC-REGION,
POST_CODE1 LIKE ADRC-POST_CODE1,
TEL_NUMBER LIKE ADRC-TEL_NUMBER,
END OF ADRC_TYPE,
ADRC_T_TYPE TYPE TABLE OF ADRC_TYPE.
DATA: IT_ADRC TYPE ADRC_T_TYPE WITH HEADER LINE.
IF NOT IT_DETAIL[] IS INITIAL.
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
ENDIF.
Thanks,
SKJ -
CX_SY_DYNAMIC_OSQL_SEMANTICS error with dynamic SELECT statement
Hello Gurus,
We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
SELECT (lt_select_flds)
FROM (lf_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
FOR ALL ENTRIES IN <lt_source_data>
WHERE (lf_where).
In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
This code was working fine till we were in BW 3.5 and is causing issues after we moved to BW 7.31 recently. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS. THE ERROR TEXT SAYS 'Unable to interpret '<LT_SOURCE_data>-DOC_NUMBER'.
Can you pleasesuggest what can we do to this code to get is working correctly ? What has changed in ABAP Objects that has been introduced from BI 7.0 that could be causing this issue?
Would appreciate any help we can get here.
Thanks
ArvindHi,
Please try this.
data: lv_where type string.
concatenate 'vbeln' 'in' 'r_vbeln' into lv_where separated by space.
select *from table into itab where (lv_where).
Also please check this sample code.
REPORT ZDYNAMIC_WHERE .
TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.
SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).
LOOP AT ITAB.
WRITE 'hello'.
ENDLOOP.
Regards,
Ferry Lianto -
Put prepended "WITH" into Select statement possible?
Assume I have a SQL statement like:
with t1 as (select ......),
t2 as (select ......)
Select .... From t1, t2 Where ....;
Can I merge somehow the prepended "with" term into the actual select statement?
As far as I remember there is an equivalent statement syntax like:
Select .... from t1 as (select ....), t2 as (select ....) where ....;
but this does not work.
PeterIt will be like
Select ....
From ( select .. From ...) t1
,( select .. From ...) t2
WHERE ...
Regards
Arun -
Help needed with a SELECT statement. How can I make it run faster?
Hi,
not sure if my brain is just too tired but I can't seem to crack this problem today.
Here is my scenario.
I have 2 tables
TABLE1 (searchId INTEGER, routeId INTEGER);
TABLE2 (routeId INTEGER, cityId INTEGER);
There are indexes on all 4 columns.
(routeId on TABLE1 is a primary key).
In the data I am using, a given search has more than 500 routes, each route has between 10 and 300 cities among more than 4000 possible different cities.
Now, what I want to create is the list of route couple, within a certain search, that do not have a single city in common.
That list should populate a table with the following structure
TABLE3 (searchId INTEGER, routeId1 INTEGER, routeId2 INTEGER)
Here is the fastest select statement I have found so far.
SELECT :searchId, t1.routeId, t2.routeId FROM table1 t1, table1 t2
WHERE t1.searchId=:searchId AND t2.searchId=:searchId
AND t1.routeId>t2.routeId
AND NOT EXISTS (
SELECT cityId FROM table2
WHERE routeId=t1.routeId
INTERSECT
SELECT cityId FROM table2
WHERE routeId=t2.routeId);
But it still seem really slow to me.
Any suggestion for an improved version is welcome.
Thanks,
Martin.
Title was edited by:
user453358I originaly posted this thread because I tought I was missing something "obvious" that would perform better that would make my SELECT statement perform better.
So I did not want to go as deep as using TKPROOF yet.
Here is the statistics I gets on my statement.
1 SELECT t1.searchId,t1.routeId, t2.routeId id2
2 FROM table1 t1, table1 t2
3 WHERE t1.searchid=t2.searchid
4 AND t1.searchId=91
5 AND t1.routeId>t2.routeId
6 AND NOT EXISTS (
7 SELECT cityId FROM table2
8 WHERE routeId=t1.routeId
9 INTERSECT
10 SELECT cityId FROM table2
11* WHERE routeId=t2.routeId)
SQL> /
43302 rows.
Tidsåtgång: 00:01:55.02
Körschema
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=1 Bytes=14)
1 0 FILTER
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=1 Card=1 Bytes=7)
3 2 NESTED LOOPS (Cost=3 Card=1 Bytes=14)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=2 Card=1 Bytes=7)
5 4 INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=1 Card=1)
6 3 INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=0 Card=1)
7 1 INTERSECTION
8 7 SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)
9 8 TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)
10 9 INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)
11 7 SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)
12 11 TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)
13 12 INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)
Statistik
1 recursive calls
0 db block gets
2872765 consistent gets
0 physical reads
812 redo size
964172 bytes sent via SQL*Net to client
32245 bytes received via SQL*Net from client
2888 SQL*Net roundtrips to/from client
860256 sorts (memory)
0 sorts (disk)
43302 rows processed Looks like a big number of consistent gets! Any idea how to improve on that?
Martin. -
Need to write with single select statement
NAME
SAL
GENDER
X 10000 M
X 9000 F
Y 8000 M
Y 7000 M
Z 6000 F
Z 5000 F
A 4000 M
A 4000 F
1) How to write a query that displays the name that exist in both male and female gender. using single select statement
I tried this one
SELECT NAME FROM EMPL WHERE NAME IN (SELECT NAME FROM EMPL WHERE GENDER='F') AND GENDER='M';
It worked fine
But when i converted to single select statement it didn't work . You can find the query below. can i rewrite in any possible ways(using single select statement).
Select name from table_name where gender='M' and gender='F'
thanks in advanceIf a Name does not exist with same gender
i.e
Name Gender
X M
X M
if above sceniorio not exist in ur data than following query will work
select name from table_name
group by name
having count(name) > 1 -
Need image to update with JComboBox selection
hello, i have code here that loads an image from a JFileChooser dialog when "Add Image" is clicked, the images name and path is stored in a JComboBox, and the image name is displayed. As more images are added to the JComboBox, I would like to be able to have the picture displayed in concurrence with whatever image is selected from the comboBox. For instance, if Jessica.jpg is selected in the JComboBox, i need Jessica.jpg to be loaded into imagePanel. Here is the code. The problem lies within the JComboBox's "itemStateChanged" I believe... This is what must be used (i think) to update the pictures in the imagePanel when the combobox is manipulated....
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.border.*;
import java.awt.image.BufferedImage;
public class MyDialog extends JDialog implements ActionListener, WindowListener, ItemListener
ReminderClass dataRec;
ReminderClass originalDataRec;
Image im;
MediaTracker mt;
Toolkit tk;
JFileChooser imageDialog;
File f;
String[] comboBoxList;
String fileName;
String filePathName;
DataManager dataManager;
JPanel mainPanel1;
JPanel mainPanel2;
JPanel mainPanel3;
JPanel buttonPanel;
JPanel radioPanel;
MyImageJPanel imagePanel;
JScrollPane scrollPane1;
JScrollPane scrollPane2;
JRadioButton pendingButton;
JRadioButton documentationButton;
JRadioButton completedButton;
JRadioButton failedButton;
JRadioButton cancelledButton;
ButtonGroup radioGroup;
JComboBox imageComboBox;
JComboBox category;
JTextArea description;
JTextArea message;
JLabel descriptionLabel;
JLabel messageLabel;
JLabel fileNameLabel;
JLabel categoryLabel;
JLabel selectedFile;
GregorianCalendar dueDateTime;
GregorianCalendar reminderInterval;
GregorianCalendar terminatedDateTime;
JButton saveCont;
JButton cancel;
JButton addImage;
JButton saveExit;
JLabel dueDate;
JLabel intervalDate;
JLabel terminatedDate;
JTextField dueDateField;
JTextField intervalDateField;
JTextField terminatedDateField;
int choice;
int newIndex;
public MyDialog(DataManager aDataManager)
{//add new Reminder to list d-box
Container cp;
dataManager = aDataManager;
dataRec = new ReminderClass();
imageComboBox = new JComboBox();
imagePanel = new MyImageJPanel();
imagePanel.setPreferredSize(new Dimension(40, 40));
imageComboBox.addItemListener(this);
mainPanel1 = new JPanel(new BorderLayout());
mainPanel2 = new JPanel(new BorderLayout());
mainPanel3 = new JPanel(new GridLayout(7,2));
radioPanel = new JPanel(new GridLayout(5,1));
buttonPanel = new JPanel(new FlowLayout());
saveCont = new JButton ("Save & Continue");
saveExit = new JButton ("Save & Exit");
addImage = new JButton ("Add Image(s)");
cancel = new JButton ("Cancel");
description = new JTextArea(" ");
description.setBorder(BorderFactory.createLineBorder(Color.black));
scrollPane1 = new JScrollPane(description);
message = new JTextArea(" ");
scrollPane2 = new JScrollPane(message);
comboBoxList = CategoryConversion.categories;
category = new JComboBox(comboBoxList);
category.setSelectedIndex(0);
message.setBorder(BorderFactory.createLineBorder(Color.black));
scrollPane2 = new JScrollPane(message);
descriptionLabel = new JLabel("Description: ");
messageLabel = new JLabel("Message: ");
selectedFile = new JLabel("Selected File(s): ");
fileNameLabel = new JLabel();
categoryLabel = new JLabel("Category: ");
dueDate = new JLabel("Due date: ");
intervalDate = new JLabel ("Interval date: ");
terminatedDate = new JLabel ("Terminated date: ");
dueDateField = new JTextField(" ");
intervalDateField = new JTextField(" ");
terminatedDateField = new JTextField(" ");
pendingButton = new JRadioButton("Pending?");
documentationButton = new JRadioButton("Documentation?");
completedButton = new JRadioButton("Completed?");
failedButton = new JRadioButton("Failed?");
cancelledButton = new JRadioButton("Cancelled?");
radioGroup = new ButtonGroup();
radioGroup.add(pendingButton);
radioGroup.add(documentationButton);
radioGroup.add(completedButton);
radioGroup.add(failedButton);
radioGroup.add(cancelledButton);
radioPanel.add(pendingButton);
radioPanel.add(documentationButton);
radioPanel.add(completedButton);
radioPanel.add(failedButton);
radioPanel.add(cancelledButton);
pendingButton.addActionListener(this);
pendingButton.setActionCommand("PENDING");
documentationButton.addActionListener(this);
documentationButton.setActionCommand("DOCUMENTATION");
completedButton.addActionListener(this);
completedButton.setActionCommand("COMPLETED");
failedButton.addActionListener(this);
failedButton.setActionCommand("FAILED");
cancelledButton.addActionListener(this);
cancelledButton.setActionCommand("CANCELLED");
add(mainPanel1);
mainPanel1.add(mainPanel2, BorderLayout.CENTER);
mainPanel3.add(descriptionLabel);
mainPanel3.add(scrollPane1);
mainPanel3.add(messageLabel);
mainPanel3.add(scrollPane2);
mainPanel3.add(selectedFile);
mainPanel3.add(imageComboBox);
mainPanel3.add(categoryLabel);
mainPanel3.add(category);
mainPanel3.add(dueDate);
mainPanel3.add(dueDateField);
mainPanel3.add(intervalDate);
mainPanel3.add(intervalDateField);
mainPanel3.add(terminatedDate);
mainPanel3.add(terminatedDateField);
mainPanel2.add(radioPanel, BorderLayout.EAST);
mainPanel2.add(mainPanel3, BorderLayout.WEST);
buttonPanel.add(addImage);
buttonPanel.add(saveCont);
buttonPanel.add(saveExit);
buttonPanel.add(cancel);
mainPanel1.add(buttonPanel, BorderLayout.SOUTH);
mainPanel2.add(imagePanel, BorderLayout.CENTER);
saveCont.setActionCommand("SAVECONT");
saveCont.addActionListener(this);
saveExit.setActionCommand("SAVEEXIT");
saveExit.addActionListener(this);
cancel.setActionCommand("CANCEL");
cancel.addActionListener(this);
addImage.setActionCommand("ADDIMAGE");
addImage.addActionListener(this);
category.addItemListener(this);
addWindowListener(this);
description.setInputVerifier(new MyTextAreaVerifier(dataRec, ReminderClass.DESCRIPTION_FIELD));
message.setInputVerifier(new MyTextAreaVerifier(dataRec, ReminderClass.MESSAGE_FIELD));
//dueDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.DUE_DATE_TIME_FIELD));
//intervalDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.REMINDER_INTERVAL_FIELD));
//terminatedDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.TERMINATED_DATE_TIME_FIELD));
cp = getContentPane();
cp.add(mainPanel1);
originalDataRec = (ReminderClass)dataRec.clone();
setupMainFrameAdd();
public MyDialog(int index, DataManager aDataManager, ReminderClass newDataRec)
{//edit an existing reminder dialog
Container cp;
dataManager = aDataManager;
index = newIndex;
dataRec = newDataRec;
imageComboBox = new JComboBox();
imagePanel = new MyImageJPanel();
imagePanel.setPreferredSize(new Dimension(40, 40));
imageComboBox.addItemListener(this);
mainPanel1 = new JPanel(new BorderLayout());
mainPanel2 = new JPanel(new BorderLayout());
mainPanel3 = new JPanel(new GridLayout(7,2));
radioPanel = new JPanel(new GridLayout(5,1));
buttonPanel = new JPanel(new FlowLayout());
saveCont = new JButton ("Save & Continue");
saveExit = new JButton ("Save & Exit");
addImage = new JButton ("Add Image(s)");
cancel = new JButton ("Cancel");
description = new JTextArea(" ");
description.setBorder(BorderFactory.createLineBorder(Color.black));
scrollPane1 = new JScrollPane(description);
message = new JTextArea(" ");
scrollPane2 = new JScrollPane(message);
comboBoxList = CategoryConversion.categories;
category = new JComboBox(comboBoxList);
category.setSelectedIndex(0);
dataRec.populateComboBox(imageComboBox);
message.setBorder(BorderFactory.createLineBorder(Color.black));
scrollPane2 = new JScrollPane(message);
descriptionLabel = new JLabel("Description: ");
messageLabel = new JLabel("Message: ");
selectedFile = new JLabel("Selected File(s): ");
fileNameLabel = new JLabel();
categoryLabel = new JLabel("Category: ");
dueDate = new JLabel("Due date: ");
intervalDate = new JLabel ("Interval date: ");
terminatedDate = new JLabel ("Terminated date: ");
dueDateField = new JTextField(" ");
intervalDateField = new JTextField(" ");
terminatedDateField = new JTextField(" ");
pendingButton = new JRadioButton("Pending?");
documentationButton = new JRadioButton("Documentation?");
completedButton = new JRadioButton("Completed?");
failedButton = new JRadioButton("Failed?");
cancelledButton = new JRadioButton("Cancelled?");
radioGroup = new ButtonGroup();
radioGroup.add(pendingButton);
radioGroup.add(documentationButton);
radioGroup.add(completedButton);
radioGroup.add(failedButton);
radioGroup.add(cancelledButton);
radioPanel.add(pendingButton);
radioPanel.add(documentationButton);
radioPanel.add(completedButton);
radioPanel.add(failedButton);
radioPanel.add(cancelledButton);
pendingButton.addActionListener(this);
pendingButton.setActionCommand("PENDING");
documentationButton.addActionListener(this);
documentationButton.setActionCommand("DOCUMENTATION");
completedButton.addActionListener(this);
completedButton.setActionCommand("COMPLETED");
failedButton.addActionListener(this);
failedButton.setActionCommand("FAILED");
cancelledButton.addActionListener(this);
cancelledButton.setActionCommand("CANCELLED");
add(mainPanel1);
mainPanel1.add(mainPanel2, BorderLayout.CENTER);
mainPanel3.add(descriptionLabel);
mainPanel3.add(scrollPane1);
mainPanel3.add(messageLabel);
mainPanel3.add(scrollPane2);
mainPanel3.add(selectedFile);
mainPanel3.add(imageComboBox);
mainPanel3.add(categoryLabel);
mainPanel3.add(category);
mainPanel3.add(dueDate);
mainPanel3.add(dueDateField);
mainPanel3.add(intervalDate);
mainPanel3.add(intervalDateField);
mainPanel3.add(terminatedDate);
mainPanel3.add(terminatedDateField);
mainPanel2.add(radioPanel, BorderLayout.EAST);
mainPanel2.add(mainPanel3, BorderLayout.WEST);
buttonPanel.add(addImage);
buttonPanel.add(saveCont);
buttonPanel.add(saveExit);
buttonPanel.add(cancel);
mainPanel1.add(buttonPanel, BorderLayout.SOUTH);
mainPanel2.add(imagePanel, BorderLayout.CENTER);
fillInData(dataRec);
saveCont.setActionCommand("SAVECONT2");
saveCont.addActionListener(this);
saveExit.setActionCommand("SAVEEXIT2");
saveExit.addActionListener(this);
cancel.setActionCommand("CANCEL2");
cancel.addActionListener(this);
addImage.setActionCommand("ADDIMAGE");
addImage.addActionListener(this);
category.addItemListener(this);
addWindowListener(this);
description.setInputVerifier(new MyTextAreaVerifier(dataRec, ReminderClass.DESCRIPTION_FIELD));
message.setInputVerifier(new MyTextAreaVerifier(dataRec, ReminderClass.MESSAGE_FIELD));
//dueDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.DUE_DATE_TIME_FIELD));
//intervalDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.REMINDER_INTERVAL_FIELD));
//terminatedDateField.setInputVerifier(new MyDateAreaVerifier(dataRec, ReminderClass.TERMINATED_DATE_TIME_FIELD));
cp = getContentPane();
cp.add(mainPanel1);
originalDataRec = (ReminderClass)dataRec.clone();
setupMainFrameEdit();
void setupMainFrameAdd()
tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
setSize(d.width/3, d.height/4);
setLocation(d.width/3, d.height/3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Reminder Add New");
setVisible(true);
}//end of setupMainFrame
void setupMainFrameEdit()
tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
setSize(d.width/3, d.height/4);
setLocation(d.width/3, d.height/3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Edit Existing Reminder");
setVisible(true);
public void actionPerformed(ActionEvent e)
JOptionPane optionPane;
String temp = new String();
if (e.getActionCommand().equals("CANCEL"))
if(dataRec.compareTo(originalDataRec) != 0)
choice = JOptionPane.showConfirmDialog(this, "Are you sure you wish to exit without first saving data?","Are you sure you wish to\n" + "exit without first saving data?", JOptionPane.YES_NO_OPTION);
if(choice == JOptionPane.YES_OPTION)
dispose();
else
for (int n = 0; n<imageComboBox.getItemCount(); n++)
dataRec.addImageToArray((String)imageComboBox.getItemAt(n));
dataRec.setCategory(category.getSelectedIndex());
dataManager.add(dataRec);
fillInData(dataRec);
dispose();
else
dispose();
else if (e.getActionCommand().equals("CANCEL2"))
if (dataRec.compareTo(originalDataRec) != 0)
choice = JOptionPane.showConfirmDialog(this, "Are you sure you wish to\n" + "exit without first saving data?");
if (choice == JOptionPane.YES_OPTION)
dispose();
else
this.dispose();
else if (e.getActionCommand().equals("ADDIMAGE"))
filePathName = new String();
fileName = new String();
imageDialog = new JFileChooser();
imageDialog.showOpenDialog(this);
f = imageDialog.getSelectedFile();
tk = Toolkit.getDefaultToolkit();
fileName = f.getName();
filePathName = f.getPath();
im = tk.getImage(filePathName);
try
mt = new MediaTracker(this);
mt.addImage(im, 432);
mt.waitForAll();
catch(InterruptedException ie)
ie.getStackTrace();
imageComboBox.addItem(fileName);
dataRec.setImageFileName(fileName);
imageComboBox.setSelectedItem(fileName);
imagePanel.refreshImage(im , 50, 50);
else if (e.getActionCommand().equals("SAVECONT"))
for (int n = 0; n<imageComboBox.getItemCount(); n++)
dataRec.addImageToArray((String)imageComboBox.getItemAt(n));
temp = dueDateField.getText();
fileNameLabel.setText("");
dataRec.setCategory(category.getSelectedIndex());
dataManager.add((ReminderClass)(dataRec.clone()));
dataRec.clearFields();
fillInData(dataRec);
else if (e.getActionCommand().equals("SAVECONT2"))
fileNameLabel.setText("");
dataRec.setCategory(category.getSelectedIndex());
dataManager.replace(newIndex,(ReminderClass)(dataRec.clone()));
dataRec.clearFields();
fillInData(dataRec);
else if (e.getActionCommand().equals("SAVEEXIT"))
for (int n = 0; n<imageComboBox.getItemCount(); n++)
dataRec.addImageToArray((String)imageComboBox.getItemAt(n));
dataRec.setCategory(category.getSelectedIndex());
dataManager.add(dataRec);
fillInData(dataRec);
dispose();
//save new data to list, and exit back to main prog.
else if (e.getActionCommand().equals("SAVEEXIT2"))
for (int n = 0; n<imageComboBox.getItemCount(); n++)
dataRec.addImageToArray((String)imageComboBox.getItemAt(n));
dataRec.setCategory(category.getSelectedIndex());
dataManager.replace(newIndex, (ReminderClass)(dataRec.clone()));
fillInData(dataRec);
dispose();
else if (e.getActionCommand().equals("PENDING"))
dataRec.setStatus("Pending");
else if (e.getActionCommand().equals("DOCUMENTATION"))
dataRec.setStatus("Documentation");
else if (e.getActionCommand().equals("COMPLETED"))
dataRec.setStatus("Completed");
else if (e.getActionCommand().equals("FAILED"))
dataRec.setStatus("Failed");
else if (e.getActionCommand().equals("CANCELLED"))
dataRec.setStatus("Cancelled");
public void itemStateChanged(ItemEvent e)
JComboBox cb = (JComboBox)e.getSource();
int categorySelection;
if(cb == category)
categorySelection = cb.getSelectedIndex();
if (cb == imageComboBox)
tk = Toolkit.getDefaultToolkit();
fileName = dataRec.getImageFileName();
filePathName = f.getPath();
im = tk.getImage(filePathName);
try
mt = new MediaTracker(this);
mt.waitForAll();
mt.addImage(im, 432);
imagePanel.refreshImage(im , 50, 50);
catch(InterruptedException ie)
ie.getStackTrace();
public void fillInData(ReminderClass d)
fileNameLabel.setText(d.getImageFileName());
description.setText(d.getDescription());
message.setText(d.getMessage());
category.setSelectedIndex(d.getCategory());
public void windowOpened(WindowEvent e)
//no action to take
public void windowClosing(WindowEvent e)
JOptionPane j = new JOptionPane("Are you sure you wish to exit \n" + "without saving data first?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);;
public void windowClosed(WindowEvent e)
// no action to take
public void windowIconified(WindowEvent e)
// no action to take
public void windowDeiconified(WindowEvent e)
// no action to take
public void windowActivated(WindowEvent e)
// no action to take
public void windowDeactivated(WindowEvent e)
// no action to take
}Here is the main "ReminderClass" with all methods and accessors/mutators....
import java.util.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
//search for Java Thumb Wheel under Google.
public class ReminderClass extends Object implements Cloneable, Comparable
private int category;
private String description;
private String message;
private GregorianCalendar dueDateTime;
private GregorianCalendar reminderInterval;
private GregorianCalendar terminatedDateTime;
private int displayStyle;
private int compareKey;
private String status;
String[] imagePathArray;
String[] imageArray;
String imageFileName;
int numImages;
public final static int CATEGORY_FIELD = 1;
public final static int DESCRIPTION_FIELD = 2;
public final static int MESSAGE_FIELD = 3;
public final static int DUE_DATE_TIME_FIELD = 4;
public final static int REMINDER_INTERVAL_FIELD =5;
public final static int TERMINATED_DATE_TIME_FIELD = 6;
public final static int DISPLAY_STYLE_FIELD = 7;
public final static int COMPARE_KEY_FIELD = 8;
public final static int STATUS_FIELD = 9;
static boolean showDescription = false;
static boolean showDate = false;
static boolean showCategory = false;
static boolean showMessage = false;
static boolean showDueDateTime = false;
static boolean showReminderInterval = false;
static boolean showTerminatedDateTime = false;
static boolean showImageName = false;
static boolean showStatus = false;
//******************REMINDER CLASS DEFAULT CONSTRUCTOR***************
ReminderClass()
numImages = 0;
imageArray = new String[20];
imagePathArray = new String[20];
imageFileName = "";
category = -1;
description = "";
message = "";
dueDateTime = new GregorianCalendar();
reminderInterval = new GregorianCalendar();
terminatedDateTime = new GregorianCalendar();
displayStyle = -1;
compareKey = -1;
// *****************REMINDER CLASS INITIALIZER CONSTRUCTOR*************
ReminderClass(int initCategory, String initDescription, GregorianCalendar initDueDateTime, String[] initImagePathArray, String[] initImageArray, String initImageFileName,
GregorianCalendar initReminderInterval, GregorianCalendar initTerminatedDateTime, String initMessage, String initStatus,
int initCompareKey, int initDisplayStyle)
imagePathArray = new String[20];
imageArray = new String[20];
for (int n = 0; n<initImageArray.length; n++)
imageArray[n] = initImageArray[n];
for (int n = 0; n<initImagePathArray.length; n++)
imagePathArray[n] = initImagePathArray[n];
imageFileName = initImageFileName;
category = initCategory;
description = initDescription;
dueDateTime = (GregorianCalendar)initDueDateTime.clone();
reminderInterval = (GregorianCalendar)initReminderInterval.clone();
terminatedDateTime = (GregorianCalendar)initTerminatedDateTime.clone();
message = initMessage;
status = initStatus;
compareKey = initCompareKey;
displayStyle = initDisplayStyle;
//*********************LOAD DATA FROM FILE WITH CONSTRUCTOR*****************************
public ReminderClass(DataInputStream dataInStream) throws IOException
imageFileName = dataInStream.readUTF();
category = dataInStream.readInt();
description = dataInStream.readUTF();
message = dataInStream.readUTF();
dueDateTime = new GregorianCalendar(dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt());
reminderInterval = new GregorianCalendar(dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt());
terminatedDateTime = new GregorianCalendar(dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt(), dataInStream.readInt());
displayStyle = dataInStream.readInt();
compareKey = dataInStream.readInt();
status = dataInStream.readUTF();
//********************SAVE DATA TO FILE***************************
public void write(DataOutputStream dataOutStream) throws IOException
dataOutStream.writeUTF(imageFileName);
dataOutStream.writeInt(category);
dataOutStream.writeUTF(description);
dataOutStream.writeUTF(message);
dataOutStream.writeInt(dueDateTime.get(Calendar.YEAR));
dataOutStream.writeInt(dueDateTime.get(Calendar.MONTH));
dataOutStream.writeInt(dueDateTime.get(Calendar.DAY_OF_MONTH));
dataOutStream.writeInt(dueDateTime.get(Calendar.HOUR));
dataOutStream.writeInt(dueDateTime.get(Calendar.MINUTE));
dataOutStream.writeInt(dueDateTime.get(Calendar.SECOND));
dataOutStream.writeInt(reminderInterval.get(Calendar.YEAR));
dataOutStream.writeInt(reminderInterval.get(Calendar.MONTH));
dataOutStream.writeInt(reminderInterval.get(Calendar.DAY_OF_MONTH));
dataOutStream.writeInt(reminderInterval.get(Calendar.HOUR));
dataOutStream.writeInt(reminderInterval.get(Calendar.MINUTE));
dataOutStream.writeInt(reminderInterval.get(Calendar.SECOND));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.YEAR));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.MONTH));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.DAY_OF_MONTH));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.HOUR));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.MINUTE));
dataOutStream.writeInt(terminatedDateTime.get(Calendar.SECOND));
dataOutStream.writeInt(displayStyle);
dataOutStream.writeInt(compareKey);
//dataOutStream.writeUTF(status);
public void clearFields()
numImages = 0;
imageFileName = "";
category = -1;
description = "";
message = "";
dueDateTime = new GregorianCalendar();
reminderInterval = new GregorianCalendar();
terminatedDateTime = new GregorianCalendar();
displayStyle = -1;
status = "";
compareKey = -1;
//************* OVERRIDE clone METHOD***********************
public Object clone()
ReminderClass c = new ReminderClass();
try
c = ((ReminderClass)super.clone());
c.setImageArray(imageArray);
c.setImagePathArray(imagePathArray);
c.imageFileName = (String)imageFileName;
c.category = (int)category;
c.description = (String)description;
c.message = (String)message;
c.status = (String)status;
c.compareKey = (int)compareKey;
c.displayStyle = (int)displayStyle;
c.dueDateTime = (GregorianCalendar)(dueDateTime.clone());
c.reminderInterval = (GregorianCalendar)(reminderInterval.clone());
c.terminatedDateTime = (GregorianCalendar)(terminatedDateTime.clone());
catch (CloneNotSupportedException e)
System.out.println("Fatal Error: " + e.getMessage());
System.exit(1);
return c;
//**************** OVERRIDE toString METHOD*************************
public String toString()
String s = new String();
s = description;
if (showCategory)
s = s + "," + CategoryConversion.categories[category];
if (showImageName)
s = s + "," + "'" + imageFileName + "'";
if (showMessage)
s = s + "," + message;
if (showStatus)
s = s + "," + status;
if (showDueDateTime)
s = s + ", " + dueDateTime.get(Calendar.MONTH);
s = s + "/" + dueDateTime.get(Calendar.DAY_OF_MONTH);
s = s + "/" + dueDateTime.get(Calendar.YEAR);
s = s + " " + dueDateTime.get(Calendar.HOUR);
s = s + ":" + dueDateTime.get(Calendar.MINUTE);
s = s + ":" + dueDateTime.get(Calendar.SECOND);
if (showReminderInterval)
s = s + ", " + reminderInterval.get(Calendar.MONTH);
s = s + "/" + reminderInterval.get(Calendar.DAY_OF_MONTH);
s = s + "/" + reminderInterval.get(Calendar.YEAR);
s = s + " " + reminderInterval.get(Calendar.HOUR);
s = s + ":" + reminderInterval.get(Calendar.MINUTE);
s = s + ":" + reminderInterval.get(Calendar.SECOND);
if (showTerminatedDateTime)
s = s + ", " + terminatedDateTime.get(Calendar.MONTH);
s = s + "/" + terminatedDateTime.get(Calendar.DAY_OF_MONTH);
s = s + "/" +terminatedDateTime.get(Calendar.YEAR);
s = s + " " + terminatedDateTime.get(Calendar.HOUR);
s = s + ":" + terminatedDateTime.get(Calendar.MINUTE);
s = s + ":" + terminatedDateTime.get(Calendar.SECOND);
return s;
//******************COMPARE TO OBJECT*********************************
public int compareTo(Object r)
ReminderClass x;
x = (ReminderClass)r;
if (
(x.getCategory() == this.category)
&& (x.getDescription().equals(this.description))
&& (x.getMessage().equals(this.message))
&& (x.getImageFileName().equals(this.imageFileName))
&& (x.getDueDateTime().equals(this.dueDateTime))
&& (x.getReminderInterval().equals(this.reminderInterval))
&& (x.getTerminatedDateTime().equals(this.terminatedDateTime))
return 0;
else
return 1;
//*************** ACCESSORS AND MUTATORS INCLUDING DISPLAY STYLE*******
public void setDisplayStyle(int newDisplayStyle)
displayStyle = newDisplayStyle;
public int getDisplayStyle()
return displayStyle;
public int getCompareKey()
return compareKey;
public void setCompareKey(int newCompareKey)
compareKey = newCompareKey;
public int getCategory()
return category;
public void setImageFileName(String newFileName)
imageFileName = newFileName;
public String getImageFileName()
return imageFileName;
public void setCategory(int newCategory)
category = newCategory;
public String getDescription()
return description;
public void setDescription(String newDescription)
description = newDescription;
public void setImageArray(String[] array)
imageArray = new String[20];
for (int n = 0; n<array.length; n++)
imageArray[n] = array[n];
public void setImagePathArray(String[] array)
imagePathArray = new String[20];
for (int n = 0; n<array.length; n++)
imagePathArray[n] = array[n];
public String getImagePathArray(int index)
return imagePathArray[index];
public void populateComboBox(JComboBox jcb)
for (int n = 0; n<numImages; n++)
jcb.addItem(imageArray[n]);
public void addImageToArray(String s)
imageArray[numImages] = s;
numImages++;
public String getMessage()
return message;
public void setMessage(String newMessage)
message = newMessage;
public GregorianCalendar getDueDateTime()
return dueDateTime;
public void setDueDateTime(int newYear, int newMonth, int newDay, int newHours, int newMins,
int newSecs)
dueDateTime = new GregorianCalendar(newYear, newMonth, newDay, newHours, newMins, newSecs);
public GregorianCalendar getReminderInterval()
return reminderInterval;
public void setReminderInterval(int newYear, int newMonth, int newDay, int newHours, int newMins,
int newSecs)
reminderInterval = new GregorianCalendar(newYear, newMonth, newDay, newHours, newMins, newSecs);
public GregorianCalendar getTerminatedDateTime()
return terminatedDateTime;
public void setTerminatedDateTime(int newYear, int newMonth, int newDay, int newHours, int newMins,
int newSecs)
terminatedDateTime = new GregorianCalendar(newYear, newMonth, newDay, newHours, newMins, newSecs);
public String getStatus()
return status;
public void setStatus(String selection)
status = selection;
static public void setShowDate(boolean state)
showDate = state;
static public boolean getShowDate()
return showDate;
static public void setShowCategory(boolean state)
showCategory = state;
static public boolean getShowCategory()
return showCategory;
static public void setShowImageName(boolean state)
showImageName = state;
statYou don't really expect us to read through 300 lines of code do you?
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.
In the meantime I suggest you read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html]How to Use Combo Boxes for a working example that does exactly what you want. -
IC won't update with simple ABAP statements
Hi,
I am trying to analyze an update rule. The standard rule has all the IF and ELSE statements, so I took them out. I then put only theses statement
RESULT = COMM_STRUCTURE-DLV_QTY.
RETURNCODE = 0.
ABORT = 0.
For some reason the IC will not update. I check the PSA and RSA3, and there are values for this field DLV_QTY.
What else should I do to check why the IC wouldn't update?
ThanksHi,
in the request monitor, select a datapackage, right click on it and select simulate update. In the following popup you can select what to debug, UR or TR as well as the no. of records to be used for debugging.
Just Try by Hard Coding in your Update Routine with BREAK-POINT.
1. Find the Activated Program which you can in the Update rules -> Extras -> Activated Program will give you the activated program. Go to SE38 and display the program and place a soft break-point in the program from where you want to Debug.
2. Go to the monitor, load the data using the psa. Once Loaded go into the details tab of the monitor (Right Hand Side) and right click on the Datapackage and click on Simulate update.
3. In the new screen, click on the update rules and activate debugging in update rules and click on simulation which ill take u into the program press F8 until u get the Break-point which you would have placed.
There are two methods of debugging update routines.
1. Debugging with Soft break point
2. Debugging with Hard break points
1. If you are in production envirnoment and client is not modifiable, it is not possible to hard code 'Break-Point' statement in the update routine. So you need to load data in PSA and from monitor need to go to processing of data package and then you can select routine which is to be debugged from the debuge window 'overview' tab.
2. Debugging with Hard break points is insertion of break-point statement in the code prior to the statement where debugging is to be started. Rest procedure remains same as explain above.
It is important to remove break point statement once debugging is over . Else it will give short dumps while loading data in foreground.
Regards,
Hareesh -
Update using a select statement How to?
Greetings
I have a table of customer records that has a unique customer number.
I have another table that has multiple entries for each customer record number reflecting updates over time.
Each time a change is made a new record is inserted and a change date field is set to the current date.
I want to get the oldest change date inserted into a field in the master Customer table.
I have attempted a number of different queries. i was wondering if someone might be able to point to my failings.
This query gets the value that i want.
select BI_ACCT_CODE, min(bi_date_chng) from gen_bitaccttable group by BI_ACCT_CODE
61638538 29/JUL/04
61638547 29/MAY/04
61638556 30/JUL/04
61638565 29/OCT/11
61638574 29/JUL/05
61638583 29/JUL/89
61638592 29/JUL/05
61638609 29/JUL/06
etc.............
BI_ACCT_CODE is the customer number that exists in both tables.
This is the current state of my query.
update CDM_CUSTOMER
set CUS_REGISTRATIONDATE =( select BI_ACCT_CODE ,min(bi_date_chng) from gen_bitaccttable
group by BI_ACCT_CODE where gen_bitaccttable.BI_ACCT_CODE = CDM_CUSTOMER.CUS_SEQNO);
This complains with the following error.
Error starting at line 147 in command:
update CDM_CUSTOMER set CUS_REGISTRATIONDATE =( select BI_ACCT_CODE, min(bi_date_chng) from gen_bitaccttable group by BI_ACCT_CODE where gen_bitaccttable.BI_ACCT_CODE = CDM_CUSTOMER.CUS_SEQNO)
Error at Command Line:147 Column:118
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
ThanksThanks for responding.
I modified it to:
update CDM_CUSTOMER set CUS_REGISTRATIONDATE =( select min(bi_date_chng) from gen_bitaccttable group by BI_ACCT_CODE where gen_bitaccttable.BI_ACCT_CODE = CDM_CUSTOMER.CUS_SEQNO)
This still gives the error.
Error starting at line 153 in command:
update CDM_CUSTOMER set CUS_REGISTRATIONDATE =( select min(bi_date_chng) from gen_bitaccttable group by BI_ACCT_CODE where gen_bitaccttable.BI_ACCT_CODE = CDM_CUSTOMER.CUS_SEQNO)
Error at Command Line:153 Column:118
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action: -
Problem with my select statement
Dear buddies,
Really seeking someone to guide me in this sql issue.
Here is the scenario.
- should check for the number of prospects(to be customers) downloaded from a file for every dealer based on the
region
description about columns shown
1st column, region
2nd column, dealer code
3rd column, number of prospect received
4th column, the percentage of conversion
5th column, i must order by the 4th column and select the top 20 percentage and take its average.
sample data
region dealer_code no. of no of % of % of Comparing with
prospect prospect prospect Top 20 top 20 conversion
received converted conversion Conversion
A dealer 1 150 50 33% 56% Red
dealer 2 100 40 40% 56% Red
dealer 3 120 60 50% 56% Red
130 70 54% 56% Red
200 20 10% 56% Red
B 140 60 43% 56% Red
110 60 55% 56% Red
100 60 60% 56% Green
130 69 53% 56% Red
140 75 54% 56% Red
D 110 40 36% 56% Red
100 30 30% 56% Red
140 74 53% 56% Red
100 70 70% 56% Green
110 65 59% 56% Green
E 130 85 65% 56% Green
150 65 43% 56% Red
150 70 47% 56% Red
160 95 59% 56% Green
170 100 59% 56% Green
F 200 150 75% 56% Green
100 65 65% 56% Green
120 40 33% 56% Red
140 80 57% 56% Green
150 85 57% 56% Green
Legend (for the sample data)
when % of prospect conversion > % of top 20 conversion, then green
when % of prospect conversion = % of top 20 conversion, then yellow
when % of prospect conversion < % of top 20 conversion, then red
NOTE
i have a few more columns after this, but if i know how to fix these columns, i can manage them too.
here is my sql
select a.dealer_region,
a.dealer_code,
count(b.id) as "No of Prospect Received",
COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end) "No of Prospect Converted to Booking",
(COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%')"%of Prospect Conversion" ,
((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/20 )* 100 || '%')"% Top 20 Conversion",
/*(avg((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%'))
(case when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100) > ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100)
then 'Green'
when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100) = ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <5)
then b.id end)
/ 20 )* 100)
then 'Yellow'
else
'Red'
end) "Comparison with Top 20 Convers",
/* i can handle this part if the sql given above is solved */
COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code)
then b.id end) "#of Lead ConvertedC",
(COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%')"%of Lead ConversionC",
((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100 || '%')"% Top 20 ConversionC",
/* (avg((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%'))
(case when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100) > ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100)
then 'Green'
when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100) = ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100)
then 'Yellow'
else
'Red'
end) "Comparison with Top 20 ConverC"
from dealers a, prospect_list b, files c, marketing_details e, customer f
where b.file_id = c.file_uid
and c.dealer_code = a.dealer_code
and b.id = e.id
and e.id = f.id
group by a.dealer_region, a.dealer_code; hope someone can help me out.
i actually can change the count(d.dealer_code) to 20 and solve the problem but what if they are less than 20 dealers in the table?
because the table will be refreshed every morning with new data and the unnecessary one will be removed.
it works fine now when i divide it by 20.
pls advice
thanks
alagu
Edited by: user645399 on Jul 1, 2009 7:49 PM
Edited by: user645399 on Jul 1, 2009 7:56 PM
Edited by: user645399 on Jul 1, 2009 8:14 PM
Edited by: user645399 on Jul 1, 2009 10:20 PMHope this helps. First rank all the rows. Then find the average for the top3 using CASE statement
LPALANI@l11gr2>select ename, sal, dense_rank() over (order by sal desc) dr,
2 avg(sal) over() avg_sal_all
3 from scott.emp;
ENAME SAL DR AVG_SAL_ALL
KING 5,000 1 2,073
FORD 3,000 2 2,073
SCOTT 3,000 2 2,073
JONES 2,975 3 2,073
BLAKE 2,850 4 2,073
CLARK 2,450 5 2,073
ALLEN 1,600 6 2,073
TURNER 1,500 7 2,073
MILLER 1,300 8 2,073
WARD 1,250 9 2,073
MARTIN 1,250 9 2,073
ADAMS 1,100 10 2,073
JAMES 950 11 2,073
SMITH 800 12 2,073
14 rows selected.
LPALANI@l11gr2>
LPALANI@l11gr2>select ename, sal,
2 avg(case when dr <=3 then sal end) over () avg_sal_top,
3 count(case when dr <=3 then 1 end) over() cnt_of_top3_earners,
4 avg_sal_all,
5 dr
6 from (select ename, sal, dense_rank() over (order by sal desc) dr, avg(sal) over() avg_sal_all from scott.emp);
ENAME SAL AVG_SAL_TOP CNT_OF_TOP3_EARNERS AVG_SAL_ALL DR
KING 5,000 3,494 4 2,073 1
FORD 3,000 3,494 4 2,073 2
SCOTT 3,000 3,494 4 2,073 2
JONES 2,975 3,494 4 2,073 3
BLAKE 2,850 3,494 4 2,073 4
CLARK 2,450 3,494 4 2,073 5
ALLEN 1,600 3,494 4 2,073 6
TURNER 1,500 3,494 4 2,073 7
MILLER 1,300 3,494 4 2,073 8
WARD 1,250 3,494 4 2,073 9
MARTIN 1,250 3,494 4 2,073 9
ADAMS 1,100 3,494 4 2,073 10
JAMES 950 3,494 4 2,073 11
SMITH 800 3,494 4 2,073 12 -
Pl/sql function body returning SQL query - if with in select statement
hello all,
I have a condition where when summary field is checked alone we have show that column for the users in the report. Is IF statement possible for this case ? I have given the code below.. is it possible to write something like below or is there any other way to do it ?
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,';
v_sql := v_sql ||' TBLCASES.CASENUMBER as CASENUMBER,';
v_sql := v_sql ||' TBLCASES.OPENDATE as OPENDATE,';
v_sql := v_sql ||' TBLCASES.ESTCOMPLETE as TARGETDATE,';
v_sql := v_sql ||' TBLCASES.STATUS as STATUS,';
v_sql := v_sql ||' TBLCASES.CASECODE as CASECODE,';
v_sql := V_sql ||' TBLCASES.FAIR_HOTLINE as FAIRHotline,';
v_sql := v_sql ||' TBLCASES.NYSIG as NYSIGCase,';
v_sql := v_sql ||' TBLCASES.REGION as Region,';
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_sql := v_sql||' TBLCASES.SUMMARY as SUMMARY,';
END IF ;
v_sql := v_sql ||' TBLCASES.PROGAREA as PROGArea ';
v_sql := v_sql ||' from TBLCASES where 1=1';
..\Hi Lucy,
You are adding and removing a column from a report so it may help to have the extra on the end of the query.
Do you get an error? If so paste it in...
BUT - this I would put a condition on the column where ':P44_INCLUDE_SUMMARY_FIELD is not null '
Under he report's "Column Attributes" Select the column edit icon and it has a "Condition" breadcrumb.
Select "Value of Item in Expression 1 is Not Null" and put P44_INCLUDE_SUMMARY_FIELD in Expression 1 text area.
And I make it more readable like this when I do dynamic SQL:
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_INCLUDE_SUMMARY_FIELD := ' TBLCASES.SUMMARY as SUMMARY ';
END IF ;
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,
TBLCASES.CASENUMBER as CASENUMBER,
TBLCASES.OPENDATE as OPENDATE,
TBLCASES.ESTCOMPLETE as TARGETDATE,
TBLCASES.STATUS as STATUS,
TBLCASES.CASECODE as CASECODE,
TBLCASES.FAIR_HOTLINE as FAIRHotline,
TBLCASES.NYSIG as NYSIGCase,
TBLCASES.REGION as Region,
TBLCASES.PROGAREA as PROGArea,'||
v_INCLUDE_SUMMARY_FIELD ||
'from TBLCASES where 1=1; ';
Hope it helps,
BC -
Can I query with a select statement in the from statement
I'm working with an application that creates a MASTERTABLE that keeps track of DATATABLEs as it creates them. These data tables are only allowed to be so big, so the data tables are time stamped. What I need to do is to be able to query the MASTERTABLE to find out what the latest datatable is and then query the specific datatable.
I've tried
select count(*) from (select max(timestamp) from mastertable)
and it always comes back with a count of 1.
Is this possible, or is there a better way?Well, I'm trying to understand... and if I understand, then you need something dynamic. I did create the following example, of course not exactly as yours (I don't have your data). Each employee has a table with his name, containing the sal history, and I want to query that table starting from actual sal :
SCOTT@db102 SQL> select ename from emp where sal= 3000;
ENAME
SCOTT
FORD
SCOTT@db102 SQL> select * from scott;
SAL_DATE SAL
01-JAN-85 2500
01-JAN-95 2750
01-JAN-05 3000
SCOTT@db102 SQL> set serveroutput on
SCOTT@db102 SQL> declare
2 v_rc sys_refcursor;
3 tname varchar2(30);
4 v_date date;
5 v_sal number;
6 begin
7 select max(ename) into tname
8 from emp
9 where sal = 3000;
10 open v_rc for 'select * from '||tname;
11 loop
12 fetch v_rc into v_date,v_sal;
13 exit when v_rc%notfound;
14 dbms_output.put_line(v_date||' '||v_sal);
15 end loop;
16* end;
SCOTT@db102 SQL> /
01-JAN-85 2500
01-JAN-95 2750
01-JAN-05 3000
PL/SQL procedure successfully completed.
SCOTT@db102 SQL>
Maybe you are looking for
-
Can't drag files into folders in PDF portfolio
I have created a PDF portfolio that contains primarily PDFs converted from e-mail messages, along with a few files from various Microsoft Office products. The portfolio has been added to over time, and now we have almost 100 files in the portfolio, s
-
Mapping Errors Log file to be sent via FTP
Hi All, Functional specs of a file to file scenario require to create an aditional log file containing the file name, creation date and a list with the lines were a problem occurred with an error description and then send it to R3 via FTP. Does anyon
-
Uploading flash, how much is too large?
Hi, I am trying to create a web site suing adobe Dreamweaver and flash, for the first time. I am trying to upload a webpage that contains swf. When I check mu site I could only see a blank page with the webpage title at the top of the page. When I co
-
Jsf 1s phase of life cycle how knows ths components of the jsp with jsf tag
i wish to know how faces servlet knows the jsp s view components while creaTI NG component tree at first request to input jsp which may have jsf tags.in the first phase faces servlet doesnot know input jsp with jsf tags what componnets it has. it is
-
Am I able to use multiple trials?
I don't have enough money to get even 1 month of membership of the app I like. Am I able to use multiple trials on it?