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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String editing

Status
Not open for further replies.

cobolist

Programmer
Joined
Jan 13, 2009
Messages
8
Location
FI
I found that in Cobol there are alphanumeric strings and numeric strings. I wondered how to make a program where we have an input like "A30" and we want to multiply the number 30 by 11 to get output "A330".
 
Define it as a group level with an alpha part and a numeric part.

Measurement is not management.
 
How can I code to reformat any one of these telephone # to a 10 byte number:

eg: (614) 123-4567 to 6141234567
614-123-4567 to 6141234567
 
can an "unstring" "STRING" or "Inspect" be used. There is knowing how many spaces will between the "-" or brackets...
 
No trivial solution comes to my mind for this.

It's hard to provide the best solution for your situation without more information, but a fairly general approach is to loop through the input field. Test each byte for numeric and, if numeric, move it to the output field. Something like:
Code:
01  WS-INPUT        PIC X(??).
01  WS-OUTPUT       PIC 9(10).
.
.
.
MOVE ZEROS          TO WS-OUTPUT
MOVE 1              TO IDX2
PERFORM VARYING IDX FROM 1 BY 1
          UNTIL IDX > LENGTH OF (WS-INPUT) OR
                IDX2 = 10
    IF WS-INPUT(IDX:1) IS NUMERIC
        MOVE WS-INPUT(IDX:1) TO WS-OUTPUT(IDX2:1)
        ADD 1       TO IDX2
    END-IF
END-PERFORM
When using this approach, you will have to make sure you the input contains 10 digits (or more) or you have to deal with WS-OUTPUT not containing 10 valid digits on exit.

Regards.

Glenn
 
Here's one. There's no sanity check on the number of digits but it seems to do the job.

Code:
IDENTIFICATION DIVISION.
 PROGRAM-ID. FILTER01.
 ENVIRONMENT DIVISION.
 INPUT-OUTPUT SECTION.
 FILE-CONTROL.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  PROCESSING-DATA.
     04  INPUT-VALUE        PIC X(20).
     04  TEMP-VALUE1        PIC X(20).
     04  TEMP-VALUE2        PIC X(20).
     04  POINTER-VALUE      PIC S9(4) BINARY.
     04  OUT-VALUE          PIC X(20).
     04  OUT-NUMBER         PIC 9(10).
     04  OUT-NUM-TEXT REDEFINES OUT-NUMBER PIC X(10) JUST RIGHT.
     04  OUT-BINARY         PIC S9(10) BINARY.
     04  EOS-FLAG           PIC X.
     04  DUMMY-CHAR         PIC X.
 PROCEDURE DIVISION.
 0000-MAIN SECTION.
     DISPLAY "TESTING FILTER.  TYPE QUIT IN ALL CAPS TO END.".
     PERFORM 1000-PROCESS UNTIL INPUT-VALUE = "QUIT".
     GOBACK.

 1000-PROCESS SECTION.		
     DISPLAY "ENTER PHONE NUMBER.".
     MOVE SPACES TO INPUT-VALUE.
     ACCEPT INPUT-VALUE.
     INSPECT INPUT-VALUE CONVERTING "(-)" 
                                 TO "   ".
     MOVE 1 TO POINTER-VALUE.
     MOVE SPACES TO OUT-VALUE.
     MOVE "N" TO EOS-FLAG.
     PERFORM UNTIL POINTER-VALUE > 20
       UNSTRING INPUT-VALUE DELIMITED BY ALL SPACES
                INTO TEMP-VALUE1
                WITH POINTER POINTER-VALUE
       END-UNSTRING
       MOVE SPACES TO TEMP-VALUE2
       STRING OUT-VALUE DELIMITED BY SPACES
            TEMP-VALUE1 DELIMITED BY SPACES
            INTO TEMP-VALUE2
       END-STRING
       MOVE TEMP-VALUE2 TO OUT-VALUE
     END-PERFORM.
     UNSTRING OUT-VALUE DELIMITED BY SPACES
              INTO OUT-NUM-TEXT
     END-UNSTRING.
     MOVE OUT-NUMBER TO OUT-BINARY.
     DISPLAY "PHONE NUMBER IS: " OUT-BINARY.

Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top