Page 1 of 2

Extract lines of code

PostPosted: Wed Nov 14, 2018 3:32 pm
by kbkanade
Hi
Team, can someone help me to get some logic for REXX. I have requirement that I need to search in my cobol program if REDEFINE keyword is used, and if yes i need to pull its whole structure with its parent item. Like in below case i need to pull all below four lines as there is REDEFINES used.
As of now i have coded the logic to find the REDEFINES keyword but don't know how to fetch above and below set of lines. Please help.

01 A PIC X(10)
01 B REDEFINES A
02 B PIC X(5)
02 B PIC X(5)

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 3:57 pm
by expat
Using an ISPF edit macro you can determine the line where the cursor is, after finding the REDEFINES keyword, and then perform your logic from that point moving both up and down the dataset.

Or maybe use a stem variable if you only use REXX rather than ISPF under REXX.

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 4:33 pm
by kbkanade
Thank you Sir but is it possible for you to give some logic code using REXX how to fetch above and below lines of code. I am searching but not able to get concrete solution.

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 4:46 pm
by enrico-sorichetti
all depends on the overall logic

if You will be using an edit macro
You could parse the line where the REDEFINES appears to extract the name of the original variable
and use a FIND PREV to locate the original definition

if You will be using a stem,
outer loop to examine each line for the REDEFINES word
extract the original variable name
inner loop ONE to backtrack to the original line and save the line number
inner loop TWO ( at the same level of loop ONE ) to find out the last line number
inner loop THREE ( at the same level of loop ONE and TWO) to output the lines

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 5:18 pm
by expat
kbkanade wrote:Thank you Sir but is it possible for you to give some logic code using REXX how to fetch above and below lines of code. I am searching but not able to get concrete solution.

Logic - YES - Enrico has started you in the right direction
Logic & code - YES - My opening bid is 600 GBP per day for tested and documented code

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 7:08 pm
by enrico-sorichetti
what really bothers me on these forums are people who ask for the logic.
I condone people asking for coding hints, a beginner is not expected to master the small nuances of a programming language
but anybody in the IT profession should be able to devise a logic for such a task ... or any application logic anyway
I seldom found occurrences of complex logic in a business application

to make things clearer for the ts, lets transpose the problem to matrices/array

given a two dimensional matrix/array with N rows and 2 columns - A(N,2)

how would the ts solve the similar task of ...

being positioned at row J

find the previous row where A(X,1) = A(J,2) ... X < J

find the next row where A(Y,2) = A(J,1) ... Y > J

the logic would pretty similar

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 7:31 pm
by expat
I have seen some COBOL programs where there are multiple redefines of the same field depending on the value of a given control variable.
e.g. If Field_A = 1 Then the next 20 bytes redefines to 5 fields of 4 bytes each,
but if Field_A = 2 Then the next 20 bytes redefines to four fields of 5 bytes each.

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 7:44 pm
by enrico-sorichetti
well ... the right answer would be to reinvent the wheel and write a full parser for copybooks :mrgreen:

Re: Extract lines of code

PostPosted: Wed Nov 14, 2018 8:34 pm
by expat
enrico-sorichetti wrote:well ... the right answer would be to reinvent the wheel and write a full parser for copybooks :mrgreen:

OK, can you give me 10 minutes :lol:

Re: Extract lines of code

PostPosted: Thu Nov 15, 2018 10:34 am
by kbkanade
thanks all for your help