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

Help needed with INSPECT


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

New User


Joined: 23 Jun 2005
Posts: 2

PostPosted: Thu May 31, 2018 1:10 am
Reply with quote

hi,

I have two fields with lengths up to 20 [ PIC X(20) ] and each field can contain the different number of characters. And my requirements are:

1) How to calculate the length of the two fields using INSPECT or any other way
2) Then I would be comparing the lengths of the two fields
3) If the lengths are equals for two fields then I would be exiting the logic
3) If the lengths are not equal then I would be searching the ALL the characters from the smaller field into the bigger field e.g. Search exact match on ABC in smaller field on longer field where ABC would be found in BABCD
Another Example exact match on SMITH is found in JONESMITH


Please suggest how this can be coded in COBOL...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu May 31, 2018 4:22 am
Reply with quote

As long as you're using a reasonably current Enterprise COBOL (untested code):
Code:
MOVE FUNCTION REVERSE (FIELD1) TO RFIELD1
MOVE FUNCTION REVERSE (FIELD2) TO RFIELD2
INSPECT RFIELD1
     TALLYING VAR1 FOR LEADING SPACES
INSPECT RFIELD2
     TALLYING VAR2 FOR LEADING SPACES
which gives you the number of characters in each variable (once subtracted from 20); the rest you should be able to figure out easily since this is a forum for experts.
Back to top
View user's profile Send private message
yvalhe

New User


Joined: 23 Jun 2005
Posts: 2

PostPosted: Fri Jun 01, 2018 12:08 am
Reply with quote

Thank you so much. I will try it.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun Jun 03, 2018 2:31 pm
Reply with quote

Never forget to initialize the counter before:
Code:
    MOVE 0 TO LNG1, LNG2

    INSPECT FUNCTION REVERSE (FIELD1)
        TALLYING LNG1 FOR LEADING SPACES
    COMPUTE LNG1 = LENGTH OF FIELD1 - LNG1

    INSPECT FUNCTION REVERSE (FIELD2)
        TALLYING LNG2 FOR LEADING SPACES
    COMPUTE LNG2 = LENGTH OF FIELD2 - LNG2
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

 


Similar Topics
Topic Forum Replies
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
No new posts Help needed to assemble IMS sample co... ABENDS & Debugging 4
No new posts RABBIT HOLE NEEDED - "Live"... All Other Mainframe Topics 0
No new posts Mainframe profiles needed @ Cognizant Mainframe Jobs 0
No new posts COBOL Student learning COBOL File Han... COBOL Programming 3
Search our Forums:

Back to Top