Menu

Inspect X replacing allowed but Inspect upper-case X replacing gives error

David Wall
2022-01-08
2022-01-08
  • David Wall

    David Wall - 2022-01-08

    Just seems illogical ??.

     
    • Simon Sobisch

      Simon Sobisch - 2022-01-08
       INSPECT UPPER-CASE(FIELD) TALLYING TALLY FOR ALL "A".
       INSPECT UPPER-CASE(FIELD) REPLACING ALL "A" BY "B".
      

      DISPTEST.cob:15: error: invalid target for REPLACING

      That's totally logical, isn't it?

      The first one is allowed, because TALLYING stores the result in TALLY, the second one isn't allowed, because you cannot change the value of an intrinsic function - UPPER-CASE(FIELD) is the target of REPLACING.

      To do this you need to only have FIELD as target - as this can be changed, or two REPLACING clauses, or one CONVERTING:

       INSPECT FIELD REPLACING ALL "a" BY "B", ALL "A" BY "B".
       INSPECT FIELD CONVERTING "aA" BY "BB". *> better performance
      
       

Anonymous
Anonymous

Add attachments
Cancel