COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only
  • 1.  Find out the Compiler version in run-time

    Posted Tue November 27, 2018 01:29 AM

    Hi.

    I have a question regarding how to, in run-time, find out which compiler processed a certain code. The reason for asking is that we employ a routine to search for some specific CSECT (Program-Id) names in the backwards call chain and we have seen that the positioning of this information differs between compiler versions.

    Currently we have code working for OS/VS COBOL (which we don´t run anymore but the analyzing code is still there), VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL  V4.2. It seems however that the scheme was changed starting with  Enterprise COBOL  V5.

    One thing I´ve known about for many years, but haven´t been too concerned with up to now, is the STKLANG (first word in the save area which I have understood is some kind of compiler identification. For instance I´ve seen:

    • COBOL V4.2 places hex 00104001 and
    • COBOL V6.1 places hex 00110301

    in that word.

    Now for the question:

    Is there some kind of document that is accessible by IBM customers that will cross-reference that value with COBOL compiler version?

    I have been searching the web but have not com up with anything.

    Also, have I misunderstood the meaning of the STKLANG, maybe it is not a 1:1 correspondence to compiler version?

    If I was able to identify the compiler version it would do much to the actual coding to find the name as I said before we have it working in all versions pre V5 and I found a nice instruction, Finding the program name and compile time stamp in Enterprise COBOL V5 or V6 programs, that documents the way to reveal the name.

     

    So, finally, hoping to hear from somebody soon.

    Regards Lars

    lbjerges


  • 2.  Re: Find out the Compiler version in run-time

    Posted Tue November 27, 2018 11:55 AM

    Starting with Enterprise COBOL V5 and upwards, the compiler version can be found from a section named 'Timestamp and Version Information' below.
    (Compile a COBOL code with 'LIST' to view this information)

    https://www.ibm.com/support/knowledgecenter/en/SS6SG3_6.2.0/com.ibm.cobol62.ent.doc/PGandLR/ref/rpbugppa.html

     

    897                      Timestamp and Version Information
    898   000CD0  F2F0  F1F8                                             =C'2018'           Compiled Year
    899   000CD4  F1F1  F2F2                                             =C'1122'           Compiled Date MMDD
    900   000CD8  F1F6  F3F1  F4F7                                       =C'163147'         Compiled Time HHMMSS
    901   000CDE  F0F6  F0F2  F0F0                                       =C'060200'         VERSION/RELEASE/MOD LEVEL OF PROD

     

    LINE.901 means COBOL 6.2.0. The location can be calculated at runtime by 1) Find PPA1 2) Find PPA2 3) Find 'TIMESTMP-PPA2'

    For example, LINE137 is the entry point of a program 'X1'. Note, LINE141, 550, and 671 which leads to the 'TIMESTMP' section.

    137      000000                     000002            PROC    X1
    138      000000  47F0 F014          000002            BC      R15,20(,R15)          #  Skip over constant area
    139      000004  01C3 C5C5          000002            DC      X'01C3C5C5'           #  Eyecatcher: CEE
    140      000008  0000 0168          000002            DC      X'00000168'           #  Stack Size
    141      00000C  0000 05C8          000002            DC      X'000005C8'           #  Offset to PPA1

     

    547                      PPA1:  Entry Point Constants
    548 1PP 5655-EC6 IBM Enterprise COBOL for z/OS  6.2.0 P181122       X1        Date 11/27/2018  Time 11:46:07   Page    14
    549 0 0005C8  1CCEA506                                               =F'483304710'      Flags
    550   0005CC  00000788                                               =A(PPA2-X1)
    551   0005D0  000006F8                                               =A(PPA3-X1)
    552   0005D4  00000000                                               =F'0'              No EPD

     

    667 0                    PPA2:  Entry Point Constants
    668   000788  04002203                                               =F'67117571'       Flags
    669   00078C  FFFFF878                                               =A(CEESTART-PPA2)
    670   000790  00000058                                               =F'88'             A(PPA4-PPA2)
    671   000794  FFFFFFB0                                               =A(TIMESTMP-PPA2)
    672   000798  FFFFF878                                               =A(PrimaryEntryPoint-PPA2)
    673   00079C  02000000                                               =F'33554432'       Flags

     

    The layout of PPA1/PPA2 can be found from z/OS Language Env Vendor interface
    https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.ceev100/rtnlyout.htm

     

    This is also the same idea
    https://www.ibm.com/support/knowledgecenter/en/SS6SG3_6.2.0/com.ibm.cobol62.ent.doc/migrate/igymapxd025.html

     

    This is simpler. Note the member ID 04 is for COBOL 5 and 6.

    https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.ceev100/cee1v223.htm

    The Member Identifier (PPA2 offset X'00') identifies the product origin of the running code by compiler. Language Environment-enabled language member identifiers show the codes for the various compiler products. The product codes are assigned by IBM® and the assignment codes are in decimal. The member list table's implementation size is bound to a maximum of 17 (0 through 16) for Language Environment.

    Figure 1. Language Environment-enabled language member identifiers
    00  Reserved
    01  Language Environment  (CEL)
    02  Reserved
    03  OS/390 C/C++, C VM/ESA, XL C/C++
    04  COBOL V5
    05  COBOL for OS/390 & VM, COBOL for MVS & VM
    06  z/OS Debugger
    07  VS FORTRAN
    08  Reserved
    09  Available
    10  PL/I for MVS & VM
    11  VisualAge PL/I for OS/390
    12  Berkeley Sockets
    13  Available
    14  Reserved
    15  ASSEMBLER
    16  Reserved

    Roy Bae


  • 3.  Re: Find out the Compiler version in run-time

    Posted Wed November 28, 2018 12:46 AM

    Thank you for the informative answer. I´ve already been looking at PPA1 to get hold of the program name (which by the way works different in LE-enabled HLASM and COBOL V5+, in HLASM you don´t multiply the offset by two it seems at least not in my sample case).

    Anyway, I´ll pursue the PPA2 track preceded by some checking of entry-point type and take it from there.

    I looked at the vendor interface documentation before but did not find what I was looking for or maybe looked for the wrong things, so thank you for putting me in the right direction.

     

    Regards Lars

    lbjerges


  • 4.  RE: Re: Find out the Compiler version in run-time

    Posted Fri October 16, 2020 10:52 AM
    Edited by Roy Bae Fri October 16, 2020 11:44 AM

    This is a sample to use. It works with IBM Ent COBOL 6.3.  Without 'function hex-of' from the sample, it would work with all COBOL 5 and 6.

    IDENTIFICATION DIVISION. PROGRAM-ID. X1. ********************************************************** * DESC: * USING THE ENTRY ADDRESS OF X1SUB, FIND ITS NAME IN PPA1 * ACTUAL OUTPUT: * EP :2690C164 * OFFSET_TO_PPA1:00000874 * BYTE2 IN PPA1 :20CE * NAME IN PPA1 :2690CA18 * PGM NAME :X1SUB ********************************************************** ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01. 02 EP usage pointer. 02 EP_fptr redefines EP usage function-pointer. 02 EP_bin redefines EP PIC 9(9) comp-4. 02 PPA1 usage pointer. 02 PPA1_bin redefines PPA1 PIC 9(9) comp-4. 02 ADDR usage pointer. 02 ADDR_bin redefines ADDR PIC 9(9) comp-4. LINKAGE SECTION. 01 PGMENTRY. 02 PGM_12BYTES PIC X(12). 02 OFFSET_TO_PPA1 PIC 9(9) comp-4. 01 PPA1ENTRY. 02 BYTE2 PIC 9(2) comp-4. 01 PGM_NAME. 02 LEN pic 9(2). 02 NAME pic x(6). PROCEDURE DIVISION. ENTRY 'X1SUB' set EP_fptr to entry 'X1SUB' display "EP :" function hex-of(EP) set address of PGMENTRY to EP display "OFFSET_TO_PPA1:" function hex-of(OFFSET_TO_PPA1) compute PPA1_bin = EP_bin + OFFSET_TO_PPA1 set address of PPA1ENTRY to PPA1 display "BYTE2 IN PPA1 :" function hex-of(BYTE2) * PPA1 + (FIRST BYTE in PPA1 * 2) compute ADDR_bin = PPA1_bin + (BYTE2 / 16 / 16 * 2) display "NAME IN PPA1 :" function hex-of(ADDR_bin) set address of PGM_NAME to ADDR display "PGM NAME :" NAME stop run. END PROGRAM X1.








    ------------------------------
    Roy Bae
    ------------------------------



  • 5.  RE: Re: Find out the Compiler version in run-time

    Posted Fri October 22, 2021 10:35 PM
    In the previous posting, the offset in the following is incorrect as the listing snippets were copied from multiple examples.
    897                      Timestamp and Version Information
    898   000CD0  F2F0  F1F8                                             =C'2018'           Compiled Year
    899   000CD4  F1F1  F2F2                                             =C'1122'           Compiled Date MMDD
    900   000CD8  F1F6  F3F1  F4F7                                       =C'163147'         Compiled Time HHMMSS
    901   000CDE  F0F6  F0F2  F0F0                                       =C'060200'         VERSION/RELEASE/MOD LEVEL OF PROD​

    If I manually corrected it, it should be 

    898   000738  F2F0  F1F8                                             =C'2018'           Compiled Year
    899   00073C  F1F1  F2F2                                             =C'1122'           Compiled Date MMDD
    900   000740  F1F6  F3F1  F4F7                                       =C'163147'         Compiled Time HHMMSS
    901   000746  F0F6  F0F2  F0F0                                       =C'060200'         VERSION/RELEASE/MOD LEVEL OF PROD​

    Because  FFFFFFB0  in A(TIMESTMP-PPA2)  is a 2's comp signed offset, value of -0x50 . Therefore 0x788(PPA2) - 0x50 = 0x738(Time Stamp and Ver)

    ------------------------------
    Roy Bae
    ------------------------------