Nearly all AI models are not usable with COBOL questions, as the training days they had didn't include much COBOL "knowledge". You can see this on basic questions like these, which every COBOL developer could answer after some days of training (no offense for you - but for AI models).
There are "specialized" (commonly fine tuned) models that can make this better (and I'm quite sure IBMs would be different), but I highly suggest to do what developers did since the language was created:
Check COBOL compiler documentation and free documentation like the programmers guide instead for questions like: what is CONTAINS used for. And/or read cobc/parser.y which commonly gives a good overwrite (where does the compiler accepts that token).
Back to your question: if you want to use that directly in a condition, you'd have to write a user defined function. The common war would be to use an INSPECT ... TALLYING, if you want to ignore the case, then use FUNCTION LOWER() - once for the searched word, and directly in the INSPECT of your check.
... and in a real world application with thousands of elements, you would create a separate ISAM file with applicable foreign keys that reference the book - with the authors split and already lowercased (or possibly better, their phonetic value stored to catch different but similar versions - again all depending on the use case).
> Generative: 'how to determine if a string is part of another in GNU COBOL > without using the CONTAINS reserved word.'
IDENTIFICATIONDIVISION.PROGRAM-ID.SubstringCheck.DATADIVISION.WORKING-STORAGESECTION.01main-stringPICX(100)VALUE'GNU COBOL is great for learning COBOL programming.'.01search-stringPICX(20)VALUE'COBOL'.01search-lengthPIC9(02).01main-lengthPIC9(03).01found-flagPICXVALUE'N'.01remaining-stringPICX(100).PROCEDUREDIVISION.MAIN-PROCEDURE.MOVELENGTHOFsearch-stringTOsearch-lengthMOVELENGTHOFmain-stringTOmain-lengthPERFORMCHECK-SUBSTRINGVARYINGmain-lengthFROM1BY1UNTILmain-length<search-lengthORfound-flag='Y'IFfound-flag='Y'DISPLAY"Substring found."ELSEDISPLAY"Substring not found."STOPRUN.CHECK-SUBSTRING.MOVESPACETOremaining-stringMOVEmain-string(main-length:)TOremaining-stringINSPECTremaining-stringTALLYINGmain-lengthFORLEADINGSPACESIFmain-length=0UNSTRINGremaining-stringDELIMITEDBYSPACEINTOremaining-stringIFremaining-string(1:search-length)=search-stringMOVE'Y'TOfound-flagEND-IFEND-IF.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> Generative: 'create a callable procedure designed to determine if a string > is part of another in GNU COBOL without using the CONTAINS reserved word.
*> Include parameters into the linkage section.'
IDENTIFICATION DIVISION.
PROGRAM-ID. SubstringCheck.
Whilist
cobc --list-reserved
list CONTAINS as supported, and VsCode does as well, we're at a loss as how to use it. Copilot, too:Any ideas on how to enabile string-support for CONTAINS? The syntax railroads seem to be missing a demo, as well.
Last edit: Randall Nagy 2024-12-21
Nearly all AI models are not usable with COBOL questions, as the training days they had didn't include much COBOL "knowledge". You can see this on basic questions like these, which every COBOL developer could answer after some days of training (no offense for you - but for AI models).
There are "specialized" (commonly fine tuned) models that can make this better (and I'm quite sure IBMs would be different), but I highly suggest to do what developers did since the language was created:
Check COBOL compiler documentation and free documentation like the programmers guide instead for questions like: what is CONTAINS used for. And/or read cobc/parser.y which commonly gives a good overwrite (where does the compiler accepts that token).
Back to your question: if you want to use that directly in a condition, you'd have to write a user defined function. The common war would be to use an INSPECT ... TALLYING, if you want to ignore the case, then use FUNCTION LOWER() - once for the searched word, and directly in the INSPECT of your check.
... and in a real world application with thousands of elements, you would create a separate ISAM file with applicable foreign keys that reference the book - with the authors split and already lowercased (or possibly better, their phonetic value stored to catch different but similar versions - again all depending on the use case).
Thanks.
Survey said:
> Generative: 'how to determine if a string is part of another in GNU COBOL
> without using the CONTAINS reserved word.'
This was fun, too:
> Generative: 'create a callable procedure designed to determine if a string
> is part of another in GNU COBOL without using the CONTAINS reserved word.
*> Include parameters into the linkage section.'
IDENTIFICATION DIVISION.
PROGRAM-ID. SubstringCheck.
Also: If support for one reservered is A.W.O.L, one wonders how many more ... ?
Anyone keeping a list they'd like to share?