Catch in Loop w/o exiting loop.
Hi,
I'm performing a LOOP at table. ENDLOOP. Within the loop I have a TRY. ENDTRY. CATCH. This is so I can perform a arithmatic statement and catch any errors. The problem is, if an error occurs it exits the LOOP. I don't want to exit the entire LOOP statement. I just want to continue on with the next record in my internal table. But instead, the loop is exited.
Any ideas?
Example code:
LOOP AT t_pcts ASSIGNING <wa_pcts>.
TRY.
<wa_pcts>-percent = <wa_pcts>-expprod / <wa_pcts>-actprod.
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
ENDLOOP.
Hi,
check if your program is activated. TRY CATCH in LOOP works fine.
For my program:
DATA gt_vbrp TYPE TABLE OF vbrp WITH HEADER LINE.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
LOOP AT gt_vbrp.
TRY.
gt_vbrp-fkimg = 100 / gt_vbrp-fkimg.
CATCH cx_root.
WRITE: / 'Exception'.
ENDTRY.
WRITE: / sy-tabix.
ENDLOOP.
I get correct result:
Exception
1
Exception
2
Exception
3
Program does not interrupt the loop.
Regards,
Przemysław
Similar Messages
-
How can I Catch the program to prevent exit all?
Hi,
I am actually implementing a Ptolemy GUI for my subject. And I am now facing a very serious problem. I build an application to call the Ptolemy application to probe up a plotting graph program. Every time after I call the run Simulation() the program call the plotting from Ptolemy, but when I press close from the plotting, everything close including all applications that are not expected to close.
The problem I think is located here:
PtolemyApplication exec_model = new PtolemyApplication(argument);
So I would like to know how can I catch its exit to avoid closing everything.
Can anyone give me suggestion please?
below are the method I call:
public void runSimulation()
try{
File file = new File("default.xml");
DataOutputStream out =
new DataOutputStream(new FileOutputStream(file));
SimGraphWriter writer = new SimGraphWriter();
boolean checkAllConnected;
checkAllConnected = writer.write(graphpane.getGraphModel(),
graphpane.getGraphView(),currDirector, out);
if(checkAllConnected){
("//d/Ptolemyii/ptII0.4/ptII0.4beta/bin/ptolemy.bat ./default.xml");
String argument[] = {"default.xml"};
try {
PtolemyApplication exec_model =
new PtolemyApplication(argument);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this.dispose();
catch(Exception ex) {
System.out.println(ex);
ex.printStackTrace();
catch(Exception ex){
System.out.println(ex);
ex.printStackTrace();
}Thread is an object that u create just like String /or whatever eg;-
Thread firstThread, secondThread, thirdThread;
once they're declared u can stop, start + run them individually with boolean values (true /false) and therefore control what u want to do when.
Play with the code examples + mess around with it - it's not absolute beginner stuff - but it isn't that tough either -
Urgent: How can I catch the exception when application exit by accident
Can anyone give me advice and idea?
I want to catch the exception when application goes down by accident for example: Power off, turn off the machine without closing the appliction properly.
Because I want to notify the server and remove it from register.
How can I do this????
Please help,
Thanks very mich,
PeterShrubz,
I tested my application as follows:
1. start rmiregistry
2. start rmi server
3. start two clients
I printed out the client's object information as below:
first clinet:
RemoteObserver is com.ss8.qos.qcsm.policy.policyui.PanelMain_Stub[RemoteStub [ref: [endpoint:[192.168.70.237:4706](remote),objID:[-73a6662b:e75af455a5:-8000, 0]]]]
second client:
RemoteObserver is com.ss8.qos.qcsm.policy.policyui.PanelMain_Stub[RemoteStub [ref: [endpoint:[192.168.70.237:4711](remote),objID:[-73a6665a:e75af48703:-8000, 0]]]]
Now I stop the second client by clicking ^C (ctrl c)
I noticed that this client has not been removed from the server register (Vector).
next, I am working on first client for example add one record. After server received this record, it will update all clients who have already registered with server. Because now in the server register there are two clinets (first and second), so it will try to update two clients. The exception will be thrown when server tries to update second client which has already been stoped. I used printStackTrace() to print out the message as follow:
Catch ConnectException
Connection refused to host: 192.168.70.237; nested exception is:
java.net.ConnectException: Connection refused: no further information
java.rmi.ConnectException: Connection refused to host: 192.168.70.237; nested exception is:
java.net.ConnectException: Connection refused: no further information
java.net.ConnectException: Connection refused: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:125)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:112)
at java.net.Socket.<init>(Socket.java:269)
at java.net.Socket.<init>(Socket.java:98)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:29)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:124)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:497)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:194)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:178)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:87)
at com.ss8.qos.qcsm.policy.policyui.PanelMain_Stub.update(PanelMain_Stub.java:53)
at com.ss8.qos.qcsm.policy.policydb.Observable.performNotify(Observable.java, Compiled Code)
at com.ss8.qos.qcsm.policy.policydb.Observable.notifyObservers(Observable.java:71)
at com.ss8.qos.qcsm.policy.policydb.PolicyServer.ServerAddPolicy(PolicyServer.java:102)
at java.lang.reflect.Method.invoke(Native Method)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:237)
at sun.rmi.transport.Transport$1.run(Transport.java:140)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:137)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:422)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:634)
at java.lang.Thread.run(Thread.java:479)
*** end here ***
I don't see any information related to object ID. How can I handle this?
Please give me suggestion.
Many Thanks,
Peter -
Hi All,
I am using a third party tool which is internally calling System.exit sometimes and my application
got terminated most of the times.
It is happening always when i call a particular method of that third party tool.
Is there any way to catch or avoid the System.exit while using the particular method?
I need this urgently...Please kindly help.....
Thanks,
J.KathirThere's a fair bit to it, and you should refer to the appropriate java Tutorials. Bascially you create a .policy file and install a sercurity manager with:
System.setSecurityManger(new SecurityManager());The policy file grants a set of permissions to various "code sources", basically each codesource is a classpath entry. You could grant "AllPermissions" to your own code, and a more restricted set of permissions to the application you're running. But you can't subtract permissions, i.e. you can't say "this code can do anything except call System.exit().
I doubt this is going to provide you with a good solution. It's tiresome to set up, and when the client app called System.exit it would crash, which might not result in a clean status.
I'd consider if you should be using this client app in the same JVM, rather than creating a subordinate JVM using Runtime.exec. -
hi all, im quite new to java and am having a bit of trouble with a try catch statement
try
System.out.println("Enter your level: ");
level = data.nextInt();
while (!VLevel(level))
System.out.println("Enter your level: ", LEVEL);
dstfloor = read_in.nextInt();
catch(InputMismatchException exception)
System.err.println("Invalid level");
continue;
the problem i have is that when it triggers the exception, it just repeats the 'invalid level' line infinitely. any ideas?
thanksIf this line is causing an exception: dstfloor = read_in.nextInt();Then dstfloor's value will not change.
Because you are using continue in the catch, the loop will run unfinately with dstfloor having the same value.
You will need to modify the dstfloor var either in the catch or in the finally.
Edited by: Azzer_Mac on Apr 24, 2008 9:08 AM -
Pocket slow down after exit application
Hi,
I have an application that runs normally in a Pocket PC, Windows Mobile 2003, 64 MB RAM. But when i exit application, the Pocket almost freezes ! Sometimes I need to inicialize Pocket again.
I exit my application this way:
ConnectDB.disconnect();
try{
Config.getClientSocket().getSocket().close(); //Finish Socket connection with server application
}catch(IOException e){
MsgDialog msg = new MsgDialog(this, true, "Falha ao encerrar conex�o ", MsgDialog.MSG_WARNING);
msg.dispose();
new Thread(){
public void run(){
try{
sleep(400);
}catch(InterruptedException e){
}.start();
System.exit(0); I have two threads I've created running at this moment. Could it be a problem for Pocket performance after exit application ?
Thanks !Hi,
I have an application that runs normally in a Pocket PC, Windows Mobile 2003, 64 MB RAM. But when i exit application, the Pocket almost freezes ! Sometimes I need to inicialize Pocket again.
I exit my application this way:
ConnectDB.disconnect();
try{
Config.getClientSocket().getSocket().close(); //Finish Socket connection with server application
}catch(IOException e){
MsgDialog msg = new MsgDialog(this, true, "Falha ao encerrar conex�o ", MsgDialog.MSG_WARNING);
msg.dispose();
new Thread(){
public void run(){
try{
sleep(400);
}catch(InterruptedException e){
}.start();
System.exit(0); I have two threads I've created running at this moment. Could it be a problem for Pocket performance after exit application ?
Thanks ! -
Regarding SavIng of reports output into appl. or presentation server
Hello Everyone I am working on ALE IDoc I am getting my output in forms of XML. I want to save my reports output directly to presentation server or application server (i have neither any flat file on desktop nor any file on application server).
I have following codes which convert my Idoc into XML:
*& Report ZIDOC_XML_CONVERSION
report ZIDOC_XML_CONVERSION.
types: TRESLIN(4096) type X,
TRESTAB type standard table of TRESLIN.
data: RESSTR type ref to IF_IXML_OSTREAM.
data: RESTAB type TRESTAB.
data: XSLTP type ref to CL_XSLT_PROCESSOR.
data: G_IXML type ref to IF_IXML,
G_STREAM_FACTORY type ref to IF_IXML_STREAM_FACTORY,
DIR type STRING.
data: IDOC type ref to CL_IDOC_XML1.
data: PROGNAME type CXSLTDESC.
data: STR type STRING.
data: XSTR type XSTRING.
data: RESSIZE type I.
data: ID type EDI_STYLE.
data GLOBAL_DOCNUM type EDI_DOCNUM.
data GLOBAL_STYLEID type EDI_STYLE.
data: GLOBAL_OK_CODE(30).
data: HTML_CONTROL type ref to CL_GUI_HTML_VIEWER.
data: FCODE_WA(30).
data: FCODE_TAB type standard table of CHAR30.
data: MS_DEFAULT_STYLE type EDI_STYLE.
data: SAP_DEFAULT_STYLE type EDI_STYLE.
data: SAP_TEXT_STYLE type EDI_STYLE.
data: SAP_CONTEXT_STYLE type EDI_STYLE.
data: TEXT_MS_DEFAULT_STYLE(30).
data: TEXT_SAP_DEFAULT_STYLE(30).
data: TEXT_SAP_TEXT_STYLE(30).
data: TEXT_SAP_CONTEXT_STYLE(30).
data ACTION like SY-UCOMM.
parameters: IDOCNUM like EDIDC-DOCNUM,
IDSTYLE type EDI_STYLE,
ACTIONS type EDI_STFLAG.
class CL_IXML definition load.
class CL_ABAP_CHAR_UTILITIES definition load.
class CL_GUI_FRONTEND_SERVICES definition load.
class CL_GUI_HTML_VIEWER definition load.
data: CONTAINER type ref to CL_GUI_CUSTOM_CONTAINER.
data: REPID like SY-REPID, DYNNR like SY-DYNNR.
data: WA_OBJ_LOCATION type IDOCSTYLE.
data: LOCAL_XSLID type EDI_STYLE.
data: BASE_URL(30).
data: DATA_TABLE type TAB_RAW512.
data: LEN type I.
data: UI_FLAG type I.
data: MYEVENT_TAB type CNTL_SIMPLE_EVENTS,
MYEVENT type CNTL_SIMPLE_EVENT.
data: LOCAL_STYLEID type EDI_STYLE.
data: PARENT type ref to CL_GUI_CONTAINER.
data: LINE type I.
data: WA_SRC type STRUCT_SRC.
data: LOCAL_EDIDC type EDIDC.
data: TAB_OBJ_LOCATION type standard table of IDOCSTYLE .
data: GEN_EX type ref to CX_XSLT_EXCEPTION.
data: SRCSTR type ref to IF_IXML_ISTREAM.
*load-of-program.
try.
create object XSLTP.
catch CX_XSLT_EXCEPTION.
write / TEXT-E01. exit. " XSLT not supported
endtry.
G_IXML = CL_IXML=>CREATE( ).
G_STREAM_FACTORY = G_IXML->CREATE_STREAM_FACTORY( ).
DIR = ''.
call method CL_GUI_FRONTEND_SERVICES=>GET_TEMP_DIRECTORY
changing
TEMP_DIR = DIR.
*start-of-selection.
GLOBAL_DOCNUM = IDOCNUM.
GLOBAL_STYLEID = IDSTYLE.
get parameter id 'IDOC_STYLEID' field GLOBAL_STYLEID.
if GLOBAL_STYLEID is initial.
GLOBAL_STYLEID = 'IE5'.
endif.
clear FCODE_TAB.
clear GLOBAL_OK_CODE.
clear ACTION.
we only support action "deletemark" + "closeproce"
if ACTIONS ' X X '.
FCODE_WA = 'DELM'.
append FCODE_WA to FCODE_TAB.
FCODE_WA = 'CLPR'.
append FCODE_WA to FCODE_TAB.
endif.
Create Object and create IDOC_XML
create object IDOC
exporting
DOCNUM = IDOCNUM
exceptions
ERROR_LOADING_IDOC = 1
ERROR_BUILDING_XML = 2
others = 3.
if SY-SUBRC 0.
message id SY-MSGID type 'E' number SY-MSGNO
with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
raising NO_IDOC_XML_LOADED.
endif.
Determine transformation program.
clear TAB_OBJ_LOCATION.
select * from IDOCSTYLE into table TAB_OBJ_LOCATION
where ( STYLEID = GLOBAL_STYLEID or STYLEID = '' )
and ( MESTYP = LOCAL_EDIDC-MESTYP or MESTYP = '')
and ( DIRECT = LOCAL_EDIDC-DIRECT or DIRECT = '')
and OBJNR = 0.
describe table TAB_OBJ_LOCATION lines LINE.
if LINE > 0.
loop at TAB_OBJ_LOCATION into WA_OBJ_LOCATION.
move WA_OBJ_LOCATION-URL to PROGNAME.
clear WA_OBJ_LOCATION.
exit.
endloop.
else.
message E110(IDOC_XML1) with LOCAL_XSLID WA_OBJ_LOCATION-URL
raising ERROR_LOADING_OBJECT.
endif.
Transformation
call method IDOC->GET_XMLDATA_AS_STRING
importing
DATA_STRING = STR.
RESSTR = G_STREAM_FACTORY->CREATE_OSTREAM_ITABLE( TABLE = RESTAB )
RUN
try.
call transformation (PROGNAME)
source xml STR
result xml RESSTR.
catch CX_XSLT_EXCEPTION into GEN_EX.
message E110(IDOC_XML1) with LOCAL_XSLID WA_OBJ_LOCATION-URL
raising ERROR_LOADING_OBJECT.
exit.
endtry.
write : / STR.
I am getting following output:
<?xml version="1.0"?><RSREQUST><IDOC BEGIN = "1"><EDI_DC40 SEGMENT="1"><TABNAM><![CDATAEDI_DC40]></TABNAM><M
i want to save this output on my application server or presentation server, my data is not on presentation server or in application server, its on form of output and i want to save my output directly to application server or presentation server.hope that you people will help me out please reply me for this query.
Thanks & Regards
Vimarsh B.Hello Subhash,
Try this
data: sheet TYPE ole2_object.
data: lv_file(512) default 'C:tst.xls'.
* Save excel speadsheet to particular filename
GET PROPERTY OF h_excel 'ActiveSheet' = sheet.
CALL METHOD OF sheet 'SaveAs'
EXPORTING
#1 = lv_file "filename
#2 = 1. "fileFormat -
Submit Report as an attachement Excel via mail
Hi,
I want to send an email with the result of report O4B1 as attachment Excel with columns separated in Excel.
Best regards.REPORT YJAJUR_EMAILOPTIONS .
tables: kna1.
data: begin of it_kna1 occurs 0," with header line,
kunnr like kna1-kunnr,
land1 like kna1-land1,
name1 like kna1-name1,
end of it_kna1.
data: w_sender like somlreci1-receiver.
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
data: it_mess_att like solisti1 occurs 0 with header line,
gd_attachment_desc type sopcklsti1-obj_descr.
data: gd_subject like sodocchgi1-obj_descr,
it_mess_bod like solisti1 occurs 0 with header line,
gd_sender_type like soextreci1-adr_typ,
gd_attachment_name type so_obj_des.
select-options: p_email for w_sender no intervals.
PARAMETER mailid TYPE adr6-smtp_addr NO-DISPLAY.
data : it_kna2 type kna1 occurs 0 with header line.
select kunnr
land1
name1
from kna1 into table it_kna1 .
select * from kna1 into table it_kna2.
concatenate 'EMSIL OPTIONS DONE BY sANTOSH.s.jAJU' 'MODEL WISE upto' Into gd_attachment_desc separated by space.
concatenate 'Custmer' 'custmer name' 'custmer land1' con_tab into
it_mess_att separaTED BY con_tab.
CONCATENATE con_cret it_mess_att INTO it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
*loop at p_email.
*endloop.
data: i1 type string.
perform email.
loop at p_email.
i1 = i1 + 1.
concatenate 'email' ':' i1 space p_email-low into it_mess_bod.
it_mess_bod = p_email-low..
APPEND it_mess_bod.
clear it_mess_bod.
perform send_mail.
endloop.
perform display_data..
*& Form email
text
--> p1 text
<-- p2 text
FORM email .
loop at it_kna2.
concatenate con_cret it_kna2-kunnr con_tab
it_kna2-name1 con_tab it_kna2-land1 into it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
endloop.
ENDFORM. " email
*& Form send_mail
text
--> p1 text
<-- p2 text
FORM send_mail .
DATA: send_request TYPE REF TO cl_bcs,
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO cl_cam_address_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
lt_tab TYPE TABLE OF makt,
lt_fields TYPE TABLE OF w3fields,
lt_html TYPE TABLE OF w3html.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type sopcklsti1-obj_descr,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
MOVE P_EMAIL TO MAILID.
SELECT * FROM makt UP TO 10 ROWS INTO TABLE lt_tab WHERE spras = 'E'.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
TABLES
html = lt_html[]
fields = lt_fields
itable = lt_tab.
TRY.
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_html
i_subject = 'Table' ).
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( MAILID ).
send_request->add_recipient( EXPORTING i_recipient = recipient
i_express = 'X' ).
send_request->set_send_immediately( 'X' ).
send_request->send( EXPORTING i_with_error_screen = 'X'
RECEIVING result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
EXIT.
ENDTRY.
ld_email = p_email-low.
ld_mtitle = gd_attachment_desc.
ld_format = 'XLS'.
ld_attdescription = gd_attachment_desc.
concatenate gd_attachment_desc '.XLS' into ld_attfilename.
ld_attfilename = p_filename.
ld_sender_address = w_sender.
ld_sender_address_type = 'INT'.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
clear w_doc_data.
read table it_mess_att index 1.
w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( it_mess_att ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = gd_attachment_desc.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_mess_bod lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
describe table it_mess_att lines t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
Add the recipients email address
clear t_receivers.
refresh t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
append t_receivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
packing_list = t_packing_list
contents_bin = it_mess_att
contents_txt = it_mess_bod
receivers = t_receivers
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
wait up to 5 seconds.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
ENDFORM. " send_mail
*& Form display_data
text
--> p1 text
<-- p2 text
FORM display_data .
loop at it_kna2.
write:/ it_kna2-kunnr,it_kna2-land1,it_kna2-name1.
endloop.
ENDFORM. " display_data
ref this code i guess this will works -
PrintWriter not working !!
import java.io.*;
public class FileDemo {
public static void main(String args[]) {
if (args.length != 1) {
System.out.println("Must enter text to write to file");
return;
try {
PrintWriter myWriter = new PrintWriter(new BufferedWriter(new FileWriter("myfile.xyz")),true);
catch (Exception e) {
// handle exception here
String myString = args[0];
myWriter.println(myString);
myWriter.close();
}I can't understand why this won't compile :
FileDemo.java:30: cannot find symbol
symbol : variable myWriter
location: class FileDemo
myWriter.println(myString);
^
FileDemo.java:32: cannot find symbol
symbol : variable myWriter
location: class FileDemo
myWriter.close();
^
2 errors
cheersYes - any variable declared inside a block is only good for that
block.
It's sort of logical: after all, variables declared in a method
don't "leak" out of the method's block and become visible
to other methods.
In the same way you are free to create "throwaway" variables like counters in a for loop. They won't be visible - and hence won't cause
problems - outside of the block containing the loop.
In the case of try/catch blocks it may be a bit more subtle. Suppose
you were allowed to declare a variable inside a try/catch block
and use it later outside. Now an error could occur and be caught
before the variable had been initialised (or even declared). If the
"catch" bit doesn't actually exit the method you would be left with
references to something that hasn't been initialised. This is sure
to cause problems! - or at least it would except that Java never
allows this to happen.
The rule followed has the virtue of being simple: a variable is visible
in and only in the block where it's declared (including sub blocks). -
Send an smartform as body of a mail
Hello,
I would like know if there is another way of doing this: "Send an smartform as body of a mail". Now it is sending attached as pdf but the user prefers to view the smartform on the body of the message.
This is a CS formulary and I think that (perhaps) at the options of "output_options TYPE ssfcompop," should be another of this.
ThanksI have included our code to process/send our smartform via email. you should be able to see the solution in there.....
form process_webform
* activate XSF Output Mode
ls_output_options-xsf = c_charx. " XSF Output active
ls_output_options-xsfcmode = c_charx. " Get XSF params from program
ls_output_options-xsfoutmode = c_application. " Application
ls_output_options-xsfformat = c_charx. " Formatting ON
clear ls_output_options-xsfoutdev.
ls_xsfparam_line-name = 'GRAPHICS'.
ls_xsfparam_line-value = 'EXTRACT'.
append ls_xsfparam_line to ls_output_options-xsfpars.
ls_xsfparam_line-name = 'GRAPHICS-DIRECTORY'. "#EC NOTEXT
ls_xsfparam_line-value = c_gr_dir.
append ls_xsfparam_line to ls_output_options-xsfpars.
ls_xsfparam_line-name = 'CONTENT-ID'. "#EC NOTEXT
ls_xsfparam_line-value = 'ENABLE'. "#EC NOTEXT
append ls_xsfparam_line to ls_output_options-xsfpars.
* silent mode ON
ls_output_options-tdimmed = space.
ls_output_options-tdnewid = space.
ls_control_parameters-no_dialog = c_charx.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = pi_form
importing
fm_name = l_fm_name
exceptions
no_form = 1
no_function_module = 2
others = 3.
if sy-subrc <> 0.
* error handling
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
call function l_fm_name
exporting
control_parameters = ls_control_parameters
output_options = ls_output_options
user_settings = space
importing
job_output_info = ls_output_data
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5.
if sy-subrc <> 0.
* error handling
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
po_html = ls_output_data-xmloutput-trfresult.
po_t_graphics = ls_output_data-xmloutput-xsfgr.
endform. "process_webform
form send_webform
clear l_html_xstr.
loop at pi_s_html-content into l_html_raw.
concatenate l_html_xstr l_html_raw into l_html_xstr in byte mode.
endloop.
l_html_xstr = l_html_xstr(gs_html_data-length).
call function 'SCP_TRANSLATE_CHARS'
exporting
inbuff = l_html_xstr
incode = '4110' " utf-8
csubst = c_charx
substc_space = c_charx
importing
outbuff = l_html_str
outused = l_html_len
exceptions
others = 1.
if sy-subrc ne 0.
"do nothing
endif.
* change encoding utf-8 to latin1
replace all occurrences of 'utf-8' in l_html_str with 'latin1' ignoring case.
replace all occurrences of 'absolute' in l_html_str with 'relative' ignoring case.
replace all occurrences of 'overflow : auto'
in l_html_str with 'overflow : hidden' ignoring case.
* The following code will replace the standard text shown in an html link
* such as (www.sap.com) with the text passed along with the link (contained in
* brackets [ ] ). An example would be: "www.sap.com[Click me]" will then be
* displayed as a link on the email with "... Click me ..." as the text. HTML links
* without brackets will be displayed normally (ie. www.sap.com)+
do.
* Get the length for the entire HTML code for the URL and Name
find '<a href="' in section offset l_aref_end of l_html_str match offset l_aref_start.
if sy-subrc ne 0.
exit.
endif.
find '</a>' in section offset l_aref_start of l_html_str match offset l_aref_end.
l_aref_length = ( l_aref_end + 4 ) - l_aref_start.
* Find the URL/name
l_lnk_start = l_aref_start + 9.
find '">' in section offset l_aref_start of l_html_str match offset l_lnk_end.
l_lnk_length = l_lnk_end - l_lnk_start.
* Save the URL/name
l_link_all = l_html_str+l_lnk_start(l_lnk_length).
* Find where the name starts and ends
find '[' in l_link_all match offset l_name_start.
if sy-subrc ne 0.
continue.
endif.
find ']' in l_link_all match offset l_name_end.
if sy-subrc ne 0.
continue.
endif.
* Seperate out the URL
l_link_url = l_link_all+0(l_name_start).
* Seperate out the name
l_name_start = l_name_start + 1.
l_name_length = l_name_end - l_name_start.
l_link_name = l_link_all+l_name_start(l_name_length).
* Replace the first URL/Name occurence with just the URL
replace first occurrence of l_link_all
in section offset l_aref_start length l_aref_length
of l_html_str with l_link_url.
* Replace the second URL/Name occurence with just the Name - first
* substitute special characters.
replace all occurrences of '&' in l_link_all with '&'.
replace all occurrences of '>' in l_link_all with '>'.
replace all occurrences of '<' in l_link_all with '<'.
replace first occurrence of l_link_all
in section offset l_aref_start length l_aref_length
of l_html_str with l_link_name.
* Reset ending point
l_aref_end = l_aref_end - ( l_lnk_length + 2 ).
enddo.
l_html_len = strlen( l_html_str ).
l_offset = 0.
l_length = 255.
while l_offset < l_html_len.
l_diff = l_html_len - l_offset.
if l_diff > l_length.
ls_soli-line = l_html_str+l_offset(l_length).
else.
ls_soli-line = l_html_str+l_offset(l_diff).
endif.
append ls_soli to lt_soli.
add l_length to l_offset.
endwhile.
create object lo_mime_helper.
call method lo_mime_helper->set_main_html
exporting
content = lt_soli.
loop at pi_t_graphics into gs_graphic.
clear l_gr_xstr.
loop at gs_graphic-content into l_gr_raw.
concatenate l_gr_xstr l_gr_raw-line into l_gr_xstr in byte mode.
endloop.
l_gr_xstr = l_gr_xstr(gs_graphic-length).
l_offset = 0.
l_length = 255.
clear lt_solix[].
while l_offset < gs_graphic-length.
l_diff = gs_graphic-length - l_offset.
if l_diff > l_length.
ls_solix-line = l_gr_xstr+l_offset(l_length).
else.
ls_solix-line = l_gr_xstr+l_offset(l_diff).
endif.
append ls_solix to lt_solix.
add l_length to l_offset.
endwhile.
concatenate c_gr_dir gs_graphic-graphics '.bmp' into l_filename.
concatenate c_gr_dir gs_graphic-graphics '.bmp' into l_content_id.
l_content_type = gs_graphic-httptype.
l_obj_len = gs_graphic-length.
call method lo_mime_helper->add_binary_part
exporting
content = lt_solix
filename = l_filename
extension = 'BMP'
content_type = l_content_type
length = l_obj_len
content_id = l_content_id.
endloop.
try.
l_standard_txt = pi_smartform.
call function 'READ_TEXT'
exporting
id = 'ST'
language = sy-langu
name = l_standard_txt
object = 'TEXT'
tables
lines = lt_lines.
read table lt_lines into ls_lines index 1.
replace '&1' in ls_lines-tdline with pi_belnr.
replace '&2' in ls_lines-tdline with pi_bukrs.
move ls_lines-tdline to l_subject.
lo_doc_bcs = cl_document_bcs=>create_from_multirelated(
i_subject = l_subject
i_multirel_service = lo_mime_helper ).
* Add Attachment
* types: begin of email_docs,
* type type so_obj_tp,
* subject type so_obj_des,
* content_text type soli_tab,
* content_hex type solix_tab,
* end of email_docs.
* types: email_docs_t type standard table of email_docs.
* data: documents type email_docs_t,
* documents_line like line of documents.
* data: soli_tab type soli_tab,
* soli type soli.
* soli = 'This is line one'.
* append soli to soli_tab.
* soli = 'And this is line two'.
* append soli to soli_tab.
* documents_line-type = 'RAW'.
* documents_line-subject = 'Subject'.
* documents_line-content_text = soli_tab.
* append documents_line to documents.
* call method lo_doc_bcs->add_attachment
* EXPORTING
* i_attachment_type = documents_line-type
* i_attachment_subject = documents_line-subject
* i_att_content_text = documents_line-content_text.
catch cx_document_bcs.
* error handling
exit.
catch cx_bcom_mime.
* error handling
exit.
catch cx_gbt_mime.
* error handling
exit.
endtry.
* create send_request
try.
lo_bcs = cl_bcs=>create_persistent( ).
catch cx_send_req_bcs.
* error handling
exit.
endtry.
try.
lo_bcs->set_document( i_document = lo_doc_bcs ).
catch cx_send_req_bcs.
* error handling
exit.
endtry.
* create recipient
if pi_recipient ns '@'.
l_username = pi_recipient.
translate l_username to upper case. "#EC *
try.
lo_recipient = cl_sapuser_bcs=>create( l_username ).
catch cx_address_bcs.
* error handling
exit.
endtry.
else.
l_mail_address = pi_recipient.
try.
lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = l_mail_address ).
catch cx_address_bcs.
* error handling
exit.
endtry.
endif.
try.
lo_bcs->add_recipient( i_recipient = lo_recipient ).
catch cx_send_req_bcs.
* error handling
exit.
endtry.
* send
try.
* RECEIPTS ONLY FOR ERRORS
call method lo_bcs->send_request->set_requested_status
exporting
i_requested_status = 'N'. "#EC NOTEXT
lo_bcs->send( ).
commit work.
catch cx_send_req_bcs.
* error handling
exit.
endtry.
endform. "send_webform -
Class CL_BCS Query for body part of mail
HI,
I want to send the mail with out attachement using Class CL_BCS. Can any body help me on how to send the message body in the mail using CL_BCS class....
Thanx & Regards,
SameerHi Sameer
I've been struggling with this class CL_BCS too for a while and I want to give my experience with that class. Following a code example which will submit a report to memory and send the report as an attachment by mail thru the SMTP interface.
*& Report ZOBR_SEND_TRIP_SIM_BY_MAIL *
*& This program does following:
*& 1. Submit a travel expense report to memory
*& 2. Read the travel expense report from memory
*& 3. Convert the travel expense report to HTML format
*& 4. Copy the travel expense report from format RAW(1000) to RAW(255)
*& 5. Send an email with body text and attachtments
REPORT zobr_send_trip_sim_by_mail .
DATA:
gi_abaplist TYPE TABLE OF abaplist,
gi_html TYPE w3htmltab,
gs_html LIKE LINE OF gi_html,
gw_string TYPE string,
gw_length TYPE i,
gw_length_c TYPE so_obj_len,
gi_solix TYPE solix_tab,
gs_solix LIKE LINE OF gi_solix,
gi_soli TYPE soli_tab,
gs_soli LIKE LINE OF gi_soli,
go_send_request TYPE REF TO cl_bcs,
go_document TYPE REF TO cl_document_bcs,
go_sender TYPE REF TO cl_sapuser_bcs,
go_recipient TYPE REF TO if_recipient_bcs,
go_exception TYPE REF TO cx_bcs.
* Submit report to memory
SUBMIT rprtef00 "USER sy-uname
EXPORTING LIST TO MEMORY AND RETURN
WITH pnppernr EQ '00001000'
WITH pnptimra EQ 'X'
WITH pnpxabkr EQ 'D2'
WITH pnppabrp EQ '11'
WITH pnppabrj EQ '2006'
WITH s_reisen EQ '0002600221'
WITH hinz_dru EQ space
WITH hinz_weg EQ space
WITH hinz_dyn EQ 'X'
WITH allesdru EQ 'X'
WITH reisepro EQ 'X'
WITH reisetxt EQ 'X'
WITH sw_antrg INCL 'X'
WITH addinfo EQ 'X'
WITH extperio EQ '000'
WITH simulate EQ space
WITH einkopf EQ space.
* Read report from memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = gi_abaplist
EXCEPTIONS
not_found = 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.
* Convert report to HTML format
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
* EXPORTING
* REPORT_NAME =
* TEMPLATE_NAME = 'WEBREPORTING_REPORT'
TABLES
html = gi_html
listobject = gi_abaplist.
LOOP AT gi_html INTO gs_html.
CONCATENATE gw_string
gs_html
INTO gw_string.
ENDLOOP.
gw_length = STRLEN( gw_string ).
gw_length_c = gw_length.
* copy table from format raw(1000) to raw(255)
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = gi_abaplist
out = gi_solix.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
TRY.
* Create persistent send request
go_send_request = cl_bcs=>create_persistent( ).
* Create document (body text in text format)
gs_soli = 'Trip is now settled, see attachment.'.
APPEND gs_soli TO gi_soli.
gs_soli = 'Reimbursement is paid out by your next salary.'.
APPEND gs_soli TO gi_soli.
go_document = cl_document_bcs=>create_document( i_type = 'RAW'
i_text = gi_soli
i_subject = 'Trip reimbursement' ).
* Add attachment (ABAP list format)
CALL METHOD go_document->add_attachment
EXPORTING
i_attachment_type = 'ALI'
i_attachment_subject = 'Expense report(ALI)'
i_att_content_hex = gi_solix.
* Add attachment (HTML format)
CALL METHOD go_document->add_attachment
EXPORTING
i_attachment_type = 'HTM'
i_attachment_subject = 'Expense report(HTM)'
i_att_content_text = gi_html.
* Add note (Text format)
CALL METHOD go_send_request->set_note( gi_soli ).
* Add document to send request
CALL METHOD go_send_request->set_document( go_document ).
* Get sender object
go_sender = cl_sapuser_bcs=>create( sy-uname ).
* Add sender
CALL METHOD go_send_request->set_sender
EXPORTING
i_sender = go_sender.
go_recipient = cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
* Add recipient with its respective attributes to send request
CALL METHOD go_send_request->add_recipient
EXPORTING
i_recipient = go_recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
* set send immediately flag
go_send_request->set_send_immediately( 'X' ).
* Send document
CALL METHOD go_send_request->send( ).
COMMIT WORK.
* Exception handling
CATCH cx_bcs INTO go_exception.
EXIT.
ENDTRY.
Notice that the only way to put a body text in the email is to call the method cl_document_bcs=>create_document with input of a type 'RAW'.
Be aware of the settings of the SMTP node in SAPConnect (transaction SCOT) because the seetings could cource an unwanted conversion of the email.
1. Doubbelclick on the TMTP node and a popup screen will show.
2. Click on the 'Set' button next to 'Internet' under 'Supported address type' and a popup screen will show.
3. Set output format for SAP documents as 'SAPscript/Smart forms' = 'PDF', 'ABAP list' = 'PDF', 'RAW text' = 'TXT'.
This setting will convert 'SAPscript/Smartforms', 'ABAP list' to PDF format. If 'RAW text' = 'PDF' the body text wil be converted to 'PDF' format and change to an attachment and the body text will disappear.
Hope this is usefull for you and others.
Best regards
Ove Bryntesson
Applicon A/S -
-5002 error ("No Data ") when adding record to a UserTable
B1 2007A
Here's my code. I've stripped it about as far as I could to try and solve this problem... but I must be missing something. Basically, I referenced the UIDIBasicApp for the UserTables portion.
In the "PopulateUserTable" subroutine, where I attempt to add the record with:
lngRetCode = objUserTable.Add()
... lngRetCode comes back as "-5002". The error message is "No Data ".
I've added records with the same data into the table through B1 User-Defined Windows and it accepts the data without a problem. I've been re-checking the code, and searching the forums and the help file since last week, and I haven't found any reference to a problem like this.
Any ideas? Thanks!
Module Module1
Public WithEvents objSboApp As SAPbouiCOM.Application
Public WithEvents objSboCompanyDi As SAPbobsCOM.Company
Public Sub Main()
ConnectUI()
ConnectDI()
CreateUserTable("TP_WhereUsed")
PopulateUserTable("TP_WhereUsed")
End Sub
Public Function ConnectUI()
Dim objSboUiApi As SAPbouiCOM.SboGuiApi
objSboUiApi = New SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"
objSboUiApi.Connect(sConnectionString)
objSboApp = objSboUiApi.GetApplication
End Function
Public Function ConnectDI()
objSboCompanyDi = New SAPbobsCOM.Company
Try
objSboCompanyDi = objSboApp.Company.GetDICompany()
Catch
objSboApp.MessageBox(Err.Description)
Exit Function
End Try
End Function
Public Sub CreateUserTable(ByVal TableName As String)
Dim lngRetCode As Long
Dim lngErrCode As Long
Dim strErrMsg As String
Dim oUserTablesMD As SAPbobsCOM.UserTablesMD
oUserTablesMD = objSboCompanyDi.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
oUserTablesMD.TableName = TableName
oUserTablesMD.TableDescription = TableName
lngRetCode = oUserTablesMD.Add
If lngRetCode <> 0 Then
Select Case lngRetCode
Case Is = -2035
'Table already exists.
Exit Sub
Case Else
objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)
objSboApp.MessageBox("Error - Table not created: " & strErrMsg)
End Select
Else
objSboApp.SetStatusBarMessage("Table: " & oUserTablesMD.TableName & " was added successfully", SAPbouiCOM.BoMessageTime.bmt_Short, False)
End If
End Sub
Private Sub PopulateUserTable(ByVal TableName As String)
Dim lngRetCode As Long, lngErrCode As Long, strErrMsg As String
Dim strCode As String, strName As String, intArrayCounter As Integer
Dim objUserTable As SAPbobsCOM.UserTable
objUserTable = objSboCompanyDi.UserTables.Item(TableName)
intArrayCounter = 0
Do Until intArrayCounter > 10
strCode = "Code" & CStr(intArrayCounter)
strName = "Name" & CStr(intArrayCounter)
lngRetCode = objUserTable.Code = strCode
lngRetCode = objUserTable.Name = strName
lngRetCode = objUserTable.Add()
intArrayCounter = intArrayCounter + 1
objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)
Loop
End Sub
End ModuleHi
Try your code with the lines I've added to the code of your CreateUserTable function. Hope it works!
Public Sub CreateUserTable(ByVal TableName As String)
Dim lngRetCode As Long
Dim lngErrCode As Long
Dim strErrMsg As String
Dim oUserTablesMD As SAPbobsCOM.UserTablesMD
oUserTablesMD = objSboCompanyDi.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
oUserTablesMD.TableName = TableName
oUserTablesMD.TableDescription = TableName
lngRetCode = oUserTablesMD.Add
If lngRetCode <> 0 Then
Select Case lngRetCode
Case Is = -2035
'Table already exists.
Exit Sub
Case Else
objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)
objSboApp.MessageBox("Error - Table not created: " & strErrMsg)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
oUserTablesMD = Nothing
GC.Collect() ' free occupied resource
End Select
Else
objSboApp.SetStatusBarMessage("Table: " & oUserTablesMD.TableName & " was added successfully", SAPbouiCOM.BoMessageTime.bmt_Short, False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
oUserTablesMD = Nothing
GC.Collect() ' free occupied resource
End If
End Sub -
New to sockets. How to implement multithreaded servers?
I have been reading the JAVA tutorial, but can't get a simple "echo" threaded server working here:
EchoServerThread.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class EchoServerThread extends Thread{
private Socket s;
public EchoServerThread(Socket socket){
super("EchoServerThread");
this.s=socket;
public void run(){
try {
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String rline;
while((rline=in.readLine())!=null){
/*if(rline.equalsIgnoreCase("exit")) {
out.println("exit");
break;
out.println(rline);
in.close();
out.close();
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}EchoServer.java
import java.io.IOException;
import java.net.ServerSocket;
public class EchoServer {
public static void main(String[] args) {
ServerSocket ssoc = null;
try {
ssoc = new ServerSocket(4444);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
while(true)
try {
new EchoServerThread(ssoc.accept()).run();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}EchoClient.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class EchoClient {
public static void main (String [] args){
try {
Socket soc = new Socket("localhost",4444);
PrintWriter out = new PrintWriter(soc.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
BufferedReader stdIn= new BufferedReader(new InputStreamReader(System.in));
String rline;
while((rline=stdIn.readLine())!=null){
out.println(rline);
//System.out.println("written: "+rline);
/*String fromServer = in.readLine();
if(fromServer.equals("exit")){
System.out.println("Server is going down....");
System.out.println("fuck");
break;
else{*/
System.out.println("echo: "+in.readLine());
in.close();
out.close();
stdIn.close();
soc.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(2);
}What happens, is that the server only accepts another connection after a client dies. If I do some input on the 2nd opened client ( the 1st is still beeing served) it produces no output until the 1st one ends, then it produces all the correct output.Hi,
it's just an idea that has come to my mind rigth now while eating my pizza, probably a big mistake. You could try to flush the BufferedReader cause maybe it remains blocked in this while((rline=in.readLine())!=null){
/*if(rline.equalsIgnoreCase("exit")) {
out.println("exit");
break;
out.println(rline);
}while loop. Just an idea though, probably it's wrong!
JoY?TiCk -
I'm getting desperate for a solution to this problem (as is the rest of the development team!).
Basically we've been trying to create a system that automatically assigns values (frequencies) to objects (nodes) based on a rule set. Each node contains a varying number of sub-objects (radios) and each radio needs one frequency. The database has been set up and has test data for our Solution class to go through. However, we've run into an odd problem where our ResultSets are suddenly closing.
The classes work like this:
Database Broker (handles connection to DB, as well as executeQuery and executeUpdate statements.)
Entry Broker (Holds all SQL statements for data retrieval in various methods. Each method contains an SQL statement to access data, and code to format that data into something useable by the main class.
Solution/Main class (Contains methods to use the data from the Entry Broker to test valid solutions. Certain rules apply to assigning frequencies to radios and this class ensures that the data applies to these rules before it writes the data back to the DB (via the EntryBroker).
The problem we continually run into is that whilst the ResultSets work fine in the Entry Broker, they are closed when they return to the Main class.
Here's the catch: It seems in most cases that only the FIRST ResultSet returned in each method is closed, the remaining ResultSets work fine. We worked around this problem by creating a 'dummy' ResultSet, which obtained data from the database which was never used (the project name). We put this in its own try catch bracket so it would not interrupt the project.
It worked fine for a few classes, but for others (notably the following one) it was ineffective. We've searched and searched but we cannot find anyone with a similar complaint (except a few people who have commented about ODBC version problems). Our ODBC version is 3.520.7713.0
Here's an example method from the Solution class (The entire class is over 1000 lines):
// Method to test Harmonic resonance for nodes within 10m
private boolean resonanceGlobal (boolean tstResonanceG, double txFreq, double rxFreq, int distance) {
System.out.println("Beginning global harmonic resonance check");
try {
// Getting Nodes
rsNode2 = eBroker.getNodes(projectNo);
// node loop
while (rsNode2.next()) {
System.out.println("602 Test Marker GHarm 1");
// get next node, store in nodeTemp
nodeTemp = rsNode2.getInt(1);
// System out to show which nodes will pass if statement
System.out.println(node + " compare to " + nodeTemp);
// avoid testing the same node against itself
if (nodeTemp != node) {
// distance check (only neccesary within 10m)
System.out.println("Test Marker Before Distance check");
distance = getDistance(node, nodeTemp, distance);
System.out.println("Test Marker After Distance check");
// distance check if statement
if (distance <= 10) {
System.out.println("618 Test Marker GHarm 2");
// get the radios of the node, foreign node
rsRadiosTemp = eBroker.getRadios(node);
rsDummy = eBroker.getDummy(projectNo);
rsRadios2 = eBroker.getRadios(nodeTemp);
// This dummy ResultSet normally fails so that
// the other ResultSets perform normally
try {
rsDummy.next();
} // end try
catch (java.sql.SQLException dummyException) {
System.out.println("dummyException " + dummyException);
} // end catch
// radio loop
while (rsRadiosTemp.next()) { // error occurs here
System.out.println("627 Test Marker GHarm 3");
// loop for foreign node radios
while (rsRadios2.next()) {
System.out.println("631 Test Marker GHarm 4");
// get next radio
radioTemp = rsRadios2.getInt(1);
// get the TX and RX of the radio
genericTX = getTX(radioTemp);
radioTempCon = getConnection(radioTemp);
genericRX = getTX(radioTempCon);
// calculate bounds for harmonics test
txLo = ((txFreq * 2) - genericTX) - 4; // 4Mhz below TX harmonics check
txHi = ((txFreq * 2) - genericTX) + 4; // 4Mhz above TX harmonics check
rxHi = ((rxFreq * 2) - genericRX) + 4; // 4Mhz above RX harmonics check
rxLo = ((rxFreq * 2) - genericRX) - 4; // 4Mhz below RX harmonics check
// checks TX and RX of foreign radio against TX, RX of current radio for separation
if ((txLo > genericTX && txHi < genericTX) || (rxLo > genericRX && rxHi < genericRX)) {
tstResonanceG = false;
break;
} //end if
else {
tstResonanceG = true;
} // end else
} //end foreign radio loop
// breaking out of loops for return
if (tstResonanceG == false)
break;
} // end radio loop
rsRadios2.close();
rsRadiosTemp.close();
} // end sameradio check
} // end distance check
}// end node loop
rsNode2.close();
} // end try
// Catch statement to stop from crashing in the
// event of an error during SQL statements.
catch (java.sql.SQLException resonanceGlobalException) {
// Prints out the error message produced
System.out.println(resonanceGlobalException);
} // end catch
// returns result
return tstResonanceG;
} //end checkHarmonicResonanceGlobal()
My apologies if it is a little hard to read, but the indenting is accurate. The Entry Broker methods which this method uses are here:
public ResultSet getNodes (int projectNo) {
// creating SQL statement
sqlStatement = "SELECT nodeNo from tblNode WHERE projectNo = " + projectNo;
System.out.println(sqlStatement);
// executing SQL statement
rsNodes = db.runQuery(sqlStatement);
// returns ResultSet
return rsNodes;
} // end getNodes
// Method to get the distance between any two nodes
public int getDistance (int projectNo, int node, int tempNode) {
ResultSet rsX1; // Used for obtaining the X-coord of node 1
ResultSet rsX2; // Used for obtaining the X-coord of node 2
ResultSet rsY1; // Used for obtaining the Y-coord of node 1
ResultSet rsY2; // Used for obtaining the Y-coord of node 2
double distance = 0; // Used in Global checks
int dist = 0; // Used in Global checks
int x1 = 0; // Used in calculating distance
int x2 = 0; // Used in calculating distance
int y1 = 0; // Used in calculating distance
int y2 = 0; // Used in calculating distance
int xDist = 0; // Used in calculating distance
int yDist = 0; // Used in calculating distance
int distint = 0; // Used to store converted values
try {
// get the X and Y co-ordinates of both nodes
sqlStatement = "SELECT xCoord FROM tblNode WHERE nodeNo = " + node + " AND projectNo = " + projectNo;
rsX1 = db.runQuery(sqlStatement);
rsX1.next();
x1 = rsX1.getInt(1);
sqlStatement = "SELECT yCoord FROM tblNode WHERE nodeNo = " + node + " AND projectNo = " + projectNo;
rsY1 = db.runQuery(sqlStatement);
rsY1.next();
y1 = rsY1.getInt(1);
sqlStatement = "SELECT xCoord FROM tblNode WHERE nodeNo = " + tempNode + " AND projectNo = " + projectNo;
rsX2 = db.runQuery(sqlStatement);
rsX2.next();
x2 = rsX2.getInt(1);
sqlStatement = "SELECT yCoord FROM tblNode WHERE nodeNo = " + tempNode + " AND projectNo = " + projectNo;
rsY2 = db.runQuery(sqlStatement);
rsY2.next();
y2 = rsY2.getInt(1);
} // end try
catch (java.sql.SQLException getDistanceException) {
System.out.println(getDistanceException);
// calculating distance
yDist = y2 - y1;
xDist = x2 - x1;
// perform pythagoras theorem for distance
dist = (xDist * xDist) + (yDist * yDist);
distance = java.lang.Math.sqrt(dist);
Double roundFreqTemp = new Double(freqTemp);
distint = roundFreqTemp.intValue() ;
return distint;
} // end get distance method
// Method to get all the radios in a node
public ResultSet getRadios(int node) {
ResultSet rsRadios; // Used for obtaining radios in a node
// creating sql Statement
sqlStatement = "SELECT * FROM tblRadio WHERE nodeNo =" + node;
System.out.println(sqlStatement);
// executing sql Statement
rsRadios = db.runQuery(sqlStatement);
System.out.println("EB Test Marker 1: Line 261");
// returning radio no
return rsRadios;
}//end getRadio
public double getTX(int radioTemp){
double txTemp = 0; // Used for storing TX of a radio
int freqNoTemp = 0; // Used for storing the frequency ID
rsDummy = getDummy(projectNo);
// creating SQL statement
sqlStatement ="Select frequencyNo from tblRadio where radioNo = " + radioTemp;
System.out.println(sqlStatement);
// executing SQL statement
rsTX = db.runQuery(sqlStatement);
try {
System.out.println("Test Marker EB1: 317");
try {
rsDummy.next();
} // end try
catch (java.sql.SQLException dummyException) {
System.out.println("dummyException" + dummyException);
} // end catch
System.out.println("Test MarkerEB2: 330");
// moving to first position in rs
rsTX.next();
System.out.println("Test MarkerEB3: 334");
// obtaining data from rs
freqNoTemp = rsTX.getInt(1);
System.out.println("Test MarkerEB4: 337");
rsTX.close();
} // end try
catch (java.sql.SQLException rsTXException) {
System.out.println("rsTXExeption: " + rsTXException);
} // emd catch
System.out.println("Frequency No is: " + freqNoTemp);
rsDummy = getDummy(projectNo);
sqlStatement = "Select frequency from tblFreq where frequencyNo = " + freqNoTemp;
System.out.println(sqlStatement);
rsRX = db.runQuery(sqlStatement);
try {
try {
System.out.println("Test MarkerEB6: 361");
rsDummy.next();
} // end try
catch (java.sql.SQLException dummyException) {
System.out.println("dummyException" + dummyException);
} // end catch
System.out.println("Test MarkerEB5: 373");
rsRX.next();
System.out.println("Test MarkerEB7: 376");
txTemp = rsRX.getDouble(1);
System.out.println("Test MarkerEB8: 379");
rsRX.close();
} // end try
catch (java.sql.SQLException rxException) {
System.out.println("rxException " + rxException);
} // end catch
System.out.println("393 Before return");
return txTemp;
} //end getTX
public int getConnection(int radio) {
int nodeCon = 0; // Used to return the connected node no
ResultSet rsConnection; // Used for obtaining the foreign radio
// creating SQL statement
sqlStatement = "SELECT radioNo FROM tblRadio where recRadio = " + radio;
System.out.println(sqlStatement);
// executing SQL statement
rsConnection = db.runQuery(sqlStatement);
try {
// moving to first position in rs
rsConnection.next();
// obtaining data from rs
nodeCon = rsConnection.getInt(1);
} // end try
catch (java.sql.SQLException getConnectionException) {
System.out.println("getConnectionException : " + getConnectionException);
} // end catch
// returns node no.
return nodeCon;
And finally, the dummy rs:
// Dummy method to fix resultSet closed error
public ResultSet getDummy (int projectNo) {
sqlStatement = "Select projectName from tblProject where projectNo = " + projectNo;
System.out.println(sqlStatement);
rsDummy = db.runQuery(sqlStatement);
return rsDummy;
Here is some sample output that we have:
----jGRASP exec: java MainGui
slider value constructor: 50
116: if(singleton==null) {
120: singleton=new Resolvotron
Connection to D/Base establised
Select projectName from tblProject where projectNo = 3
Init OK. Beginning solve process
main OK: beginning frequency assign process
SELECT nodeNo from tblNode WHERE projectNo = 3
267: Node number = 2
SELECT * FROM tblRadio WHERE nodeNo =2
EB Test Marker 1: Line 261
Test Marker 1: Line 289
298: Radio number = 4
Test Marker 5: Line 308
Test Marker 3: Line 313
SELECT frequency from tblFreq WHERE projectNo = 3
125.5
Beginning test process
Test Marker 4: Line 386
Beginning check 257072
Test Marker 6: Line 774
70 Mhz Margin = false
Beginning local 10Mhz separation check
SELECT * FROM tblRadio WHERE nodeNo =2
EB Test Marker 1: Line 261
Getting TX of radio: 4
Select projectName from tblProject where projectNo = 3
Select frequencyNo from tblRadio where radioNo = 4
Test Marker EB1: 317
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB2: 330
Test MarkerEB3: 334
Test MarkerEB4: 337
Frequency No is: 2
Select projectName from tblProject where projectNo = 3
Select frequency from tblFreq where frequencyNo = 2
Test MarkerEB6: 361
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB5: 373
Test MarkerEB7: 376
Test MarkerEB8: 379
393 Before return
432: getting connection
SELECT radioNo FROM tblRadio where recRadio = 4
438: getting TX of radio: 6
Select projectName from tblProject where projectNo = 3
Select frequencyNo from tblRadio where radioNo = 6
Test Marker EB1: 317
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB2: 330
Test MarkerEB3: 334
Test MarkerEB4: 337
Frequency No is: 2
Select projectName from tblProject where projectNo = 3
Select frequency from tblFreq where frequencyNo = 2
Test MarkerEB6: 361
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB5: 373
Test MarkerEB7: 376
Test MarkerEB8: 379
393 Before return
java.sql.SQLException: ResultSet is closed
10 Mhz Local = true
Beginning 10 Mhz separation check
SELECT nodeNo from tblNode WHERE projectNo = 3
Node number is 2
10 Mhz Global = false
Beginning local harmonic resonance check
SELECT * FROM tblRadio WHERE nodeNo =2
EB Test Marker 1: Line 261
Select projectName from tblProject where projectNo = 3
Select frequencyNo from tblRadio where radioNo = 4
Test Marker EB1: 317
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB2: 330
Test MarkerEB3: 334
Test MarkerEB4: 337
Frequency No is: 2
Select projectName from tblProject where projectNo = 3
Select frequency from tblFreq where frequencyNo = 2
Test MarkerEB6: 361
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB5: 373
Test MarkerEB7: 376
Test MarkerEB8: 379
393 Before return
SELECT radioNo FROM tblRadio where recRadio = 4
Select projectName from tblProject where projectNo = 3
Select frequencyNo from tblRadio where radioNo = 6
Test Marker EB1: 317
dummyExceptionjava.sql.SQLException: ResultSet is closed
Test MarkerEB2: 330
Test MarkerEB3: 334
Test MarkerEB4: 337
Frequency No is: 2
Select projectName from tblProject where projectNo = 3
Select frequency from tblFreq where frequencyNo = 2
Test MarkerEB6: 361
I'll leave it at that, since the program goes into an endless loop. The dummy Exceptions are our dummy resultsets crashing so the rest can survive. The other stuff is from different methods. You should be able to locate the logic of the program by following the System.outs
Test Markers with EB refer to the Entry Broker.
Any help would be appreciated since we cannot find any other way of running this class successfully.
SteveOk problem solved...
Basically I was calling one ResultSet after another. Thanks to the Database Broker's structure, this was killing the first ResultSet. I fixed up the loops so that ResultSets were only ever called just before they were needed, and it fixed the problem. The only other errors were simple logic faults which I drummed out in short order. Thanks for the help everyone! -
Hi Guys,
Ive recently placed a new Infinity 2 order, porting from a TalkTalk ADSL service.
When I placed the order I did not have my TalkTalk MAC code, however I received this on Sunday via email.
When I go into the ordertracking page to input the MAC code, the web page does not recodnise the code (I never get past Step 1 of whats indicated to be a 2 step process)
I called the 0800 number indicated on the BT welcome email, and gave the MAC code verbally to somone who spoke English as a second language. He appeared to struggle with the MAC code input as well, and after several attempts announced there seemed to be a systems problem, but it had finally gone through.
My issue is that when I look at the ordertracker today (48 hours after verbally being told the MAC code has been accepted) the order update still says that the MAC code is outstanding and no dates have been confirmed for installation.
Is this a problem, or does the ordertracker status always lag behind the status on any internal BT system?
Cheers,
JKW.So the plot thickens....
Ive talked to a UK BT agent who checked the order progress, and they confirmed that the MAC code is still outstanding.
I gave them the TalkTalk MAC code I was issued with, only to be told that its in the wrong format!
The issued MAC has the following format: XXXX1234567/XX12X.
However the BT portal is requesting the MAC in the following format: XXXX12345678/XX12X. So my TalkTalk MAC code is one digit short. BT asked me to go back to Talk Talk and request they check the MAC code issued is correct, which they have.
They also said the MAC code digits can be between 7-9 digits long.
I was also then told by Talk Talk that the MAC code for my current service is actually provided by BT themselves (I assume via Openreach?) as Im on a BT provided LLU service. In addition, I cant request for another MAC code until a full 30 days has elapsed from when the current one was issued.
My Infinity 2 order is currently still unconfirmed, awaiting MAC code.
Are there any BT moderators who can assist? I seem to be caught in a Catch 22 loop between BT and Talk Talk, with BT themself not recodnising the MAC code that they apparently issued to Talk Talk!
I just knew this would turn into a mare........
JKW.
Maybe you are looking for
-
WiFi issues after 3.1.1 upgrade
Hello, I've upgraded my iPod Touch. Now, I can't connect to any WiFi Network. I tried different AP vendors (Cisco, 3Com, DLINK) and security modes (Open, WEP,WPA,WPA2). I always get the same message: "No ha sido posible conectarse a la red "AP_NAME"
-
Free Characterstics working in First Tab but not rest of the tabs
Hi Experts, I am having a problem with my Web Application Designer Output, I have incorporated 3 Queries with 3 different Tab Strips and when I am executing this in the output for the First Tab Free Characters are working fine that is... when I drag
-
Printing labels. I need help
I am trying to print mailing labels from address book and it is printing the last name first. I have gone into preferences and changed the setting but it still won't work. Any ideas how to fix this?
-
Oracleasm RPMs not available at OTN for Kernel version 2.6.18-155
Hi, I have installed RHEL5.4, 64-bit. Oracleasm rpms are not present at OTN for kernel version 2.6.18-155.el5 (RHEL 5.4, 64-bit). I am referring to the following link: http://www.oracle.com/technetwork/server-storage/linux/downloads/rhel5-084877.html
-
NI Vision Video compression on-the-fly
Any ideas how to compress Video stream on-the-fly to 3-4 compressed video streams (high-quality, low, web...), built-in NI Vision filters are not good enough. FFDSHOW is not labview friendly, Quick-time is alright but requires complete AVI or go thro