Page 1 of 1

Search a word in String

PostPosted: Fri Nov 19, 2010 3:02 pm
by nm992
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.

Re: Search a word in String

PostPosted: Sat Nov 20, 2010 1:09 am
by dick scherrer
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.

Re: Search a word in String

PostPosted: Tue Nov 23, 2010 3:14 pm
by nm992
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..

Re: Search a word in String

PostPosted: Tue Nov 23, 2010 3:24 pm
by enrico-sorichetti
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 ?

Re: Search a word in String

PostPosted: Tue Nov 23, 2010 3:30 pm
by Valenteno123
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?

Re: Search a word in String

PostPosted: Tue Nov 23, 2010 3:32 pm
by Valenteno123
You can search the word using INSPECT statement. Check for the string modifcation topics in cobol reference book.
Hope this helps!!!

Re: Search a word in String

PostPosted: Wed Nov 24, 2010 3:19 pm
by sriraj1122
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....!

Re: Search a word in String

PostPosted: Wed Nov 24, 2010 3:26 pm
by enrico-sorichetti
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.

Re: Search a word in String

PostPosted: Thu Nov 25, 2010 2:09 am
by dick scherrer
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). . .