Output with decimal point



Unicenter CA-Easytrieve Plus Report Generator: CA's information retrieval and data management tool

Output with decimal point

Postby charlessxavier » Wed Jul 06, 2011 10:04 am

Hi all,

am a beginner in easytrieve programming.. am really sorry if the question seems so noob.. and i have searched the forum but did not get a firm idea on this

i m retrieving a field from the IMS database which is declared as 06 P 2

Now i need to read it and write in another file where i should display the same with two decimal digits...

Could somebody tell me how to do it ???
charlessxavier
 
Posts: 11
Joined: Sun Aug 29, 2010 11:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: Output with decimal point

Postby BillyBoyo » Wed Jul 06, 2011 12:38 pm

Why don't you want it on the output file in the same format, with an implied decimal place?

If you really, really, want to do it, you can't do it directly. Easytrieve Plus only puts the explicit decimal place in for PRINT/DISPLAY statements.

So, you'll have to do it "by hand". Start by moving the packed decimal to a zoned decimal, defined as 11 N 2. "Redefine" this as two fields, 9 N and 2 N. Create two new fields as 9 N and 2 N that beneath a longer field. Define a 1 A with a value of "." in between these two so that you have a 12 byte field with the "." where you want.

Now do all the moves.

What about the sign of the field? Even if you don't want it, I think you'd need a bit extra in the above to deal with it properly.

Or, you could just get the spec changed and

outfile-packed-decimal-name * 6 P 2

outfile-packed-decimal-name = w-packed-decimal-from-ims


If this is something you are going to be doing lots (doing it the "silly" way for the next system on) then I'd suggest investing some time (not much) in writing a "file exit" to aid you.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Output with decimal point

Postby charlessxavier » Wed Jul 06, 2011 1:35 pm

oh i wasnt aware that we cant display a decimal directly..

anyway thanks for the idea you have given..

and i dont think this wil take much time :)

wil let u know once i m done with it.. thanks again
charlessxavier
 
Posts: 11
Joined: Sun Aug 29, 2010 11:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: Output with decimal point

Postby BillyBoyo » Wed Jul 06, 2011 1:51 pm

You can "display" or "print" the decimal directly. What you can't do is other than for a printed-output statement get Easytrieve to process the MASK for the field.

In Cobol, you define a field for you packed number, another for your output with the "editing" that you want. In your case, you'd just define a field with editing in your output file (in Cobol). Easytrieve defines the print MASK alongside the field definition, but will only use the MASK for printed output. So, if you need an edited field in a different place than printed output, you have to do the extra work.

Remember about the sign.

By suggesting an EXIT to do the stuff if you need it regularly, this is not for the amount of code per se, but the potential for introducing errors in the extra code. If you let Easytrieve do the formatting, with the full mask, but can use that formatted field rather than "print" it, it gives you what you want without a bunch of extra code for each field.

But, if you don't need it lots, go with the manual approach.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Output with decimal point

Postby neeraj430 » Sun Apr 29, 2012 10:27 pm

I am facing a simlar issue mentioned by charles. Here is my scenario iam retrieving a value from db2 table declared as "06 P 2".

Then i moved this value to 11 n 2 mask ('$,$$$,$$$,$$9.99). I want to insert this value as comments in another db2 table which is a varchar field.(ws-comments-VC 250).

This is what happening then which i fail to understand.The value which is inserted in comments field is displayed as 000000036.59 after following above process. I want the value to be displayed as 36.59(zeroes supressed). Is der any way to do it?

Looking forward for suggestions. Thanks in advance.
neeraj430
 
Posts: 3
Joined: Sat Apr 28, 2012 4:15 pm
Location: chennai
Has thanked: 1 time
Been thanked: 0 time

Re: Output with decimal point

Postby BillyBoyo » Sun Apr 29, 2012 11:12 pm

I'll try the explanation again.

When you specify a MASK, Easytrieve Plus only uses it for printed output, from a DISPLAY statement or when you PRINT a report.

Which means what you want to do cannot be done directly with Easytrieve Plus.

Two methods, then:

The manual method - do the "editing" yourself, by redefinining, putting the decimal place in, sign if necessary, and define an OCCURS so you can loop from the start to the first non-zero character, or the digit in front of the decimal point, setting zeros to space.

The automatic method - write a Cobol program which will be a "FILE EXIT" which will return the value given to it. Define a PRINTER file which will use the EXIT. DISPLAY your field to the PRINTER file. Easytrieve will call the Cobol program with the edited field, which you can copy into an additional parameter.

If your site is only ever going to do this once, you can consider the manual way.

If your site is going to do this in multiple programs, either use the EXIT method or at least try to create a MACRO to do the manual method. The danger in not doing it in either of these ways is a proliferation of different code to do it in different programs, which reduces ease of comprehension and introduces potential for errors.

If you do the EXIT, put everything in MACROs so that it is "transparent" to the programmer.

These users thanked the author BillyBoyo for the post:
neeraj430 (Sun Apr 29, 2012 11:33 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Output with decimal point

Postby neeraj430 » Mon Apr 30, 2012 12:22 am

Thnx for the reply billy...

I will go with the manual method for now. Please suggest if the below code is same as what you have explained.(define an OCCURS so you can loop from the start to the first non-zero character, or the digit in front of the decimal point, setting zeros to space.)

WS-amount W 01 A OCCURS 9

DEFINE ws-amount-1 01 A OCCURS 9 INDEX ONE-IX

NAME-SUB = 1
ONE-IX = 0

DO UNTIL WS-amount EQ 10
IF WS-amount (NAME-SUB) E '0'
WS-amount (NAME-SUB) = ' '
ONE-IX = ONE-IX + 1
NAME-SUB = NAME-SUB + 1
ELSE
NAME-SUB = 9
END-IF

ONE-IX = ONE-IX + 1
ws-amount-1 = ws-amount.
neeraj430
 
Posts: 3
Joined: Sat Apr 28, 2012 4:15 pm
Location: chennai
Has thanked: 1 time
Been thanked: 0 time

Re: Output with decimal point

Postby BillyBoyo » Mon Apr 30, 2012 12:56 am

neeraj430 wrote:Thnx for the reply billy...

I will go with the manual method for now. Please suggest if the below code is same as what you have explained.(define an OCCURS so you can loop from the start to the first non-zero character, or the digit in front of the decimal point, setting zeros to space.)

WS-amount W 01 A OCCURS 9

DEFINE ws-amount-1   01  A  OCCURS 9 INDEX ONE-IX

NAME-SUB = 1
  ONE-IX = 0

DO UNTIL WS-amount EQ 10
       IF WS-amount (NAME-SUB) E '0'
          WS-amount (NAME-SUB) = ' '
          ONE-IX = ONE-IX + 1
          NAME-SUB = NAME-SUB + 1
       ELSE
          NAME-SUB = 9
       END-IF

ONE-IX = ONE-IX + 1
    ws-amount-1  = ws-amount
.


Well, I can't see an END-DO and I don't think you mean WS-amount EQ 10 at the top of the DO.

I'd start like this:

W-SPLIT-NUMBER W 11 N 2
    W-SN-INTEGER W-SPLIT-NUMBER   9 A
    W-SN-DECIMAL W-SPLIT-NUMBER +9 2 N 0

W-EDITED-NUMBER W 12 A
    W-EN-INTEGER W-EDITED-NUMBER 9 A
    W-EN-DECIMAL-POINT W-EDITED-NUMBER +9 1 A
    W-EN-DECIMAL W-EDITED-NUMBER +10 2 N

    W-SPLIT-NUMBER = source-number
    W-EN-INTEGER = W-SN-INTEGER
    W-EN-DECIMAL-POINT = "."
    W-EN-DECIMAL = W-EDITED-NUMBER


Then you can redefine the W-EN-INTEGER with the OCCURS.

Your DO wants to go for a max of eight, probably, as it is more usual to have "0.xx" than ".xx", but I don't know what you need.

You need to stop your DO when you hit a value of 1 through 9, otherwise you'll be changing significant zeros to space.

Note the way I've done the redefine of the decimal part as numeric. This is important as for Easytrieve anything with decimal places is "signed". If you did it as A straight away, it would run the risk of a non-number appearing in your output, representing the sign. So, defined as two with zero decimal places first, so it is signed. Then assigned to two with no decimal places, so any sign disappears, becoming the "F" in the sign "zone".

If your numbers can be signed, just increase the edited field to the right for the sign, and test original for LT ZERO.

EDIT: I wouldn't assign the decimal-point each time, personally, I'd do it in a START proc.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Output with decimal point

Postby neeraj430 » Sat May 05, 2012 2:25 pm

Thanks a bunch billy...I got desired solution for my problem i.e Supressing zeroes in output. Thanks for you time and guidance.

WS-AMT-UNUSED-INT:000000036
WS-AMT-EDITED-INT: 36
neeraj430
 
Posts: 3
Joined: Sat Apr 28, 2012 4:15 pm
Location: chennai
Has thanked: 1 time
Been thanked: 0 time

Re: Output with decimal point

Postby BillyBoyo » Sat May 05, 2012 4:19 pm

neeraj430 wrote:Thanks a bunch billy...I got desired solution for my problem i.e Supressing zeroes in output. Thanks for you time and guidance.
WS-AMT-UNUSED-INT:000000036
WS-AMT-EDITED-INT:       36


No problem.

For future reference, notice the use of the Code tags to preserve the formatting. There are buttons above the Full Editor screen. Highlight the text, use the Code button. Use the Preview button next to submit to check that the formatting is OK before using Submit.

Click on Quote to see how someone has done the formatting.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to CA-Easytrieve

 


  • Related topics
    Replies
    Views
    Last post