Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to move a 9(11) variable to 9(9)v99.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
balasu

New User


Joined: 10 Jul 2008
Posts: 23
Location: bangalore

PostPosted: Sat Jan 31, 2009 7:53 pm    Post subject: How to move a 9(11) variable to 9(9)v99.
Reply with quote

Hi,
I had a requirement of moving a value from the input file to a amount field. Pleas help me out on this.
ex., Input value:
112345678911 - input value
I want to move this i/p value to a amount field of 9(9)v99, since the value from input file is a amount value. When i try to move this value to a variable of 9(9)v99, Last two digit is truncated and getting as 234567891100 as the output. Please help me out on this.
Thanks,
bala.M
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sat Jan 31, 2009 8:14 pm    Post subject:
Reply with quote

Use REDEFINES to convert the 9(9)V99 to 9(11) and move to the 9(11) field. Then the 9(9)V99 will contain the correct value.

Or, COMPUTE 9(9)V99 = 9(11) / 100.

TIMTOWTDI
Back to top
View user's profile Send private message
balasu

New User


Joined: 10 Jul 2008
Posts: 23
Location: bangalore

PostPosted: Sat Jan 31, 2009 8:45 pm    Post subject: Reply to: How to move a 9(11) variable to 9(9)v99.
Reply with quote

See the input is of 99999999999 and i need to make it as 999999999.99.
Back to top
View user's profile Send private message
balasu

New User


Joined: 10 Jul 2008
Posts: 23
Location: bangalore

PostPosted: Sat Jan 31, 2009 8:49 pm    Post subject: Reply to: How to move a 9(11) variable to 9(9)v99.
Reply with quote

FYI:

VALUE BEF MOVE 00000050979
after move: AMOUNT: 000050979.00
I am getting like this. Please advise robert..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sat Jan 31, 2009 8:57 pm    Post subject:
Reply with quote

Have you bothered trying either of the methods I posted? What were your results?
Back to top
View user's profile Send private message
balasu

New User


Joined: 10 Jul 2008
Posts: 23
Location: bangalore

PostPosted: Sat Jan 31, 2009 9:00 pm    Post subject:
Reply with quote

Robert you asked me to convert 9(9)v99 to 9(11). but mine is opposite.
How to conver 9(11) to 9(09)v99, without lost of data.or with out any truncation happens??please advise.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sat Jan 31, 2009 9:10 pm    Post subject:
Reply with quote

COMPUTE 9(09)V99 = 9(11) / 100 takes an 11-byte field and divides it by 100 giving 9 digits before the decimal point and 2 digits after the decimal point. The REDEFINES allows you to exactly the same thing in a different way. Your original problem statement is to take an 11-byte number and change it to 9(9)V99 without losing the decimal digits.

Perhaps before you criticize a solution you haven't tested yet, you should either try it or figure out what it does first.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jan 31, 2009 11:16 pm    Post subject:
Reply with quote

Hello,

If you don't yet have this working, try this:

Code:

05 my-9-11-num    pic 9(11).
05 my-9s-v99-num  redefines my-9-11-num pic 9(9)v99.

05 my-target-num  pic 9(9)v99.


The my-9-11-num is the original input. To get what i believe you want
Code:
move my-9s-v99-num to my-target-num.
The redefines effectively divides the original value by 100 generating the decimal places you want.

As Robert mentioned, it is best to try the suggestions (in a test environment) before posting replies. . .
Back to top
View user's profile Send private message
balasu

New User


Joined: 10 Jul 2008
Posts: 23
Location: bangalore

PostPosted: Sun Feb 01, 2009 12:26 am    Post subject:
Reply with quote

Hi robert & Dick,
I got it.
Many a Thanks,

Thanks,
Bala.M
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Sun Feb 01, 2009 1:02 am    Post subject:
Reply with quote

I have a question.

112345678911 - input value
When moving i/p value to a amount field of 9(9)v99 why is it coming as 234567891100 as the output.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Sun Feb 01, 2009 1:12 am    Post subject:
Reply with quote

Because COBOL aligns to the decimal point. PIC 9(11) is implied PIC 9(11)V so the decimal points are aligned and digits before the decimal are moved, truncating the first two digits. The digits after the decimal point are filled with zero since they don't exist on the sending field.
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 12:30 pm    Post subject: Reply to: How to move a 9(11) variable to 9(9)v99.
Reply with quote

Hi,

In addition to the Robert post, numeric variable has Right to left movement.
Therefore, PIC 9(11) will try to move 11 bytes in 9 bytes of output field.
First 2 bytes of input field will truncate.
'V' in PIC clause implies the inclusive of decimal point.
To see the decimal point in output you need to use Editing picture clause.

Thanks & Regards,
Shashank
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Mon Feb 02, 2009 6:15 pm    Post subject:
Reply with quote

Shashank: have you any proof for your statement of
Quote:
In addition to the Robert post, numeric variable has Right to left movement.
Therefore, PIC 9(11) will try to move 11 bytes in 9 bytes of output field.
Because I compiled the code
Code:
 01  WS-VARIABLES.
     05  WS-VAR-11               PIC 9(11) VALUE 12345678901.
     05  WS-VAR-11-R             REDEFINES WS-VAR-11

                                 PIC 9(09)V99.
     05  WS-VAR-09               PIC 9(09)V9(02).

 LINKAGE SECTION.
ise COBOL for z/OS  3.4.1               MF0056    Date 02/02/2009
*A-1-B--+----2----+----3----+----4----+----5----+----6----+----7-|
/
 PROCEDURE DIVISION.
 S1000-MAIN       SECTION.
     MOVE WS-VAR-11              TO  WS-VAR-09.
     DISPLAY WS-VAR-11.
     DISPLAY WS-VAR-11-R.
     DISPLAY WS-VAR-09.
and reviewed the assembler generated for the MOVE statement:
Code:
000024  MOVE
   00033E  D201 8014 C022          MVC   20(2,8),34(12)          WS-VAR-09+9
   000344  D208 800B 8002          MVC   11(9,8),2(8)            WS-VAR-09
   00034A  96F0 8013               OI    19(8),X'F0'             WS-VAR-09+8
In case you are not aware of it, the generated MVC instruction is not a right-to-left instruction. It is a left-to-right instruction. The variables are aligned on the decimal place for the MOVE and COBOL only moves as much data as will fit in the receiving variable. There is no right-to-left movement of data.
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 7:19 pm    Post subject:
Reply with quote

Hi Robert,

[quote="Robert Sample"]Shashank: have you any proof for your statement of [quote]

Please find below the test run details to support my statement.
Code:
01 WS-VALUES.                                                   
     05 WS-OUTPUT                 PIC 9(03)V9(02) VALUE ZEROES. 
     05 WS-SAMPLE1                PIC 9(01)V9(02) VALUE 0.46.   
     05 WS-SAMPLE2                PIC 9(03)V9(01) VALUE 382.2.   
     05 WS-SAMPLE3                PIC 9(02)V9(03) VALUE 23.632. 
     05 WS-SAMPLE4                PIC 9(04)V9(02) VALUE 7892.23.


Code:
MOVE WS-SAMPLE1        TO  WS-OUTPUT. 
DISPLAY 'WS-OUTPUT : '     WS-OUTPUT. 
MOVE ZEROES            TO  WS-OUTPUT. 
                                       
MOVE WS-SAMPLE2        TO  WS-OUTPUT. 
DISPLAY 'WS-OUTPUT : '     WS-OUTPUT. 
MOVE ZEROES            TO  WS-OUTPUT. 
                                       
MOVE WS-SAMPLE3        TO  WS-OUTPUT. 
DISPLAY 'WS-OUTPUT : '     WS-OUTPUT. 
MOVE ZEROES            TO  WS-OUTPUT. 
                                       
MOVE WS-SAMPLE4        TO  WS-OUTPUT. 
DISPLAY 'WS-OUTPUT : '     WS-OUTPUT. 
MOVE ZEROES            TO  WS-OUTPUT. 


Output =>
Code:
WS-OUTPUT : 00046
WS-OUTPUT : 38220
WS-OUTPUT : 02363
WS-OUTPUT : 89223


I have displayed the output in SPOOL.

Numeric field has Right to left movement whereas decimal part of numeric field has Left to Right movement.
That means, PIC 9(03)V9(02)
9(03) => Right to Left
V9(02) => Left to Right


---------------
Shashank
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Mon Feb 02, 2009 7:26 pm    Post subject:
Reply with quote

Sorry, all you've shown is lack of understanding of how COBOL works. If you use the LIST compile option and review the generated code for each of your MOVE statements you will find that Assembler MVC instructions are used. MVC is a left to right instruction. You will see that the generated MVC instructions use different starting position because COBOL aligns to the decimal and generates the MVC based on how many bytes to move; it does not start at the decimal point and move bytes right to left.
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Mon Feb 02, 2009 8:46 pm    Post subject: Reply to: How to move a 9(11) variable to 9(9)v99.
Reply with quote

Hi Robert,

Definitely I am unaware of the assembler instructions that how exactly it works.
My post was on the output basis.

Request you to share some more points on this MVC instructions i.e.
1) On what basis cobol decides that from where it needs to truncate the data i.e. either from Right or Left?
2) As we can see in output if the input is more than the output in numeric field then data gets truncated from left. Similarly in case of decimal part data gets truncated from Right.

Thanks for bringing this in notice.

-------------
Shashank
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Mon Feb 02, 2009 9:11 pm    Post subject:
Reply with quote

1) COBOL aligns to the decimal -- wherever the V (or .) is (and there is always a V since it is implied after the rightmost digit if not otherwise specified). Once that is done, COBOL will truncate or pad with zeros left or right depending on the picture clauses of the sending and receiving fields. Truncation or padding will not occur if the field components are the same size (number of digits).
2) There are four possibilities:
- If the sending field integer part (before the V) is larger than the receiving field integer part, the extra digits are truncated off the left.
- If the sending field integer part is smaller than the receiving field integer part, there are zeroes padded on the front of the receiving field
- If the sending field decimal part (after the V) is larger than the receiving field decimal part, the extra digits are truncated off the right
- If the sending field decimal part is smaller than the receiving field decimal part, there are zeros padded on the end of the receiving field.

Be aware the rules are slightly different for numeric edited fields (which has PIC clauses including -, +, Z, etc).
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Feb 03, 2009 12:46 am    Post subject:
Reply with quote

Hello,

Quote:
In addition to the Robert post, numeric variable has Right to left movement.
Therefore, PIC 9(11) will try to move 11 bytes in 9 bytes of output field.
First 2 bytes of input field will truncate.
'V' in PIC clause implies the inclusive of decimal point.
To see the decimal point in output you need to use Editing picture clause.

Numeric field has Right to left movement whereas decimal part of numeric field has Left to Right movement.
Where did you learn this? If it came from some book or some teacher, suggest you no longer use them as a technical reference. . .
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Tue Feb 03, 2009 10:12 am    Post subject:
Reply with quote

Hello,
Shashank.kapoor wrote:
That means, PIC 9(03)V9(02)
9(03) => Right to Left
V9(02) => Left to Right
What's the source of information using which you are telling this - 'am eager to know?
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Tue Feb 03, 2009 1:09 pm    Post subject:
Reply with quote

Thanks Robert!! icon_smile.gif icon_smile.gif

-------------
Shashank
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us