× 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 Tue, 29 Jul 2003, Carlos Kozuszko wrote:
>
> I want to create a procedure to return a varchar from a given number, len
> and dec positions, like this:
>
> eval MsgData = Filename + Filelib + CharNum(size: 7: 0)

varchar?  You mean varying, right?


> I want to use CharNum() primarily to set the messagedata for my message
> descriptions. Any ideas on how to accomplish this as elegantly as possible ?
> My original thought is to create a DS like this:
>
> D  NUM_P_0                1     15P 0
> D  NUM_P_1                1     15P 1
> D  NUM_P_2                1     15P 2
> D  NUM_P_3                1     15P 3
> D  NUM_P_4                1     15P 4
> D  NUM_P_5                1     15P 5
> D  NUM_P_6                1     15P 6
> D  NUM_P_7                1     15P 7
> D  NUM_P_8                1     15P 8
> D  NUM_P_9                1     15P 9
> D  CHARNUM                1     15A

Eww... Instead of that ugly data structure, just pass the parameter by
value.   When you pass by value, the data type and decimal places do not have
to match, it'll be auto-converted to the type you specify in the
parameter.

> and then according to the parameters passed as LEN & DEC assign the numeric
> value to the corresponding field and return the data as a substr of CHARNUM.
> I know it will work, but I really dont like this approach, any ideas would
> be greatly appreciated.

Here is how I would do it.  Note that the input can be any size as long as
it does not exceed 21 digits to the left of the decimal point, or 9
digits to the right...

Note that the actual CharNum routine is only 3 lines! Most of this code is
to test it out :)

     H DFTACTGRP(*NO)

     D CharNum         PR            30A   varying
     D   peNumber                    30S 9 value
     D   peSize                      10I 0 value
     D   peDecPos                    10I 0 value

     D wwTest1         s             15P 3 inz(123.991)
     D wwTest2         s             15P 0 inz(12345678)
     D wwTest3         s             10S 4 inz(9843.1112)
     D wwTest4         s             10I 0 inz(98765)

     D Msg             s             52

      ** test packed w/decimals
     c                   eval      Msg = 'Test1: ' + CharNum(wwTest1:15:3)
     c     Msg           dsply

      ** test packed w/out decimals in packed, but with decimals in char
     c                   eval      Msg = 'Test2: ' + CharNum(wwTest2:15:1)
     c     Msg           dsply

      ** test zoned, add a dec pos
     c                   eval      Msg = 'Test3: ' + CharNum(wwTest3:10:5)
     c     Msg           dsply

      ** test int, reduce to 5 digits
     c                   eval      Msg = 'Test4: ' + CharNum(wwTest4:5:0)
     c     Msg           dsply

      ** test literal.  Output as 10 long with 9 dec
     c                   eval      Msg = 'PI: ' + CharNum(3.141592653:10:9)
     c     Msg           dsply

      ** test reserved named constant
     c                   eval      Msg = 'Year: '  + CharNum(*YEAR:4:0)
     c                   dsply                   Msg

     c                   eval      *inlr = *on


     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
     D wwStart         s             10I 0

     c                   eval      wwRetVal = %editc(peNumber:'X')
     c                   eval      wwStart  = (22 - peSize) + peDecPos
     c                   eval      wwRetVal=%subst(wwRetVal:wwStart:peSize)

     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.