Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Cost associated with INSPECT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ashutosh.pr

New User


Joined: 13 Apr 2007
Posts: 36
Location: Pune

PostPosted: Thu Oct 15, 2009 10:53 am    Post subject: Cost associated with INSPECT
Reply with quote

Hi,
We have to implement a logic where we have to replace a part of a string which has value ABC to a value DEF.
The structure of the string is such that the value ABC can appear in the last three bytes or three bytes before the last byte.
Illustrating:
The value can be :
FFFPABC1

or

FFFP1ABC

We have to replace the ABC with DEF so that we get the corresponding values as below:
FFFPDEF1

or

FFFP1DEF

Following are the variables declarations:

Code:
01  WS-VARS.
    10 WS-VARS-APPLICATION          PIC  X(03) VALUE SPACES.
    10 WS-VARS-VAL                  PIC  X(01) VALUE SPACES.
    10 WS-VARS-FEED.
      15 WS-VARS-TYPE1              PIC  X(03) VALUE SPACES.
        88 WS-VARS-ABC1                        VALUE 'ABC'.
      15 WS-VARS-FILL1              PIC  X(01) VALUE SPACES.
    10 WS-VARS-FEED2   REDEFINES    WS-VARS-FEED.
      15 WS-VARS-FILL2              PIC  X(01).
      15 WS-VARS-TYPE2              PIC  X(03).
        88 WS-VARS-ABC2                        VALUE 'ABC'.


Right now we are using the following logic:

Code:
   MOVE WS-GROUP-VAR TO WS-VARS


    IF WS-VARS-ABC1       
        MOVE 'DEF'              TO WS-VARS-TYPE1
    ELSE
        IF WS-VARS-ABC2
            MOVE 'DEF'          TO WS-VARS-TYPE2
        END-IF
    END-IF
    MOVE WS-VARS                 TO WS-GROUP-VAR



Where WS-GROUP-VAR contains the value FFFPABC1 or FFFP1ABC

I just wanted to know that if instead of the above logic, we use the below logic, is it going to be costly (in terms of CPU usage), as we have been told that INSPECT function is costly as compared to the above logic of using IF?

Code:
INSPECT WS-GROUP-VAR REPLACING ALL 'ABC' BY 'DEF'


We are sure that there would not be any ABC anywhere else in the string except the last 4 bytes.

Thanks,
Ashutosh
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Thu Oct 15, 2009 4:01 pm    Post subject: Reply to: Cost associated with INSPECT
Reply with quote

Instead of using "REPLACING", substitute with "CONVERTING", change "BY" to "TO" and remove "ALL".

INSPECT CONVERTING (as illustrated, using literals) generates (under the covers) an in-line Assembler TR, whereas, REPLACING always causes a BALR (CALL) to a COBOL run-time routine.

Code:

INSPECT WS-GROUP-VAR CONVERTING 'ABC' TO 'DEF'


Bill
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Oct 16, 2009 7:08 am    Post subject:
Reply with quote

Bill, in this case, shouldn't the REPLACING option be used instead of the CONVERTING? I don't have mainframe access at present, but wouldn't 'AXC' be converted to 'DBF' which is not the desired result.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 16, 2009 7:25 am    Post subject: Reply to: Cost associated with INSPECT
Reply with quote

Terry,

The INSPECT REPLACING example (which the OP supplied), was coded as "Replace all 'ABC' with 'DEF'".

I just got rid of REPLACING, BY and ALL and substituted with CONVERTING and TO. The ALL was removed altogether as it wasn't necessary.

To tell you the truth, if that's not what the OP wanted, then I missed it by a mile. icon_redface.gif

Bill
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Oct 16, 2009 8:46 am    Post subject:
Reply with quote

I also prefer the CONVERTING to REPLACING for the reasons you've explained, but my interpretation of how CONVERTING works is that all As will be converted to Ds, all Bs to Es, and all Cs to Fs given the following statement:
Code:
INSPECT WS-GROUP-VAR CONVERTING 'ABC' TO 'DEF'
As I mentioned, without mainframe access, I can't test this.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Oct 16, 2009 9:22 am    Post subject:
Reply with quote

Ashutosh,
I also have heard that INSPECT is more costly than IF, but it depends on how many times this conversion is done. CPU speeds being what they are, it would take a lot of these to notice much difference I would suspect. If you're really that concerned, your IF statements should suffice as long as the fields always remain defined as they are, and you can guarantee that the ABC, if it is present, will always be in the last 4 bytes of the 8 byte field. As Bill mentioned, the ALL is not needed given your conditions.
Back to top
View user's profile Send private message
ashutosh.pr

New User


Joined: 13 Apr 2007
Posts: 36
Location: Pune

PostPosted: Fri Oct 16, 2009 2:37 pm    Post subject:
Reply with quote

Thank you very much Terry!

----------
Ashutosh
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 16, 2009 4:04 pm    Post subject: Reply to: Cost associated with INSPECT
Reply with quote

The INSPECT example, regardless whether it is using REPLACING or CONVERTING, will not work as expected.

What it will do is to change all occurences of 'A' to 'D', 'B' to 'E' and 'C' to 'F'.

So, if you know where the the target literal can be found in the field, then check for it there. Otherwise, an in-line PERFORM using reference modification will work as well.

Note that if you use an in-line PERFORM, the UNTIL value will be the target field length minus two.

For example, if the field is 20-bytes long, the UNTIL value will be 18, because the last valid byte-position to check for the three-byte literal will be 18.

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Report cost in CA-dispatch Nileshkul CA Products 3 Wed Jun 07, 2017 10:32 pm
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm
No new posts Using Inspect in cobol Ajay Dwivedi COBOL Programming 8 Sat Sep 26, 2015 11:33 pm
No new posts EQUIVALENT OF COBOL INSPECT IN REXX pshongal CLIST & REXX 2 Fri Nov 22, 2013 10:44 am
No new posts Cost of an UPDATE query when executed... sasanka DB2 3 Sun Oct 13, 2013 12:06 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us