IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Dynamic Decimal validation


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Wed Dec 05, 2012 9:20 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Dec 05, 2012 9:34 pm
Reply with quote

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 icon_cool.gif
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Dec 05, 2012 9:34 pm
Reply with quote

You wanted to change the value of Ws-a and Ws-b?

or the host variables dynamically?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Wed Dec 05, 2012 9:54 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Dec 05, 2012 10:29 pm
Reply with quote

Rohit,

Did you check Enrico's reply?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Dec 05, 2012 11:06 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Thu Dec 06, 2012 12:36 am
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Thu Dec 06, 2012 12:37 am
Reply with quote

But the question is can WS-A and WS-B be used as shown? or any alternative for this?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Dec 06, 2012 12:47 am
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 06, 2012 12:50 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Dec 06, 2012 12:54 am
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Dec 06, 2012 1:20 am
Reply with quote

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 icon_cool.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Mon Mar 25, 2013 10:08 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 26, 2013 8:06 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Tue Mar 26, 2013 8:26 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Mar 26, 2013 8:36 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Tue Mar 26, 2013 8:48 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Mar 26, 2013 9:16 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 26, 2013 9:44 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Wed Mar 27, 2013 12:41 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 27, 2013 1:05 am
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Wed Mar 27, 2013 1:59 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 27, 2013 2:07 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts JCL Dynamic System Symbols JCL & VSAM 3
No new posts Need Help with Packed Decimal Signs DFSORT/ICETOOL 4
No new posts Synctool-dynamic split job for varyin... JCL & VSAM 7
Search our Forums:

Back to Top