View previous topic :: View next topic |
Author |
Message |
chandra Beginner
Joined: 26 Sep 2003 Posts: 130 Topics: 36
|
Posted: Mon May 05, 2008 3:53 pm Post subject: COMP field in COBOL |
|
|
Hi All,
I have a copy book in assembler as follows
Code: |
CBNMLEN DS XL1 NAME OR ADDR LENGTH
CBNMID DS CL1 NAME OR ADDR ID
CBNMDATA DS 0C NAME OR ADDR (VARIABLE LENGTH)
SPACE 1
CBVNMEND EQU *
ORG CBNMLEN
CBVNMLEN DS CL(CBVNMEND-CBNMLEN)
|
I want to declare a similar copy book in my COBOL program. I have declared as follows.
Code: |
05 WS-NAME-PART.
10 WS-NAME-PART-LENGTH PIC 9(2) COMP.
10 WS-NAME-PART-ID PIC X(1).
10 WS-NAME-PART-NAME PIC X(78).
|
In assembler copy book the CBNMLEN is one byte. I don't know how to declare variable with one byte containing binary data.
For example:
If CBNMLEN has X'18' it will be store in one byte as follows
but the variable WS-NAME-PART-LENGTH that I have defined is storing as follows
Could you please let me know how to define correctly in COBOL. _________________ Regards,
Chandra |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon May 05, 2008 5:18 pm Post subject: |
|
|
chandra,
The equivalent COBOL definition for X data type in Assembler is Character. So define as
Code: |
WS-NAME-PART-LENGTH PIC X(1). |
Hope this helps...
Cheers
Kolusu |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Mon May 05, 2008 7:39 pm Post subject: |
|
|
If you need to populate that byte with a binary number, define it as PIC S9(4) COMP-5 and redefine it as a group name with 2 elementary names of PIC X each. _________________ ....Terry |
|
Back to top |
|
 |
chandra Beginner
Joined: 26 Sep 2003 Posts: 130 Topics: 36
|
Posted: Mon May 05, 2008 10:45 pm Post subject: |
|
|
Hi Kolusu,
Thanks for your reply... I need to use this field in computation.
Terry,
I tried your solution by defining as follows
Code: |
01 OUT1-REC.
05 OUT-CNTR-NBR PIC S9(4) COMP-5.
05 OUT-CNTR REDEFINES OUT-CNTR-NBR.
15 FRST-BYTE PIC X(01).
15 SEC-BYTE PIC X(01).
05 FILLER PIC X(78).
|
And try to move the X'18' into OUT-CNTR-NBR but it moved as X'0008'.
Can you please suggest me what I am doing wrong. _________________ Regards,
Chandra |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue May 06, 2008 12:48 am Post subject: |
|
|
MOVE ZERO TO OUT-CNTR-NBR
MOVE X'18' TO SEC-BYTE
sorry, no time or desire to explain. RTFM. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Tue May 06, 2008 9:10 am Post subject: |
|
|
MOVE 24 TO OUT-CNTR-NBR
SEC-BYTE should contain X'18' after the move. Dick's method will have the same result as mine. See Language Reference Manual for valid types of MOVE statements. _________________ ....Terry |
|
Back to top |
|
 |
chandra Beginner
Joined: 26 Sep 2003 Posts: 130 Topics: 36
|
Posted: Tue May 06, 2008 9:27 am Post subject: |
|
|
Thank Dick and Terry.
Both your solutions worked. _________________ Regards,
Chandra |
|
Back to top |
|
 |
|
|