Alphanumeric to COMP-3 data movement

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS
Gaurav Chauhan
Posts: 12
Joined: Mon Nov 05, 2007 1:50 pm
Skillset: Cobol,DB2,CICS,JCL,VSAM
Referer: thru friends

Alphanumeric to COMP-3 data movement

Postby Gaurav Chauhan » Thu Nov 08, 2007 8:44 am

Why can't we move Alphanumeric ( PIC X ) data to COMP-3 variables directly without using Display 0r Zoned numeric variables intermediately.....
I want to know how the movement takes place in the variables internally...

pooja.jadhav
Posts: 1
Joined: Wed Nov 07, 2007 10:49 am
Skillset: mainframe
Referer: internet

Re: Alphanumeric to COMP-3 data movement

Postby pooja.jadhav » Thu Nov 08, 2007 10:50 am

hi,
In comp-3 data representation is in packed decimal and in alphanum data is stored in ascii form so bcuz of data incompatibility Alphanumeric to COMP-3 data movement is not possible.
Regards,
poojaj

Gaurav Chauhan
Posts: 12
Joined: Mon Nov 05, 2007 1:50 pm
Skillset: Cobol,DB2,CICS,JCL,VSAM
Referer: thru friends

Re: Alphanumeric to COMP-3 data movement

Postby Gaurav Chauhan » Thu Nov 08, 2007 11:45 am

Yes....but I want to know how data movement takes place internally in these variables...
Take these 2 cases:

a) 05 WS-1 PIC X(03) VALUE 'ABC'.
05 WS-2 PIC 9(03) VALUE ZEROES.
05 WS-3 PIC S9(03) COMP-3 VALUE ZEROES.

b) 05 WS-4 PIC X(03) VALUE '123'.
05 WS-5 PIC 9(03) VALUE ZEROES.
05 WS-6 PIC S9(03) COMP-3 VALUE ZEROES.

MOVE WS-1 to WS-2
Move WS-2 to WS-3

MOVE WS-4 to WS-5
Move WS-5 to WS-6

How will data movement take place for these 2 cases internally ??

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Alphanumeric to COMP-3 data movement

Postby dick scherrer » Fri Nov 09, 2007 1:38 am

Hello,

in alphanum data is stored in ascii form
This is incorrect. Data in files and in programs is almost never stored in ascii on the mainframe.

How will data movement take place for these 2 cases internally ??


In both cases the first "move" generates an assembler move instruction and the second generates an assembler zero-and-add-packed (zap) instruction.

To better understand what happens internally, it may be helpful to look at the actual assembler code generated by the compile.
Hope this helps,
d.sch.

Gaurav Chauhan
Posts: 12
Joined: Mon Nov 05, 2007 1:50 pm
Skillset: Cobol,DB2,CICS,JCL,VSAM
Referer: thru friends

Re: Alphanumeric to COMP-3 data movement

Postby Gaurav Chauhan » Tue Nov 13, 2007 7:00 pm

Thnx....It helped !!!

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Alphanumeric to COMP-3 data movement

Postby dick scherrer » Tue Nov 13, 2007 8:13 pm

You're welcome :)

jvinoth
Posts: 132
Joined: Fri Nov 18, 2011 3:13 pm
Skillset: mainframe
Referer: googe search

Re: Alphanumeric to COMP-3 data movement

Postby jvinoth » Tue Jan 03, 2012 3:55 pm

i have code is this correct and how to move alphanueric to comp-3

IDENTIFICATION DIVISION.
PROGRAM-ID PROGRAM1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A1 PIC 9(5) COMP-3.
01 A1-NUM PIC X(5).
01 WS-COMP3 PIC 9(6)V99 COMP-3.
01 B1 PIC X(5).
PROCEDURE DIVISION.
MOVE 'TESTING' TO WS-COMP3.
DISPLAY WS-COMP3.
STOP RUN.

BillyBoyo
Global moderator
Posts: 3805
Joined: Tue Jan 25, 2011 12:02 am
Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
Referer: Google

Re: Alphanumeric to COMP-3 data movement

Postby BillyBoyo » Tue Jan 03, 2012 4:01 pm

When you have a new question, please start a new topic. If you have found another topic you think relevant, you can link to it.

Why would you want to do this? If you consult your manuals, you'll find that moving alphanumeric literals to comp-3 fields is not allowed.

If you have a numeric value in a PIC X(n) field, redefine it as a PIC 9(n) field. Test that field for being numeric before doing the move. MOVE to the comp-3 field.

User avatar
dick scherrer
Global moderator
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am

Re: Alphanumeric to COMP-3 data movement

Postby dick scherrer » Wed Jan 04, 2012 1:34 am

Hello,

i have code is this correct and how to move alphanueric to comp-3

01 WS-COMP3 PIC 9(6)V99 COMP-3.

MOVE 'TESTING' TO WS-COMP3.
No, this is not correct. You should not try to force alpha values into a packed-decimal (comp-3) field.
Hope this helps,
d.sch.