Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inspect replacing problem 1

Status
Not open for further replies.
Not clever, but it might work (untested)...
Code:
...
01  IN-CURSOR         PIC 999.
01  OUT-CURSOR        PIC 999.
01  SEGMENT-SIZE      PIC 999.

01  INPUT-AREA        PIC X(something).
01  OUTPUT-AREA       PIC X(somethingelse).
....

MOVE 1 to IN-CURSOR, OUT-CURSOR.
perform UNTIL IN-CURSOR > LENGTH OF INPUT-AREA
    MOVE 0 TO SEGMENT-SIZE
    INSPECT INPUT-AREA (IN-CURSOR:) TALLYING SEGMENT-SIZE
            FOR CHARACTERS BEFORE INITIAL "'"
    IF SEGMENT-SIZE > 0
        STRING INPUT-AREA (IN-CURSOR:SEGMENT-SIZE)
                 DELIMITED BY SIZE
            "\'" DELIMITED BY SIZE
            INTO OUTPUT-AREA
            POINTER OUT-CURSOR
            ON OVERFLOW [i]handle error case[/i]
        END-STRING       
    ELSE
        STRING "\'" DELIMITED BY SIZE
            INTO OUTPUT-AREA
            POINTER OUT-CURSOR
            ON OVERFLOW [i]handle error case[/i]
        END-STRING       
    END-IF
    ADD SEGMENT-SIZE, 1 TO IN-CURSOR
end-perform.

Tom Morrison
 
You could also use reference modification to do this....
I made an assumption that input field was 15 bytes long. Moved it to a 25 byte field to work on. Just needs to be at least 1 byte longer than input since I check for all spaces to indicate when I am done. Whenever I find the apostrophe, I move data to output area and then shift the input data to the left to start at position 1 again. This has not been fully tested. You will have to be sure that the input field is not all spaces as one check.

Code:
03  AA-A                     PIC S9(03).      
03  AA-B                     PIC S9(03).      
03  AA-X                     PIC S9(03).  

03  IR-DATA                  PIC X(15).       
                                                                        
03  FLD-1                    PIC X(25).       
03  FLD-2                    PIC X(25).       


MOVE +1       TO AA-A                          
                 AA-B                          
                 AA-X                         
MOVE IR-DATA                TO FLD-1.                     
MOVE SPACES                 TO FLD-2.                     
PERFORM UNTIL FLD-1 = SPACES                                
    IF FLD-1 (AA-X:) = SPACES       
        MOVE FLD-1(1 : AA-X - 1) TO FLD-2 (AA-B : AA-X - 1) 
        MOVE SPACES          TO FLD-1                      
    ELSE       
        IF FLD-1 (AA-X:1) = "'"            
            IF AA-X NOT = +1           
                MOVE FLD-1(1 : AA-X - 1)        
                             TO FLD-2 (AA-B : AA-X - 1) 
            END-IF                       
            COMPUTE AA-B = AA-B + AA-X - 1
            MOVE "\'"        TO FLD-2 (AA-B:2)             
            COMPUTE AA-B = AA-B + 2                         
            MOVE FLD-1 (AA-X + 1:)   TO FLD-1
            MOVE +1          TO AA-X
        ELSE
            ADD +1           TO AA-X        
        END-IF
    END-IF
END-PERFORM.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top