Problem with numeric field with sign in last digit

Ask/Clarify the questions on EASYTRIEVE

Moderators: DikDude, Moderator Group

Post Reply
cees post
Member
Posts: 2
Joined: Mon Mar 26, 2007 3:47 pm
Location: Amsterdam

Problem with numeric field with sign in last digit

Post by cees post » Tue Apr 03, 2007 2:24 pm

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
With kind regards
Cees Post

User avatar
Krishna
Site Admin
Posts: 1052
Joined: Fri Jan 27, 2006 7:50 am

EASYTRIEVE - MASK

Post by Krishna » Tue Apr 03, 2007 9:37 pm

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

cees post
Member
Posts: 2
Joined: Mon Mar 26, 2007 3:47 pm
Location: Amsterdam

Re: EASYTRIEVE - MASK

Post by cees post » Wed Apr 04, 2007 11:34 am

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
With kind regards
Cees Post

User avatar
Krishna
Site Admin
Posts: 1052
Joined: Fri Jan 27, 2006 7:50 am

easytrieve MASK

Post by Krishna » Wed Apr 04, 2007 6:50 pm

Hi Cees,

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

or

Use MASK
Last edited by Krishna on Thu Apr 05, 2007 12:54 am, edited 1 time in total.

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

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

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.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others