View previous topic :: View next topic
|
Author |
Message |
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Hello Team,
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG500A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 O-RATE PIC 9(2)V9(3) usage comp-3.
01 ws-RATE PIC X(10).
01 WS-A PIC 9(3) value '2'.
01 WS-B PIC 9(3) value '3'.
LINKAGE SECTION.
PROCEDURE DIVISION.
MOVE '$3.125%' TO WS-INTEREST-RATE
PERFORM 05-DO-VALD-DEC
.
05-DO-VALD-DEC.
EXEC SQL
SELECT DECIMAL(CHAR(REPLACE(REPLACE(
REPLACE(:WS-RATE,'%',''),'$','')
,',',''),40),:WS-A,:WS-B)
INTO :O-RATE
FROM SYSIBM.SYSDUMMY1
END-EXEC |
Can WS-A and WS-B changed dynamically?
Or is there any way to create a gereic routine which can be called for any type of decimal validation? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Or is there any way to create a gereic routine which can be called for any type of decimal validation? |
it is weird that after more that 50 years of IT there is still an organization which has not implemented a general use validation <function>
putting an SQL/DB2 dependency just for decimal validation and formatting is not the smartest move
been there seen that ... people almost sacked foe pseudo smart moves |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
You wanted to change the value of Ws-a and Ws-b?
or the host variables dynamically? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
You wanted to change the value of Ws-a and Ws-b? |
Yes WS-A and WS-B needs to changed dynamically. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Rohit,
Did you check Enrico's reply? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Many organizations do not permit using SQL statements in code that has no need to . . . .
It is rather incomplete to issue an SQL statement and not check for successful execution.
Why is this being called "validation"? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Hello Dick,
I am agree to you and others but my shop follow some standard practices and I don't have any other option than adhering to it strictly.
Validation here it means, to get the data in ZD and convert it to PD so any invaid format of ZD comes then its the error. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
But the question is can WS-A and WS-B be used as shown? or any alternative for this? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Can you say what exactly you want to happen?
NUMVAL/NUMVALC can turn "text" into numerics.
You have a simple-looking case (I see it comes from your previous topic?).
To use NUMVALC you'd use INSPECT to get rid of the percent sign. To use NUMVAL you'd need to get rid of the dollar sign as well. Is dollar the only currency symbol invoved? Can they be two-character symbols (or longer)?
The "normal" way to do this is to have a field for currency, a field for the value, and the name of the field for the value to include the word "percent". Your data-provider continues to do you a disservice, which presumably no-one is going to bother doing anything about.
If absolutely stuck with the data like that, I'd use INSPECT and UNSTRING if the "currency" part is a simple one-character, otherwise ODO... |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
You could do the same set of operations through Inspect and reference modification in Cobol or even Sort for that matter
Probably this needs to be addressed in COBOL forum |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Validation here it means, to get the data in ZD and convert it to PD so any invaid format of ZD comes then its the error |
Code: |
MOVE '$3.125%' TO. . . |
That literal is NOT a Zoned-DECIMAL value. How is "the error" detected?
Quote: |
But the question is can WS-A and WS-B be used as shown? |
What happens when you run the posted sql? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
... my shop follow some standard practices ... |
OK...
but for what reason those standard idiots do not provide standard tested and working snippets for standard tasks |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Is querying on SYSIBM.SYSDUMMY1 is a performance issue? I mean if we do the same validations using COBOL fuctions as mentioned by you then would it be more efficient over SYSIBM.SYSDUMMY1? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Is querying on SYSIBM.SYSDUMMY1 is a performance issue? |
Suggest you not be concerned about the performance implications of using SYSIBM.SYSDUMMY1 . . . There are many other database interractions that will have more impact.
Quote: |
I mean if we do the same validations using COBOL fuctions as mentioned by you then would it be more efficient over SYSIBM.SYSDUMMY1? |
Which functions do you have in mind? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
Which functions do you have in mind? |
NUMVAL in COBOL or any MATH/DATE calculations.
Quote: |
Suggest you not be concerned about the performance implications of using SYSIBM.SYSDUMMY1 . . . There are many other database
interractions that will have more impact. |
Very true, but just would like to know is it a good practice to use SYSIBM.SYSDUMMY1 over COBOL fuctions or which one is more faster in terms of executions. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Very true, but just would like to know is it a good practice to use SYSIBM.SYSDUMMY1 over COBOL fuctions or which one is more faster in terms of executions. |
what is that is not clear when we tell that it is a BAD PRACTICE to have a DB2 dependency just to check for numerics ???
is this the first time in Your organization somebody has to check for a valid numerics ???
the fastest/most effective way would be to have a standard function callable in ONE simple statement to do it
pseudocode
Code: |
if checknumber(number) != 0 then do
process the format error
end
|
the write once use always subroutine/function could be expanded to provide more advanced application dependent facilities
BTDTGTTS
anyway from a pure performance point of view the COBOL should beat DB2 hands down |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
anyway from a pure performance point of view the COBOL should beat DB2 hands down |
Yes, Just would like to know this.
Quote: |
what is that is not clear when we tell that it is a BAD PRACTICE to have a DB2 dependency just to check for numerics ??? |
Already it is a COBOL-DB2 program and the questions was which choice to be taken for decimal validations, by COBOL or SYSIBM.SYSDUMM1.
Quote: |
is this the first time in Your organization somebody has to check for a valid numerics ??? |
It is already in place thru some COBOL logics lots of unstring,INSPECT...
Quote: |
the write once use always subroutine/function could be expanded to provide more advanced application dependent facilities |
Agree. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Things may have changed but...
DB2 is not the fastest thing in the world - although much faster than it used to be - so the less work you give it the faster it is for everyone else who is using it and you probably wouldn't notice any performance degradation of your COBOL program. In fact, it may well improve! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
How might you use SYSDUMMY1 to accomplish the functionality of NUMVAL?
How would you use this in place of COMPUTE or ADD or ?
If your intent is to improve performance, i believe this is Not the place to concentrate. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
How might you use SYSDUMMY1 to accomplish the functkinoality of NUMVAL? |
We can use cast,decimal,char,replace fuctions over sysdummy1 and formats the data
Quote: |
How would you use this in place of COMPUTE or ADD or ? |
Not for this operations.
Quote: |
If your intent is to improve performance, i believe this is Not the place to concentrate. |
true,
My question was just to confirm any harm using sysdummy1 over COBOL functions for decimal data validations. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I would say yes, there could be harm . . . But not merely for performance reasons. To do what i believe you would try to implement, you would have some rather strange code in many places to accomodate various requirements.
Almost everywhere i've supported has a common date valadition routine and a common numeric validation routine (as well as many other "common routines". These are called from whatever application code needs the functionality. The code is not scattered all over the system.
Quote: |
We can use cast,decimal,char,replace fuctions over sysdummy1 and formats the data |
There is simply no reason to code these via sql for a non-SQL need. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
I would say yes, there could be harm . . . But not merely for performance reasons. To do what i believe you would try to implement, you would have some rather strange code in many places to accomodate various requirements.
Almost everywhere i've supported has a common date valadition routine and a common numeric validation routine (as well as many other "common routines". These are called from whatever application code needs the functionality. The code is not scattered all over the system. |
Perfectly said, but currently I am new to this shop and I don't see they follow this type routines but earlier shop had.
Quote: |
There is simply no reason to code these via sql for a non-SQL need. |
Indeed, but if it is going to be a COBOL-DB2 program then I think this is better than COBOL fuctions. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It sounds like what you think is more important to you than the comments from multiple proven experts - as yet you are a promising beginner.
If you are determined to just do what you want (even if it is the poorer choice), you will, so this topic should soon be closed. . .
Quote: |
and I don't see they follow this type routines but earlier shop had. |
No good reason that this cannot be started. |
|
Back to top |
|
|
|