Hi,
Can I move comp-3 variable directly to another comp-3 variable? Or I need any alphanumeric in between?
My answer was that we can move one comp-3 to another comp-3 but interview said what happen to the v in say var1 is comp3 PIC 9(4)v9(2) and var2 is PIC 9(6)v9(3)? He said what happens to v in this movement? I could not answer this, can someone please answer.
Move comp-3 to comp-3.
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: Move comp-3 to comp-3.
You tell me what happen, I reduced your time in writing program
Output
Code: Select all
IDENTIFICATION DIVISION.
PROGRAM-ID DISP01.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(4)V9(2) COMP-3.
01 B PIC 9(6)V9(3) COMP-3.
01 C PIC 9(9) .
01 D PIC ZZZZZ9.999.
PROCEDURE DIVISION.
MAIN-PARA.
INITIALIZE A B C D
COMPUTE A = 1234 / 100
MOVE A TO B C D
DISPLAY 'A= ' A
DISPLAY 'B= ' B
DISPLAY 'C= ' C
DISPLAY 'D= ' D
INITIALIZE C D
MOVE B TO C D
DISPLAY 'B= ' B
DISPLAY 'C= ' C
DISPLAY 'D= ' D
STOP RUN.
Code: Select all
A= 001234
B= 000012340
C= 000000012
D= 12.340
B= 000012340
C= 000000012
D= 12.340
zprogrammer
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Move comp-3 to comp-3.
The V in a PICTURE clause represents an implied decimal point (implied as in the decimal point is NOT in the data). So COBOL will align the sending field decimal point and the receiving field decimal point and it will then move data based on that alignment. If the sending field has more digits to the left (or right) of the decimal point than the receiving field, truncation will occur. If the sending field has fewer digits to the left (or right) of the decimal point, zero will be used to fill the extra positions.
The Language Reference manual has a very detailed and exhaustive chart of all allowed moves in COBOL. Generally, like can be moved to like (numeric to numeric, alphanumeric to alphanumeric, national to national) but unlike (national to numeric, for example) may or may not be allowed.
The Language Reference manual has a very detailed and exhaustive chart of all allowed moves in COBOL. Generally, like can be moved to like (numeric to numeric, alphanumeric to alphanumeric, national to national) but unlike (national to numeric, for example) may or may not be allowed.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute