Page 1 of 1

Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 1:27 am
by Yvoncita
Hi,

If i have this instructions :

01 VAR-1 PIC X(5) VALUE 'PL/I'.
01 VAR-2 PIC X(10).
01 VAR-3 PIC X(2).
01 RESULT PIC X(5).

MOVE 'COBOL' TO RESULT
MOVE VAR-1 TO VAR-2
MOVE VAR-2 TO VAR-3
MOVE VAR-3 TO RESULT

Can you help me finding the value of the field RESULT please ?
Many thanks for your help !

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 1:40 am
by Robert Sample
What happened when you tried it yourself?

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 1:48 am
by Yvoncita
It is a test question and i don't understand the response
They said the correct response is : RESULT = 'PL___' where '___' are 3 spaces
I am not agree, for me the response is : RESULT = 'PLBOL' as the variable RESULT has not been initialized after the first instruction when we move 'COBOL' inside ...

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 2:30 am
by Robert Sample
The result will be 'PL ' (PL followed by 3 spaces). The reason is that the MOVE statement replaces EVERY byte of the receiving variable -- whether with source bytes or with spaces. After the first MOVE, RESULT has 'COBOL'. After the second MOVE, VAR-2 has 'PL/I' followed by six spaces. After the third MOVE, VAR-3 has 'PL' (since MOVE statements will truncate to the PICTURE size). Hence the final MOVE will put 'PL' in the first two bytes, and since the receiving variable has a PICTURE size of 5, the last 3 bytes are changed to spaces. If the final MOVE had been
MOVE VAR-3 TO RESULT (1 : 2)
then RESULT would have 'PLBOL' in it, but since reference modification was not used the entire RESULT variable is replaced causing the trailing spaces.

And initialization has NOTHING to do with this problem. It doesn't matter if RESULT is initialized or not -- the final MOVE changes each and every byte of the variable.

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 2:35 pm
by Yvoncita
Ok many thanks for your anwser.
I understand that if we assume all the fields have been initialized with low values first, var-2 will have 6 low-values after the move of "PL/I".
But in the case of the RESULT field, it hasn't low values at the time of the third move, it already contains "COBOL".
When you said "the MOVE statement replaces every byte in the receiving field" it's depending in the compilator used ?
Because we have had, in the past, several errors, when doing a move in a not initialized variable, the field contains for example "MONDAYDAY" which means a first move put "WEDNESDAY" and a second move put "MONDAY", hence the program gives an error because no data = MONDAYDAY has found in the table.

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 3:33 pm
by NicC
Show us:
1 - the code that move WEDNESDAY to the variable
2 - the code that moved MONDAY to the variable
3 - the variable definitions
4 - the compiler and version in use

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 6:07 pm
by Yvoncita
Dear,

I've finally found the definition of the instruction MOVE :

Z1 and Z2 are alphanumeric fields

MOVE Z1 TO Z2

lenght Z1 = lenght Z2 no problème
lenght Z1 < lenght Z2 on complète avec des blancs à droite
lenght Z1 > lenght Z2 on tronque at Z2 size

You were right, many thanks for your help !
The error case I was describing is for an online program in which the developer forgot to initialize the variables. So, from time to time we got the present value mixed with the precedent value during the precedent execution of the program .

Have a nice day. :)

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 6:13 pm
by prino
Yvoncita wrote:The error case I was describing is for an online program in which the developer forgot to initialize the variables. So, from time to time we got the present value mixed with the precedent value during the precedent execution of the program .

Which you've been told is not possible. Don't continue spouting bullexcrement, move doesn't behave different in batch or online programs!

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 6:18 pm
by Robert Sample
The error case I was describing is for an online program in which the developer forgot to initialize the variables. So, from time to time we got the present value mixed with the precedent value during the precedent execution of the program .
Yes, there can be many special cases to consider (for example, behavior may be different for WORKING-STORAGE SECTION variables compared to FILE SECTION variables). But in general, MOVE works as I described (as you found out).

Re: Moving alphanumeric fields

PostPosted: Thu Jan 24, 2019 6:21 pm
by Yvoncita
Wow ! thank you very much for your kindness.
If I come here is to request some ideas ... and not to spouting bullshit !