Page 1 of 1

In Built function - SUBSTR clarification.

PostPosted: Sat Jun 08, 2013 4:50 pm
by Viswanathchandru
Dear all,

I'm trying to list a VSAM file to get the "HI-U-RBA" and the "HI-A-RBA". I'm listing the file and writing it to a PS file. Through EXECIO * DISKR i'm reading it followed by a substr statement to find the required value and it goes as given below. To my surprise it's not capturing the required value. Instead its going for the last line. I tried to find the position still it says the particular string "HI-U-RBA" is not found(Returns 0). Can anyone guide me where do i go wrong please? Here is the code I'm using.

/*REXX*/
PULL DSN
X=OUTTRAP('RET.')                           
DSNF = STRIP(DSN)                         
"LISTC ENT('"DSNF"') ALL"           
X=OUTTRAP=('OFF')                           
"EXECIO * DISKR OUTTR(STEM RET. FINIS"     
DO IX=1 TO RET.0                           
VAR1 =SUBSTR(RET.IX,POS('HI-U-RBA',RET.IX)+14)
VAR2 =SUBSTR(RET.IX,POS('HI-A-RBA',RET.IX)+14)                 
END                                         
SAY VAR1                                   
SAY VAR2

Re: In Built function - SUBSTR clarification.

PostPosted: Sat Jun 08, 2013 5:46 pm
by MrSpock
Get rid of this line:

"EXECIO * DISKR OUTTR(STEM RET. FINIS"

It's completely unnecessary.

Re: In Built function - SUBSTR clarification.

PostPosted: Sat Jun 08, 2013 5:48 pm
by enrico-sorichetti
what happened when You tried running the script with a Trace ?

and why not proceed in small steps, and after the LISTC

Do i = 1 to YourStemVar.0
    say YourStemVar.i
end

to see what is going on

and why not test the return code after the list ?

Re: In Built function - SUBSTR clarification.

PostPosted: Sat Jun 08, 2013 6:26 pm
by Viswanathchandru
Hi Enrico, Thanks for addressing the post.

When I coded this after LISTC

Do i = 1 to RET.0
    say RET.i
end


I was able to get the output of LISTC as usual. The RC says 0.


Mr.Spock. thanks for addressing the post.

I made a mistake while copying the code. There is a DISKW before the DISKR. My apologize for that.

Re: In Built function - SUBSTR clarification.

PostPosted: Sat Jun 08, 2013 7:07 pm
by enrico-sorichetti
You are not checking if You are on the good line

VAR1 =SUBSTR(RET.IX,POS('HI-U-RBA',RET.IX)+14)
VAR2 =SUBSTR(RET.IX,POS('HI-A-RBA',RET.IX)+14)   


before assigning the HURBA You should do something like

if pos('HI-U-RBA,RET.IX) = 0 then iterate /* the line does not contain the HURBA */
do whatever

and ...
since the HARBA line comes before the HURBA line
just process them in the right order

and...
when processing the HURBA check that the HARBA has been processed

and ...
since a listc provides the HARBA/HURBA quite a few times
you should check which of which You are dealing with
ALLOCATION or EXTENT
and which association

and...
it would be wise to set some flags to check that You are processing the records in the right order for the right components
LISTC provides things in the proper way, the flags are needed to make sure that YOU are processing things the way they should

the flags might be needed for the cluster, ALLOCATION. association, component extent number...

Re: In Built function - SUBSTR clarification.

PostPosted: Mon Jun 10, 2013 1:30 pm
by Viswanathchandru
Hello Enrico,

Thanks for the detailed explanation and time!!

Regards,
Viswa