View previous topic :: View next topic
|
Author |
Message |
kunal jain
New User
Joined: 19 May 2011 Posts: 59 Location: India
|
|
|
|
I am comparing all the strings present in two working storage tables.
01 WS-STRING1-TBL.
STRING1 OCCURS 1000 TIMES PIC X(165).
01 WS-STRING2-TBL.
STRING2 OCCURS 1000 TIMES PIC X(165).
Sometimes STRING1(I) gets splitted into two consecutive strings of STRING2(J),STRING2(J+1)
For ex:-
STRING1(10) = 'This is IBM mainframe Forum where u can post query'
STRING2(10) = 'This is IBM mainframe Forum where '
STRING2(11) = ' u can post query '
The above case is the acceptable difference and should not come to the compare output.
Please let me know the logic(or code) by which I can achieve this check of comparing a string in STRING1(I) with two consecutive strings of STRING2(J),STRING2(J+1). |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
Only if You provide the logic to determine a split ! |
|
Back to top |
|
|
kunal jain
New User
Joined: 19 May 2011 Posts: 59 Location: India
|
|
|
|
Like i will be comparing every records of two tables line by line.
So when the corresponding record doesnt match then I will check whether this is case of splitting of a string into 2 consecutive string.
PERFORM LOOKUP-ROUTINE VARYING I FROM 1 BY 1
UNTIL END-OF-WS-STRING1-TBL.
LOOKUP-ROUTINE.
SET STRING2-INDEX TO +1
SEARCH WS-STRING2-TBL
AT END PERFORM NOT-FOUND-ROUTINE
WHEN STRING1(I) = STRING2( STRING2-INDEX )
Display 'Match'
WHEN Check for case of splitting a string into 2 consecutive string
AT END perform NOT-FOUND-ROUTINE
END-SEARCH.
Need to know the logic or code for "Check for case of splitting a string into 2 consecutive string" in the above.
Hope the above logic would be sufficient one to let you understand my query.
Please let me know on the same. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
as enrico implied:
both tables have items of 165 char.
how can you have table1.item1 = table2.item1 || table2.item2?
where table1.item1 would be 165 char
and table2.item1 || table2.item2 would be 330 char?
unless you provide a different (any) method of 'splitting',
you would have to
Code: |
PERFORM VARYING A FROM 1 BY 1 UNTIL A > TABLE1 ITEM COUNT
PERFORM VARYING B FROM 1 BY 1 UNTIL B > TABLE2 CHAR COUNT - 165
IF TABLE1(A) = TABLE2(B:165)
THEN
DIVIDE B BY 165 GIVING QUOTIENT REMAINDER
IF REMAINDER > 0
THEN
DISPLAY 'TABLE1 OCCURANCE ' A '= TABLE2 OCCURANCES ' QUOTIENT ' AND ' QUOTIENT + 1
ELSE
DISPLAY 'TABLE1 OCCURANCE ' A '= TABLE2 OCCURANCE ' QUOTIENT
END-IF
END-IF
END-PERFORM
END-PERFORM
|
and that would just find strings within strings. |
|
Back to top |
|
|
kunal jain
New User
Joined: 19 May 2011 Posts: 59 Location: India
|
|
|
|
The string will always be of max 165 chars, by saying this i meant that the length of the actual content of a string will be 165 chars.
Like I mentioned earlier that
STRING1(10) = 'This is IBM mainframe Forum where u can post query' STRING2(10) = 'This is IBM mainframe Forum where '
STRING2(11) = ' u can post query '
Here the length of actual content (i.e ''This is IBM mainframe Forum where u can post query') in STRING2(10)||STRING2(11) will of max 165 chars. Hope i am able to understand you here clearly.
So my method of checking a split would be:
1.Extract all the words of a string in Table1.item1 into a temp1 variable.
For the above ex:
Temp1='ThisisIBMmainframeForumwhereucanpostquery'
2. Extract all the words of the two consecutive strings - table2.item1 || table2.item2 into a temp2 variable.
Temp2='ThisisIBMmainframeForumwhereucanpostquery'
3. Now compare temp1 and temp2 variables; if they are same then display 'match' else display 'not match'.
For above ex: Temp1 = Temp2. so it is 'MATCH.
Please let me know how can I -
a.) extract all the words in Table1.item1 into TEMP1 variable
b.) extract all the words in table2.item1 || table2.item2 into TEMP2 variable.
Thanks |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
does not matter if you can understand us,
we can not understand you.
as far as cramming 330 bytes into 165,
string table2.item(x)
delimited by spaces
table2.item(x+1)
delimited by spaces
into temp-area
end-string |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
by the way,
even the english do not screw with the language so bad as to say
splitted.
the conjugation of split requires as past particple: split.
the file has been split. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
kunal jain wrote: |
[...]
Please let me know how can I -
a.) extract all the words in Table1.item1 into TEMP1 variable
b.) extract all the words in table2.item1 || table2.item2 into TEMP2 variable.
[...]
|
So, you have a maximum of 165 characters which, for some reason, might be split at some random point across two fields of 165 characters each. Never more than 165 characters but could occupy 330 characters with 165 or more consecutive spaces?
Can a word be split?
For a) and b) look at Dick's next to last post, look at STRING in the Cobol manual and try it out.
If you can't get anywhere with that, come back, there are lots of ways to skin various cute animals. |
|
Back to top |
|
|
kunal jain
New User
Joined: 19 May 2011 Posts: 59 Location: India
|
|
|
|
No, a word cant get split.
Also I have went thru the STRING VERB in Manual. I thunk i need to use it in a loop to get all the words since a single STRING will only gives a single word, I believe.
Actually I am not so comfortable with using STRING verb. If you can help me with the code then it would be great . |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@kunal jain
Morning Sir !
Please let me know how can I -
a.) extract all the words in Table1.item1 into TEMP1 variable
b.) extract all the words in table2.item1 || table2.item2 into TEMP2 variable.
Please habe a closer look at String/Unstring, using the options
Count In & With Pointer |
|
Back to top |
|
|
nigelosberry
New User
Joined: 06 Jan 2009 Posts: 88 Location: Ggn, IN
|
|
|
|
I can only guess about the actual requirement that TS has.
What about preparing the 2 arrays beforehand so as to make the match-making process easy?
Can we use the first 2 bytes of each array element to store the actual length of the string following that. A separate section can be written which scans the 2 tables and prepare the table with prefix "stringlengths".
Once this is done we can compare the length of 2 strings on each side and join 2 substrings only if there is a mismatch in the length.
Its just an idea. Draft version of code needs to be written to prove this. |
|
Back to top |
|
|
kunal jain
New User
Joined: 19 May 2011 Posts: 59 Location: India
|
|
|
|
I would like to know the code whch can extract all the words from a string of 165 chars |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@kunal jain
Just a little hint. No running code. It's to early for my sleepy brain.
If you want to eliminate all spaces of the strings, you have to create a little loop over the variable. For example, unstring String-1 into Temp-1, elininating the spaces.
move 1 to Z1 ...counter used by Unstring
move 1 to X1 ...index in Temp-1
move 0 to P1 ...pointer used by Unstring
unstring String-1 delimited by space
into temp1(x1) count in Z1
with pointer P1
Now the first word would be unstringed into the temp-area
Then add (count+1) to pointer. Increase the index by Z1.
Unstring next words until end of String-1 is reached.
Something like that. Hope it helps. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Kunal, UmeySan is "pointing" you in the right direction.
I understand that you are not, yet, happy with using STRING. But the best way to get happy with it is to use it. It is going to do what you want.
If you want another way, I'll give you something which will take you a lot more code, but is the way I would do it before STRING existed (I mean the Cobol Verb, not string in general :-) ).
Find the last non-blank character (indexed/subsricpted field redefining your 165) by going "backwards" from 165. Check that your code works for all the "obvious", like entirely blank, no trailing blanks, one trailing blank.
Now you know the length of the words, move them from the "front" byte by byte until all done. Do the same for the second part of your string, but starting the destination from where you left off with the first part.
No need to do for the other string which is not split, as there is no need to remover the spaces between the words.
Compare the two. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
I always wondered what a performant logic was of finding the next line that is equal, but too lazy to ever figure it out.
Hope you will. |
|
Back to top |
|
|
|