Use of constants
Hi,
I want to avoid hard coding in the where condition as i have done in the below code. Is there any other way out?
select ebeln ebelp from ekpo into table it_ekpo
where werks in s_werks
and elikz = 'X'
and erekz = ' '.
I want to avoid harcoding X and ' '.
instead of hard coding use constant statement. CONSTANT statement declares a constant data object. The content of a constant cannot be changed at runtime of an ABAP program.
in your case just declare two constant statements at the top of the program.
CONSTANTS: TRUE VALUE 'X',
FALSE VALUE ' '.
instd of using 'X' and ' ' use TRUE & FALSE where ever required in the program, suppose if you want to change vise versa simply change the constansts content values, it will reflicate automatically throught the program.
Similar Messages
-
Using package constants in package SQL - acts as bind variable or literal?
I'm looking for confirmation on the performance impact of using package constants in package SQL.
Let's say I have a number of queries in package code that refer to various literals that are prone to typos e.g. "CANCELLED" instead of "CANCELED". To reduce the chances of this happening, I have an APP_GLOBALS package where I declare constants for each literal:
C_CANCELED CONSTANT VARCHAR2(12) := 'CANCELED';And in queries that refer to literal 'CANCELED' I use APP_GLOBALS.C_CANCELED instead. This way the typo is caught during compilation. For example:
BEGIN
--Do something with all 'Canceled' orders
FOR r IN (SELECT order_id
FROM orders
WHERE status = APP_GLOBALS.C_CANCELED)
LOOP
END LOOP;
END;Assume that:
- the STATUS column is indexed
- the possible values are PENDING, APPROVED, CANCELED
- a small percentage of orders are CANCELED
From the optimizer's perspective is the query equivalent to
SELECT order_id
FROM orders
WHERE status = :varor
SELECT order_id
FROM orders
WHERE status = 'CANCELED'?
According to what I see in v$sqltext_with_newlines, it's the first one. Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos? Worst case, I suppose I can start with constants so that it compiles successfully then do a global replace of the constants with the literals.Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos?I cannot think of any. But, here is the thing. If the typos are there, then, it technically is a bug even though both the codes would compile. The bug will be hunted down when the program doesn't work as intended. Wouldn't most typos be caught in unit testing of the code?
Also, if you replace a string literal with a variable, then, maybe (just maybe, depending on your version of the dbms), it may end up picking a different execution plan. That might be an unintended consequence. -
Hello!
I�m new in JSF and I want to use a constant into a jsf tag but I don�t know how to do it. I know in JSTL but not in FSF.
This is what I want:
<h:outputText id="test" value="<%Constantes.DOCUMENT%>"/> I have tried so many things to use my constant in the value element but I don�t know the way
Thanks.first off Scriplets are bad practice in JSF and should be avoided.
I use this workaround for constants in jsf. Create a my constant as properties on a FacesConstants class, which is defined as a Managed Bean with scope of none and having getters for each property.
public class FacesConstants implements MyConstants{
public String document = DOCUMENT;
public String getDocument(){
return document;
<managed-bean>
<description>used to get faces constants for refereing in EL Expresssions</description>
<managed-bean-name>constants</managed-bean-name>
<managed-bean-class>com.myproj.faces.util.FacesConstants</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>
so in the jsf code just say #{constants.document}
Not sure if this is best practice? in fact I'd prefer a more elegant solution
Edited by: scottyb on Apr 8, 2008 5:10 AM
Edited by: scottyb on Apr 8, 2008 5:12 AM -
Use of const keyword in java ?
Hi All,,
I want to know the use of const keyword with proper example.
Many many thx in advance
Cheers
SouvikI want to know the use of const keyword with proper example.
There is no proper example, because const is not used in Java. If you want to create a constant, use the final keyword. -
Suns standard classes use of constants - bad coding convention
Wasn't sure where to post this, it didn't quite fit into Java Runtime Environment or Java Virtual Machine forums.
I was browsing through The Java Standard classes and was amazed by their use of constants. Throughout the codes there is inserted direct constants in the code without any use of global constant declarations.
Eg: java.lang.StringCoding:
All over the code is inserted "ISO-8859-1" (used as default encoding) directly instead of using a declared constant DEFAULTENCODING. What if Sun want to change default encoding?
Seems strange to me that such coding conventions are used by Sun. Any reason for this or just sloppy programing?
GilLooks like sloppy programming to me. I see no possible
reason for it. You're not the first person to
criticise Sun's source code. Maybe they outsourced it
to http://www.newtechusa.com/PPI/main.asp (I can never
remember how to format links, no matter how often
people tell me!)
RObinThere's logic in getting primates to program.
Based on the popular theory that an infinite number of monkeys could
randomly produce the works of Shakespeare, they could also produce the perfect software implementation of any given problem. The downside being that the printed documentation will be smeared liberally with faeces.
regards,
Owen -
Optimization of using text constants
Does Forms compiler optimize using text constants when it make *.fmx
file, if yes then how?
What I mean. In many cases Forms programmers use text constants to do
any actions, for sample:
- do_key('EXECUTE_QUERY');
- if (:system.mode = 'ENTER-QUERY') then /* ... */ end if;
- execute_trigger('ON-POPULATE-DETAILS');
- show_alert('ASK_SAVE');
- go_block('ORDERS') or go_item('ORDERS.NAME');
- set_block_property(bid,DEFAULT_WHERE,':orders.pay > '||:r.pay_rate);
As I have undestood myself, Forms divide such constant on types:
- standart text constants('EXECUTE_QUERY','ENTER-QUERY' ...);
- user's text constants ('ASK_SAVE','ORDERS.NAME');
And Forms do any optimization with standart text constants: in *.fmx file
I found only one enter for every from such constants.
But for user's text constants Forms does not optimization: in *.fmx file
I found more then one enter for such constants.
If above is right then is there benefit from creating a package in form
module and creating constants in the package, that contain frequently used
user's text constants(block and items names, e.t.c.) and then writing down
in program these package constants instead of user's text constants?I get to answer my own question. I found a workaround should you ever what to be sure a certain font is used and not replaced. Granted, this will add my download time but you at least can preserve the look.
Simply make any text with a shadow. But make the offset 0 and the transparency to 1 (you can't make it 0). You won't even notice the "shafow" and the text will be made into a graphic every time.
Stephen -
Is it possible to use a CONSTANT as Default Namespace?
Hi,
I create from a table and an XML-field a view. For the command XMLTABLE I have to use a DEFAULT namespace.
Is it possible instead of a fixed string to use a constant variable which I read using a function?
As example:
CREATE OR REPLACE VIEW pain_001 AS
SELECT i.iban_ausz_id IBAN_AUSZ_ID
,oc.PmtCdtInstrId PmtInf_CdtInstrId
FROM IBAN_AUSZ_E i
,XMLTABLE(XmlNamespaces(DEFAULT 'http://www.six-interbank-clearing.com/de/pain.001.001.03.ch.02.xsd'),
'/Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf'
PASSING i.pain_001
COLUMNS
PmtCdtInstrId NUMBER PATH 'PmtId/InstrId'
) oc
I want to replace 'http://www.six-interbank-clearing.com/de/pain.001.001.03.ch.02.xsd' with a function wich returns a constant variable like "package_name.get_const".
Is this possible?
Thanks in Advance.odie_63 wrote:
Hi,
I want to replace 'http://www.six-interbank-clearing.com/de/pain.001.001.03.ch.02.xsd' with a function wich returns a constant variable like "package_name.get_const".
Is this possible?No, it's not possible. It has to be a string literal.but for dynamic sql (EXECUTE IMMEDIATE) looks like it's possible -
Exact use of const type fiels ...equipment master
Dear experts,
Plz tell me the exact use of const type field of equipment master.....???
thanks
RGRDS
DMdHi,
if you have 100 equipments of same type no need to create 100 master records for that create one equipment BOM for that and put it in the const. type in the equipment master data.
Regards
Satish -
I am trying to use a package constant in a query as follows:
SELECT field1 FROM table t WHERE CEIL(sysdate - t.field2) > schema.package.constant
field1 is a name
field2 is a timestamp
constant is an integer indicating the expiration time in days
basically I am trying to find all expired items.
I get the error "ORA-06553: PLS-221: 'constant' is not a procedure or is undefined" on this query.
I use this same query as a cursor in the package itself with no errors.Unfortunately you cannot directly use package global variables in select statements like this.
One workaround is to use bind variables for that:
<p>
SQL> CREATE OR REPLACE PACKAGE pkg
AS
myconstant VARCHAR (20) := 'This is my constant';
END pkg;
Package created.
SQL> VAR myconstant VARCHAR2 (20)
SQL> EXEC :myconstant := pkg.myconstant
PL/SQL procedure successfully completed.
SQL> SELECT :myconstant
FROM DUAL
:MYCONSTANT
This is my constant -
Use of Constants in Report Painter
Dear All,
I am designing a report in Report Painter. For this, I need to introduce a line with constant value in every column. I need this value to be subsequently used in formulae.
Is this possible. What is the use of a 'Constant'. I created a Constant, but am not able to bring it in the report.
Please help. Full points would be awarded..
ThanksHi Kash,
Thanks for your reply..
Can you elaborate bit further. You mean to say I should create a Constant with some value.
Thereafter how should I bring that in the form. But, How do I enter the Constant in the Formula... There is no key for entering any text in the formula.. there are only ID (the values which we bring in the form and which can be selected for the formula) and numbers which can be entered.
So how do I enter the name of the Constant?
I tried just keying in the name of the Constant, and I could check the formula also, However, while saving the form, I am getting an error,
Element WCaplimit Bis letztem ATag bis &$BISD is not defined correctly -> check definition
Message no. KH206
Diagnosis
In element WCaplimit Bis letztem ATag bis &$BISD the system adds quantities and values or different currencies.
Can you please revert back with step by step solution?
Appreciate your prompt reply.... Thanks -
Report Painter - Use of Constants / Local Formula Variable
Hi,
I am using constant and/or local formula variable in report painter in FSI.
I could use both the values for calculating percentages, ie. it can be used for multiplication or division. However, when I try to use it for addition or subtraction, I am getting the error message no. KH206.
In all cases, I am using different values in the formula, i.e. a absolute figure and a GL based figure.
I am not able to understand, why it even allows me for calculating percentage.
Can anyone help me in using a absolute figure for input and thereafter use it in addition / subtraction.
I would prefer an immediate solution to this as I am in the final stages of this report.
Full points guaranteed.....Hi Kash,
Thanks for your reply..
Can you elaborate bit further. You mean to say I should create a Constant with some value.
Thereafter how should I bring that in the form. But, How do I enter the Constant in the Formula... There is no key for entering any text in the formula.. there are only ID (the values which we bring in the form and which can be selected for the formula) and numbers which can be entered.
So how do I enter the name of the Constant?
I tried just keying in the name of the Constant, and I could check the formula also, However, while saving the form, I am getting an error,
Element WCaplimit Bis letztem ATag bis &$BISD is not defined correctly -> check definition
Message no. KH206
Diagnosis
In element WCaplimit Bis letztem ATag bis &$BISD the system adds quantities and values or different currencies.
Can you please revert back with step by step solution?
Appreciate your prompt reply.... Thanks -
How to use a constant defined as a concat of char values in an IN clause
Greetings,
I defined a CONSTANT as a concatenation of values and attempted to use it in an IN clause without success ...
CREATE OR REPLACE PACKAGE PKG_TEST AS
Q_IDS CONSTANT VARCHAR2(25) : = '''3'''||','||'''14'''||','||'''16'''||','||'''18'''||','||'''24''';
procedure insert_test;
END PKG_TEST;
CREATE OR REPLACE PACKAGE BODY PKG_TEST AS
PROCEDURE insert_test as
BEGIN
insert into test1
select *
from test_table
where q_id in ( Q_IDS );
END insert_test;
END PKG_TEST;
I'm guessing this doesn't work because the CONSTANT is being treated as one long string as opposed to a succession of comma separated values.
Is there a way to do this?
Any feedback would be appreciated.
Thank you.One example:
SQL> ed
Wrote file afiedt.buf
1 select *
2 from emp
3 where ename in (
4 with t as (select '&input_string' as txt from dual)
5 select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
6 from t
7 connect by level <= length(regexp_replace(txt,'[^,]*'))+1
8* )
SQL> /
Enter value for input_string: SCOTT,JAMES
old 4: with t as (select '&input_string' as txt from dual)
new 4: with t as (select 'SCOTT,JAMES' as txt from dual)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 19-04-1987 00:00:00 3000 20
7900 JAMES CLERK 7698 03-12-1981 00:00:00 950 30
SQL> -
Flat File vs using final constants - which is better appraoch
Hi
i have a requirement where i have set some states variable.
it goes like this:
state A , some indicator A ,indicator B ,flag A : final state set to be set
1 , true , A , 0 : Declined
1 , false , B ,0 : PreDeclined...
...... like this i have some 20+ rows.. below 50
since these are states .. this may increase.. but not frequently
i would like to know which is best way to implement the above logic. My peer suggested to capture all that data as constants /hard code. I was thinking to store them in CSV and then read. but my peer was mentioning using I/O operations slows performance. can u please suggest me a better way ( not DB since its requires lots of permission etc..)thats interesting. can u please let me know how to use enums to fit my above requrement.
i have used enums eariler where my requirement is just return descriptionstring to code. . ie.. is just only one constant.more over those enums are generated .. and they do correspond to a db table.
but here what i want is a basically look up based upon 3 elements. and return 4 the element..
i'm not sure on how to use enums for that. -
How to use a constant rather than a "getter"?
I'd like to refer to a constant rather than a property using a "getter" (accessor), but I'm not sure how.
For example:
<f:selectItem itemLabel="Option1" itemValue="#{Constants.MINIMUM}"/>
But of course this results in trying to call getMINIMUM(), which isn't what I'm trying to so.
Any ideas?hi ,
as far i know u cannot access a variable unless using a getter method !!
Viel spasss... -
Pro/Con using symbolic constants in path names (Newbie)
I am a complete novice when it comes about JSP and would like to
ask your opinion in a design question:
Assuming a project where a lot of JSP and Java files
refer to filenames in the same directory, i.e.
in .jsp :
<img src="/foo/bar/myfile1.jpg" />
<img src="/foo/bar/myfile2.jpg" />
in .java :
String myfile = "/foo/bar/myfile3.jpg";
etc., I thought it would make sense to introduce a common constant
to represent the base directory for all these files:
class MyConst { public final String mybase="/foo/bar"; }
and use it, say in the jsp files, like this:
<img src="<%= MyConst.mybase>/myfile1.jpg" />
This would clearly ease the maintenance, in case the pictures
are moved to a different location.
Now to my questions:
(1) Do you see any disadvantage in my solution - say, a performance
penalty due to the introduction of several dozens of scriptlet
expressions in each jsp file?
(2) Do you see a better possibility to achieve my goal?
RonaldNo What I meant by putting them in Properties File is becoz,
let us say when I developed the application all the gifs, jpegs i had them places in a folder names /images
Now during prodction, they have placed these in a folder named /pics
Now I need to change the Constant Java file and then compile all the files and then create war , ear respectively. Which is not possible in production environment. So such changes we would reduce by placing such references in the Properties file.
What i do is read the values during Application startup. Then use these in the Screens. The advantage is I dont need to compile the Java files.
Thanks and regards,
Senior Software Engineer,
IT Solutions India Pvt. Ltd.,
Madras - 600 006
Maybe you are looking for
-
I cannot order new apps or upgrade old apps. iPad keeps asking for info for a card I no longer use and it won't csncel.
-
Can you combine two Apple IDs?
I have iPad2, iPhone4, iPhone3S, MacBook Air 2011 and a Macbook Pro 2010...all running on Lion OS and iOS 5. My Issue is I have two apple accounts, one on gmail and the other on mobile me. I have lots of music from both and want to combine them so
-
JNI generated header file does not match the class file
We have had a JNI project for many years and all has been fine. Within our libraries we have several classes that have inner enum classes. Recently we have moved to JDK1.7. Up to now when JNI generated the methods where the signature used the inner e
-
How do I get rid of KeyChain Access?
I just switched over to Safari from Internet Explorer (since I'm told they're not making any more updates for Mac users). Everytime I try to access a new site, I get a pop-up message saying that Safari wants access to my keychain and to enter a user
-
How do i edit the logo of my website using adobe photoshop
actually i need to change my website's logo and make it transparent more in background format. actually i tried to create but i get blackish and whitish backgroung on my blog when i upload it. please help me regarding this and also my elements arent