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
Bill Woodger

Moderator Emeritus


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

PostPosted: Sun Dec 02, 2012 5:09 am
Reply with quote

I don't use reference modification a lot, and having used it here to allow the 2nd and 3rd INSPECTs to do less work, I thought I'd check it out against the "potentially INSPECT the whole field" version below:

Code:
            INSPECT W-DATA-TO-UNSTRING
              REPLACING                  ALL X'6B' BY X'7C'
               BEFORE                    X'7F'
            INSPECT W-DATA-TO-UNSTRING
              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 ) "<"


The three INSPECTs in the first version occupy 53 Assembler instructions. The two INSPECTs in the latest, only six Assembler instructions (all five INSPECTS actually use a Cobol-subroutine to do the INSPECT, IGZIN1, all the extra stuff is to do the counting in the first INSPECT and handle the variable-length fields from the reference-modification).

Yes, in the first program fewer bytes will be used in the INSPECT, but much more work will be done (with only 60 bytes in question) to save those few bytes.

I suspect doing the INSPECT with OCCURS DEPENDING ON limiting the length would be even more "wordy" than reference-modification, but I like the flexibility/maintainability of the ODO over the reference-modification.

Note: if the input is actually variable in length, it would perform better to MOVE it to a fixed-length field first thing and then work with that, than to use a variable-length field.

Note also: this is a specific solution for that specific problem. If the data was like this:

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


the fish would be of a different kettle. However, as long as the possibly-quoted-fields are trailing and interspersed by no more than one non-quoted-field, then it'll be OK.

Oh dear. Thinking about those three dollar amounts, the second-to-last one may only be unquoted in this case. If it were bigger rather that zero, as in over 999.99, then there would be another quoted field. OK, that's no problem. But, what if the last field is less than 1000? That would be a problem with the solutions provided with INSPECT/UNSTRING only.

So, for the specific example, you need an appropriate:

Code:
           INSPECT W-DATA-TO-UNSTRING
             REPLACING                  ALL X'6B7F' BY X'7C7F'
                                        ALL X'7F6B' BY X'7F7C'
                                        ALL X'6Bxx' BY X'7Cxx'


replacing the existing one. It is "appropriate" in the sense of whether use choose reference-modification or fixed-length field, and in the value of xx, which is the hex for the dollar symbol, which I didn't include as yours may well be different from mine.

Test it Rohit. It may just be that the data never allows the one field to have a different number of significant digits than the other, but it seems unlikely unless the fields will always be equal. Now I think the code will cover all the possibilities for those last three fields, but remember that "Bill thinks that it is so" is not a substitute for thorough testing and cuts no ice at all with your Boss.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Sun Dec 02, 2012 12:49 pm
Reply with quote

hahaha...icon_smile.gif

It is really proud to see the detailed explanation over this , many a new things I learned ( as I always icon_biggrin.gif ),

Surely, I am going to test this out and post you with results and as per my knowledge
Quote:
"Bill thinks that it is so"
holds true 99.99% icon_smile.gif

Thanks everyone again!!
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Sun Dec 02, 2012 1:52 pm
Reply with quote

Also, I forgot to add one condition,
Code:


IF  WS-START-POSN  > WS-DATA-LEN
    MOVE   ';'    TO WS-TEMP-DATA(WS-POSN:1)
END-IF   
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 Previous  1, 2

 


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