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

Performing calculations using Signed variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jijesh

New User


Joined: 09 May 2006
Posts: 4

PostPosted: Mon Oct 30, 2006 4:50 pm
Reply with quote

Hi I need some light to be thrown on using Signed variables.

in my program i am using signed variables for calculation. in the input file has the amount field is defined as:
IN-AMT-VAR 9(9)V99
IN-AMT-SIGN X(01)
the amount and its sign are defined seperately. i have to do some calculations by taking them together. i redefined the layout and tried to read input record into a signed variable IN-AMT-TEMP S9(9)V99.

while computing i am getting SOC7 error. How should i proceed???

Also i want to read the signed variable back to the same input layout i.e. as amount seperate and sign seperate.
Back to top
View user's profile Send private message
annujp

New User


Joined: 31 Aug 2005
Posts: 39
Location: St Paul,MN

PostPosted: Mon Oct 30, 2006 5:06 pm
Reply with quote

What you can do is
set a flag (positive or negative) by checking the sign variable. If the sign variable is "-" then you can multiply the amount value variable by -1 and store it the result in a signed variable.
At the end of the program, you can check the value of this variable. If <0 move "-" to the sign variable and write it into the file.

Guys...please let me know if there is any other method to do this.... icon_biggrin.gif
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Oct 30, 2006 5:41 pm
Reply with quote

Hi !

Use comp-3 fields.

Before moving test your sign-flag and if negative do multipy with -1.
Then for all other aritmethic funktions use the comp-3 fields.

Regards, UmeySan
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Oct 31, 2006 7:34 am
Reply with quote

You could also define your 2 fields as subordinate to an 01 level then redefine it as a sign is separate trailing variable:
Code:

01  var-w-sign.
      05  IN-AMT-VAR   pic 9(9)V99.
      05  IN-AMT-SIGN  pic X(01).   
01  sign-is-sep-var    redefines
      var-w-sign       pic 9(9)v99 sign separate trailing.
Back to top
View user's profile Send private message
jijesh

New User


Joined: 09 May 2006
Posts: 4

PostPosted: Tue Nov 07, 2006 4:26 pm
Reply with quote

Thanks guys for the suggestions.

i tried the first one and it worked. thanks a lot.

i had previuosly tried the 3rd option also (i.e.) redefining the structure but didnt work.

i have another similar issue, where i did the following operation

C = A/B

where
C = V9(6)
A = 9(07)V99
B = 9(10)V99

i tried
(i) redefining the structure of A as similar to B.
(ii) declared a new group varaible D and tried to move the values in A to D as:
01 D-varaible
05 D1-var 9(10).
05 D2-var V99.
01 A-varaible
05 A1-var 9(07).
05 A2-var V99.
and then tried to move the A values to the respective D values and finally used D in place of A in the formula.

both the approaches didnt work. what can i do to do the manipulation.????
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Nov 07, 2006 4:37 pm
Reply with quote

Hi !

Coming back to my suggestion.
Why don't using signed comp-3 fields.

Field Pic S9(16)V9(02)

Before moving test your sign-flag and if negative do multipy with -1.
Then for all other aritmethic funktions use the comp-3 fields.

Plse, prefer simple solutions. Do not make it too complicated.

Regards, UmeySan
Back to top
View user's profile Send private message
jijesh

New User


Joined: 09 May 2006
Posts: 4

PostPosted: Tue Nov 07, 2006 6:16 pm
Reply with quote

Thanks Umey

i'll try the same.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts JCL with variables JCL & VSAM 1
No new posts JCL Variables JCL & VSAM 1
No new posts reset/clear ALL application profile v... TSO/ISPF 3
No new posts Cobol-DB2 Programming - Better perfor... DB2 1
No new posts REXX - Adding variables CLIST & REXX 8
Search our Forums:

Back to Top