View previous topic :: View next topic
|
Author |
Message |
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
I am trying to search a HEX string in a file. Its not picking this up.
Code: |
"ALLOC DA('"USERID()".TOOL.INPUT') F(MPRMAIN) OLD REUSE"
"EXECIO * DISKR MPRMAIN (STEM MPRMAIN. FINIS"
DONE = 'NO'
LINENO = 0
DO WHILE DONE = 'NO'
"EXECIO 1 DISKR MPRMAIN"
IF RC = 0 THEN /* RECORD WAS READ */
DO
PULL RECORD
CHECK = X'0352856421901C'
LINENO = LINENO + 1 /* COUNT THE RECORD */
IF INDEX(RECORD,CHECK) \= 0 THEN
DO
SAY 'FOUND IN RECORD' LINENO
SAY 'RECORD = ' RECORD
DONE = 'YES'
END
ELSE NOP
SAY "HI"
END
ELSE
DONE = 'YES'
END
|
Input file is like
Code: |
POS r T074 e P 0 0 0 0 ~ ~
0AB00000000DDE000040098EFFF4444058629144444D444004F004F00AB00AB004F004F00A200A20
4FA0000000C7625C043C09C30740000325410C0000070000290029004FA04FA02900290071007100
|
Can anyone suggest what I am doing wrong in this. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
immediately after the
/* REXX */ statement
insert
trace ?r
then rerun you REXX Script
and tell us what is going on,
if you can not figure it out. |
|
Back to top |
|
|
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
Code: |
6 *-* "ALLOC DA('"USERID()".TOOL.INPUT') F(MPRMAIN) OLD REUSE"
>>> "ALLOC DA('AAAAAAA.TOOL.INPUT') F(MPRMAIN) OLD REUSE"
7 *-* "EXECIO * DISKR MPRMAIN (STEM MPRMAIN. FINIS"
>>> "EXECIO * DISKR MPRMAIN (STEM MPRMAIN. FINIS"
8 *-* DONE = 'NO'
>>> "NO"
9 *-* LINENO = 0
>>> "0"
10 *-* DO WHILE DONE = 'NO'
>>> "1"
11 *-* "EXECIO 1 DISKR MPRMAIN"
>>> "EXECIO 1 DISKR MPRMAIN"
12 *-* IF RC = 0
>>> "1"
*-* THEN /* RECORD WAS READ */
13 *-* DO
14 *-* PULL RECORD
.
.
. "
15 *-* CHECK = X'0352856421901C'
>>> "X0352856421901C"
16 *-* LINENO = LINENO + 1 /* COUNT THE RECORD */
>>> "1"
17 *-* IF INDEX(RECORD,CHECK) := 0
>>> "0"
23 *-* ELSE
*-* NOP
24 *-* SAY "HI"
>>> "HI"
25 *-* END
28 *-* END
10 *-* DO WHILE DONE = 'NO'
>>> "1"
11 *-* "EXECIO 1 DISKR MPRMAIN"
>>> "EXECIO 1 DISKR MPRMAIN"
+++ RC(2) +++
12 *-* IF RC = 0
>>> "0"
26 *-* ELSE
27 *-* DONE = 'YES'
>>> "YES"
28 *-* END
10 *-* DO WHILE DONE = 'NO'
>>> "0"
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why are you doing this:
Code: |
"EXECIO 1 DISKR MPRMAIN"
|
|
|
Back to top |
|
|
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
It just I am trying to read one record at a time. I think my check for checkign for hex character is failing. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
a few comments:
1. POS is the preferred command. INDEX is not that portable.
2. instead of using a negation symbol, use <> for not equal.
the negation symbol is not that portable.
3. suggest that you learn how to use stems.
the second EXECIO that i mentioned in my last post is part of your problem.
after the first EXECIO:
Code: |
"EXECIO * DISKR MPRMAIN (STEM MPRMAIN. FINIS"
|
all the records are in stem MPRMAIN.
also, do not use the same word for a variable or filename and a stem name.
it can become problematic (as in sex) if you miss a period.
4. get into the habit of checking RC after each service call.
in this case, the first EXECIO.
by portable, i mean from one system to another. |
|
Back to top |
|
|
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
I changed my whole coding logic as per yous uggestion, but still its not working..
Code: |
"ALLOC DA('"USERID()".TOOL.INPUT') F(MPRIN) OLD REUSE"
"ALLOC DA('"USERID()".TOOL.OUTPUT') F(MPROUT) OLD "
"EXECIO * DISKR MPRIN (STEM NEWVAR. FINIS"
IF RC = 0 THEN
DO
DO I =1 TO NEWVAR.0
RECORD = NEWVAR.I
STRNG = X'0352856421901C'
STRNGPOS = POS(STRNG,NEWVAR.I)
IF STRNGPOS <> '0' THEN
DO
PUSH NEWVAR.I
"EXECIO 1 DISKW MPROUT"
SAY "WRITTEN"
END
ELSE
SAY "NOT WRITTEN"
END
END
"EXECIO 0 DISKW MPROUT (FINIS"
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Why didn't you run the Trace for the new code? Look at the trace output yourself, try to work out the problem. Don't start the trace where you think the problem might be, cover everything.
Why set the string each time in the loop? What do you now do with RECORD? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
well, your problem is here
had you bothered to look at your trace (that is why you run a REXX Script in trace mode, by the way)
you would have found your problem:
Code: |
15 *-* CHECK = X'0352856421901C'
>>> "X0352856421901C" |
in addition:
Code: |
"ALLOC DA('"USERID()".TOOL.INPUT') F(MPRIN) OLD REUSE"
RTNCD = RC
IF RTNCD <> 0 THEN
DO
SAY 'ALLOCATION OF INPUT FILE SUCKS: ' RTNCD
FREE MPRIN
EXIT
END
"EXECIO * DISKR MPRIN (STEM NEWVAR. FINIS"
RTNCD = RC
IF RTNCD <> 0 THEN
DO
SAY 'EXECIO OF INPUT FILE SUCKS: ' RTNCD
FREE MPRIN
EXIT
END
/* */
OUTSTEM. = ""
OUTSTEM.0 = 0
OCNT = 0
STRNG = X'0352856421901C' /* fix this ====================*/
DO I = 1 TO NEWVAR.0
IF POS(STRNG,NEWVAR.I) <> 0 THEN
DO
OCNT = OCNT + 1
OUTSTEM.OCNT = NEWVAR.I
END
END
OUTSTEM.0 = OCNT
"ALLOC DA('"USERID()".TOOL.OUTPUT') F(MPROUT) OLD "
RTNCD = RC
IF RTNCD <> 0 THEN
DO
SAY 'ALLOCATION OF OUTPUT FILE SUCKS: ' RTNCD
FREE MPROUT
EXIT
END
"EXECIO 0 DISKW MPROUT (STEM OUTSTEM. FINIS"
RTNCD = RC
IF RTNCD <> 0 THEN
DO
SAY 'EXECIO OF OUTPUT FILE SUCKS: ' RTNCD
FREE MPROUT
EXIT
END
FREE MPROUT
SAY NEWVAR.0 ' RECORDS READ'
SAY OUTSTEM.0 ' RECORDS WRITTEN'
EXIT
|
i provided you what i think is a better script....... |
|
Back to top |
|
|
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
Thanks for a better REXX script.
I tried one more combination, but still it didnt work
Code: |
27 *-* /*IF POS(STRNG,NEWVAR.I) <> 0 THEN */
28 *-* IF POS(X'0352856421901C',NEWVAR.I) <> 0
>>> "0"
33 *-* END
26 *-* DO I = 1 TO NEWVAR.0
34 *-* OUTSTEM.0 = OCNT
>>> "0"
|
|
|
Back to top |
|
|
scorp_rahul23
New User
Joined: 06 May 2008 Posts: 96 Location: Delhi
|
|
|
|
Got it.....
Thanks a lot.
Code: |
IF POS('0352856421901C'X,NEWVAR.I) <> 0 THEN
|
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
EDIT: Subtle advice no longer required. |
|
Back to top |
|
|
|