IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help required to reset decimal points to 0 in a PD field


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nimisanand

New User


Joined: 22 Nov 2005
Posts: 26

PostPosted: Tue Dec 03, 2024 8:30 pm
Reply with quote

Hello All,

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.

I tried below option.

SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(23,01,CH,EQ,C'1'),
OVERLAY=(475:475,6,PD,EDIT=(TTTTTT),C'00',TO=PD,LENGTH=6))

Gives error:
OVERLAY=(475:475,6,PD,EDIT=(TTTTTT),C'00',TO=PD,LENGTH=6))
$
ICE006A 0 OPERAND DEFINER ERROR
ICE751I 0 C5-I79519 C6-NONE C7-I76950 C8-I76518 E7-I76950
Back to top
View user's profile Send private message
nimisanand

New User


Joined: 22 Nov 2005
Posts: 26

PostPosted: Tue Dec 03, 2024 10:01 pm
Reply with quote

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
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Wed Dec 04, 2024 12:02 am
Reply with quote

nimisanand wrote:
decimal point of this field will need to be reset to 0

How can you reset a decimal point??? 824.gif
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:
Code:
 SORT FIELDS=COPY
 INREC IFTHEN=(WHEN=(23,01,CH,EQ,C'1'),
               OVERLAY=(475:475,6,PD,EDIT=(TTTTTT),
                        C'00',TO=PD,LENGTH=6))
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Wed Dec 04, 2024 2:16 am
Reply with quote

nimisanand wrote:
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?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Wed Dec 04, 2024 9:44 pm
Reply with quote

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.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Wed Dec 04, 2024 11:16 pm
Reply with quote

nimisanand wrote:
I have a VB file length 5204

One more note.

The sentence above means, that your dataset with RECFM=VB contains 5204 records inside of it...

Besides of the fact there are no files on mainframe, the "file length" can be measured IN NUMBER OF RECORDS only!

Maybe you meant:
"I have a dataset of VB records, with record length 5204"?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Thu Dec 05, 2024 1:10 am
Reply with quote

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
Code:
X'0000000001331C' --> X'F0F0F0F0F0F0F0F0F0F1F3F3C1'

2) replace last two digits = last two bytes of unpacked value with the constant of two zero characters (C'00')
Code:
X'F0F0F0F0F0F0F0F0F0F1F3F3C1' --> X'F0F0F0F0F0F0F0F0F0F1F3F0F0'
Z'0000000001331' --> C'0000000001300'

3) convert the unpacked decimal value (13 bytes) back to packed decimal (7 bytes) - it is conversion ZD to PD in SORT
Code:
X'F0F0F0F0F0F0F0F0F0F1F3F0F0' --> X'0000000001300C'

The final result is equivalent to the value 13.00
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Thu Dec 05, 2024 6:28 pm
Reply with quote

(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:
Code:
13.31 <-> 1331        => X'0000000001331C'
1331 / 100 = 13       => X'0000000000013C'
13 * 100 = 1300       => X'0000000001300C'
1300 <-> 13.00        => X'0000000001300C'


* * *

Before creating ANY code in ANY language one needs to understand deeply all those details.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2184
Location: USA

PostPosted: Mon Dec 09, 2024 7:45 pm
Reply with quote

As I can see, no detailed help can help, unless it is a copy-and-paste ready solution?…
Back to top
View user's profile Send private message
knv09

New User


Joined: 13 Jan 2011
Posts: 1
Location: Canada

PostPosted: Fri Dec 20, 2024 7:55 pm
Reply with quote

Hi nimisanand,

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" icon_smile.gif

Let's say your input file (FB in my case, not VB) contains 1 record as follows:

Code:


       
444400135444444444444444444444444444444444444444444444444444444444444444
00000024C000000000000000000000000000000000000000000000000000000000000000



Let's consider those hexadecimal
Code:

X'000012345C'


(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:
Code:


INREC OVERLAY=(005:((5,5,PD),DIV,(+100)),TO=PD,LENGTH=5)



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
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1376
Location: Bamberg, Germany

PostPosted: Fri Dec 20, 2024 9:34 pm
Reply with quote

This should also work:

Code:
INREC IFTHEN=(WHEN=INIT,                       
  OVERLAY=(5:5,5,PD,MUL,+10,TO=PD,LENGTH=5,8:Z,
           5:5,5,PD,DIV,+10,TO=PD,LENGTH=5))
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Unable to interpret a hex value to De... COBOL Programming 7
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts small int to zoned decimal conversion DFSORT/ICETOOL 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top