Try catch implementation in dynamic query
I am fetching values by dynamic selection (select a,b,..from (var)...) .
Eveytime if I am selecting garbage value of var it will throw dump . Can u tell me how we implement try catch method / exception handling method so that I can avoid dump in dynamic query
Appropriate answer will rewarded with points that is for sure .
Here is the usage of th try statements ...
PARAMETERS number TYPE i.
DATA: result TYPE p LENGTH 8 DECIMALS 2,
oref TYPE REF TO cx_root,
text TYPE string.
TRY.
IF ABS( number ) > 100.
RAISE EXCEPTION TYPE cx_demo_abs_too_large.
ENDIF.
PERFORM calculation USING number
CHANGING result
text.
CATCH cx_sy_arithmetic_error INTO oref.
text = oref->get_text( ).
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
IF NOT text IS INITIAL.
WRITE / text.
ENDIF.
WRITE: / 'Final result:', result.
FORM calculation USING p_number LIKE number
CHANGING p_result LIKE result
p_text LIKE text
RAISING cx_sy_arithmetic_error.
DATA l_oref TYPE REF TO cx_root.
TRY.
p_result = 1 / p_number.
WRITE: / 'Result of division:', p_result.
p_result = SQRT( p_number ).
WRITE: / 'Result of square root:', p_result.
CATCH cx_sy_zerodivide INTO l_oref.
p_text = l_oref->get_text( ).
CLEANUP.
CLEAR p_result.
ENDTRY.
ENDFORM.
<b>please see this link for detailed explaination of the TRY & ENDTRY ...</b>
<a href="http://">http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm</a>
reward points if it is usefull......
Girish
Similar Messages
-
TRY CATCH with dynamic ORDER BY
Some stored procs need a dynamic ORDER BY, unfortunately.
Can I use a TRY CATCH with ORDER BY?
SELECT ...
FROM ...
WHERE...
BEGIN TRY
ORDER BY ...complex stuff
END TRY
BEGIN CATCH
ORDER BY ColumnA
END CATCHHi mmmtbig,
Syntactically, it is ok to use any valid sql statement in the TRY AND CATCH block.
SELECT 1 as num
BEGIN TRY
SELECT 1/0 AS seq UNION SELECT 2 ORDER BY seq;
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE();
SELECT 1 AS seq UNION SELECT 2 ORDER BY seq;
END CATCH
For more details, You can reference
TRY...CATCH.
The confusion about your question is the "dynamic ORDER BY". What do you mean by that, can you elaborate your requirement, like in what scenario you'd like to use the code block in your post and what issue have stopped you from doing that?
If you have any feedback on our support, please click
here.
Eric Zhang
TechNet Community Support -
How to get the returned error messages in the Try/Catch block in DS 3.0?
A customer sent me the following questions when he tried to implement custom error handling in DS 3.0. I could only find the function "smtp_to" can return the last few lines of trace or error log file but this is not what he wants. Does anyone know the answers? Thanks!
I am trying to implement the Try/Catch for error handling, but I have
hard time to get the return the msg from DI, so I can write it to out
custom log table.
Can you tell me or point me to sample code that can do this, also, can
you tell me which tables capture these info if I want to query it from
DI system tablesHi Larry,
In Data Services XI 3.1 (GAd yesterday) we made several enhancements for our Try/Catch blocks. One of them is the additional of functions to get details on the error that was catched :
- error_message() Returns the error message of the caught exception
- error_number() Returns the error number of the caught exception
- error_timestamp() Returns the timestamp of the caught exception.
- error_context() Returns the context of the caught exception. For example, "|Session Datapreview_job|Dataflow debug_DataFlow|Transform Debug"
In previous versions, the only thing you could do was in the mail_to function specify the number of lines you want to include from the error_log, which would send the error_log details in the body of the mail.
Thanks,
Ben. -
Returning a result set/record from a dynamic query
There seems to be plenty of examples for using Native Dynamic Sql to formulate and execute a dynamic query, however there are no examples of returning a result set or records which contain the rows of data that are retrieved by executing the query. Could someone give us an example?
Welcome to the Oracle forum....
CREATE OR REPLACE PACKAGE curspkg_join AS
TYPE t_cursor IS REF CURSOR ;
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);
END curspkg_join;
Create the following Oracle package body on the Oracle server:
CREATE OR REPLACE PACKAGE BODY curspkg_join AS
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
IS
v_cursor t_cursor;
BEGIN
IF n_EMPNO <> 0
THEN
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO
AND EMP.EMPNO = n_EMPNO;
ELSE
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;
END IF;
io_cursor := v_cursor;
END open_join_cursor1;
END curspkg_join;
Dim Oraclecon As New OracleConnection("Password=pwd;" & _
"User ID=uid;Data Source=MyOracle;")
Oraclecon.Open()
Dim myCMD As New OracleCommand()
myCMD.Connection = Oraclecon
myCMD.CommandText = "curspkg_join.open_join_cursor1"
myCMD.CommandType = CommandType.StoredProcedure
myCMD.Parameters.Add(New OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output
myCMD.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 123
Dim myReader As OracleDataReader
Try
myCMD.ExecuteNonQuery()
Catch myex As Exception
MsgBox(myex.Message)
End Try
myReader = myCMD.Parameters("io_cursor").Value
Dim x, count As Integer
count = 0
Do While myReader.Read()
For x = 0 To myReader.FieldCount - 1
Console.Write(myReader(x) & " ")
Next
Console.WriteLine()
count += 1
Loop
MsgBox(count & " Rows Returned.")
myReader.Close()
Oraclecon.Close()
The above code is working in one of our application; which is using ref cursor as result set and get from procedure. I hope you can found more code by google and/or search in this forum as well; if above code is not useful to you.
HTH
Girish Sharma -
Enhancing a Dynamic Query Object
Hi All,
I've added a new field to the contract header using the EEWB, I then added the field to an append on the dynamic query object BTQSrvCon. The entry in CRMC_REPDY and the BADI implementation of BADI CRM_RF_SEARCH_EEW have been created automatically.
This is working fine when I use the 'IS' separator on the search screen and enter the field exactly.
I would like to use the dynamic query separators (contains, starts with etc.) but when I try I get the error message
Search contains fields where wild card search is not allowed
Has anyone implemented this functionality?
Thanks,
GregorThe range operator is in the generated code:
method IF_EX_CRM_RF_SEARCH_EEW~EXTEND_RF_QUERY.
INCLUDE crm_object_names_con.
DATA: lv_fieldname TYPE name_komp,
ls_qupart LIKE LINE OF ct_quparts,
ls_qupart_and LIKE LINE OF ct_quparts,
ls_range_value TYPE crmt_bsp_range.
READ TABLE it_range_value INDEX 1
INTO ls_range_value.
IF sy-subrc <> 0.
RETURN.
ENDIF.
CHECK NOT ls_range_value-low IS INITIAL.
CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
EXPORTING
iv_token = 'AND'
IMPORTING
ev_qupart = ls_qupart_and-querypart.
lv_fieldname = flt_val.
CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
EXPORTING
iv_entityname = gc_objectname_reporting-ORDERADM_H
iv_fieldname = lv_fieldname
iv_token = 'RAN'
it_rangetab = it_range_value
IMPORTING
ev_qupart = ls_qupart-querypart.
APPEND ls_qupart TO ct_quparts.
APPEND ls_qupart_and TO ct_quparts.
endmethod.
I've put a break in the code which is not being triggered so something may be up with the BADI implementation. -
Dynamic query in where clause while looping in an internal table.
Hi,
Had a small question : How can i make a dynamic query for the WHERE clause while looping at an internal table.
i want to implement a dynamic where clause query for the below example.
it_cfx_col is an internal table and wa_cfx_col is a work area for it_cfx_col
DATA :
i_cfx_col TYPE TABLE OF cfx_col,
wa_cfx_col LIKE LINE OF i_cfx_col.
DATA : count TYPE i VALUE 0.
DATA : l_where_clause TYPE string,
l_where_clause2 TYPE string,
l_name type string.
l_name = 'NANDANOM'.
l_scenario = 'collaboration'.
LOOP AT it_cfx_col INTO wa_cfx_col
WHERE CREATED_BY = l_name
AND SCENARIO = l_scenario.
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
Now i want to write a dynamic query for the where clause.
DATA : count TYPE i VALUE 0.
DATA : l_where_clause TYPE string,
l_where_clause2 TYPE string,
l_name type string.
l_name = 'NANDANOM'.
l_scenario = 'collaboration'.
l_where_clause = 'CREATED_BY = l_name'.
l_where_clause2 = 'AND SCENARIO = l_scenario'.
if l_scenario is not initial.
CONCATENATE l_where_clause l_where_clause2
INTO l_where_clause SEPARATED BY space.
endif.
LOOP AT i_cfx_col INTO wa_cfx_col
WHERE (l_where_clause).
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
when i compile this i get an error message as { Statement concluding with "...(l_where_clause)" ended unexpectedly}
Even i changed the initilization of the variable l_where_clause2 to [ l_where_clause2 = 'AND SCENARIO = l_scenario.'. ]
added the end of line demarkation ".", but still i got the same error message.
Is it a limtation in ABAP that i cannot write a dynamic query for the where clause while looping at an internal table?
Regards,
omHi savita,
there in no such 1 limitaion in abap for dynamic query .. i think the error meassge is only beacuse of your synatx delcartaion.
>> LOOP AT i_cfx_col INTO wa_cfx_col
WHERE (l_where_clause).
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
afted delclarataion also , in the where statement you should specify both the field name and value bname
LOOP AT i_cfx_col INTO wa_cfx_col
WHERE l_where_clause = 'CREATED_BY = l_name' .
count = count + 1.
hope it helps.
regads
priya. -
Dynamic Query
When I run the following dynamic query in the stored procedure and try to build the report then I get the following error Rep:1401 Fatal PL/SQL error occured, Ora-00936 Missing expression. When I am generating the report standalone using the following query , everything is working fine but in Stored procedure , it's giving me the above error, pls help.
create or replace package REP_DELIVERY_LOC_STATISTICS is
TYPE REP_DELIVERY_LOC_STAT_rec IS RECORD(
p_coordinating_facility_id sis_education_pgm_session.coordinating_facility_id%TYPE,
p_PSE_MUNICIPALITY_ID pse_education_pgm_session.PSE_MUNICIPALITY_ID%TYPE,
p_pse_education_pgm_session_id sis_education_pgm_session.pse_education_pgm_session_id%TYPE,
p_course_session_id course_session.course_session_id%TYPE);
TYPE REP_DELIVERY_LOC_STAT_cur IS REF CURSOR RETURN REP_DELIVERY_LOC_STAT_rec;
Type REP_DELIVERY_LOC_STAT_cur_Dyn is REF CURSOR;
FUNCTION REP_DELIVERY_LOC_STATISTICS(p_college_id IN pse_education_pgm_session.delivery_institution_id%TYPE,
p_start_date IN pse_education_pgm_session.session_strt_dte%TYPE,
p_end_date IN pse_education_pgm_session.session_strt_dte%TYPE,
p_coord_facility_join IN varchar2) return REP_DELIVERY_LOC_STAT_cur_Dyn;
end REP_DELIVERY_LOC_STATISTICS;
create or replace package body REP_DELIVERY_LOC_STATISTICS is
FUNCTION REP_DELIVERY_LOC_STATISTICS(p_college_id IN pse_education_pgm_session.delivery_institution_id%TYPE,
p_start_date IN pse_education_pgm_session.session_strt_dte%TYPE,
p_end_date IN pse_education_pgm_session.session_strt_dte%TYPE,
p_coord_facility_join varchar2) return REP_DELIVERY_LOC_STAT_cur_Dyn IS
REP_DELIV_LOC_STAT_CUR_Dyn_Q REP_DELIVERY_LOC_STAT_cur_Dyn;
BEGIN
OPEN REP_DELIV_LOC_STAT_CUR_Dyn_Q FOR
'SELECT distinct
seps.coordinating_facility_id,
peps.PSE_MUNICIPALITY_ID,
seps.pse_education_pgm_session_id,
cs.course_session_id
FROM pse_education_pgm_session peps,
sis_education_pgm_session seps,
course_session cs,
facility fac,
desc_sis_reporting_area depa,
desc_sis_reporting_type dept,
pse_education_program pep
WHERE peps.delivery_institution_id (+) = ' || p_college_id
|| ' and peps.session_strt_dte between ' ||p_start_date||' and ' || p_end_date
|| ' and seps.coordinating_facility_id = fac.facility_id (+)
and seps.pse_education_pgm_session_id (+) = peps.pse_education_pgm_session_id
and seps.pse_education_pgm_session_id = cs.pse_education_pgm_session_id (+)
and pep.pse_education_program_id = peps.pse_education_program_id
and dept.desc_sis_reporting_area_id = depa.desc_sis_reporting_area_id
and pep.desc_sis_reporting_type_id = dept.desc_sis_reporting_type_id
and dept.desc_sis_reporting_area_id = depa.desc_sis_reporting_area_id
and fac.desc_facility_id in (2,3)' || NVL (p_coord_facility_join, '1=1');
return REP_DELIV_LOC_STAT_CUR_Dyn_Q;
END;
end REP_DELIVERY_LOC_STATISTICS;I would sugest to grab a book like
Inside Microsoft SQL Server 2008 T-SQL Querying (chapter 12 - Graphs, Trees, Hierarchies and Recursive Queries) or
Joe Celko's Trees and Hierarchies in SQL for Smarties to get familiar with how model hierarchies using SQL.
What is the meaning of the asterisks in the path?
Here is a dirty example using the Adjacency List model.
SET NOCOUNT ON;
USE tempdb;
GO
CREATE TABLE dbo.T1 (
id int NOT NULL UNIQUE CLUSTERED,
name varchar(50),
rootid int NULL
INSERT INTO dbo.T1 (id,name,rootid)
SELECT 1, 'animals', NULL
UNION ALL
SELECT 2, 'mamal', 1
UNION ALL
SELECT 3, 'cephalopod mollusc', 1
UNION ALL
SELECT 4, 'salt water fish', 1
UNION ALL
SELECT 5, 'fresh water fish', 1
UNION ALL
SELECT 6,'whale', 2
UNION ALL
SELECT 7,'pirana', 5
UNION
SELECT 8,'shark', 4
UNION
SELECT 9, 'octopus', 3;
GO
WITH Tree AS (
SELECT
id, name, rootid,
CAST('/' + [name] + '/' AS varchar(900)) AS mat_path
FROM
dbo.T1
WHERE
rootid IS NULL
UNION ALL
SELECT
C.id, C.name, C.rootid, CAST(P.mat_path + C.name + '/' AS varchar(900))
FROM
Tree AS P
INNER JOIN
dbo.T1 AS C
ON P.id = C.rootid
SELECT
FROM
Tree
ORDER BY
mat_path;
GO
DROP TABLE dbo.T1;
GO
Excuse my poor knowledge of zoology or animal biology.
AMB
Some guidelines for posting questions...
AYÚDANOS A AYUDARTE, guía básica de consejos para formular preguntas -
Dynamic Query in Report Builder
HI
I have a doubt:
I need to receive a parameter in my report and I need this parameter in the query, that means, I need to create a dynamic query depending on the value that I receive in one of the parameters that has my report.
I tried to use the resource of Searching by Reference Cursor tool, it is a blue circle in the Data Model View of Report Builder.
When I click this tool, I have an initial code, It is:
function QR_1RefCurDS return <RefCurType> is
begin
end;
In PL/SQL I tried to create to test and to play, this code:
Note: If you want to try only to test, it is simple and works:
create or replace package TEST_REFCURTYPE as
type refcurtype is ref cursor;
function TEST_REFCURTYPE (P_DATE_TO nvarchar2) return refcurtype;
end;
create or replace package body TEST_REFCURTYPE as
function TEST_REFCURTYPE (P_DATE_TO nvarchar2)
return refcurtype is
refcur refcurtype;
mysql varchar(1000);
begin
If P_DATE_TO is not null then
mysql := 'select '''|| P_DATE_TO ||''' from dual';
else
mysql := 'select sysdate from dual';
end if;
open refcur for mysql;
return refcur;
end;
end;
The problem is to pass this example of code to the function QR_1RefCurDS, I do not have a place to make reference to the type:
type refcurtype is ref cursor;
I tested the Unit Program in the Report Builder but it did not work, because all the code I try to write and create, for example in the Event BEFORE REPORT, it opens Funcion( ) …., and I can not make reference to the type refcurtype inside a Function( ).
Would you help me please?
Or there is another way to make a dynamic query in the Report Builder?
Sorry for my English, I am a Brazilian living in Spain.Hi,
you can use lexical parameters in your queries. Instead of a ":" use in the query before the parameter a "&". Then the parameter stands for a part of the query and not for a value (Bind parameter). In the before report trigger you can set this parameters. They can contain parts of SQL like order or where. Make sure that the default value for this lexical parameters are set to get a valid query.
SELECT ENAME, &p_column as COL2 FROM EMP &p_order
and in the trigger something like
IF :p_which_column = 1 THEN
:p_column := 'SAL'
ELSE
Saludos
Rainer -
How to enhance Dynamic Query Object TerrSearch (Territory Management)?
Hello Friends,
In the TerrSearch dynamic query object, There are 2 fields Territory_ID and Level_ID. Now i have a requirement to Enhance the Search object using the new field called TERRITORY PATH ID. using which we can search all the entities not only for the terrritory level which we have selected (for example we have assigned the value '01' to LEVEL_ID) but also all the below territory levels of selected territory level.
If we enhance the search object structure CRMST_TMIL_SEARCH (structure of TerrSearch object) using AET to add the Z field called TERRITORY_PATH_ID then which is the suitable BADI where we can add the necessary code to select all the entities based on all the territory levels below the selected territory level.
Please guide me friends how to enhance the TerrSearch object.Hi friend,
Try using MACRO and dynamic WHERE condition.
Group simialr Select statements under a Macro.
Build a dynamic where by checking conditions
Call macro passing dynamic where condition.
TABLES afpo.
DATA: str TYPE string.
*Macro definition
DEFINE operation.
select single *
from afpo into afpo
where (&1). " Dynamic condition
END-OF-DEFINITION.
*Build dynamic WHERE by checking some conditions
*If conditon
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
*Else
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
*Endif.
*Call Macro passing dynamic WHERE condition
operation str. -
Hey,
I am trying to implement dynamic querying using the query by example concept. My requirement is as follows:
"Say I have 5 inputs , I need to fetch rows from the database using those 5 inputs as a part of my where clause"
The user input are optional. Hence using the query by example concept I was able to filter rows.
But the problem is as follows:
1) I have a "time from" and "a time to" field as user inputs. I need to filter the fetched rows so that time is in that time range only. I do not know how to implement this also along with the above concept as there is no place for a where clause.
Any help/suggestions would be appreciated.
ThanksI tried applying the patch, but it gives the following error:
OPatch detects your platform as 207 while this patch 6133448 supports platforms:
0 (Generic Platform)
This patch is not suitable for this operating system.
Please contact support for the correct patch.
ERROR: OPatch failed during pre-reqs check.
OPatch returns with error code = 150
I downloaded for the OS I am on, but always the generic patch downloads; i guess this generic one should work for all platforms. Opatch version is 1.0.0.0.56. -
Implementing a dynamic dropdown list
Hi All,
I am implementing an Adaptive RFC model that uses two custom RFC's. First RFC returns a table that has list of countries and the second RFC returns a table that lists the states of a particular country.
Now using these two RFC's how do I implement a dynamic dropdown...i mean the first dropdown should show the list of countries and the second dropdown should show the list of states depending on the country selected.
Thanks,
TomHi Tom,
Please try this,
IWDNodeInfo multiplenode = multipleinfo.addChild("MultiNode" , null, true, false, true, true, false, true, null, null, null);
multiplenode.addAttribute("roles", "ddic:com.sap.dictionary.string");
Assign values for Dropdown
IWDNode node1 = wdContext.nodeNodeA().getChildNode("MultiNode", IWDNode.NO_SELECTION);
IWDNodeElement elem1;
for(int s=0;s<5;s++){
elem1 = node1.createElement();
elem1.setAttributeValue("roles","Value"+s);
node1.addElement(elem1);
Inside Domodifyview create IWDDropDownByIndex UI Element and Bind it.
IWDDropDownByIndex dropDownList = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class, "drop");
IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");
dropDownList.bindTexts(info);
dropDownList.setWidth("100");
Regards,
Ramganesan K. -
Unable to retrieve results using dynamic query
Hi Experts,
I have created a custom table and have created a custom bol to integrate it with web ui. I have redefined the dynamic query result method of genil layer. I find the data into LT_RESULT but when I invoke the root list method the LR_OBJECT does not contain the values.
Please see below the code that I have written.
====================================
METHOD IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT.
DATA: LR_OBJECT TYPE REF TO IF_GENIL_CONT_ROOT_OBJECT,
LT_RESULT TYPE TABLE OF ZCRMST_XXXX,
LV_DYN_WHERE TYPE STRING,
LV_LEN TYPE I,
LS_RANGE TYPE SELOPTOBJ.
DATA: LT_XXXX TYPE TABLE OF SELOPTOBJ,
LT_YYYY TYPE TABLE OF SELOPTOBJ.
FIELD-SYMBOLS: <LFS_RESULT> TYPE ZCRMST_XXXX,
<LFS_SELECTION_RANGE> TYPE GENILT_SELECTION_PARAMETER.
decomposition of selection parameters and build a dynamic where condition
SELECT * FROM ZXXXX INTO TABLE LT_RESULT[].
CHECK LINES( LT_RESULT[] ) > 0.
LOOP AT LT_RESULT[] ASSIGNING <LFS_RESULT>.
LR_OBJECT = IV_ROOT_LIST->ADD_OBJECT( IV_OBJECT_NAME = 'Root'
IS_OBJECT_KEY = <LFS_RESULT>-XXXX ).
CHECK LR_OBJECT IS BOUND.
LR_OBJECT->SET_QUERY_ROOT( ABAP_TRUE ).
ENDLOOP.
ENDMETHOD.
==================================================
Thanks in advance,Hi,
Please check your get_objects method of the genil class. I made some changes to my implementation of get_objects method and it fixed the problem.
Regards,
Sandeep -
Return statement and Try Catch problem
Hi!!
I've got the next code:
public ResultSet DBSelectTeam(String query) {
try {
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(query);
return rs;
} catch (Exception err) {
JOptionPane.showMessageDialog(null, "ERROR: " + err);
But I need a return statement in the catch-block, but I don't know what's the best option.
Help...
Many thanks.The error message is: "missing return statement", Yes, I know.
You have to either return from the catch statement, or throw from the catch statement, or return or throw after the catch statement.
The only ways your method is allowed to complete is by returning a value or throwing an exception. As it stands, if an exception is thrown, you catch it, but then you don't throw anything and you don't return a value.
So, like I said: What would you return from within or after catch? There's no good value to return. The only remotely reasonable choice would be null, but that sucks because now the caller has to explicitly check for it.
So we conclude that catch shouldn't return anything. So catch must throw something. But what? You could wrap the SQLE in your own exception, but since the caller is dealing with JDBC constructs anyway (he has to handle the RS and close it and the Statement), there's no point in abstracting JDBC away. Plus he has to deal with SQLE anyway in his use of the RS and Statement. So you might as well just throw SQLE.
So since you're going to just throw SQLE anyway, just get rid of the try/catch altogether and declare your method throws SQLException -
How to use dynamic query for this ??
hi , i am new to ABAP. i got a requirement to write dynamic query for the following code.
kindly address. two set of queries are same.but condition is different.
.IF p_psd EQ ' '.
*C--End of change DF 1232137- (Transport # :CIDK980530 )
*C--FETCH THE Deliverd Quantiity and Material Number
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng IN s_dqt
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
IF sy-subrc = 0.
SORT t_afpo BY aufnr matnr pwerk.
*C--FETCH THE OBJECT NUMBER
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_aufk BY aufnr objnr.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng IN s_tqt.
IF sy-subrc = 0.
SORT t_afko BY aufnr .
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
*C--Begin of change DF 1232137- (Transport # :CIDK980530 )
ENDIF.
IF p_psd EQ c_x.
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng > 0
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
if sy-subrc = 0.
*C--FETCH THE OBJECT NUMBER
IF NOT t_afpo[] IS INITIAL.
SORT t_afpo BY aufnr matnr pwerk.
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF NOT t_afpo[] IS INITIAL.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng <> t_afpo-wemng .
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tagsHi friend,
Try using MACRO and dynamic WHERE condition.
Group simialr Select statements under a Macro.
Build a dynamic where by checking conditions
Call macro passing dynamic where condition.
TABLES afpo.
DATA: str TYPE string.
*Macro definition
DEFINE operation.
select single *
from afpo into afpo
where (&1). " Dynamic condition
END-OF-DEFINITION.
*Build dynamic WHERE by checking some conditions
*If conditon
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
*Else
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
*Endif.
*Call Macro passing dynamic WHERE condition
operation str. -
How to create custom BOL object for dynamic query in CRM 7.0
Hi,
Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
Regards,
Kamesh Bathla
Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PMHi Justin,
First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
Thanks in Advance,
mallikj2.
Maybe you are looking for
-
Is there an easy way to compare two null columns?
I need to compare a significant number of columns between records in two tables for a data conversion. I really need a comparison that will return true if: 1) both columns are null; or 2) both columns are not null and equal. I want it to return false
-
when I set up my new iphone and signed in with my apple id, all of my downloaded podcasts (in the podcasts app) showed up withougt having to download them again. so I assume they were being backed up in a cloud -- but where? according to the apple we
-
How can I see the full path under File when doing a search of a site or folder? Seeing the file name and folder it is in is not all that helpful when you have lots of other directories with the same named sub directories and files. A search shows the
-
I need to get an i7 late2011 logic board
My macbook pro 13" is having a fault with the logic board so I need to replace it and I wanna know where I can get a cheap and durable one. it's a 2.8GHz. Thanks.
-
I update my iphone 3gs from 4.1 to iOs 6.1 but after I update it says you need to activate your phone. I can't activate it thru itunes or wifi.