Loading

COMP and COMP-3 equivalent variables in Easytrieve

I suggest you to read Easytrieve variable declaration first to see how to declare variables in Easytrieve. That will give you a better idea about Easytrieve variable.

COMP in Cobol is a Binary variable.

It can be of 2 bytes, 4 bytes or 8 bytes.

COMP variables are always signed. It is also known as BINARY in cobol.

COMP or BINARY Number of Bytes Easytrieve variable
S9(1) COMP.

..

S9(4) COMP.

9(1) COMP.

..

9(4) COMP.

S9(1) BINARY.

S9(4) BINARY.

9(1) BINARY.

..

9(4) BINARY.

2 bytes WS-VAR W 2 B
S9(5) COMP.

..

S9(9) COMP.

9(5) COMP.

..

9(9) COMP.

S9(5) BINARY.

S9(9) BINARY.

9(5) BINARY.

..

9(9) BINARY.

4 bytes WS-VAR W 4 B
S9(10) COMP.

..

S9(18) COMP.

9(10) COMP.

..

9(18) COMP.

S9(10) BINARY.

S9(18) BINARY.

9(10) BINARY.

..

9(18) BINARY.

8 bytes WS-VAR W 8 B

COMP-3 or Packed decimal variables.
P stands for Packed – in Easytrieve variable declaration.
Length specified in Easytrieve always specifies the number of bytes occupied and not number of digits.
For eg,

 WS-VAR S9(3) COMP-3.

will be occupying 2 bytes and the corresponding Easytrieve declaration is

 WS-VAR W 2 P 0 


The zero after P specifies the number of digits after decimal point (implicit).

Another eg,

 WS-VAR S9(5)V99 COMP-3.

will be occupying 4 bytes and the corresponding Easytrieve declaration is

 WS-VAR W 4 P 2


The 2 is for the 2 digits after decimal point, and the 4 still means the total 4 bytes occupied. Note that the 2 is not 2 bytes and just specifies the 2 digits after decimal point.

Read more about Easytrieve variable declaration.

Related Posts




blog comments powered by Disqus

There's 5 Comments So Far

  •   Lakshmi
    May 23rd, 2013 at 4:28 am

    Hi Karthik,

    I am trying to access a VSAM file and the key for the same is defined as below:

    DEFINE WS-vsam-KEY W 29 A
    DEFINE WS-f1 WS-vsam-KEY 3 N
    DEFINE WS-f2 WS-vsam–KEY +3 19 A
    DEFINE WS-f3 WS-vsam–KEY +22 4 B 0
    DEFINE WS-REC-TYPE WS-vsam–KEY +26 1 N VALUE 1
    DEFINE WS-REC-NUMB WS-vsam–KEY +27 2 B

    and I am reading a ps file INPS1 and getting the WS-f1,WS-f2 and WS-f3 values and I am moving 0 to WS-REC-NUMB by decalring a numeric variable.

    and I know there is matching keys in the vsam file however the program is showing the file status as ’16′.
    Please see my code below.

    GET INPS1
    WS-f1 = INPS1-f1
    WS-f2 = INPS1-f2
    WS-f3 = INPS1-f3

    DO WHILE NOT EOF INPS1
    READ vsam-file KEY WS-vsam-KEY STATUS
    if vsam-file : file-status eq 0
    ———
    ———
    else
    DISPLAY ‘FILE-STATUS’ FILE-STATUS
    DISPLAY ‘f1 NOT FOUND IN AMSS :’ INPS1-f1
    DISPLAY ‘f2 NOT FOUND IN AMSS :’ INPS1-f2
    DISPLAY ‘f3 NOT FOUND IN AMSS :’ INPS1-f3

    and the output is showing as below:

    FILE-STATUS 16
    f1 NOT FOUND IN inps1 :141
    f2 NOT FOUND IN inps1 :1411113765100010800
    f3 NOT FOUND IN inps1 :2,012,002
    and the ley is dispalyed as below:1411411113765100010800 1

    Please suggest me how to handle the binary key fields while accesing a vsam file.I guess there is some issue with the way how I am accessing those because when I am trying to dispaly them using numeric fields the values are displayed correctly however while accessing it is saying the records not found.

    Kindly provide some solution for this.

    Thanks in Advance,
    Lakshmi

  •   Karthik
    May 23rd, 2013 at 10:37 am

    I’m not sure why it doesn’t work.
    Instead of the below assignment statements, can you try MOVE statements?
    WS-f1 = INPS1-f1
    WS-f2 = INPS1-f2
    WS-f3 = INPS1-f3

  •   Lakshmy
    May 24th, 2013 at 10:31 am

    Hi Karthik,

    I got the solution,requirment states that the ws-f3 has to be multiplied by -1.After modifying the code as per that I was able to retrieve the records.

    Thanks for the help.

    Lakshmi

  •   Senthil
    October 23rd, 2013 at 9:57 am

    I was getting a error while using Binary of size 8 byte ( s9(18) comp )
    XX-SEC-ID 44 8 B
    *******B097 LENGTH INVALID FOR TYPE – B

    Is easytrieve does not allow binary field of size 8

Who Linked To This Post?

  1. Moving Numeric values between variables in Easytrieve

Share your thoughts, leave a comment!