View previous topic :: View next topic
|
Author |
Message |
JAYANT KUMAR SAHOO
New User
Joined: 15 Mar 2006 Posts: 14
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
What exactly is it that you believe the C2D function does? |
|
Back to top |
|
|
JAYANT KUMAR SAHOO
New User
Joined: 15 Mar 2006 Posts: 14
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|