how to pass parameters to stored procedure from crystal reports designer
and in code also ??
If you use required stored procedure as source for report, while building report itself, you can pass stored procedure parameters from code as the following;
ReportDocument rptDocument = new ReportDocument();
// Load report.
rptDocument.Load(Server.MapPath("rptFileNameOrPath"));
ParameterFields parameterFields = new ParameterFields();
ParameterField parameterField = null;
ParameterDiscreteValue parameterValue = null;
parameterField = new ParameterField();
parameterValue = new ParameterDiscreteValue();
parameterField.Name = "#ContactId";
parameterValue.Value = "1";
parameterField.CurrentValues.Add(parameterValue);
parameterFields.Add(parameterField);
this.rptDocument.SetParameterValue("#ContactId", parameterValue);
#ContactId: is a parameter for required stored procedure.
Finally, you can either export report or print it based on your requirements.
// 0, 0: to print all the pages.
this.rptDocument.PrintToPrinter(1, false, 0, 0);
Regarding Crystal Report Designer, you just use View Report option, you will be asked to enter values for all report parameters, just enter required values.
Related
I have a custom dialog dynpro including an input field named DYN_MATNR as listbox for which I have included a list of particular materials as selection.
How can I set a specific material (of that list) as selected when the dialog dynpro is opened?
PBO of dialog dynpro:
data lt_values type vrm_values.
select matnr,
maktx
into table #data(lt_materials)
from makt
where matnr in #so_matnr
and spras = 'D'
order by matnr.
loop at lt_materials assigning field-symbol(<material>).
append initial line to lt_values assigning field-symbol(<value>).
<value>-key = <material>-matnr.
<value>-text = <material>-maktx.
endloop.
call function 'VRM_SET_VALUES'
exporting
id = 'DYN_MATNR'
values = lt_values
exceptions
id_illegal_name = 1
others = 2.
if sy-subrc <> 0.
" ...
endif.
This works and it shows the list of materials as listbox values. To select a particular material I have included the FM DYNP_VALUES_UPDATE afterwards and also in PBO but this did not work:
data lv_stepl type syst-stepl.
call function 'DYNP_GET_STEPL'
importing
povstepl = lv_stepl
exceptions
stepl_not_found = 1
others = 2.
if sy-subrc <> 0.
" ...
endif.
data(lt_dynpfields) = value dynpread_tabtype(
( fieldname = 'DYN_MATNR'
stepl = lv_stepl
fieldvalue = gcl_helper->get_matnr( ) " matnr which should be selected is stored here
fieldinp = space )
).
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = sy-repid
dynumb = sy-dynnr
tables
dynpfields = lt_dynpfields
exceptions
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
others = 8.
if sy-subrc <> 0.
" ...
endif.
I am also not able to directly set DYN_MATNR as it is not available in PBO.
Any hints?
Got it:
You need to additionally define a global(!) variable with the name and (wished) type of the input field (e.g. in the top include of the report or in a separate include of the dynpro logic):
data dyn_matnr type matnr.
Then you can set the initial value of the dynpro field in PBO directly:
dyn_matnr = gcl_helper->get_matnr( ).
As this becomes rather irritating when using various dialog dynpros I recommend including the dynpro number in those variables and input fields.
I have followed the previous code and try to call a stored procedure
ALTER PROCEDURE [dbo].[sp_test]
#in char(5) = ' ',
#out smallint = 0 output
AS
BEGIN
SET NOCOUNT ON;
SET #out = 100
END
Then in the VB6, i try to request this stored procedure by below
strConn = "Select * from TBL where 1=2"
Set rsCmd = objCCS.ExecuteStatement(strConn, adUseServer, adOpenDynamic, adLockBatchOptimistic)
Dim rdoqry_data2 As ADODB.Command
Set rdoqry_data2 = CreateObject("Adodb.command")
Set rdoqry_data2 = rsCmd.ActiveCommand
rdoqry_data2.CommandType = adCmdStoredProc
rdoqry_data2.CommandText = "sp_test"
rdoqry_data2(0).Direction = adParamReturnValue
rdoqry_data2(1).Direction = adParamInput
rdoqry_data2(2).Direction = adParamOutput
rdoqry_data2(2).Type = adSmallInt
rdoqry_data2(1) = "123"
rdoqry_data2.Execute
But it flow an exception ODBC driver does not support the requested properties.
Can anyone find the problem?
Thanks.
Where exactly does the exception appear? I guess the exception is the result of calling the procedure sp_test and not the result of executing objCCS.ExecuteStatement, right?
My approach to call the stored procedure sp_test from VB6 would be:
Dim rdoqry_data2 As ADODB.Command
Set rdoqry_data2 = New ADODB.Command
With rdoqry_data2
Set .ActiveConnection = (your connection object)
.Parameters.Append rdoqry_data2.CreateParameter("#in", adVarchar, adParamInput, 5, "123")
.Parameters.Append rdoqry_data2.CreateParameter("#out", adSmallInt, adParamOutput, 2)
.CommandType = adCmdStoredProc
.CommandText = "sp_test"
.Execute
End With
First you have to create the command object and assign the connection object to it. In this case you need two parameter objects. First parameter is an input parameter with a maximum size of 5 bytes (char(5)) and the content "123". Second parameter is an output parameter with a max. size of 2 bytes (smallint). Finally you have to tell the command object to call a stored procedure with the name "sp_test".
Does this work for you?
I am using crystal report and trying to print an invoice. I am populating the crystal report through list of objects instead of database.But I am facing the crystal report database connection window. I need to bypass it.
My code is as below:
List<ReportHeader> RH = new List<ReportHeader>();
RH.Add(new ReportHeader("212EE212", "000004", "Asghar", "2234", "Ahmad", "Nice Transaction", "2/25/2016", "16:45"));
List<ReportDetail> RD = new List<ReportDetail>();
RD.Add(new ReportDetail("inpironD610", 3, 35000, 105000));
RD.Add(new ReportDetail("inpironD986", 3, 35000, 105000));
List<ReportFooter> RF = new List<ReportFooter>();
RF.Add(new ReportFooter(210000,4500,214500));
ReportDocument rptDoc = new ReportDocument();
InvoiceReport IR = new InvoiceReport();
IR.SetDataSource(RH);
IR.SetDataSource(RD);
IR.SetDataSource(RF);
IR.PrintToPrinter(1, true, 0, 0);
InvoiceReportViewer.ReportSource = IR;
I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.
I am trying to get value returned by a Sybase user-defined stored procedure, following is the code snippet.
from com.ziclix.python.sql import zxJDBC
def callStoredProc(conn, procName, *args):
conn.execute("USE DB")
sql = """DECLARE #ret int
EXEC #ret = %s %s
SELECT #ret""" % (procName, ','.join(['?'] * len(args)))
return int(conn.execute(sql, args).fetchone()[0])
jdbc_url = "jdbc:sybase:Tds:192.168.1.100:3397/stagingdb"
username = "sa"
password = ""
driver = "com.sybase.jdbc4.jdbc.SybDriver"
conn = zxJDBC.connect(jdbc_url, username, password, driver)
cursor = conn.cursor()
print callStoredProc(cursor, "usp_find", "Apples" )
But when I run script, it says;
zxJDBC.Error: Stored procedure 'usp_find' may be run only in unchained transaction mode. The 'SET CHAINED OFF' command will cause the current session to use unchained transaction mode. [SQLCode: 7713], [SQLState: ZZZZZ]
However, if I add conn.execute("SET CHAINED OFF") in callStoredProc() it return None.
Is there any way to get returned value off sybase stored procedure in Jython/Python?
I do not know how to change chainde transation mode, but I want you to try "clear" JDBC and CallableStatemet. Such code looks like (I do not have Sybase so I cannot test it):
db = DriverManager.getConnection(db_url, usr, passwd)
proc = db.prepareCall("{ ? = call usp_find(?) }");
proc.registerOutParameter(1, Types.INTEGER)
proc.setString(2, "Apples");
proc.execute();
r = proc.getInt(1)
print('result: %d' % (r))