COBOL data maping in file and report



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

COBOL data maping in file and report

Postby ajuatsgp » Thu Jun 17, 2010 2:32 pm

Hi,
I have a field defined as PIC9(17).
I need to show this field in a report as 9(9).9(2),the above field basically refers to an amount fied.
How to do that??? I have another amount field in a file of x(21) I need to send this field to my field in a file as9(9).9(3). How to do that???

-----------------
You can use COMPUTE or MOVE to move a PIC 9(17) variable to any numeric field, even one defined 9(9).9(2). The first 8 digits of the 17-digit variable will not appear on the report, and the two digits after the decimal point will be zeroes.

You can MOVE a PIC X(21) variable to a PIC 9(9).9(3) variable. The decimal point is implied after the 21st character so the three digits after the decimal point will all be zeroes. The first twelve characters will not be moved. And if you have non-numeric data in the last 9 characters you may cause a S0C7 abend depending upon what you do with the receiving variable.

Both of these cases are quite thoroughly explained in the COBOL Language Reference manual. I recommend you get a copy and keep it handy.
----------
Hi
I have already tried the above things as described by you.
when i am tryig to move a 9(17) field to a 9(9).9(2), there will be preceding zeroes and also if I am using cobol editing field types such as z(9).9(2) to supress the leading zeroes my problem is not getting resolved.
Basically the file I am using is so defined that it has a predetermined NOD of 2, I mean if I enter 1000 in the amount field then it will treat it as 10.00 for all of its processing however if we will see the file it will show 1000 only.
So now when I am moving this fied of mine to report variable I am getting 1000.00 but it should show 10.00.

And for the second case I have a field define with X(21) with edit pattern as ZZZZZZZZZ,ZZZ,ZZZ.99 when i am trying to move this field to 9(9).9(3), i am getting SOC7 probably due to the commas.
ajuatsgp
 
Posts: 82
Joined: Thu May 20, 2010 6:50 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL data maping in file and report

 

Re: COBOL data maping in file and report

Postby Robert Sample » Thu Jun 17, 2010 5:36 pm

Although it is not entirely clear from your post what you are saying, I think your first problem is that you need to redefine the PIC 9(17) variable as PIC 9(15)V99 so the decimals will be moved correctly. A V in a COBOL PICTURE clause is an implied decimal point -- meaning no bytes are reserved for the decimal point, it is merely understood that the decimal point is there. Since there is nothing to indicate the decimal point is there, if you create a variable that does not have the V in the right spot in the PICTURE, the default COBOL rule applies -- which says the implied decimal point occurs after the last digit.

As far as the second problem, you can redefine the PIC X(21) variable as a numeric edited variable and move the redefined variable instead of the PIC X(21) -- although I have not tested this to verify the behavior. And yes, commas will cause S0C7 abends.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL data maping in file and report

Postby ajuatsgp » Thu Jun 17, 2010 7:25 pm

Robert
My problem is there is a field of 9(17) in a file which is an amount field and our system is defined such a way that if we enter a value of 1000 the field will show 1000 when opened in file-aid but while any operation it will take the value as 10.00.Now I want to move the above field to a report variable which is 9(9).9(2).So when I am doing movement cobol is understanding the value in the field as 1000 instead of 10 and the report shows 1000.00, but as per my requirement it should be 10.00.
So how to do it????

Can you please be bit more clear regarding the second solution you have suggested.
ajuatsgp
 
Posts: 82
Joined: Thu May 20, 2010 6:50 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL data maping in file and report

Postby Robert Sample » Thu Jun 17, 2010 8:31 pm

05  WS-X PIC 9(17).
05  WS-XR REDEFINES WS-X
          PIC 9(15)V99.
.
.
.
MOVE WS-XR TO REPORT-VARIABLE.


Similarly, as long as the field matches the picture you provided
05  WS-X  PIC X(21).
05  WS-XR REDEFINES WS-X
          PIC ZZZZZZZZZ,ZZZ,ZZZ.99
.
.
.
MOVE WS-XR TO NUMERIC-VARIABLE
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL data maping in file and report

Postby ajuatsgp » Fri Jun 18, 2010 9:17 am

Thanks for the first solution

For the second case let say the file has a data of ,895 then after movement my field shows 000000000.895, where as it should show 000000895.000.

Please help me how to handel this???
ajuatsgp
 
Posts: 82
Joined: Thu May 20, 2010 6:50 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL data maping in file and report

Postby dick scherrer » Fri Jun 18, 2010 9:27 am

Hello,

You need to provide the correct info. . .

If the receiving field is ZZZZZZZZZ,ZZZ,ZZZ.99 how is the value 000000000.895 even possible?

You need to show the code you used and the input record (not a representation of the data, but the actual data) you used.

You did notice the bit of Robert's info that said:
And yes, commas will cause S0C7 abends.
So, did the unwanted result or the 0c7 or both for different tests? If multiple tests were run, the input and the code for each needs to be posted. Not the entire progran, just these particular lines of code.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: COBOL data maping in file and report

Postby ajuatsgp » Fri Jun 18, 2010 1:11 pm

I got the solution for second one as well...

after redifining as said by Robert I am moivng my field to Z(09).9(03) and hence I am getting the desired output...

Thanks to all for your valuable contribution...
ajuatsgp
 
Posts: 82
Joined: Thu May 20, 2010 6:50 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL data maping in file and report

Postby shaik.Abdul Firoz » Fri Jun 18, 2010 9:36 pm

hi
This is firoz.....here
my problem is , while i was working with conditional names mainly in files i got confused.

like
if i define a field as 01 ws-a pic value 'n'.
88 ws-a-y value 'y'.

when i worked with this i goty confused in perform statement.like,
perform until ws-a-y.
read infile
at end
set ws-a-y to true
not at end
display 'wt ever ur record'.

please resolve my problem how its internally executes & please explain me as graphically..........
shaik.Abdul Firoz
 
Posts: 1
Joined: Fri Jun 18, 2010 8:49 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL data maping in file and report

Postby Robert Sample » Fri Jun 18, 2010 10:42 pm

Conditional names are not associated with files -- they are associated with COBOL variables (which could be in WORKING-STORAGE, LINKAGE, or FILE SECTION).
SET WS-A-Y TO TRUE
means exactly the same thing as
MOVE 'Y' TO WS-A
and COBOL implements them the same.
       01  WS-A                        PIC X(1) VALUE 'N'.
           88  WS-A-Y                           VALUE 'Y'.

       PROCEDURE DIVISION.
       MAIN-PARA.
           SET WS-A-Y                  TO  TRUE.
           MOVE 'Y'                    TO  WS-A.
assembles to
 000017  *MAIN-PARA
 000018  SET
    00030C  92E8 8000               MVI   0(8),X'E8'              WS-A
 000019  MOVE
    000310  92E8 8000               MVI   0(8),X'E8'              WS-A
 000021  EXIT
so there is literally no difference to COBOL which statement you use.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL data maping in file and report

Postby ajuatsgp » Mon Jun 21, 2010 9:31 am

Hi Firoz,

I think your doubt is cleared if not can you be little more specific what you want to know about the code....
ajuatsgp
 
Posts: 82
Joined: Thu May 20, 2010 6:50 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post