I am using the SCAN statement to find a value within a 1000 Byte record. For example:
(#INPUT-FILE is 1000 byte record)
IF #INPUT-FILE = SCAN '12LTU3'
ADD +1 TO #COUNTER
WRITE(1) #TR-DATE ' ' #TR-ACCTNO ' ' #TR-ACCTNAME
END-IF
WRITE(1) 'TOTAL RECORDS FOUND' #COUNTER
My question is... is there a way to write out the position spot where the record was found? Say it found '12LTU3' in position 152 of 1000. The program would write out 152.
Thank you in advance.
SCAN / Find Position in file
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: SCAN / Find Position in file
SCAN is simply an option of the IF statement, rather than a System Function. All it can do is answer the question "Does the string exist in the source variable?"
The EXAMINE statement can do what you need.
And here is the result:
Off topic: The blanks in your WRITE statement could be confusing. Natural automatically inserts a space between items in the list, so you were separating your variables by 3 (space-' '-space-#TR-ACCTNO). If that was intended, try
The EXAMINE statement can do what you need.
Code: Select all
DEFINE DATA LOCAL
1 #INPUT-FILE (A1000) INIT <' 12LTU3'>
1 #COUNTER (I4)
1 #TR-DATE (D) INIT <*DATX'>
1 #TR-ACCTNO (N3) INIT <123>
1 #TR-ACCTNAME (A5) INIT <'Zbrog'>
1 #P (I4)
END-DEFINE
EXAMINE #INPUT-FILE FOR '12LTU3' GIVING POSITION #P
IF #P > 0
THEN
ADD 1 TO #COUNTER
WRITE (0) #TR-DATE
#TR-ACCTNO
#TR-ACCTNAME
END-IF
WRITE (0) 'TOTAL RECORDS FOUND' #COUNTER
END
Code: Select all
Page 1 10/04/12 06:37:50
10/03/12 123 Zbrog
TOTAL RECORDS FOUND 1
Off topic: The blanks in your WRITE statement could be confusing. Natural automatically inserts a space between items in the list, so you were separating your variables by 3 (space-' '-space-#TR-ACCTNO). If that was intended, try
Code: Select all
WRITE (0) #TR-DATE
3X #TR-ACCTNO
3X #TR-ACCTNAME
Code: Select all
Page 1 10/04/12 06:45:26
10/04/12 123 Zbrog
TOTAL RECORDS FOUND 1
-
- Posts: 20
- Joined: Fri Sep 07, 2012 11:25 pm
- Skillset: JCL, EASYTRIEVE, NATURAL
- Referer: Google
Re: SCAN / Find Position in file
This worked perfect. Thank you 

-
- Similar Topics
- Replies
- Views
- Last post
-
- 11
- 3580
-
by Pedro
View the latest post
Tue Dec 27, 2022 11:24 am
-
-
REXX Code to find if PDS JCL member has how many DD
by abhilashanaik » Tue Sep 14, 2021 11:17 am » in CLIST & REXX - 5
- 2252
-
by sergeyken
View the latest post
Wed Sep 15, 2021 6:02 am
-
-
- 3
- 1195
-
by sergeyken
View the latest post
Wed May 18, 2022 4:40 pm
-
-
Find the version of a cobol program through its load module
by vinigim » Fri Oct 30, 2020 3:16 am » in IBM Cobol - 5
- 5122
-
by chaat
View the latest post
Sat Nov 07, 2020 8:40 am
-
-
-
EZIOE004 Logical I/O error on file occurred reading VB file
by savitha_y » Mon Feb 15, 2021 7:54 pm » in CA-Easytrieve - 3
- 4946
-
by savitha_y
View the latest post
Wed Feb 17, 2021 5:02 am
-