2

I know that there's the DIPSLAY operand that let's you "log" any variable value. However, my question is: is there someway to do something like the var_dump of PHP of console.log of javascript which when you give them a variable, they print with values and also name of variable.

Let's say for example I have the following data:

01 MY-DATA.
   05 FIRST-PART      PIC X(05) VALUE 'DATA1'.
   05 SECOND-PART     PIC X(05) VALUE 'DATA2'.

My question is: is there someway to have something like this on my log (with a single call and for any given variable):

'MY-DATA:'

'FIRSTPART : DATA1'

'SECOND PART: DATA2'

Thanks

Community
  • 1
  • 1
elkolotfi
  • 5,645
  • 2
  • 15
  • 19

3 Answers3

4

Not with any currently supported mainframe IBM COBOL compiler (I see you have tagged your question with "mainframe").

There used to be the EXHIBIT statement, which is not implemented in Enterprise COBOL. There is some discussion at that link about implementing similar functionality yourself.

I wrote an ISPF edit macro for myself to generate COBOL code to do the equivalent DISPLAY as indicated at the IBM documentation link above.

Overkill would be to call CEE3DMP, but I've been known to engage in overkill when frustrated.

You might be able to use one of the other, more granular Language Environment dump services such as CEEVDMP or CEEHDMP.

cschneid
  • 10,237
  • 1
  • 28
  • 39
3

With Enterprise COBOL V6R1, you can use JSON GENERATE statement on MY-DATA, then convert the output from UTF-16 to EBCDIC, then DISPLAY it.

   Working-storage section.
     01 MY-DATA.
       05 FIRST-PART      PIC X(05) VALUE 'DATA1'.
       05 SECOND-PART     PIC X(05) VALUE 'DATA2'.
     1 i pic 9999 comp.
     1 jn pic N(100).
   Procedure division.
     example.
       json generate jn from MY-DATA count i
       display function display-of(jn(1:i))
       stop run.

and the output would look like:

{"MY-DATA":{"FIRST-PART":"DATA1","SECOND-PART":"DATA2"}}

It's not exactly as what you wanted, but it's 'closer'. You can easily change the example above into a section and then you can PERFORM it (which would be like a 'single call')

Ka Lam
  • 381
  • 1
  • 6
  • This was my first thought after reading the question, but I didn't have the time to write it up as an answer.... – piet.t Jul 05 '19 at 05:44
2

There is no built-in option for this in most programming languages (many OO programing languages for example have a toString (or similar) method, but this does what the object says (and may not include a single actual content of the a variable at all).

COBOL works with statements (like the DISPLAY you've mentioned) while var_dump is a php built-in function. Different OO programming languages have the option to use a kind of reflection allowing you (with some prerequisites) to write a var_dump function on your own but as far as I know no COBOL compiler that supports OO has a reflection feature.

As @cschneid mentioned there was the EXHIBIT statement (actually that link is the best doc I've found for it) but no implementation that supports it (as far as I know) display's the record's sub-fields as separate like var_dump does. CEE3DMP as z/OS would not help you as it dumps everything you specify - but you cannot specify a single variable. Other dump routines there will also not workas you've asked (for the record, splitted into subfields).

So to answer the to the question is - "no, there is no standard option to dump records".

If you aren't restricted to any COBOL implementation you could add this language feature into GnuCOBOL, also works as 64bit-COBOL on z/OS ;-)

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38