ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%scanrpl

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %scanrpl

    I have an account# that I want to strip out the dash from the first 16 positions and put the remainder in a 15 character field (DL27)

    The account number is 003-0001-001-001-250-01

    When I execute
    DL27 = %Scanrpl('-':'':djacct:1:16);

    it populates DL27 with '0030001001001-2'

    So apparentlly it strips out the dash from the 1st 16 positions which produces a 13 character string which it populates into the leftmost 13 pos of DL27 and then continues populating DL27 with the remaing characters after pos 16 of DJACCT until DL27 is filled. I only want the 1st 16 positions of djacct. I guess I have to use %Substr along with %Scanrpl or is there a better option.

  • #2
    Re: %scanrpl

    No better option I know of. You were telling it to do the replacement in the 1st 16 positions of the field, so instead you'll need to use both BIFs. This should work:

    DL27 = %Scanrpl('-':'':%subst(djacct:1:16));

    Comment


    • #3
      Re: %scanrpl

      Originally posted by gregwga50
      it populates DL27 with '0030001001001-2'
      That shows us what you get. Can you show us what you want?
      I only want the 1st 16 positions of djacct.
      What is "positions"? Do you mean that you want the first 16 digits? (Into a 15 character field??)

      Are you saying that you only want characters from the first 16 bytes that are not minus symbols? If so, you're probably right that you have to tell the function to only consider the beginning substring. As coded, you're telling the function to return the value after replacing the minus symbols in the first 16 positions. After it does that, the intermediate value becomes 20 bytes long. The first 15 bytes fit into your result variable.
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment


      • #4
        Re: %scanrpl

        If I'm reading this correctly, you want to A) strip out the '-' characters--all of them. Then, B) you want the first 15 characters of the result.

        So, try something like...

        Code:
        DL27 = %SubSt(%ScanRpl('-':'':djacct):1:15);
        HTH,
        Robert

        EDIT:
        Upon re-reading your original post, maybe this:

        Code:
        DL27 = %ScanRpl('-':'':%SubSt(djacct:1:16));
        ...because you are only concerned with the first 16 characters of the original account number (which includes the dashes)?
        Last edited by Robert Clay; April 16, 2014, 07:08 AM. Reason: another idea
        "Contrariwise, if it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic."--Tweedledee

        Comment

        Working...
        X