× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On Wed, 30 Jul 2003, Carlos Kozuszko wrote:

> RE: RPGIV: Converting Packed to Char.Well... i already did what i needed
> using the ugly approach that wanted to avoid: here's my proc.
>
> P CharNum         B
> D CharNum         PI            30A   varying
> D   peNumber                    30S 9 value
> D   peSize                      10I 0 value
> D   peDecPos                    10I 0 value
> D wwRetVal        s             30A   varying

The number is a 30S 9, but you're stuffing it into a 15-byte (29-digit)
packed number.   Why not make peNumber be 29 digits?

[SNIP -- removed data structure and select group]
> c                   eval      wwRetVal = %subst(CHAR_NUM:
> c                                               %int(peSize / 2 + 1))

Is this code correct?   It seems to me that you want peSize/2 + 1 to be
the length of the result, not the offset into the character string?!  Does
this code work?

> Any ideas to improve it ?

Here's how I'd do it.   Note that I eliminated the SELECT group, and
simplified the data structure by adding one line of multiplication.
I changed the logic for the %subst() because I couldn't get your
logic to work.

     P CharNum         B
     D CharNum         PI            15A   varying
     D   peNumber                    29P 9 value
     D   peSize                      10I 0 value
     D   peDecPos                    10I 0 value

     D                 ds
     D  CHAR_NUM                     15A
     D  NUM_P_0                      29P 0 overlay(CHAR_NUM)

     D wwRetVal        s             30A   varying
     D wwStart         s             10I 0
     D wwBytes         s             10I 0

      ** packed numbers must be an odd number of digits:
     c                   if        %rem(peSize: 2) = 0
     c                   eval      peSize = peSize + 1
     c                   endif

      * this is how many bytes the returned value will be:
     c                   eval      wwBytes = (peSize + 1) / 2

      * calculate the returned value:
     c                   eval      wwStart = (%size(CHAR_NUM) - wwBytes) + 1
     c                   eval      NUM_P_0 = peNumber * (10**peDecPos)
     c                   eval      wwRetVal = %subst(CHAR_NUM: wwStart:
     c                                              wwBytes)

     c                   return    wwRetVal
     P                 E

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.