Page 1 of 1

REXX code to extract a field from a file

PostPosted: Fri Jan 23, 2009 9:40 am
by munnu
Hi,
I need a REXX code to extract all the fields starting with "EDI-" from a cobol program.
can anyone provide me the required code??

Thanks,
Munnu

Re: REXX code to extract a field from a file

PostPosted: Mon Jan 26, 2009 5:36 pm
by expat
Your request is not clear. Is EDI a COBOL field name or does EDI appear in the actual data.
You need to show us what the records look like, and the locations of the fields that you need to extract

Re: REXX code to extract a field from a file

PostPosted: Tue Jan 27, 2009 6:42 pm
by munnu
Hi,
these "EDI-" fields are defined in a copybook and my program uses this copybook and also these "EDI-" feilds (not all EDI- fields that are defined in the copybook)are used explicitly.These fields dont have any fixed position to identify. I just want to get all those variables starting with "EDI-".

the pgm lokks like

MOVE EDI-444A-SR-CATEGORY TO WS-CLAIM-TYPE
MOVE EDI-499A-CL-ROUTED-TO TO WS-WLC-LOCATION-CODE
PERFORM
VARYING WS-TABLE-NDX FROM WS-NUM-1 BY WS-NUM-1
UNTIL WS-TABLE-NDX > WS-NUM-5
IF EDI-461L-CONDITION-CODE(WS-TABLE-NDX) = WS-LIT-02
SET DDC-CD-WRKRS-COMP-REQ
TO TRUE

Thanks,
Munnu

Re: REXX code to extract a field from a file

PostPosted: Wed Jan 28, 2009 5:33 am
by dick scherrer
Hello,

What do you want as "output" from your process?

You mention a copybook, but the code posted shows some procedure division code?

Please post some sample output and explain the rules for selecting that particular output.

Also, please keep in mind that while your requirement is completely clear to you, it may not be to others who would like to help.

Re: REXX code to extract a field from a file

PostPosted: Wed Jan 28, 2009 9:42 am
by munnu
Yes, I just want to retrieve all "EDI-" variables that are used in the procedure division code without dupclicate. ie; theEDI- variables that are used in two different places in the procedure division should not be repeatedly retrieved after REXX execution.
Regarding copybook I meant that all these "EDI-" variables are defined in a copybook which is included in my pgm by the statement "copy EBSIDC".
EBSIDC is the copybook.

The output should look like:
All the EDI- variables extracted to a file as

EDI-444A-SR-CATEGORY
EDI-499A-CL-ROUTED-TO
EDI-499A-ROUTED-LIC
EDI-499A-ROUTED-NO
......

Please get back to me if my requirement is not clear.

Thanks,
Munnu

Re: REXX code to extract a field from a file

PostPosted: Wed Jan 28, 2009 9:56 am
by dick scherrer
Hello,

Please get back to me if my requirement is not clear.
We're getting closer :)

Is it possible that anything other than fields in that copybook could begin with "EDI-"?

I'm not sure if this would help, but the info you want is available in the cobol compile cross reference. . .

Re: REXX code to extract a field from a file

PostPosted: Fri Feb 13, 2009 4:51 pm
by ritwik.das
Hello Munnu,

Here is a code I developed which will list all "EDI-" variables from a code and write to an output file. After that you may apply DFSORT on the output with SUM FIELDS=NONE option to remove the duplicates. It'd be cumbersome to do with REXX.

P.S - I developed this exec without mainframe and hence could not run it. Please test it before use.

/* REXX */

DROP INREC.                                                           
DROP OUTREC.     
/* HARD-CODE INPUT & OUTPUT FILE */
INFILE  = "XXX.YYY.ZZZ(AAA)"
OUTFILE = "PPP.QQQ.RRR(SSS)"
                                                                     
"ALLOCATE FI(INDSN) DA('"INFILE"') SHR REUSE"                         
"EXECIO * DISKR INDSN (STEM INREC. FINIS"

K = 1
J = 1
POSITION = 0

DO WHILE K <= INREC.0
POSITION = POS("EDI-",INREC.K)
   IF POSITION > 0 THEN DO    
      OUTREC.J = EXTRACTFLD(INREC.K)
      J = J + 1
      SAY "ONE EDI- FIELD FOUND"
   END
   K = K + 1      
END
OUTREC.0 = J - 1
"ALLOCATE FI(OUTDSN) DA('"OUTFILE"') SHR REUSE"                         
"EXECIO * DISKR OUTDSN (STEM OUTREC. FINIS"

/* END MAIN */

EXTRACTFLD:
/* THIS WILL EXTRACT THE VARIABLE NAME FROM THE LINE */
ARG INLINE
DO WHILE SUBSTR(INLINE,POSITION,1) <> " " 
   FLD = FLD || SUBSTR(INLINE,POSITION,1)
   POSITION = POSITION + 1
END   
FLD = STRIP(FLD)
RETURN FLD

/* END EXTRACTFLD */                                                                     

Re: REXX code to extract a field from a file

PostPosted: Thu Nov 05, 2009 8:32 pm
by sureshkumar454
Hi,

I am beginner in REXX. I have used the above code to extract a field from a file. I am able to find the string but unable to extract the same to another file. I am gettting the below error while executing the code.
Error running TESTING, line 34: Invalid whole number

I have coded SAY "RC=" RC before RETURN to check the return code. I got RC=0 at that point and after that i am getting the error as mentioned. Please suggest.

Thanks in advance.

Re: REXX code to extract a field from a file

PostPosted: Thu Nov 05, 2009 8:43 pm
by MrSpock
Please post the TRACE output from your exection of your exec.