I have a VB file length 5204 and has a field in position 475 with definition S9(11)V99 COMP-3. My requirement is decimal point of this field will need to be reset to 0 when the field in position 19 has the value '1'. Kindly help with the Sort.
A small correction on the query - the field that needs to be overlayed at 475, the integer part needs to be intact only the decimal needs a reset. For example, if the field has value 13.31, it needs to be changed to 13.00
decimal point of this field will need to be reset to 0
How can you reset a decimal point???
This is completely new terminology...
There is full mess in your post: where do you need a packed decimal value, where it must be an unpacked decimal, and where at all is any decimal point???
Please, present the hexadecimal sample: what do you have on input (with byte positions), and what you want on output (with NEW byte positions)?
Do not forget to use the Code button to format your post properly!!!
Your samples MUST look like this, to be polite to your potential readers:
A small correction on the query - the field that needs to be overlayed at 475, the integer part needs to be intact only the decimal needs a reset. For example, if the field has value 13.31, it needs to be changed to 13.00
FYI:
In the format S9(11)V99 COMP-3 your value 13.31, when stored in memory, looks as follows:
X'0000000001331C' -> 7 bytes
If so, it is not clear, what and how you are trying to do with your data by your sample of SORT statements?
As the first step you must learn:
- what are the different data formats in mainframe and/or COBOL,
- how they are stored in memory, and
- how to manipulate them?
Since there is a complete mess in your head, I recommend to start NOT from your real production task, but first try to learn the mainframe basics "in a sandbox" - e.g. using simple examples, and trivial test datasets.
The initial value is stored in the record's field described as PIC 9(11)V99 COMP-3 in COBOL. This field in memory has the length 13 digits plus decimal sign (4 bits each) = 7 bytes. For SORT utility COMP-3 is equivalent to PD.
When you save a value like 13.31 into this field, the result in memory looks as follows:
Code:
X'0000000001331C'
When separated by bytes it looks like:
Code:
X'00,00,00,00,01,33,1C'
Since fractional part of this value (.31) occupies half of the last byte, and half of previous part, it may be a problem: how to "reset" it (e.g. set it to zero value) without touching other parts of the same two last bytes?
For SORT, one solution may be:
1) convert packed decimal values 9(11)V99 COMP-3 (7 bytes) to equivalent unpacked decimal 9(11)V99 (13 bytes) - it is conversion PD to ZD in SORT
(If you are still interested in a solution for your uncommon task?)
Another approach, more simple, though a bit tricky for a beginner.
The COBOL definition PIC 9(11)V99 defines so called "assumed" position for the decimal point, such as - before the last two digits for this example. That is, the value is stored in memory as if it was a whole number, but during any operation over this value the COBOL compiler "keeps in mind" that last two digits of the value are in fact its fractional part.
So, the value 13.31 is stored in memory exactly as the value 1331
Code:
format PIC 9(11)V99 C'0000000001331'
format PIC 9(11)V99 COMP-3 X'0000000001331C'
but
Code:
format PIC 9(11)V.99 C'00000000013.31'
while format PIC 9(11)V.99 COMP-3 doesn't make much sense.
The SORT utility considers all packed decimal values (PD) as whole numbers, not taking into account possible fractional parts. Due to this specific feature, we can "reset" the assumed fractional part by simple arithmetic with whole numbers:
13.31 <-> 1331 - are both coded in memory in the same manner
1331 / 100 = 13 13 * 100 = 1300 1300 <-> 13.00 - are both coded in memory in the same manner
All operations in SORT can be done in PD format, without conversion to and from ZD format:
Well, just in case you're still interested in understanding how to complete your task with DFSORT I would like to give you a similar task (a bit simpler) based on sergeyken's explanations (which are very good by the way although not such ... how to say it... "USER friendly"
Let's say your input file (FB in my case, not VB) contains 1 record as follows:
(format PD, 5 bytes from the 5-th position, Packed Decimal, or COMP-3 in Cobol)
as the digit 123.45 in Cobol format SPIC 9(3).V99.
Your goal is to convert this number into 123.00 right?
The first step would be to DIVIDE (DIV in terms of DFSORT) the number by 100; as output you would get (please try it using the CODE below)
Then - according to sergeyken - you would just have to MULTIPLY (MUL in terms of DFSORT) the result by +100 in order to get your desired
X'0000123000C' --> 123.00 in Cobol SPIC 9(3).V99 format
So, the first step would be achieved by the following SORT instruction:
The SORT would take 5 bytes in PD format from the 5 position, divide it by 100 and put the result in the same format back in the same place.
Then, the next step is to multiply the result by 100 and still present it at the same 5 position as
Code:
X'0000123000C'
Can you do it on your own? If so, your real task would be very similar and kind of "peace of cake" (just do not forget about VB vs FB - my example)
Good luck