View previous topic :: View next topic
|
Author |
Message |
balasu
New User
Joined: 10 Jul 2008 Posts: 23 Location: bangalore
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
balasu
New User
Joined: 10 Jul 2008 Posts: 23 Location: bangalore
|
|
|
|
See the input is of 99999999999 and i need to make it as 999999999.99. |
|
Back to top |
|
|
balasu
New User
Joined: 10 Jul 2008 Posts: 23 Location: bangalore
|
|
|
|
FYI:
VALUE BEF MOVE 00000050979
after move: AMOUNT: 000050979.00
I am getting like this. Please advise robert.. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Have you bothered trying either of the methods I posted? What were your results? |
|
Back to top |
|
|
balasu
New User
Joined: 10 Jul 2008 Posts: 23 Location: bangalore
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
balasu
New User
Joined: 10 Jul 2008 Posts: 23 Location: bangalore
|
|
|
|
Hi robert & Dick,
I got it.
Many a Thanks,
Thanks,
Bala.M |
|
Back to top |
|
|
abin
Active User
Joined: 14 Aug 2006 Posts: 198
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Shashank.kapoor
New User
Joined: 14 Jan 2009 Posts: 24 Location: Mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Shashank.kapoor
New User
Joined: 14 Jan 2009 Posts: 24 Location: Mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Shashank.kapoor
New User
Joined: 14 Jan 2009 Posts: 24 Location: Mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Shashank.kapoor
New User
Joined: 14 Jan 2009 Posts: 24 Location: Mumbai
|
|
|
|
Thanks Robert!!
-------------
Shashank |
|
Back to top |
|
|
Debabrata Pruseth
New User
Joined: 11 Dec 2008 Posts: 59 Location: Pune , India
|
|
|
|
Hi Robert
I am afraid my understanding is similar to Shashkant . Alphanumeric values are left justified and numeric values are right justified till the decimal point and after the decimal point left justified. So when the movement happens from one variable to another the movement starts from that justified direction to the opposite ie right to left ; or left to right accordingly. This is however in literal sense.
I think MVC may be generating instruction for left to right movement in general however there might be some other internal final adjustment must be happening to give the final output that we have been discussing. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I am afraid my understanding is similar to Shashkant |
Very quickly it will be to your advantage to obtain a more correct understanding.
Quote: |
however there might be some other internal final adjustment must be happening to give the final output that we have been discussing |
If you look at the actual assembler code generated, you will see everything accounted for. There is no internal final adjustment happening. It is just simple one-instruction-at-a-time code that is executed when the code reached that section of the logic. All of the assembler generated by the compiler is visable in the compiler output. If you find some code that is questionable, post the cobol definitions and displacements for those fields as well as the generated assembler instructions and specific discussion can be done from that point. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Debabrata: as Dick said, your understanding is faulty. Some specifics from your post: there is LEFT justification (usual alphanumeric variables), RIGHT justification (alphanumeric variables with JUST RIGHT), and numeric justification -- which is neither left nor right but DECIMAL aligned. For numeric fields, the COBOL compiler determines how many bytes to move to the receiving field, and the conversion (if any is required), and generates pseudo assembler to move the bytes correctly If you move a PIC 9(7) to a PIC 9(3) field, COBOL generates a 3-byte move -- the last 3 bytes of the sending field are moved to the receiving field via an MVC (left to right move) instruction. What about the first 4 bytes? Not touched, not moved, not even considered for a move. Literally, there is no right to left move instruction. From the COBOL Language Reference manual, note that the manual on numeric data moves does not talk about left or right justification but decimal alignment:
Quote: |
5.1.6.6 Alignment rules
The standard alignment rules for positioning data in an elementary item depend on the category of a receiving item (that is, an item into which the data is moved; see "Elementary moves" in topic 6.2.24.1).
Numeric
For such receiving items, the following rules apply:
1. The data is aligned on the assumed decimal point and, if necessary, truncated or padded with zeros. (An assumed decimal point is one that has logical meaning but that does not exist as an actual character in the data.)
2. If an assumed decimal point is not explicitly specified, the receiving item is treated as though an assumed decimal point is specified immediately to the right of the field. The data is then treated according to the preceding rule.
Numeric-edited
The data is aligned on the decimal point, and (if necessary) truncated or padded with zeros at either end, except when editing causes replacement of leading zeros. |
|
|
Back to top |
|
|
Debabrata Pruseth
New User
Joined: 11 Dec 2008 Posts: 59 Location: Pune , India
|
|
|
|
Thanks a lot Robert and Dick for the information . This explains everything. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
These guys (and many more here in this forum) seem to be "walking Encyclopedia"..
Regards,
Ad |
|
Back to top |
|
|
|