Coverting real decimal into assumed decimal



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Coverting real decimal into assumed decimal

Postby yogeshvalhe » Wed Aug 18, 2010 3:37 pm

Hello,

My requirement is to add a field from input file. the field is defined as PIC 9(8).9(5)
And for all input records this field should be added and put the total in the trailer record.

And what I know is, it is not possible to add to numbers defined as real numbers i.e. PIC 9(8).9(5) in this case.

Does any one know, how can I convert PIC 9(8).9(5) into PIC 9(8)V9(5) and go on adding the number.

Thanks,
Yogesh
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Coverting real decimal into assumed decimal

Postby Robert Sample » Wed Aug 18, 2010 4:34 pm

Does any one know, how can I convert PIC 9(8).9(5) into PIC 9(8)V9(5) and go on adding the number.
Have you ever heard of the MOVE statement in COBOL?

      77  WS-REAL                     PIC 9(08).9(05).
      77  WS-IMPLIED                  PIC 9(08)V9(05).

      PROCEDURE DIVISION.
      MAIN-PARA.
          MOVE 12345768.12345         TO  WS-REAL.
          MOVE WS-REAL                TO  WS-IMPLIED.
          DISPLAY 'REAL     ' WS-REAL.
          DISPLAY 'IMPLIED  ' WS-IMPLIED.
produces for output
 REAL     12345768.12345
 IMPLIED  1234576812345
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Coverting real decimal into assumed decimal

Postby yogeshvalhe » Wed Aug 18, 2010 5:33 pm

Hello,

This will sound funny, but I had tried this solution with these variable level declared as 05.

Do you think, the variable level 77 and 05 will make a difference to this.

Thanks,
Yogesh
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Coverting real decimal into assumed decimal

Postby NicC » Wed Aug 18, 2010 5:34 pm

Why not try it and find out and read the manual to discover why level 05 to level 05 did not work?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Coverting real decimal into assumed decimal

Postby Robert Sample » Wed Aug 18, 2010 5:40 pm

Code:
       01  WS-VARS.
           05  WS-REAL                 PIC 9(08).9(05).
           05  WS-IMPLIED              PIC 9(08)V9(05).

       PROCEDURE DIVISION.
       MAIN-PARA.
           MOVE 12345768.12345         TO  WS-REAL.
           MOVE WS-REAL                TO  WS-IMPLIED.
           DISPLAY '05 LEVEL REAL     ' WS-REAL.
           DISPLAY '05 LEVEL IMPLIED  ' WS-IMPLIED.
Output:
 05 LEVEL REAL     12345768.12345
 05 LEVEL IMPLIED  1234576812345
Level numbers will only impact your results when you use groups instead of the elementary items. Otherwise, a 77 level and an 05 level and a 49 level all work exactly the same.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Coverting real decimal into assumed decimal

Postby yogeshvalhe » Wed Aug 18, 2010 6:37 pm

Hello,
I have some problem with this....

I have a copybook and I have defined :REP:-TOTAL-CHARGE (INP-TOTAL-CHARGE )
05 :REP:-TOTAL-CHARGE PIC 9(8).9(5).
05 :REP:-RESPONSE-CODE-1 PIC 9(03).
05 :REP:-RESPONSE-CODE-2 PIC 9(03).

Now, I want to get this added each time while reading new record and put the total in trailer (05 INP-T-BILLING-AMOUNT PIC 9(15).9(2) ) , and I have defined another variable to add this value - 05 BILLING-AMOUNT-1 PIC 9(13)V9(5).

I have defined another implied decimal variable - 05 IMPLIED-INP-TOTAL-CHARGE PIC 9(8)V9(5) VALUE 0.

DISPLAY 'IMPLIED DECIMAL CHARGE= 'IMPLIED-INP-TOTAL-CHARGE
DISPLAY 'INP-TOTAL-CHARGE= 'INP-TOTAL-CHARGE

MOVE INP-TOTAL-CHARGE TO IMPLIED-INP-TOTAL-CHARGE

DISPLAY 'IMPLIED DECIMAL CHARGE= 'IMPLIED-INP-TOTAL-CHARGE

COMPUTE BILLING-AMOUNT-1 = BILLING-AMOUNT-1
+ IMPLIED-INP-TOTAL-CHARGE

My output is below ...
IMPLIED DECIMAL CHARGE= 0000000000000
INP-TOTAL-CHARGE= 00000006.40000
IMPLIED DECIMAL CHARGE= 00000006.4000


and job is getting abended with S0C7 because trying to add real and implied decimal...


COMPUTE BILLING-AMOUNT-1 = BILLING-AMOUNT-1
+ IMPLIED-INP-TOTAL-CHARGE


can you suggest..what could be problem with this MOVE or declaration ?

Thank a lot in advance.

-Yogesh
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Coverting real decimal into assumed decimal

Postby Robert Sample » Wed Aug 18, 2010 6:56 pm

What is the definition of INP-TOTAL-CHARGE? Your 05 level is REP-TOTAL-CHARGE, yet you are moving INP-TOTAL-CHARGE.

I suspect what is happening -- as I said in my earlier post -- is that you have INP-TOTAL-CHARGE defined with a level number less than 05, so it includes REP-TOTAL-CHARGE and other fields. In this case, since you do not move REP-TOTAL-CHARGE, your move would be an alphanumeric to numeric and the decimal point would be moved as part of the MOVE -- which would prevent you from doing arithmetic with the receiving variable.

Your statement
MOVE INP-TOTAL-CHARGE TO IMPLIED-INP-TOTAL-CHARGE
should be changed to
MOVE REP-TOTAL-CHARGE TO IMPLIED-INP-TOTAL-CHARGE

It is absolutely critical to pay attention to level numbers in COBOL -- the wrong level number will change a numeric variable-to-numeric variable MOVE statement into an alphanumeric move, and the rules for alphanumeric moves are very different than for numeric variable moves.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Coverting real decimal into assumed decimal

Postby yogeshvalhe » Wed Aug 18, 2010 7:33 pm

:REP:-TOTAL-CHARGE is copy book variable and it becomes INP-TOTAL-CHARGE

It is part of detail record.
01 :REP:-PAI2-2-BILLING-DETAIL.
.
.
.
05 :REP:-TOTAL-CHARGE PIC 9(8).9(5).

And in my program, I have defined

01 RECORD-COUNT.
05 INPUT-REC-COUNT PIC 9(10) VALUE 0.

05 IMPLIED-INP-TOTAL-CHARGE PIC 9(8)V9(5) VALUE 0.

And I am making MOVE as below before adding

MOVE INP-TOTAL-CHARGE TO IMPLIED-INP-TOTAL-CHARGE

DISPLAY 'IMPLIED DECIMAL CHARGE= 'IMPLIED-INP-TOTAL-CHARGE --> this is still taking a decimal value

COMPUTE BILLING-AMOUNT-1 = BILLING-AMOUNT-1
+ IMPLIED-INP-TOTAL-CHARGE ---> here is the abending with S0C7




My question, is do I have to declare 05 IMPLIED-INP-TOTAL-CHARGE PIC 9(8)V9(5) VALUE 0. this as below.
01 IMPLIED-INP-TOTAL-CHARGE.
05 IMPLIED-INP-TOTAL-CHARGE PIC 9(8)V9(5) VALUE 0.

Just to make sure, it is in similar fashion to INP-TOTAL-CHARGE

Thanks in advance.
-Yogesh
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Coverting real decimal into assumed decimal

Postby Robert Sample » Wed Aug 18, 2010 7:52 pm

:REP:-TOTAL-CHARGE is copy book variable and it becomes INP-TOTAL-CHARGE
You do not show anything about how this happens; you should be using REP-TOTAL-CHARGE in your MOVE statement -- as I stated earlier. Without any indication of how REP-TOTAL-CHARGE becomes INP-TOTAL-CHARGE, and based on the error you are showing -- your code is wrong. Fix the code and you'll fix the error.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Coverting real decimal into assumed decimal

Postby yogeshvalhe » Wed Aug 18, 2010 8:14 pm

I have this -
FD BILLING-FILE-IN
RECORDING MODE IS F
RECORD CONTAINS 600 CHARACTERS
BLOCK CONTAINS 0 RECORDS
LABEL RECORD IS STANDARD.

01 BILLING-RECORD-IN PIC X(600).

COPY ELFLPAIC REPLACING ==:REP:== BY ==INP==.



My copy book get expanded to replace REP by INP and my variable becomes INP-TOTAL-CHARGE

and it is not possible to write -

MOVE REP-TOTAL-CHARGE TO IMPLIED-INP-TOTAL-CHARGE

...Are you saying that, INP-TOTAL-CHARGE is part of record of length 600 which has both mixed alphanumeric and numeric variables at various levels.
when we are moving INP-TOTAL-CHARGE to IMPLIED-INP-TOTAL-CHARGE, it is considering INP-TOTAL-CHARGE as alphanumeric being part of big record of 600 length having all type of values?
Can you come online on google talk -- my id is yogeshvalhe@gmail.com
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post