Moving alphanumeric fields



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Moving alphanumeric fields

Postby Yvoncita » Thu Jan 24, 2019 1:27 am

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 !
Yvoncita
 
Posts: 5
Joined: Thu Jan 24, 2019 12:56 am
Has thanked: 0 time
Been thanked: 0 time

Re: Moving alphanumeric fields

Postby Robert Sample » Thu Jan 24, 2019 1:40 am

What happened when you tried it yourself?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Moving alphanumeric fields

Postby Yvoncita » Thu Jan 24, 2019 1:48 am

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 ...
Yvoncita
 
Posts: 5
Joined: Thu Jan 24, 2019 12:56 am
Has thanked: 0 time
Been thanked: 0 time

Re: Moving alphanumeric fields

Postby Robert Sample » Thu Jan 24, 2019 2:30 am

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Moving alphanumeric fields

Postby Yvoncita » Thu Jan 24, 2019 2:35 pm

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.
Yvoncita
 
Posts: 5
Joined: Thu Jan 24, 2019 12:56 am
Has thanked: 0 time
Been thanked: 0 time

Re: Moving alphanumeric fields

Postby NicC » Thu Jan 24, 2019 3:33 pm

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
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Moving alphanumeric fields

Postby Yvoncita » Thu Jan 24, 2019 6:07 pm

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. :)
Yvoncita
 
Posts: 5
Joined: Thu Jan 24, 2019 12:56 am
Has thanked: 0 time
Been thanked: 0 time

Re: Moving alphanumeric fields

Postby prino » Thu Jan 24, 2019 6:13 pm

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!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Moving alphanumeric fields

Postby Robert Sample » Thu Jan 24, 2019 6:18 pm

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).
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Moving alphanumeric fields

Postby Yvoncita » Thu Jan 24, 2019 6:21 pm

Wow ! thank you very much for your kindness.
If I come here is to request some ideas ... and not to spouting bullshit !
Yvoncita
 
Posts: 5
Joined: Thu Jan 24, 2019 12:56 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post