How to hexdump dynamic alphas?

Hello all!

Hexdumping a fixed length alpha is very easy. But what about dynamics?

define data local
01 #a10 (A10)       init <'ABC'>
01 #a (A) dynamic   init <'123'>
01 #hex (A) dynamic
end-define
move edited #a10 (EM=H(10)) to #hex
display #hex (AL=70)
move edited #a   (EM=H(??))  to #hex /* how to do that?
display #hex (AL=70)
end

Do I really have to code a for loop?

regards

Matthias

Using an intermediate variable (#HEX) will cause storage problems, but dumping the value is easy - the first half, anyway.

Since the longest string can be (A1073741824), the longest edit mask can be half that.

DEFINE DATA LOCAL
1 #D (A) DYNAMIC INIT <'abc'>
END-DEFINE
PRINT #D (EM=H(536870912))
END

You’re right, it’s quite easy. But I can’t see the storage problem you mentioned…

define data local
01 #b2 (B2 ) init <H'01'>
01 #a  (a)  dynamic
end-define
write #b2
move edited #b2 (EM=H(536870912)) to #a
write  *LENGTH(#a) #a (AL=20)
end

The original code example used a temporary variable, #HEX. The following code Checks but won’t Run.

DEFINE DATA LOCAL
1 #D (A) DYNAMIC INIT <'abc'>
1 #HEX (A1073741824)
END-DEFINE
MOVE EDITED #D (EM=H(536870912)) TO #HEX
PRINT #HEX #D (EM=H(536870912))
END

To avoid dealing with additional variables I coded a simple function. Plus I want to hexdump B-fields, too. This is my second function.

define function #A2hex
  returns (A) dynamic
  define data parameter
  1 #A (A) dynamic by value
  end-define
  move edited #A (EM=H(536870912)) to #A2hex
end-function
end
*****
define function #b2hex
  returns (A) dynamic
  define data parameter
  1 #b (B) dynamic by value
  end-define
  move edited #b (EM=H(536870912)) to #b2hex
end-function
end

Try this:

define data local
01 #b2 (B2) init <H'0001'>
end-define
write #b2hex(<H'0001'>) (AL=10)
write #b2hex(<#b2    >) (AL=10)
write #a2hex(<H'0001'>) (AL=10)
write #a2hex(<#b2    >) (AL=10)
end

My output is:
0001
0001
0001
31

So when converting #b2 to (A) dynamic, the value of #b2 is treated as an unsigned integer. A real trap for the unwary…