+ Reply to Thread
Results 1 to 4 of 4

Thread: updating memory area via address, %str

  1. #1
    Guest.Visitor Guest

    Default updating memory area via address, %str

    I think the problem is that your first example (eval data = %str((ptr1 : 5)) ) returns the expected 5 bytes from memory plus a null terminator, e.g. assuming the memory starting at ptr1 contains 'abcdef...', the operation would return 'abcde~', where '~' is the null terminator byte. On the other hand, when storing a value, as in your second example (eval %str(ptr1 : 5) = ‘abcdef’ ) it's going to try to store the string + a null terminator in the maximum length of 5 bytes you specified, so you'd get something like 'abcd~' since the operation will reserve 1 byte for the null terminator, leaving 4 bytes for data, and will then truncate all data after the 4th byte. Hope this helps -- Steve Shaffar

  2. #2

    Default updating memory area via address, %str

    Steve, if you do data = %str(ptr : 5), the value returned never has a null terminator. For %str on the right-hand-side, the 5 just says how far to look for the null-terminator - if there's no x'00' in the first 5 bytes, it will return all 5 bytes. You're right about the left-hand-side version. Just to briefly repeat what I already told Gary on another forum, using %str to copy data from data structures is not a good idea, if it's even remotely possible that the data might contain x'00' (which is pretty much guaranteed if the data structure has packed, binary or UCS-2 fields). Using %subst with a 65535A based variable is a much better choice.

  3. #3
    Guest.Visitor Guest

    Default updating memory area via address, %str

    I can receive data items from an external defined DS by using the %str() right side. However using the %str() as a left side (to store a value at address) seems to work some of the time. The problem can be corrected if I adjust the %str length parm. Is this problem related to some type of byte alignment while trying to store values to a memory location? I tried the ALIGN on the DS but received the same results. a small sample is shown below, the original snippet will adjust the length param & offset based on the actual field attributes defined in the PF. dsData E DS extName(File) Align ptr1 * inz(%addr(dsData)) offset S 3 0[*] offset is the starting position of field defined in DSPFFD with field-1 starting at zero. eval ptr1 = ptr1 + offset[*] works as expected eval data = %str((ptr1 : 5))[*] does not work as expected eval %str(ptr1 : 5) = ‘abcdef’ tia

  4. #4
    Guest.Visitor Guest

    Default updating memory area via address, %str

    Is there a link to the forum? I cant picture using %subst() with a base var, are you saying some thing like...
    eval %subst(dsDataffset+1:6) = 'abcdef'
    If so, then dont I still have a data type problem if the ds contains a packed field? It will not know to do a conversion.

+ Reply to Thread

Similar Threads

  1. memory pools
    By Guest.Visitor in forum General
    Replies: 2
    Last Post: 09-23-2005, 09:21 AM
  2. Setting a value in memory...??
    By jrhoads@cdsgroup.com in forum RPG
    Replies: 1
    Last Post: 01-21-2002, 09:42 AM
  3. Does the AS/400 need more memory?
    By Guest.Visitor in forum Application Software
    Replies: 14
    Last Post: 09-08-2000, 10:23 PM
  4. Fax/400 VS Memory
    By Guest.Visitor in forum Application Software
    Replies: 0
    Last Post: 01-01-1995, 02:00 AM
  5. memory address
    By Guest.Visitor in forum Security
    Replies: 0
    Last Post: 01-01-1995, 02:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts