View previous topic :: View next topic
|
Author |
Message |
ajijoj
New User
Joined: 30 Apr 2010 Posts: 3 Location: USA
|
|
|
|
Hi,
I have the following scenario, need advice on this:
1. MOVE 20 TO A .(which has PIC X(02)).
So now A has value as 20.
2. MOVE 'A' TO B. (Which is also PIC X(02))
Now the value of B will be A as i moved a literal to B.
3. MOVE B TO X. (which is x(02))
Here in normal scenario we will move 'A' to X. so the value of X will hold 'A' (because B had VALUE as 'A').
However, in my scenario, i need to have X as 20. That means, X should hold the value of variable(A) which is in B. How can i do this? is it by Pointer? Please advice if we have any function which can do this or any way of doing this by pointer? Thanks a lot. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I cannot think of any way to do this in COBOL. You are wanting to mingle compile-time information (the address of A, for example) with run-time information (the value of B).
Furthermore, since you didn't use BBcode (the Code button) to post your code, it appears that you have errors in what you posted, anyway. If you move a one-byte value 'A' to a PIC X(02) varible, the actual hex value of the variable is C140 which is an A followed by a space -- which complicates what you want to do.
You could use an EVALUATE statement to test all possible values of B and move the appropriate variable to X, which would indirectly accomplish your goal (depending upon how many possible moves you may have, of course). |
|
Back to top |
|
|
ajijoj
New User
Joined: 30 Apr 2010 Posts: 3 Location: USA
|
|
|
|
I want to make a generic code in which i dont want hard coding.. so i cannot use Evaluate and move the data one by one. So is there any function which can get the data out of variable which is already in another variable. As mentioned X should hold 20 when i move B to X, however B has A in it and A holds the actual data of 20. Please advice if you have encounter such scenario's. Thank you. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Quote: |
I want to make a generic code in which i dont want hard coding.. |
Then COBOL is probably not the proper language. . . It may help if you explain what you really want to do rather than the stripped-down example you posted.
If you want this to be dynamic and you want to use COBOL, you could always generate the source and then compile on the fly. Many (most) organizations will not want to support this, but if you make a strong enough case - maybe. . .
If the "sending" and "receiving" fields are to be taken from a fixed list, you might also do something with one or more definition/data arrays and reference modification. This would depend on the requirement which we have not yet seen. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Please advice if you have encounter such scenario's. Thank you. |
I have never encountered such a scenario, nor have I ever had anyone (other than on this forum) interested in doing anything like this. But then, I've only been using COBOL for 35 years now and have been working full-time in IT for 33 years.
If you cannot use EVALUATE, you will need to pick some other language as Dick said. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
As all the fields must be defined in storage, the values are limited.
In that case, you can use EVALUATE
Code: |
EVALUATE B
WHEN 'A'
MOVE A TO X
WHEN 'T'
MOVE T TO X
WHEN 'Z'
MOVE Z TO X
WHEN OTHER
DISPLAY 'B CONTAINS AN INVALID VALUE'
END-EVALUATE |
|
|
Back to top |
|
|
ajijoj
New User
Joined: 30 Apr 2010 Posts: 3 Location: USA
|
|
|
|
Do we have any way to get the address of the variable??
Example, I have A and B declared in Working storage, so this variables will have the address. Now is there any way in which we can get the address of a variable by searching the data in B. For example, A as a literal is moved to B. Can i get the address of A by comparing UNTIL B which is holding A is found (something like this). If i can get the address of a variable then i may be able to move the data present in that variable to another:
I put up an example in this forum
MOVE 20 TO A
MOVE 'A' TO B
MOVE B TO X (X should hold 20).
If i can get the address of A by doing any comparison then probabely i can move the data in A to B and which in turn will move the data to X. Is it possible? Its just an assumption, I may be wrong but want to know if it can be achieved. Thank you. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If your COBOL version/release is at a minumum OS/390 COBOL 2.2.1, then you can get the address of a WS field using a POINTER.
Code: |
03 WS-POINTER POINTER.
*
SET WS-POINTER TO ADDRESS OF A.
|
Bill |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If you click on the manuals link at the top of the page, find the COBOL Language Reference manual, and search for USAGE IS POINTER, you can find exactly what can be done with the address of a variable in COBOL. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
ajijoj wrote: |
I want to make a generic code in which i dont want hard coding.. |
Remember, there are things that you want to do, there are things that you need to do and there are things that you can do.
You told us what you want, we told you what you can. We are still curious about what you need!
Robert Sample wrote: |
I have never encountered such a scenario, nor have I ever had anyone (other than on this forum) interested in doing anything like this. But then, I've only been using COBOL for 35 years now and have been working full-time in IT for 33 years. |
Together we have around 70 years of experience. Isn't that enough for you, Aji?
Oh, by the way: working with addresses won't help because all what you have is a name in a variable! |
|
Back to top |
|
|
gowda.srikanth
New User
Joined: 05 Feb 2010 Posts: 1 Location: bangalore
|
|
|
|
Hi..I also faced the same problem in my CICS- SOA webservices program for around 1700 fields.. i found out the solution.. its working fine in production also..
I cant explain everything on this post.. its lengthy process..if you people need the solution then contact me ... email address removed as per forum rules |
|
Back to top |
|
|
|