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
 
Help needed with INSPECT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Help needed with INSPECT
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: 8400
Location: Dubuque, Iowa, USA

PostPosted: Thu May 31, 2018 4:22 am    Post subject: Reply to: Help needed with INSPECT
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    Post subject:
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: 1300
Location: Israel

PostPosted: Sun Jun 03, 2018 2:31 pm    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am
No new posts Help Needed with View Direct shailesh_do CA Products 2 Wed Jul 13, 2016 10:39 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm
No new posts Information needed on using the COBAN... venugopal.dondla COBOL Programming 5 Thu Oct 08, 2015 3:34 pm
No new posts Using Inspect in cobol Ajay Dwivedi COBOL Programming 8 Sat Sep 26, 2015 11:33 pm

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