× 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.



>Lets say I have two fields: one Dec12 (12/5)
>and one Alph15 (15Alpha) I wish the 12/5
>(value of 1.5) to be in the 15Alpha field as
>000000000150000'
>
>I can do:
>   C  Z-Add   Dec12     Tmp15              15  0
>   C  Move    Tmp15     Alph15
>
>Now:  how do I do the equivalent with Eval?

I will make a FAQ out of this once we've ironed out all the kinks.

The first thing to bear in mind is that MOVE is badly named.  It really
should ConvertAndMove.  What is happening with MOVE?  The compiler converts
the numeric variable into an internal character variable.  It then moves
that internal character value to Alph15.

Given that a conversion happens and then a move, one way to do that in EVAL
is to use the numeric conversion BIF %editc.  Another bad name, essentially,
%editc converts a numeric value to a character, applying a conversion mask
or template.  If we use 'X' (no mask), the numeric value gets translated
without decimal point, negative sign or thousands separator.

In this case, we end up with a 12 character value, 000000150000.  But you
want a 15 character value.  One way is to use a temporary numeric variable
15 long, 5 decimals (you don't want to truncate the 1.5 into a 1.0, which
happens with the above code.)  This is the same problem you have with MOVE.
But if you want to be generic about it and not use the temporary variable,
you can still use EVAL.

d alph15          s             15
d dec12           s             12s 5 inz(1.5)
c                   eval      alph15 = *all'0'
c                   eval      %subst(alph15:
c                                     %len(alph15) - %len(dec12) + 1:
c                                     %len(dec12)) =
c                                       %editc(dec12: 'X')

The idea is to preload the target with the padding character (zeroes) and
then insert the (converted) source into the right side of the target.  There
are several bugs in this code for the unwary to trip over, so this presumes
that dec12 is in fact smaller or equal to alph15 in length.  There may be a
performance hit doing the padding if the target is very large, so you might
want to use another %subst instead of the straight eval alph15 = *all'0'.

Hans suggested using %dec, but I can't construct a more generic replacement
for MOVE with %dec because
c                   eval      alph15 = %editc(
c                                        %dec(
c                                          dec12:
c                                          %len(alph15):
c                                          %decpos(dec12)):
c                                        'X')

doesn't compile.  I may be missing something, but the compiler is
complaining that the second and third arguments to %dec "must be a numeric
literal; a built-in function that has a value known at compile-time; or a
numeric named constant."  I would have thought the compiler would be able to
know the length of alph15 and the decimal positions of dec12, given that

d len             s              5i 0 inz(%len(alph15))
d dec             s              5i 0 inz(%decpos(dec12))

compiles.  I also tried

c                   eval      alph15 = %editc(
c                                        %dec(
c                                          dec12:
c                                          len:
c                                          dec):
c                                        'X')

but got the same error.

Anyway Booth, MOVE is easy to say, hard to describe.  Making a generic
replacement is not all that simple given all of the possible conversions
MOVE can handle.  If the list is up to it, we might try a generic
replacement subprocedure; at least as an exercise in how to write a BIF...
  --buck


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.