Possible to declare variable on demand?
Hi,
Using Oracle 9i. I am new to PL/SQL (coming from C#), I would like to know if it is possible to declare a variable close to the where it is used. For example, in the Execution block of the procedure, let's assume I want to do:
.. existing code ...
vTest integer;
vTest := 123;
.. existing code (continued) ...
Doing so, the procedure failed to compile. The only way I know so far is to declare the vTest integer; in the declaration block. Can you please let me know how to declare the variable in the body of the procedure?
Thanks in advance.
1) The line numbers are added by SQL*Plus as you enter code in order to make it easier to debug (i.e. when the error message says there is an error on line 15, it's much easier if SQL*Plus has added line numbers than if you have to manually count them). They are not intended to be part of the code block.
2) Having nested DECLARE ... BEGIN ... END blocks in a piece of code would certainly strike me as unusual. Much like nested procedure declarations-- they are syntactically legal, and very occasionally useful, but they are sufficiently unusual that I would tend to avoid them if only because they are likely to confuse future developers that come along later. I've personally never seen code that did this in production, though I have seen a handful of folks use nested procedures, i.e.
CREATE PROCEDURE p1
AS
PROCEDURE p2
AS
BEGIN
NULL;
END p2;
BEGIN
p2;
END;I believe Tubby's point is that while it is good in general to declare variables close to where they are being used, if you have small modular code, the variable declaration block of your procedure ought to be very close to where the variable is being used. If you have a procedure that fills multiple pages and has multiple PL/SQL blocks, it is very likely that you should have factored out most of that code into smaller procedures and put everything in a single package.
Justin
Similar Messages
-
Declare variables in an MDX query
Is it possible to declare variables in an MDX query like transact sql? something like this:
DECLARE @date1 date
DECLARE @month1 int
set @date1 = '12-12-2012'
set @month1=DATEPART(m, @date1)-1
select @date1 as dt1, @mesreferencia as mt1Hi ,
In MDX , you will not be able to put variables in MDX. But Query scoped calculated measures can be used for such cases. The equivalent MDX for the above is
WITH MEMBER [MEASURES].Dt
As
CDATE('12-12-2012')
MEMBER MEASURES.DTPart
As
DATEPART("M", MEASURES.Dt)-1
SELECT {MEASURES.Dt,MEASURES.DTPart} ON 0
FROM [Adventure Works]
Best Regards Sorna -
"Reset" declared variables to initialized state?
Hiya!
This might sound like a very stupid question, but I have not figured out a way to do this. I am working on a "personal information manager", where users can enter a date in a lovely swing textfield, it get's parsed to Integer and a GregorianCalendar is created with it. Once I created the Calendar, the TextFields are emptied again, but of course the Integer instance variables are still declared with the old values. This leads to the fact that a user could click "add date" again and a date is created without entering any number at all.
My question:
Is it possible to set declared variables back to the state they had when initialized? They should be "empty"...
I can`t set them null...
Thanks for your help, it's much appreciated!The only type of variable where "empty" has any meaning is for an empty string: "". Otherwise there is no empty. Objects are by default initialized to null, numeric primitives to zero, and I think chars to '' but I could be mistaken about that one - I never use chars. So if you're using Integers, they could either be null, or an Integer - nothing else.
-
How to declare variables in standard text - so10 t.code
Hello Friends,
How to declare variables in standard text - so10 t.code? Your response will be appreciated much.
Thanks
SriFor Script & Smartform Text - &VAR&
-
Declaring Variable in Web dynpro ABAP
Hi all
I want to know how to declare variables globally and how to use internal tables from one method to another method without declaring each and every time in methods?
Please suggest me to do this
Appreciated your solution
Regards
IndiranjithnHi
This code in onselct method. For example
DATA lt_node_am_detl1 TYPE wd_this->Elements_node_am_detl1.
logic to move the data to internal table.
lo_nd_node_am_detl1->bind_table( lt_node_am_detl1 ).
Now the filterd data in internal table and
I declared this internal table in componentcontroller attributes tab like
lt_node_am_detl1 and Elements_node_am_detl1 (Associate column ) and i tick the pulic check box.
i am using another method onclick() .
As you said the internal table declaration is not required if declared already in componentcontroller attributes tab .
data wa_itab like line of lt_node_am_detl1 .
Loop at lt_node_am_detl1 to wa_itab.
endloop.
while debugging i am not getting data in internal table .. Should I declared correctly in componentcontroller attributes tab .
Tlhanks
Indiranjithn -
How to declare variable in the scipt
data is coming from standard program .
rf140-stida key entry date.
bsik-bldat posting date
i want to display difference between rf140-stida and bsik-bldat in scipt form it will give number of days.
how can i declare variables for this.
how to write code in my form.Hi
U need to create a routine to calculate the difference:
/: DEFINE &DELTA& = SPACE
/: PERFORM <FORM NAME> IN PROGRAM <PROGRAN NAME>
/: USING &RF140-STIDA&
/: USING &BSIK-BLDAT&
/: CHANGING &DELTA&
&DELTA&
The routine has to be defined in your Z-PROGRAM and to have these interface:
FORM <FORM NAME> TABLES IN_TAB_EM STRUCTURE ITCSY
OUT_TAB_EM STRUCTURE ITCSY.
DATA: DELTA TYPE I.
DATA: DATE1 LIKE SY-DATUM,
DATE2 LIKE SY-DATUM.
* ---> Rembember the date has the ouput format, so it has to be converted in the
* input format
READ TABLE IN_TAB_EM WITH KEY NAME = 'RF140-STIDA'.
IF SY-SUBRC = 0.
DATE1(4) = IN_TAB_EM-VALUE+6(4).
DATE1+4(2) = IN_TAB_EM-VALUE+3(2).
DATE1+6(2) = IN_TAB_EM-VALUE(2).
ENDIF.
READ TABLE IN_TAB_EM WITH KEY NAME = 'BSIK-BLDAT'.
IF SY-SUBRC = 0.
DATE2(4) = IN_TAB_EM-VALUE+6(4).
DATE2+4(2) = IN_TAB_EM-VALUE+3(2).
DATE2+6(2) = IN_TAB_EM-VALUE(2).
ENDIF.
DELTA = DATE1 - DATE2.
READ TABLE OUT_TAB_EM WITH KEY NAME = 'DELTA'.
IF SY-SUBRC = 0.
WRITE DELTA TO OUT_TAB_EM-VALUE.
MODIFY OUT_TAB_EM INDEX SY-TABIX.
ENDIF.
ENDFORM.
Max -
Declare variables in function module
hi gurus,
i am making a function module in which i need to make some performs so as to do code reusability. but for that i need to declare variable globally. As i am working wth function modules for the fisrt time. can anyone please help me with that. i dnt want these variables in improt or export parameters.
regards
vibhorhi vibhor,
there is a tab "display object list" on the top of the sap screen when u r in dat function module. press that.
on the left side of ur screen there will complete lists of object used in fm. in includes there will a top include, declare all the variables u need globally in that top include. u can also create more includes for different performs if u want for modularizing ur program..
regards
palak -
Can I declare variables in Reports from SQL Query
Hi
I have a Report from SQL Query published as a portlet on a page among other reports. In the query report I am using the fuction WWCTX_API.GET_USER at quite a few places to filter the data returned to the user. Can I assingn the user id to a variable at some level & replace the fuction WWCTX_API.GET_USER with the variable in all the places.
For eg:
usr varchar2(25);
usr:= PORTAL30.WWCTX_API.GET_USER;
select USER_ID, USER_LVL, BUSINESS_ID, BRANCH_ID from crs_user where user_id=usr;
can i declare variable and assign the value like the above at any level(Report or Page Level) to the acces the variale in queries.
Thanks in advanceI have found that you can't use a * in a dynamic page.
Try this:
<ORACLE>
DECLARE
usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
BEGIN
for c in
(SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
Loop
htp.p(c.<alias>);
END;
</ORACLE>
You can also add table tags for column formating:
<table>
<tr><td>column 1</td></tr><tr><td nowrap>
<ORACLE>
DECLARE
usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
BEGIN
for c in
(SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
Loop
htp.p(c.<alias>);
END;
</ORACLE>
</td></tr></table>
Martin -
Is it possible to pass variables from Tidal to the Peoplesoft run controls?
Does anyoen know
•1) Is it possible to pass variables from Tidal to the Peoplesoft run control page such as current date?
An example would be updating run control parameters for a PSQUERY.
•a) From date
•b) To date
•c) Business units
Thanks,
JayEdit the job - go to Run Controls Parameters tab - select the param you want in the Override column then click on the Variables button on the bottom and select the variable you want
-
Can we declare variable dynamic
Hi ,
Can we declare variables dynamically.
[ java uses this feature in Garbage Collection.]
Thanks ,
Adibut jvm uses this dynamic decalration in Garbage
Collection.
then can't we use the same.I'm not sure I understand what you mean? Do you mean that objects are dynamically created at runtime? Yes they are but the variables in the class definitions were all declared at compile time. -
private var _history:Vector.<BitmapData>;
can any1 plz explain me this format of declaring variable specially ".<BitmapData>" part....
Thanx..A Vector is a special kind of array than can only hold one 'type' of data. So in your example, the array _history will only hold BitmapData objects. This makes the access of the array much faster. Contrast this with _myArray:Array that might contain a mixture of object types as in:
_myBitmap:Bitmap
_myMovieClip:MovieClip
_myArray = new Array();
_myArray.push(_myBitmap);
_myArray.push(_myMovieClip;
If you pushed _myMovieClip into your _history Vevctor, you would get an error at run time since _myMovieClip is not a BitmapData object.
You can see more here: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html -
Is it possible to transport variables without the planning areas??
Someone knows if it's possible to transport variables without the planning areas, only the variables?
Regards
GuilhermeHi,
Yes, if the p.area is available in target system.
Use this report: UPC_TRANSPORT_BPS_ALL
Regards,
Suan -
Is it possible to declare an interface without any methods?
Hi Guys!
is it possible to declare an interface without any methods?
Thanx
-SasiOf course, Serializable interface of Java is an example.
-
Declare Variable in Smartforms from BT and EPF tables
Hi All,
I am developing a smartform to display the payslip of employees.
In my smartform I need to use fields from the BT table and EPF Table.
I need to declare variables for the same fields in smartform.
How can this be achieved.
Any pointers or suggestions would be helpful.
Thanks,
SaherHi
Please search with the search term smartforms and u will get many threads which will answer your question.
In general, in form interface of smartform we declare the tables whose values are passed from the print program.
IN global definitions, we declare the variables we use in the smartform.
Regards,
Vishwa. -
Is it possible to declare method with non-finite argument list ?
Hi, everyone,
Is it possible to declare method with non-finite argument list
and to read values of these arguments inside this method ?
I'm not talking about main() method (i know it can), but
values to this method are passed through array. That won't do
do for me.
If it is possible, could someone show an example how to do this.void method(Object[]o)
for (int i=0; i<o.length; i++)
if (oinstanceof Integer)
System.out.println("is is an integer: "+o[i]);
else if (o[i]instanceof Point)
System.out.println("is is an Point: "+((Point)o[i]).x+"/"+((Point)o[i]).y);
else if (o[i]instanceof String)
System.out.println("is is an String: "+o[i]);
if you call it like
method(new Object[]{new Integer(123), "Hello!", new Point(100, 200), "goodbye!"});then the method will output:
is is an integer: 123
is is an String: Hello!
is is an Point: 100/200
is is an String: Goodbye!
this is as powerful as varible parameter counts like in c, and it it typesafe.
Maybe you are looking for
-
DateTime issue at Universe Level
Hello Experts, We have stored date in database as datetime format. In Universe, we have created object on this date. But we have to keep type of this objet as u2018Dateu2019 as there is no datetime object type available in universe. When we dragged
-
Curious...All the themes are in non-English when I preview them. I didn't change any settings that I'm aware of. Is that normal?
-
My wife has a MacBook Air and a La Cie Rugged 1 TB external drive that she uses to back up to with Time Machine. She takes a LOT of photos, and so knowing that she had a backup available, has deleted many photos from the internal drive to keep the ma
-
Error in ME51N - Account object functional area differs in asset master
We are in the middle of going thru an upgrade - Funds & Functional Area were display fields in the old system but it was recetly changed to required fields in the Asset Master Record (AS01). Now when I try to create a Purchase Requisition for procuri
-
I have been billed twice for a movie
Can't find anywhere to have a transaction reversed. As I was downloading a movie, there was an issue and it was not completed. I downloaded it again and I have now been billed twice. What now?