View previous topic :: View next topic
|
Author |
Message |
yvalhe
New User
Joined: 23 Jun 2005 Posts: 2
|
|
|
|
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 |
|
 |
Robert Sample
Global Moderator

Joined: 06 Jun 2008 Posts: 8692 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
 |
yvalhe
New User
Joined: 23 Jun 2005 Posts: 2
|
|
|
|
Thank you so much. I will try it. |
|
Back to top |
|
 |
Marso
REXX Moderator

Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
 |
|