Page 1 of 1

Problem with numeric field with sign in last digit

Posted: Tue Apr 03, 2007 2:24 pm
by cees post
Field definition input

P1 1 6 N
Value of field is 02236A

Field definition of output
S1 1 1 A
N1 2 6 N

I want the value 022361 by processing as follows
IF P1 < 0
S1 = '-'
N1 = (P1 * -1)
ELSE
N1 = P1
END-IF

But when I proces this field I get
*******A006 PROGRAM INTERRUPT - CODE 7 (DATA EXCP)

Somebody how knows how to handel these kind of fields in easytrieve program

EASYTRIEVE - MASK

Posted: Tue Apr 03, 2007 9:37 pm
by Krishna
Hi Cees,

What is the value of P1? Is it 02236A or 022361.

If you want to display sign '-' , you can use MASK while defining
target variable. It is not required to multiply with -1.

Code: Select all


 S1    W  7 N 0 MASK&#40;'-----99'&#41;
 
 OR

 S2    W  7 N 0 MASK&#40;'ZZZZZ9-'&#41;


Let me know, if this is not answered your question.


Regards,
Krishna
http://www.geocities.com/srcsinc
http://www.ibmmainframeguru.com
http://www.jacharya.com

Re: EASYTRIEVE - MASK

Posted: Wed Apr 04, 2007 11:34 am
by cees post
Hi Krishna,

As I understand mask is only working when you display it in a report.

What I want is to write a numeric field with a character at the end (representing a sign) to a output file, so in my example is the input P1 value 02236A (where A is standing for -1) and I expect in my output file the value -022361

Thanks for your help

easytrieve MASK

Posted: Wed Apr 04, 2007 6:50 pm
by Krishna
Hi Cees,

Try with
P1 1 6 N 0 <- Add zero at the end of declaration.

or

Use MASK

Posted: Thu Apr 05, 2007 12:46 am
by Veera
Cees Post,

I am not clear on few things on ur requirement,


1) P1 1 6 N
Value of field is 02236A ---> How can a variable declared (N ->Numeric) has a alpha numeric value


2) As per ur given data P1 = 02236A

and what are you tryinG to achieve by doing this

N1 = (P1 * -1) ===> you mean N1 = 02236A * (-1) ?????

Well i am not sure what is your requirement correctrly.


But i assumed few things and coded a sample program which will give you what you have asked for in the outputfile, please find below

Code: Select all

 PARM  ABEXIT&#40;SNAP&#41; PRESIZE 1024                                         
*                                                                       
FILE INPFILE FB &#40;6 0&#41;                                                   
  INPFILE-FIELD          1   6 A   ---------------------> I/P FILE HAS A VALUE OF 02236A                                     
*                                                                       
FILE OUTFILE  FB &#40;7 0&#41;                                                  
 WS-OUTFILE-REC          1   7 A   ---------------------> Expected O/P FILE SHOULD VALUE OF  -022361                                                                          
*                                                                       
WS-INPFILE-FIELD         1   6 A                                        
    WS-INP-VALUE         1   5 N                                        
    WS-INP-SIGN          6   1 A   

*                                                                       
 WS-INP-VALUE-A          1   6 N 0                                      
*                                                                       
 WS-OUTFILE-FIELD        1   7 A                                        
    WS-OUT-SIGN          1   1 A                                        
    WS-OUT-VALUE         2   6 N                                        
*                                                                       
**********************************************************************  
*                          PROCESSING                                *  
**********************************************************************  
*                                                                       
JOB INPUT &#40;INPFILE&#41;                                                     
*                                                                       
    WS-INPFILE-FIELD    =  INPFILE-FIELD                                
    WS-INP-VALUE-A      = &#40;WS-INP-VALUE * &#40;-10&#41;&#41; - 1                    
*                                                                       
    IF WS-INP-VALUE-A   LT 0                                            
       DISPLAY ' LESS THAN ZERO '                                       
       WS-OUT-SIGN      = '-'                                           
       WS-OUT-VALUE     = &#40;WS-INP-VALUE * 10&#41; + 1                       
       WS-OUTFILE-REC   = WS-OUTFILE-FIELD                              
       PUT  OUTFILE                                                     
    ELSE                                                                
       DISPLAY ' GREATER THAN ZERO '                                    
       WS-OUT-SIGN      = '+'                                           
       WS-OUT-VALUE     = &#40;WS-INP-VALUE * 10&#41; + 1                       
       WS-OUTFILE-REC   = WS-OUTFILE-FIELD                              
       PUT  OUTFILE                                                     
    END-IF                                                      

NOTE : IN THE ABVOE CODE I ASSUME THE VALUE OF A = -1 AND DID THE CODING, IF YOUR REQUIREMNT IN THAT I/P FILE WILL HAVE HEX VALUES FROM 0 -9 , A,B,C,D,E,F,G,H....YOU NEED TO VALIDATE THOSE
AND MOVE THE CORESPONDING VALUES INSTEAD OF -/+ 1 AND -/+ 10...ACCORDINGLY.

P.S = I AM NOT 100% CLEAR REG UR REQUIREMENT, I GUESS I TRIED TO PUT THE CODE THE WAY YOU HAVE TRIED , IF YOU COME UP WITH CLEAR REQUIREMETNS REG THE FILE LAYOUT AND WHAT KIND OF VARAIBLE/DATA COMES FROM I/P FILE MAY BE YOU DONT NEED THE ENTIRE CODE ..A TRICKY DECLARATION OF THE VARAIBLE CAN DO ..THE WORK ...

Thanks,
Veera.