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

C2D function in rexx not giving me correct result.


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
JAYANT KUMAR SAHOO

New User


Joined: 15 Mar 2006
Posts: 14

PostPosted: Fri Mar 24, 2006 12:41 pm
Reply with quote

Hi All,
I am using a rexx routine to get the sum of a particular numeric field for all the records present in a file.The numeric field appears in the input file at pos 55-64.
suppose my input file has 2 records having nos
1011621000
1011621000
in 55-64 pos then the sum should be 2023242000

I am using the below code
ADDRESS TSO
"ALLOC FI(DD1) DA('F3674AO.PDTEST.OUT.REC3.IN') SHR REUS"
"ALLOC FI(DD4) DA('F3674AO.PDTEST.OUT.REC3.OUT') SHR REUS"
"EXECIO * DISKR DD1 (FINIS STEM A."
SUM = 0
DO I = 1 TO A.0
J.I = SUBSTR(A.I,55,10)
SUM = SUM + C2D('J.I')

END
"EXECIO * DISKW DD4 (FINIS STEM J."
SAY 'SUM' SUM

I know somewhere the C2D function is wrong and thats why I am not getting the proper result.Can anybody tell me how to achieve the same result.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Mar 24, 2006 4:19 pm
Reply with quote

What exactly is it that you believe the C2D function does?
Back to top
View user's profile Send private message
JAYANT KUMAR SAHOO

New User


Joined: 15 Mar 2006
Posts: 14

PostPosted: Sat Mar 25, 2006 12:59 am
Reply with quote

C2D is the decimal representation of the binary character string.Maybe I am wrong in my concept to use that for my rexx.
Could you please help me out for the same problem by providing the sample rexx code.


I am using a rexx routine to get the sum of a particular numeric field for all the records present in a file.The numeric field appears in the input file at pos 55-64.
suppose my input file has 2 records having nos
1011621000
1011621000
in 55-64 pos then the sum should be 2023242000
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Sat Mar 25, 2006 1:20 am
Reply with quote

Code:

"EXECIO * DISKR DD1 (FINIS STEM A."                 
SUM = 0                                             
DO I = 1 TO A.0                                     
  J.I = SUBSTR(A.I,55,10)                           
  SUM = SUM + J.I                                   
END                                                 
"EXECIO * DISKW DD4 (FINIS STEM J."                 
SAY 'SUM' SUM                                       

Result "SUM 2023242000"
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Mar 27, 2006 3:03 pm
Reply with quote

In fact, if you add within the loop:

SAY 'DATATYPE OF 'J.I' IS 'DATATYPE(J.I)

you will see that J.I is already a number and there is no need for conversion.

C2D is mostly used to transform a character into it's numeric value:

C2D('A') returns 193 and C2D(1) returns 241

similarly, C2X('A') returns 'C1' (a 2 chars string)
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Run rexx with JCL Job CLIST & REXX 1
No new posts Run rexx in batch job CLIST & REXX 7
No new posts Does anyone know rexx for VSE CLIST & REXX 3
No new posts TSO ALLOC In REXX Needs Improvement JCL & VSAM 3
No new posts REXX/CMS How to place command console... CLIST & REXX 4
Search our Forums:

Back to Top