IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Parsing JCL SET var=value statements


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Sat Dec 26, 2015 4:41 am
Reply with quote

It's not that hard,

Code:
//label SET var=value

is trivial

Code:
//label SET var=(a,(b,(c,d)))

is trivial, count the '(' and ')' parentheses, and (more or less the same for single quotes, just cater for embedded ones)

Code:
//label SET var=value,var2=value2

isn't very hard either, and

Code:
//label SET var=value,var2=value2,
// var3=value3

should be about the same, just check for the comma-space and append the stripped of '//' and leading spaces next line

Anyway, I've come up with

Code:
/* REXX */
  "isredit macro"
  "isredit (ZL) = linenum .zl"

  var. = 0

  do i = 1 to +zl
    "isredit (L) = line" i

    l = substr(l, 13)

    p = pos(' SET ', l, pos(' ', l))

    if p \= 0 then
      do
        vars = strip(substr(l, p + 5), 'L')' '

        do until left(vars, 1) = ' '
          parse value var.0 + 1 vars with $ var.$ '=' val.$ 1 var.0 .

          s = left(val.$, 1)
          p = 1

          select
            when s = '(' then
              do
                op = 1

                do p = 2 by 1 to length(val.$) until op = 0
                  select
                    when substr(val.$, p, 1) = '(' then op = op + 1
                    when substr(val.$, p, 1) = ')' then op = op - 1
                    otherwise
                  end
                end

                vars  = substr(val.$, p + 1)
                val.$ = left(val.$, p)
say left(var.$, 10) val.$
              end

            when s = '''' then
              do
                src = val.$ '*'

                drop t.
                t = 1

                do until src = '' | left(src, 1) \= "'"
                  parse value src with pre "'" text "'" src

                  if src \= '' then
                    do
                      t.t = text
                      t   = t + 1
                    end
                end

                val = ''
                do !=1 to t-1
                  val = val || "'" || t.! || "'"
                end
                vars  = substr(val.$, length(val) + 1)
                val.$ = val
say left(var.$, 10) val.$
              end

            otherwise
              do
                parse value vars with . '=' val.$ ' ' vars
say left(var.$, 10) val.$
              end
          end
          if left(vars, 1) = ',' then
            vars = substr(vars, 2)

          if right(val.$, 1) = ',' then
            do
              val.$ = strip(val.$,, ',')

              i     = i + 1
              "isredit (L) = line" i
              vars = strip(substr(l, 13), 'L')
            end


        end
      end
  end


to be used on the "SE'ed" JESJCL dataset. It seems to work for everything I've thrown at it, but if anyone can suggest any improvements, feel free to share them - the code will eventually be used to improve the readability of submitted JCL by removing the wrapping
Code:
IEFC653I SUBSTITUTION JCL -

messages.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Parsing Large JSON file using COBOL COBOL Programming 4
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts parsing with startat and endbefr SYNCSORT 10
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
Search our Forums:

Back to Top