IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need a help on Unstring


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 2:33 am
Reply with quote

xyz file:

Code:
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"


Here I am executing,

Code:
UNSTRING xyz-rec DELIMITED BY X'6B' into
ws-date1
ws-date2
ws-perctge
ws-amt1
ws-amt2
ws-amt3
END-UNSTRING


output I am getting is,

Code:
11/21/2012

3.125%
"$172
$0.00
"$172


But I need ,

Code:
11/21/2012

3.125%
"$172,000.00"
$0.00
"$172,000.00"




Can you please guide further to get this?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8651
Location: Dubuque, Iowa, USA

PostPosted: Thu Nov 29, 2012 2:39 am
Reply with quote

UNSTRING won't help you here. Either get the source of the data to remove the commas inside the quotes, or use reference modification (or arrays) to examine each byte, one at a time, to determine how to process it.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Nov 29, 2012 2:39 am
Reply with quote

How you propose that the comma (X'6B') delimiting the fields be distinguished from the comma (X'6B') serving as a separator in the amounts?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 2:47 am
Reply with quote

@Akatsukami:
That is the approach we decided, but now it is getting difficult to go with '6B'
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 2:51 am
Reply with quote

Robert: How reference modification will help here as the data may come and may not come like happened for ws-date2 filed in the above example
Back to top
View user's profile Send private message
Simone Salzmann

New User


Joined: 26 Nov 2012
Posts: 17
Location: Switzerland

PostPosted: Thu Nov 29, 2012 3:20 am
Reply with quote

If you can't have the delimiters changed at their origin they come into COBOL you could try this:

Before unstringing the data stream you could replace the commas outside the " " by some other character that isn't used anywhere in the datastream and unstring with the help of that character.

Try the COBOL handbooks for INSPECT (TALLYING) REPLACING...

Possibly you'll have to build a loop to get through the complete data stream, replacing the commas outside the " " and just jumping forward to the end of the " " part.

Could that be a solution for you?

It would be the easiest, though, to ask for different delimiters to be delivered.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Nov 29, 2012 3:22 am
Reply with quote

Although I am not a COBOL programmer (in the past couple of decades, anyway), the algorithm is as applicable to COBOL as it is to PL/I or Rexx.
Code:

j        = 0
mark     = 1
inquotes = FALSE

do i = 1 to length(record)
  if (char(i)=double_quote) then
    inquotes = ¬inquotes
 
  if ((char(i)=comma) & (¬inquotes)) then
  do
    j += 1
    receiving_field(j) = substr(record,mark,i-1)
    mark = i + 1
  end
end

(I assume that it's obvious what values comma and double_quote have.)
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10833
Location: italy

PostPosted: Thu Nov 29, 2012 3:24 am
Reply with quote

here is a POC in rexx


Code:
src = "11/21/2012,,3.125%,""$172,000.00"",$0.00,""$172,000.00"""
len = length(src)

str = 0
j   = 1
fld.= ""

do  i = 1 to len
    c = substr(src,i,1)
    if  c = "," then do
        if  str then ,
            fld.j = fld.j || c
        else ,
            j = j + 1
        iterate
    end
    fld.j = fld.j || c
    if  c = """" then ,
        str = \str
end

do  f = 1 to j
    say f fld.f
end


the result


Code:
1 11/21/2012
2
3 3.125%
4 "$172,000.00"
5 $0.00
6 "$172,000.00"
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 29, 2012 4:55 am
Reply with quote

Quote:
xyz file:

Code:
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"


Here I am executing,

Code:
UNSTRING xyz-rec DELIMITED BY X'6B' into
ws-date1
ws-date2
ws-perctge
ws-amt1
ws-amt2
ws-amt3
END-UNSTRING


output I am getting is,

Code:
11/21/2012

3.125%
"$172
$0.00
"$172




How do you get that output? I'd expect this:

Code:
11/21/2012

3.125%
"$172
000.00"
$0.00


Your Sort product can use PARSE with PAIR= to "protect" the embedded commas.

It shouldn't be difficult for the producer of the data to give you a file lacking the comma number-editing or using a different delimiter.

If you end up having to do it in Cobol with the file as then there is an OCCURS DEPENDING ON solution to go with those from Mr Akatsukami and enrico.
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Thu Nov 29, 2012 5:07 am
Reply with quote

I used below COBOL code for unstring the data

Code:
       WORKING-STORAGE SECTION.                                         
       *                                                                 
        01 WS-TEST-DATA             PIC X(100).                         
        01 WS-TEMP-DATA             PIC X(100).                         
        01 WS-START-POSN            PIC S9(04) COMP.                     
        01 WS-SPACE-COUNT           PIC S9(04) COMP.                     
        01 WS-DATA-LEN              PIC S9(04) COMP.                     
        01 WS-PROCESS-CNT           PIC S9(04) COMP.                     
        01 WS-POSN                  PIC S9(04) COMP.                     
       *                                                                 
        LINKAGE SECTION.                                                 
       *                                                                 
        PROCEDURE DIVISION.                                             
       *                                                                 
        0000-MAINLINE.                                                   
       *                                                                 
            MOVE '11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"' 
                                      TO WS-TEST-DATA                   
            MOVE ZERO                 TO WS-SPACE-COUNT 
            INSPECT FUNCTION REVERSE(WS-TEST-DATA)       
                    TALLYING WS-SPACE-COUNT             
            FOR LEADING SPACES                           
            COMPUTE WS-DATA-LEN = 100 -  WS-SPACE-COUNT 
            MOVE 1                    TO WS-START-POSN   
            MOVE 1                    TO WS-POSN         
            MOVE ZERO                 TO WS-PROCESS-CNT
            PERFORM UNTIL WS-PROCESS-CNT > WS-DATA-LEN   
              IF WS-TEST-DATA(WS-START-POSN:1) = ','     
                 DISPLAY 'WS-TEMP-DATA<'WS-TEMP-DATA'>' 
                 MOVE SPACES          TO WS-TEMP-DATA   
                 MOVE 1               TO WS-POSN         
                 ADD  1               TO WS-START-POSN   
                 ADD  1               TO WS-PROCESS-CNT 
              ELSE                                       
                 IF WS-TEST-DATA(WS-START-POSN:1) = '"' 
                    MOVE 1            TO WS-POSN         
                    MOVE WS-TEST-DATA(WS-START-POSN:1)   
                                      TO WS-TEMP-DATA(WS-POSN:1)     
                    ADD  1            TO WS-START-POSN               
                    ADD  1            TO WS-PROCESS-CNT               
                    PERFORM UNTIL WS-TEST-DATA(WS-START-POSN:1) = '"'
                    OR      WS-PROCESS-CNT > WS-DATA-LEN             
                      ADD 1           TO WS-POSN                     
                      MOVE WS-TEST-DATA(WS-START-POSN:1)             
                                      TO WS-TEMP-DATA(WS-POSN:1)     
                      ADD 1           TO WS-START-POSN               
                      ADD 1           TO WS-PROCESS-CNT               
                    END-PERFORM                                       
                    ADD 1             TO WS-POSN                     
                    MOVE WS-TEST-DATA(WS-START-POSN:1)               
                                      TO WS-TEMP-DATA(WS-POSN:1)     
                    ADD 1             TO WS-START-POSN               
                    ADD 1             TO WS-POSN                     
                 ELSE                                                 
                    MOVE WS-TEST-DATA(WS-START-POSN:1)               
                                      TO WS-TEMP-DATA(WS-POSN:1)   
                    ADD 1             TO WS-POSN                   
                    ADD 1             TO WS-START-POSN             
                    ADD 1             TO WS-PROCESS-CNT             
                 END-IF                                             
              END-IF                                               
            END-PERFORM                                             
            IF WS-TEST-DATA NOT EQUAL TO SPACE                     
                 DISPLAY 'WS-TEMP-DATA<'WS-TEMP-DATA'>'             
            END-IF                                                 
       *                                                           
            STOP RUN.                                               
       *                                                           
        0000-EXIT.                                                 
            EXIT.                                                   
       *                                                           



Output:
Code:

WS-TEMP-DATA<11/21/2012               
WS-TEMP-DATA<                         
WS-TEMP-DATA<3.125%                   
WS-TEMP-DATA<"$172,000.00"             
WS-TEMP-DATA<$0.00                     
WS-TEMP-DATA<"$172,000.00"
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 29, 2012 7:36 am
Reply with quote

Here's another one, a bit rough'n'ready:

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUBA.
                                                                       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  W-WHEN-COMPILED                      PIC X(8)BX(8).
       01  W-NUMBER-OF-COLUMNS             COMP PIC 9(4) VALUE 6.
       01  W-DATA-TO-UNSTRING                   PIC X(60).
       01  W-LENGTH-OF-LINE-DISP           COMP PIC 9(4).
       01  W-LENGTH-OF-THIS-COLUMN         COMP PIC 9(4).
       01  W-LENGTH-OF-STRING              COMP PIC 9(4).
       01  W-MAX-THIS-COLUMN               COMP PIC 9(4).
       01  W-COLUMN-DATA-TABLE.
           05  FILLER OCCURS 6 TIMES INDEXED BY WI-CDT-UNSTRING-INDEX.
               10  W-COLUMN-DATA                PIC X(60).
       LINKAGE SECTION.
       01  L-WORK-LINE.
           05  L-WL-LINE-TEXT-DATA.
               10  L-WL-LINE-DISPLACEMENT.
                   15  FILLER OCCURS 0 TO 60 TIMES
                        DEPENDING ON
                         W-LENGTH-OF-LINE-DISP.
                       20  FILLER               PIC X.
               10  L-WL-COLUMN.
                   15  FILLER OCCURS 0 TO 60 TIMES
                        DEPENDING ON
                         W-LENGTH-OF-THIS-COLUMN.
                       20  FILLER               PIC X.
               10  L-NEXT-BYTE-TO-LOOK-AT       PIC X.
                   88  L-NEXT-BYTE-IS-QUOTE     VALUE '"'.
                   88  L-NEXT-BYTE-IS-COMMA     VALUE ','.
                   88  L-NEXT-BYTE-IS-SPACE     VALUE SPACE.
       PROCEDURE DIVISION.
                                                                       
           MOVE WHEN-COMPILED           TO W-WHEN-COMPILED
           DISPLAY "STUBA COMPILED ON " W-WHEN-COMPILED
           MOVE '11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"'
                                        TO W-DATA-TO-UNSTRING
           PERFORM                      05-DO-THE-WORK
           MOVE SPACE                   TO W-DATA-TO-UNSTRING
           PERFORM                      05-DO-THE-WORK
           MOVE '11/21/2012,,3.125%,"$172,000.00",$0.00,$172000.00XXXXXX
      -    'XXXXX'
                                        TO W-DATA-TO-UNSTRING
           PERFORM                      05-DO-THE-WORK
           MOVE '",,,,,,,,",,3.125%,"$172,000.00",$0.00,"$172,000.00X"'
                                        TO W-DATA-TO-UNSTRING
           PERFORM                      05-DO-THE-WORK
           MOVE ',",,,,,,,",3.125%,"$172,000.00",$0.00,,'
                                        TO W-DATA-TO-UNSTRING
           PERFORM                      05-DO-THE-WORK
           GOBACK
           .
       05-DO-THE-WORK.
           DISPLAY W-DATA-TO-UNSTRING
           SET ADDRESS OF L-WORK-LINE   TO ADDRESS OF
                                            W-DATA-TO-UNSTRING
                                                                       
           PERFORM                      10-FIND-LENGTH-OF-STRING
                                                                       
           SET WI-CDT-UNSTRING-INDEX    TO 1
           MOVE ZERO                    TO W-LENGTH-OF-LINE-DISP
                                           W-LENGTH-OF-THIS-COLUMN
           PERFORM                      20-EXTRACT-COLUMNS
             W-NUMBER-OF-COLUMNS TIMES
           DISPLAY "COL 1>" W-COLUMN-DATA ( 1 ) "<"
           DISPLAY "COL 2>" W-COLUMN-DATA ( 2 ) "<"
           DISPLAY "COL 3>" W-COLUMN-DATA ( 3 ) "<"
           DISPLAY "COL 4>" W-COLUMN-DATA ( 4 ) "<"
           DISPLAY "COL 5>" W-COLUMN-DATA ( 5 ) "<"
           DISPLAY "COL 6>" W-COLUMN-DATA ( 6 ) "<"
           .
       10-FIND-LENGTH-OF-STRING.
           MOVE LENGTH OF W-DATA-TO-UNSTRING
                                        TO W-LENGTH-OF-STRING
                                           W-LENGTH-OF-LINE-DISP
           IF W-DATA-TO-UNSTRING EQUAL TO SPACE
               MOVE ZERO                TO W-LENGTH-OF-STRING
           ELSE
               SUBTRACT 1               FROM W-LENGTH-OF-LINE-DISP
               PERFORM                  10A-WIND-BACK
                 UNTIL                  NOT L-NEXT-BYTE-IS-SPACE
               COMPUTE W-LENGTH-OF-STRING =
                                        W-LENGTH-OF-LINE-DISP
                                        + 1
           END-IF
           DISPLAY "LENGTH >" W-LENGTH-OF-STRING "<"
           .
       10A-WIND-BACK.
           SUBTRACT 1                   FROM W-LENGTH-OF-LINE-DISP
           .
       20-EXTRACT-COLUMNS.
           IF L-NEXT-BYTE-IS-QUOTE
               PERFORM                  20A-FIND-NEXT-QUOTE
               PERFORM                  20D-FIND-NEXT-COMMA
           ELSE
               PERFORM                  20D-FIND-NEXT-COMMA
           END-IF
           MOVE L-WL-COLUMN             TO W-COLUMN-DATA
                                            ( WI-CDT-UNSTRING-INDEX )
           COMPUTE W-LENGTH-OF-LINE-DISP
                                        = W-LENGTH-OF-LINE-DISP
                                        + W-LENGTH-OF-THIS-COLUMN
                                        + 1
           MOVE ZERO                    TO W-LENGTH-OF-THIS-COLUMN
           SET WI-CDT-UNSTRING-INDEX    UP BY 1
           .
       20A-FIND-NEXT-QUOTE.
           ADD 1                        TO W-LENGTH-OF-THIS-COLUMN
           PERFORM                      99A-WIND-ALONG
             UNTIL L-NEXT-BYTE-IS-QUOTE
           .
       20D-FIND-NEXT-COMMA.
           COMPUTE W-MAX-THIS-COLUMN    = W-LENGTH-OF-STRING
                                        - W-LENGTH-OF-LINE-DISP
           PERFORM                      99A-WIND-ALONG
             UNTIL ( W-LENGTH-OF-THIS-COLUMN
                      EQUAL TO W-MAX-THIS-COLUMN )
             OR    L-NEXT-BYTE-IS-COMMA
           .
       99A-WIND-ALONG.
           ADD 1                        TO W-LENGTH-OF-THIS-COLUMN
           .



Output is:

Code:
STUBA COMPILED ON 11/29/12 01.56.03                               
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"               
LENGTH >0052<                                                     
COL 1>11/21/2012                                                  <
COL 2>                                                            <
COL 3>3.125%                                                      <
COL 4>"$172,000.00"                                               <
COL 5>$0.00                                                       <
COL 6>"$172,000.00"                                               <
                                                                   
LENGTH >0000<                                                     
COL 1>                                                            <
COL 2>                                                            <
COL 3>                                                            <
COL 4>                                                            <
COL 5>                                                            <
COL 6>                                                            <
11/21/2012,,3.125%,"$172,000.00",$0.00,$172000.00XXXXXXXXXXX       
LENGTH >0060<                                                     
COL 1>11/21/2012                                                  <
COL 2>                                                            <
COL 3>3.125%                                                      <
COL 4>"$172,000.00"                                               <
COL 5>$0.00                                                       <
COL 6>$172000.00XXXXXXXXXXX                                       <
",,,,,,,,",,3.125%,"$172,000.00",$0.00,"$172,000.00X"             
LENGTH >0053<                                                     
COL 1>",,,,,,,,"                                                  <
COL 2>                                                            <
COL 3>3.125%                                                      <
COL 4>"$172,000.00"                                               <
COL 5>$0.00                                                       <
COL 6>"$172,000.00X"                                              <
,",,,,,,,",3.125%,"$172,000.00",$0.00,,                           
LENGTH >0039<                                                     
COL 1>                                                            <
COL 2>",,,,,,,"                                                   <
COL 3>3.125%                                                      <
COL 4>"$172,000.00"                                               <
COL 5>$0.00                                                       <
COL 6>                                                            <
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 9:36 pm
Reply with quote

Thanks all, I wil try this out.
Also, the other way around is to formate the input file like,

Code:
11/21/2012;;3.125%;"$172,000.00";$0.00;"$172,000.00"
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Nov 29, 2012 9:50 pm
Reply with quote

If you could have done that at first hand you could have saved some time yourself and of others too

Yet this thread has very useful contents posted by other experts
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 10:26 pm
Reply with quote

With the the help of SORT-PARSE can you please guide to change the below file

Code:
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"



to

Code:
11/21/2012;;3.125%;"$172,000.00";$0.00;"$172,000.00"
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Nov 29, 2012 10:43 pm
Reply with quote

Rohit Umarjikar wrote:
With the the help of SORT-PARSE can you please guide to change the below file

Code:
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"



to

Code:
11/21/2012;;3.125%;"$172,000.00";$0.00;"$172,000.00"

Yes. Take the manual and beat the producer of the data until heesh agrees to change the delimiter. Otherwise, you have four solutions (my pseudo-code, Dr. Sorichetti's Rexx script, and Sr. Woodger's and Sri Sai's COBOL programs); it is useless to try to put off having to actually do some work.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Nov 29, 2012 10:50 pm
Reply with quote

how is the Input file created?

Cant you change the delimiters to something else unless there is no impacts?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 10:54 pm
Reply with quote

Quote:
how is the Input file created?

Cant you change the delimiters to something else unless there is no impacts?


No actually, We are getting the feed from some application and they dump it on our server with the format I mentioned thru csv file. Now I am writing a program to validate the data by doing unstring with deliminator as ",". So hence the problem.[/quote]
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Nov 29, 2012 11:02 pm
Reply with quote

I still repeat my question Why cant that application change delimiter

or send the data as fixed length



As you care a damn for solutions given to you icon_evil.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Thu Nov 29, 2012 11:53 pm
Reply with quote

The upstream process is not owned by us so they have there layouts fixed as per the requirement.So we as a receiver have to take care of these layouts.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 30, 2012 2:01 am
Reply with quote

Hello,

You need to re-read what Akatsukami (and others) provided.

You have been given ways to get what you need done.

It is now time for you to "Just Do It" . . .
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Fri Nov 30, 2012 3:01 am
Reply with quote

Yes Dick. Thank you!!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 30, 2012 3:59 am
Reply with quote

You're welcome - good luck icon_smile.gif

d
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Sat Dec 01, 2012 6:03 am
Reply with quote

To All,

I have used the below logic to convert all ',' to ';' outside the '"'.

Code:
0000-MAINLINE.                                       
                                                     
      MOVE                                           
      '11/11/2012,$0.00,"$1,111.14"'  TO WS-TEST-DATA
                                                     
                                                     
      MOVE ZERO                 TO WS-SPACE-COUNT   
                                                     
      INSPECT FUNCTION REVERSE(WS-TEST-DATA)         
              TALLYING WS-SPACE-COUNT               
              FOR LEADING SPACES                     
COMPUTE    WS-DATA-LEN = 100 -  WS-SPACE-COUNT       
MOVE 1                    TO WS-START-POSN         
MOVE 1                    TO WS-POSN               
MOVE ZERO                 TO WS-PROCESS-CNT       
PERFORM UNTIL WS-START-POSN  > WS-DATA-LEN         
IF WS-TEST-DATA(WS-START-POSN:1) = '"'         
          MOVE WS-TEST-DATA(WS-START-POSN:1)  TO   
                     WS-TEMP-DATA(WS-POSN:1)       
          ADD  1               TO WS-POSN         
          ADD  1               TO WS-START-POSN   
          SET   START-QUOTE  TO TRUE               
          PERFORM UNTIL END-QUOTE                 
             IF WS-TEST-DATA(WS-START-POSN:1) = '"'
                SET END-QUOTE    TO TRUE           
             ELSE                                       
                 MOVE WS-TEST-DATA(WS-START-POSN:1)  TO
                       WS-TEMP-DATA(WS-POSN:1)   
                 ADD  1               TO WS-POSN       
                 ADD  1               TO WS-START-POSN
           END-IF                                   
         END-PERFORM                                 
END-IF                                           
IF WS-TEST-DATA(WS-START-POSN:1) NOT = ','       
   MOVE WS-TEST-DATA(WS-START-POSN:1)  TO         
           WS-TEMP-DATA(WS-POSN:1)               
   ADD  1               TO WS-POSN               
   ADD  1               TO WS-START-POSN             
 ELSE                                             
   MOVE ';'    TO WS-TEMP-DATA(WS-POSN:1)         
   ADD  1               TO WS-POSN               
   ADD  1               TO WS-START-POSN               
 END-IF                                           
      END-PERFORM                           
      DISPLAY 'WS-TEMP-DATA:' WS-TEMP-DATA 
      DISPLAY 'WS-TEST-DATA:' WS-TEST-DATA 
      STOP RUN.                             
0000-EXIT.                                 
    EXIT.


I tested and it is working fine, also I would request you to verify.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Dec 01, 2012 4:42 pm
Reply with quote

It was suggested to me that I should have done a solution for the specific, rather than the general. He's got a big smile on now, I bet :-)

Once the first " is encountered, there are no "lonely" commas for conversion. So, count characters to first " change the "lonely" (as in can be treated as single) commas up to that point to @. From that point, change ", and ," to "@ and @" respectively. Then UNSTRING on @.

Three INSPECTs and one UNSTRING.

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. STUBB.
                                                                     
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  W-WHEN-COMPILED                      PIC X(8)BX(8).
       01  W-DATA-TO-UNSTRING                   PIC X(60).
       01  W-BEFORE-QUOTED-FIELD           COMP PIC 9(4).
       01  W-COLUMN-DATA-TABLE.
           05  FILLER OCCURS 6 TIMES.
               10  W-COLUMN-DATA                PIC X(60).
       PROCEDURE DIVISION.
                                                                     
           MOVE WHEN-COMPILED           TO W-WHEN-COMPILED
           DISPLAY "STUBB COMPILED ON " W-WHEN-COMPILED
           MOVE '11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"'
                                        TO W-DATA-TO-UNSTRING
           DISPLAY W-DATA-TO-UNSTRING
           INSPECT W-DATA-TO-UNSTRING
             TALLYING                   W-BEFORE-QUOTED-FIELD
              FOR                       CHARACTERS
              BEFORE                    X'7F'
           INSPECT W-DATA-TO-UNSTRING ( 1 : W-BEFORE-QUOTED-FIELD )
             REPLACING                  ALL X'6B' BY X'7C'
           INSPECT W-DATA-TO-UNSTRING ( W-BEFORE-QUOTED-FIELD : )
             REPLACING                  ALL X'6B7F' BY X'7C7F'
                                        ALL X'7F6B' BY X'7F7C'
           UNSTRING                     W-DATA-TO-UNSTRING
             DELIMITED                  BY X'7C'
             INTO                       W-COLUMN-DATA ( 1 )
                                        W-COLUMN-DATA ( 2 )
                                        W-COLUMN-DATA ( 3 )
                                        W-COLUMN-DATA ( 4 )
                                        W-COLUMN-DATA ( 5 )
                                        W-COLUMN-DATA ( 6 )
           DISPLAY "COL 1>" W-COLUMN-DATA ( 1 ) "<"
           DISPLAY "COL 2>" W-COLUMN-DATA ( 2 ) "<"
           DISPLAY "COL 3>" W-COLUMN-DATA ( 3 ) "<"
           DISPLAY "COL 4>" W-COLUMN-DATA ( 4 ) "<"
           DISPLAY "COL 5>" W-COLUMN-DATA ( 5 ) "<"
           DISPLAY "COL 6>" W-COLUMN-DATA ( 6 ) "<"
           GOBACK
           .


Output is:

Code:
STUBB COMPILED ON 12/01/12 11.04.08                               
11/21/2012,,3.125%,"$172,000.00",$0.00,"$172,000.00"               
COL 1>11/21/2012                                                  <
COL 2>                                                            <
COL 3>3.125%                                                      <
COL 4>"$172,000.00"                                               <
COL 5>$0.00                                                       <
COL 6>"$172,000.00"                                               <
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2942
Location: NYC,USA

PostPosted: Sun Dec 02, 2012 1:28 am
Reply with quote

@Bill: Yes icon_smile.gif

Thanks again for your extended support
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts Unstring COBOL Programming 4
No new posts UNSTRING problem COBOL Programming 3
No new posts UNSTRING a big string COBOL Programming 16
No new posts Unstring list of values into an array. COBOL Programming 8
Search our Forums:

Back to Top