How to add var in REXX



IBM's Command List programming language & Restructured Extended Executor

How to add var in REXX

Postby Mann_B » Wed Mar 23, 2011 7:19 pm

Hi

I have add comp-3 var in RExx. I am getting the field from a file using SUBSTR...Now I have substr(comp-3).But when am trying to add 2 such fields am getting error saying Bad arthimetic operation

Can anyone help me in how to add .Do we have any conversion?
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to add var in REXX

 

Re: How to add var in REXX

Postby BillyBoyo » Wed Mar 23, 2011 8:10 pm

If you search this forum I think you'll find some stuff to help. You'll need conversion. There are some excellent examples and suggestions. Ideally, you'd even have done it before asking the question. Also, a manual. Online help, if you have it (I don't know about REXX in TSO).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: How to add var in REXX

Postby Mann_B » Wed Mar 23, 2011 8:20 pm

I tried giving like this
AMOUNT = (C2X(SUBSTR(REC1.RECID,POS2,8)))
but am getting an error saying Incorrect call...
here REC1.RECID,POS2,8--ths is a comp-3 var...
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to add var in REXX

Postby Akatsukami » Wed Mar 23, 2011 8:42 pm

Mann_B wrote:I tried giving like this
AMOUNT = (C2X(SUBSTR(REC1.RECID,POS2,8)))
but am getting an error saying Incorrect call...
here REC1.RECID,POS2,8--ths is a comp-3 var...

I would check that POS2 and RECID have valid values; TRACE the logic if necessary.

C2X will give you the hexadecimal string representing the characters; i.e., if your packed decimal (COMP-3 in COBOLese, which should be avoided unless actually referring to COBOL) data are X'000000000000123C', (C2X(SUBSTR(REC1.RECID,POS2,8))) will return "000000000000123C". This will be treated as a character string in Rexx, and if used in a computational statement will cause the error noted in your first post.

There is no direct conversion in native Rexx (although there are conversion functions that can be purchased as add-ons). You'll need to write your own function, something like (untested code with all error checking omitted):
C2P:  procedure
arg string pos len .
foo = c2x(substr(string,pos,len))
bar = substr(foo,1,(2*len)-1)
 
if (substr(foo,2*len)="D") then
  bar = bar * -1

return bar
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: How to add var in REXX

Postby NicC » Thu Mar 24, 2011 1:09 am

I am not sure if I have posted this before - I know others have posted similar so your initial search - you DID search didn't you (as per the rules) - should have found one.
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/         
/* P2D function to convert a FIXED DEC field to ZONED DECIMAL        */         
/*                                                                   */         
/* Argument : Packed decimal field to be converted. Returns field in */         
/*            zoned decimal format. The calling routine will have to */         
/*            determine the decimal position. E.g. if the FIXED DEC  */         
/*            field contains 100.99 this is stored as '10099C'x and  */         
/*            the called procedure will divide the returned string,  */         
/*            10099, by 100 to get 100.99                            */         
/* Examples:                                                         */         
/*   1: stdat = Right(P2D(stdat),5,0)        - fixed dec 5,0         */         
/*   2: chamt = P2D(chamt)                   - fixed dec 11,2        */         
/*      chamt = Format(chamt / 100,,2)                               */         
/*   3: chamt = Format(P2D(chamt) / 100,,2)  - same as exmample      */         
/*-------------------------------------------------------------------*/         
p2d: Procedure                                                                 
                                                                               
   px = C2X(Arg(1))                 /* Convert value to a hex string */         
   lpx = Length(px)                 /* and get its length            */         
   nd = Digits()                    /* save current Digits setting   */         
   Numeric Digits lpx               /* Ensure enough Digits          */         
   Parse Upper Var px d =(lpx) s    /* Split px into digits and sign */         
   If Datatype(d,'W')               /* Only digits 0-9 in digits?    */         
   Then Do                                                                     
      pn = Pos(s,'BDACEF')          /* Determine sign                */         
      If pn > 2 Then Return +d      /* A,C,E or F is positive        */         
      If pn > 0 Then Return -d      /* B and D are negative          */         
   End                                                                         
   Else Nop                         /* Unsigned value                */         
   Numeric Digits nd                /* Restore Digits value          */         
                                                                               
Return px                                                                       
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: How to add var in REXX

Postby Mann_B » Mon Mar 28, 2011 7:28 pm

Thank You


I got the result..its almost the same way
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to add var in REXX

Postby Mann_B » Mon Mar 28, 2011 7:31 pm

AMOUNT = left((C2X(SUBSTR(REC1.RECID,POS2,8))) ,15)
IF SUBSTR(AMOUNT,16,1) = 'D' THEN
DO
SAY 'NEGATIVE VALUE CURRENT' AMOUNT
AMOUNTA = 0 - AMOUNTA
SAY 'AMOUNT A' AMOUNTA
END
AMOUNTB = LEFT(C2X(AMOUNT.CNT),15)

IF SUBSTR(C2X(AMOUNT.CNT),16,1) = "D" THEN
DO
SAY'NEGATIVE VALUE ARRAY'
AMOUNTL = AMOUNTA + AMOUNTB

and then the revesre conversion
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post