Hi,
How to find duplicate in variable length string in cobol.
Ex., ABCDEEFGGHII
I need to find duplicates in above string.
Finding duplicate in variable lenght string in cobol
-
- Posts: 7
- Joined: Fri Jun 17, 2022 9:59 pm
- Skillset: Mainframe - COBOL,JCL,DB2,VSAM
- Referer: internet
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Finding duplicate in variable lenght string in cobol
First, you need to understand that there isn't really a variable length string in COBOL. Alphanumeric variables (PIC X) have a length that is set at the time the program is compiled, and that length cannot be varied without editing the source code and recompiling it.
Second, your post is woefully inadequate in describing your problem. These duplicates -- are they always side-by-side in the variable? What if you have ABCDABC -- duplicates or not? How long is the variable? Is there a limit of 1 duplicate or could you have something like ABCDDDDEFF? What do you want to do when you find a duplicate? Print it out? Store it in another variable? Delete the duplicates from the variable?
Second, your post is woefully inadequate in describing your problem. These duplicates -- are they always side-by-side in the variable? What if you have ABCDABC -- duplicates or not? How long is the variable? Is there a limit of 1 duplicate or could you have something like ABCDDDDEFF? What do you want to do when you find a duplicate? Print it out? Store it in another variable? Delete the duplicates from the variable?
-
- Posts: 7
- Joined: Fri Jun 17, 2022 9:59 pm
- Skillset: Mainframe - COBOL,JCL,DB2,VSAM
- Referer: internet
Re: Finding duplicate in variable lenght string in cobol
Sorry for the less details. My input file has only one field and that is string declared as X(15). I need to find is there any duplicate alphabet in the string.
If it is duplicate i need to write that records alone in output-duplicate file. Rest i will Write in normal output file.
My sample/test records as follows:
ABCDEEFGGHIIEDH
TODAYISBESTDAYA
MAINFRAMEFILES
If it is duplicate i need to write that records alone in output-duplicate file. Rest i will Write in normal output file.
My sample/test records as follows:
ABCDEEFGGHIIEDH
TODAYISBESTDAYA
MAINFRAMEFILES
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Finding duplicate in variable lenght string in cobol
Based on your post, all three of the sample strings you provided have duplicates since you did NOT specify that duplicates have to be next to each other.
-
- Posts: 7
- Joined: Fri Jun 17, 2022 9:59 pm
- Skillset: Mainframe - COBOL,JCL,DB2,VSAM
- Referer: internet
Re: Finding duplicate in variable lenght string in cobol
In my case duplicates can be anywhere in the string. As you said all three strings are duplicates. But I need a logic to figure out the string has duplicates in COBOL program. Once i figure out the string has duplicate, then i will write that record alone into my duplicate output file.
Appreciate your help.
Appreciate your help.
-
- Global moderator
- Posts: 3006
- Joined: Fri Apr 18, 2008 11:25 pm
- Skillset: tso,rexx,assembler,pl/i,storage,mvs,os/390,z/os,
- Referer: www.ibmmainframes.com
Re: Finding duplicate in variable lenght string in cobol
google with shortest/longest repeated substring
to get the algorithm and the code snippets in python, java , c
you will have to port it to cobol yourself
to get the algorithm and the code snippets in python, java , c
you will have to port it to cobol yourself
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
-
- Posts: 7
- Joined: Fri Jun 17, 2022 9:59 pm
- Skillset: Mainframe - COBOL,JCL,DB2,VSAM
- Referer: internet
Re: Finding duplicate in variable lenght string in cobol
ok. I will try. Thank you.
-
- Global moderator
- Posts: 3006
- Joined: Fri Apr 18, 2008 11:25 pm
- Skillset: tso,rexx,assembler,pl/i,storage,mvs,os/390,z/os,
- Referer: www.ibmmainframes.com
Re: Finding duplicate in variable lenght string in cobol
the suggestion posted was for an academically correct full approach
since you only need to know if there are duplicates and not determine their value
a simple scan for repeated chars would be more than enough
here is a smal proof of concept written in rexx
the script
the result
since you only need to know if there are duplicates and not determine their value
a simple scan for repeated chars would be more than enough
here is a smal proof of concept written in rexx
the script
Code: Select all
trace "O"
strings.1 = "ABCDEEFGGHIIEDH"
strings.2 = "TODAYISBESTDAYA"
strings.3 = "MAINFRAMEFILES"
strings.4 = "noduplicates"
strings.0 = 4
do s = 1 to strings.0
say "checking >"strings.s"<"
do i = 1 to length(strings.s) - 1
c = substr(strings.s,i,1 )
do j = i+1 to length(strings.s)
if substr(strings.s,j,1 ) = c then do
say " match found for >"strings.s"<" "at" i j ">"c"<"
iterate s
end
end
end
say " no duplicates in >"strings.s"<"
end
the result
Code: Select all
~/z % rexx dups
checking >ABCDEEFGGHIIEDH<
match found for >ABCDEEFGGHIIEDH< at 4 14 >D<
checking >TODAYISBESTDAYA<
match found for >TODAYISBESTDAYA< at 1 11 >T<
checking >MAINFRAMEFILES<
match found for >MAINFRAMEFILES< at 1 8 >M<
checking >noduplicates<
no duplicates in >noduplicates<
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Finding duplicate in variable lenght string in cobol
kanipriya2785 wrote:Hi,
How to find duplicate in variable length string in cobol.
Ex., ABCDEEFGGHII
I need to find duplicates in above string.
Try to learn at least something about string processing in COBOL. The statements like: INSPECT, UNSTRING, STRING…
Javas and Pythons come and go, but JCL and SORT stay forever.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 4
- 2226
-
by sergeyken
View the latest post
Mon Jun 26, 2023 12:56 am
-
- 2
- 8417
-
by prino
View the latest post
Sat Mar 13, 2021 4:47 am
-
- 1
- 2983
-
by oliver07
View the latest post
Sat Oct 30, 2021 2:32 pm
-
- 1
- 2121
-
by chaat
View the latest post
Wed Sep 22, 2021 11:40 pm
-
-
Replace a string with another string with different length
by Devrana » Sun Jan 19, 2025 3:23 pm » in JCL - 1
- 1632
-
by sergeyken
View the latest post
Sun Jan 19, 2025 11:07 pm
-