Using Justified with Numeric field



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

Using Justified with Numeric field

Postby nikesh_rai » Mon Dec 10, 2012 1:03 pm

Hi,

Is it possible to use JUSTIFIED RIGTH or LEFT with numeric or edit numeric filed. How far I know, it is not possible but if any can suggest me a alternet way to do it, it will be helpful to me.

06 WV55-INCLD-ALWC PIC Z(10)V9(4) VALUE ZEROES .

I want to align the value of WV55-INCLD-ALWC to right or left as per my requirment.

Thanks
Nikesh
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time

Re: Using Justified with Numeric field

Postby BillyBoyo » Mon Dec 10, 2012 1:19 pm

A numeric field is justified to the right anyway, so can you be more exact about what you mean, with some examples, please.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Using Justified with Numeric field

Postby nikesh_rai » Mon Dec 10, 2012 1:32 pm

Thanks Billy,

Say 06 WV55-INCLD-ALWC have a value like 31.8200 . Based on some other key values, I have to decide whether it should be populated as Justified left or Justified right. Since the numeric fields are always right justified.. is there any way I can change them into Left Justified whenever required.
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time

Re: Using Justified with Numeric field

Postby enrico-sorichetti » Mon Dec 10, 2012 3:02 pm

Since the numeric fields are always right justified.. is there any way I can change them into Left Justified whenever required.


let' s get the terminology right ...
numbers are numbers, char-strings are char-strings

once that AS YOU SAY a number has been left justifies it is not a number any longer

but if You take the EDITED number, which at this point is just a string of characters
You can justify left the string

search the forum for examples
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Using Justified with Numeric field

Postby BillyBoyo » Mon Dec 10, 2012 3:05 pm

Again, please show some examples.

Show your input definition. Show sample values. Show the required output for the sample values.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Using Justified with Numeric field

Postby nikesh_rai » Mon Dec 10, 2012 3:42 pm

Thanks Billy

Here is the list of values for example
WV55-INCLD-ALWC
7/PS           
(42-48)       
10-------------
***-CAPS OFF-*
              0
              0
        31.8200
              0
              0
        45.4600
        45.4600
              0
              0
              0
              0
        31.8200
              0
              0
              0
              0


I need to change their allingenment to left.. and the result should looks like

0
0
31.82
0
0
45.46
45.46
0
0
0
0
31.82
0
0
0
0


Code'd
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time

Re: Using Justified with Numeric field

Postby BillyBoyo » Mon Dec 10, 2012 3:55 pm

You need to learn how to use the Code tags to preserve your spacing. If you want to see what I did, click on Quote on your post. You highlight the block and use the Code button on the full editor input screen. Use the Preview button to check it looks how you want.

Are all your values only a length of two for the integer part? What do you want 1.2100 to look like?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Using Justified with Numeric field

Postby nikesh_rai » Mon Dec 10, 2012 4:19 pm

if the value is like
 
      0
      0
31.8200
      0
      0
45.4600
45.4600
      0
      0
 1.2100
      0


it should be displayed like

 
0
0
31.8200
0
0
45.4600
45.4600
0
0
1.2100
0
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time

Re: Using Justified with Numeric field

Postby BillyBoyo » Mon Dec 10, 2012 5:10 pm

OK, so now things have changed. All you want to do his have the "zero" left-justified, leaving anything else as-is.

01  the-left-right-number.
    88  value-is-zero VALUE "      0".
    05  location-of-left-just-zero PIC X.
    05  space-for-left-just-zero.
        10  FILLER PIC X.
        10  FILLER PIC X.
            88  decimal-point-is-present VALUE ".".
        10  FILLER PIC X(03).
        10  right-just-zero PIC X.


EVALUATE TRUE
  WHEN value-is-zero
    MOVE right-just-zero TO location-of-left-just-zero
    MOVE SPACE TO space-for-left-just-zero
  WHEN decimal-point-is-present
    CONTINUE
  WHEN OTHER
    deal with an unexpected situation
END-EVALUATE
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post