Extract lines of code



IBM's Command List programming language & Restructured Extended Executor

Extract lines of code

Postby kbkanade » Wed Nov 14, 2018 3:32 pm

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)
kbkanade
 
Posts: 5
Joined: Wed Nov 14, 2018 3:07 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract lines of code

Postby expat » Wed Nov 14, 2018 3:57 pm

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.
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: Extract lines of code

Postby kbkanade » Wed Nov 14, 2018 4:33 pm

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.
kbkanade
 
Posts: 5
Joined: Wed Nov 14, 2018 3:07 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract lines of code

Postby enrico-sorichetti » Wed Nov 14, 2018 4:46 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Extract lines of code

Postby expat » Wed Nov 14, 2018 5:18 pm

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
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: Extract lines of code

Postby enrico-sorichetti » Wed Nov 14, 2018 7:08 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Extract lines of code

Postby expat » Wed Nov 14, 2018 7:31 pm

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.
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: Extract lines of code

Postby enrico-sorichetti » Wed Nov 14, 2018 7:44 pm

well ... the right answer would be to reinvent the wheel and write a full parser for copybooks :mrgreen:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Extract lines of code

Postby expat » Wed Nov 14, 2018 8:34 pm

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:
expat
 
Posts: 459
Joined: Sat Jun 09, 2007 3:21 pm
Has thanked: 0 time
Been thanked: 8 times

Re: Extract lines of code

Postby kbkanade » Thu Nov 15, 2018 10:34 am

thanks all for your help
kbkanade
 
Posts: 5
Joined: Wed Nov 14, 2018 3:07 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post