COBCH0837S Procedural code not allowed here

I am writing an Eclipse  managed cobol program.

Whenever I try to put statements in the Class Working-Storage Section, my first statement gives me

error COBCH0837S Procedural code not allowed here.

Am stumped and i hope someone can assist me.

Thanks,

Warren Mundy

  • Hi Warren,

    Can you please be more specific? What type of statements are you trying to put in working-storage? The only statements that should go into working-storage are data definition clauses.

    All procedural statements should go in the procedure division.

    Can you copy/paste what it is that you are trying to do?

    Thanks

  • I meant to say Procedure Division  Later today I will sent you the code.

    Thanks,

    Warren Mundy

  • Chris,

    Here is the little class in question.

    class-id consoleApplication24.Prog2b public.

          working-storage section.

          01  myobj1 type consoleApplication24.Prog2b

                     value new type consoleApplication24.Prog2b public.

          01  myarg type short.

          procedure division.

          invoke myobj1::getid returning myarg.       <<----gets message COBCH0837S

          display "myid is - " & myarg.

          goback.

          method-id getid public.

              local-storage section.

              linkage section.

              01  myid type short.

             procedure division returning myid.

             compute  myid = function random().

             goback.

             end method.

          end class.

  • You need a method to contain procedural code in managed code.  Add a method-id/end method around the first procedure division, or include the working-storage if that isn't class working-storage.

  • I thought that the class had it's own copy of working-storage section.  It is my intent that the first working-storage section and the procedure division be at class level and not a method level.  What have I missed?

    Thanks,

    warren mundy

  • Verified Answer

    Yes, the class can have working-storage that is global to the class.  I wasn't sure if that's what you intended.  Procedural code (statements) must be in methods.  A class does not have its own procedural code outside of a method.

  • Verified Answer

    This might help

     

    Here is a simple class below, VCList with main static method for testing, yes the 0d0a could be improved but this show a class with a main method for testing and constructors.

     

    This is from an article I wrote a long time ago.

    It demonstrates how well Visual COBOL and JAVA can integrate. It covers the core subjects of CLASSPATH, PACKAGES, BUILDING JAR files and executing programs.

     

    community.microfocus.com/.../21473.visual-cobol-and-java-integration.aspx

     

    Basically the class is self-contained, and has a static main method for testing.

     

    >>>>>> VCList.cbl

         $set sourceformat(variable)    

         $set ooctrl( p-f) intlevel"4"

         $set ilusing"java.util"

         $set ilusing"java.lang"

         $set ilusing"com.microfocus.vcexamples.list"

          

           class-id com.microfocus.vcexamples.list.VCList public.

          

           01 ls type List public.

          

           *> no argument constructor

           method-id new public.

           procedure division.

               set ls to new ArrayList[String]

               invoke ls::add("one")

               invoke ls::add("Three")

               invoke ls::add("two")

               invoke ls::add("four")

           end method.

     

         *> constructor passing a List

           method-id new public.

           procedure division using by reference ls as type List.

               set self::ls to new ArrayList(ls);

           end method.

                  *> just exercise class for getting lists about

           method-id toString override.

           01 sb type StringBuffer.

           01 val string.

          

           procedure division returning lnkmessage as string.

               set sb to new StringBuffer

               perform varying val through ls

                   invoke sb::append("<")

                   invoke sb::append(val)

                   invoke sb::append(">")

                   invoke sb::append(x'0d0a') *> dont handle \n

               end-perform  

               set lnkmessage to sb::toString()

              

           end method.

                                 

          

         *>

         *> main entry point

         *>

           method-id main public static.

           local-storage section.

           linkage section.

           01 args type String occurs any.

          

           procedure division using by value args.

               *> Create the VCList

               *> use the declare and create syntax

               declare tstVCList as type VCList

               create tstVCList

              

               display "Visual Cobol the VCList at start :"

               display "using List::tostring : ", tstVCList::ls

               display "using VCList::tostring : "

               display tstVCList

               *> Fire of a core java static method to sort

               invoke type Collections::sort(tstVCList::ls, String::CASE_INSENSITIVE_ORDER)

               display "Visual Cobol the VCList after sort :"

               display "using List::tostring : ", tstVCList::ls

               display "using VCList::tostring : "

               display tstVCList

              

     

           end method.

           end class.

    >>>>>> 

     

  • Thanks to all of you that answered my question and cleared up my misunderstanding of class vs method procedure divisions.

    Thanks again.

    Warren Mundy