Search a word in String



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Search a word in String

Postby nm992 » Fri Nov 19, 2010 3:02 pm

I have a column of x(50) in fileof size 200.I want to seach for word 'lazy' in x(50).If a particular record has that word 'lazy' I want to move it to different file.
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Search a word in String

Postby dick scherrer » Sat Nov 20, 2010 1:09 am

Hello,

Ok - sounds close to reasonable. . .

What have you done so far? Where are you stuck?

We will help but we won't do the work for you.

For starters, you need to write code that reads the input file and creates 2 output files - one with "lazy" records and the other without. There is no "record move" feature/function.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Search a word in String

Postby nm992 » Tue Nov 23, 2010 3:14 pm

Thanks DIck..

I tierd to refrence modification.

Created an array with X(50) and read each column..then I comared first occurence of L with next 3 characters..

But it seems to be performace detrioted as my file has million of records..
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Search a word in String

Postby enrico-sorichetti » Tue Nov 23, 2010 3:24 pm

if You post the full requirement, maybe we might be able to offer better suggestion
up to now You just posted a <programming> quiz :D

what happens for example when the string is there ?
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-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Search a word in String

Postby Valenteno123 » Tue Nov 23, 2010 3:30 pm

You can build a copy book for the particular file and ready the file . Then compare the particular column with you word. If it matches move to desired output file and write it. Else move the records to other file and write it.As suggested by Dick scherrer.

This can also done using "SORT" in JCL .

Let me know what code you are using?
Valenteno123
 
Posts: 5
Joined: Mon Jul 21, 2008 2:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Search a word in String

Postby Valenteno123 » Tue Nov 23, 2010 3:32 pm

You can search the word using INSPECT statement. Check for the string modifcation topics in cobol reference book.
Hope this helps!!!
Valenteno123
 
Posts: 5
Joined: Mon Jul 21, 2008 2:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Search a word in String

Postby sriraj1122 » Wed Nov 24, 2010 3:19 pm

Hi NM,

I used inspect methodology to achieve the function..pls find the below code

FILE-CONTROL.
SELECT FILE1 ASSIGN TO FILEIN
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-STATUS-IN.
SELECT FILE2 ASSIGN TO FILEOUT
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS WS-STATUS-OUT.
DATA DIVISION.
FILE SECTION.
FD FILE1
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORDING MODE F
DATA RECORD IS INPUT-REC.
01 INPUT-REC.
05 POLICY-NUMBER PIC X(20).
FD FILE2
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
RECORDING MODE F
DATA RECORD IS OUTPUT-REC.
01 OUTPUT-REC.
05 POLICY-NUMBER PIC X(20).
WORKING-STORAGE SECTION.
01 WS-STATUS-IN PIC 9(02) VALUE ZERO.
01 WS-STATUS-OUT PIC 9(02) VALUE ZERO.
01 WS-EOF PIC X VALUE 'N'.
01 WS-TOTAL PIC 9(2) VALUE ZEROS.
01 WS-CNT PIC 9(2) VALUE ZEROS.
PROCEDURE DIVISION.
PERFORM OPEN-FILES.
PERFORM READ-FILE1.
PERFORM CLOSE-FILES.
OPEN-FILES.
OPEN INPUT FILE1.
DISPLAY 'OPEN1:' WS-STATUS-IN.
OPEN EXTEND FILE2.
DISPLAY 'OPEN2:' WS-STATUS-OUT.
OPEN-FILES-EXIT. EXIT.
CLOSE-FILES.
CLOSE FILE1.
DISPLAY 'CLOSE1:' WS-STATUS-IN.
CLOSE FILE2.
DISPLAY 'CLOSE2:' WS-STATUS-IN.
CLOSE-FILES-EXIT. EXIT.
READ-FILE1.
PERFORM UNTIL WS-EOF = 'Y'
INITIALIZE WS-CNT
READ FILE1 AT END
MOVE 'Y' TO WS-EOF
END-READ
DISPLAY 'READ1:' WS-STATUS-IN
INSPECT INPUT-REC TALLYING WS-CNT FOR ALL 'LAZY'
IF WS-CNT > 0
ADD +1 TO WS-TOTAL
MOVE INPUT-REC TO OUTPUT-REC
WRITE OUTPUT-REC
DISPLAY 'WRITE2:' WS-STATUS-OUT
END-IF
DISPLAY WS-CNT
DISPLAY INPUT-REC
END-PERFORM.
DISPLAY 'TOTAL COUNT:' WS-TOTAL.
READ-FILE1-EXIT. EXIT.
STOP RUN.

*************************************

But we can achieve this much more easily by declaring a copy book structure and verify if that variable value is LAZY....

Hope this helps....!
sriraj1122
 
Posts: 19
Joined: Thu Nov 18, 2010 10:04 am
Has thanked: 0 time
Been thanked: 0 time

Re: Search a word in String

Postby enrico-sorichetti » Wed Nov 24, 2010 3:26 pm

If a particular record has that word 'lazy' I want to move it to different file.


most probably You will get a better performance by using <sort>
search the forums for examples ( there are a few around )

or look at ftp://service.software.ibm.com/storage/ ... rttrck.pdf
for more hints

quoting from there
INCLUDE/OMIT and SAVE can be used to select specific records to be included in each output data set. The INCLUDE and OMIT operands provide all of the capabilities of the INCLUDE and OMIT statements including substring search and bit logic.
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-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Search a word in String

Postby dick scherrer » Thu Nov 25, 2010 2:09 am

Hello,

But we can achieve this much more easily by declaring a copy book structure and verify if that variable value is LAZY....
Why do you believe this might be more easily accomplished with "a copybook"?

I am not aware of any function/feature that will scan/parse/inspect a field in a copybook for some value (i.e. lazy). . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post