View previous topic :: View next topic |
Author |
Message |
KOUSIK Beginner
Joined: 04 Jan 2005 Posts: 26 Topics: 13
|
Posted: Tue Aug 14, 2007 8:24 pm Post subject: Changing data-names dynamically in COBOL |
|
|
Hi all,
I tried searching through the forum and in many other forums too on how to dynamically change a data-name in COBOL.
I have a set of instructions to be executed in COBOL and the only difference is change in data-names. A sample is below. I want to change the name IP**-TABLE-LINKAGE dynamically so that I can avoid all the redundant instructions below and make them into a single statement. Or in other words, I have to replace the 3 and 4th character of the IP**-TABLE-LINKAGE variable somehow dynamically.
IF MODULE-NM = PATAP08
MOVE IP08-TABLE-LINKAGE TO TABLE-LINKAGE
END-IF
IF MODULE-NM = PATAP10
MOVE IP10-TABLE-LINKAGE TO TABLE-LINKAGE
END-IF
IF MODULE-NM = PATAP11
MOVE IP11-TABLE-LINKAGE TO TABLE-LINKAGE
END-IF
Any suggestion on this would be greatly appreciated. Thank you very much. I learn a lot through this forum.
Kousik |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Aug 14, 2007 10:52 pm Post subject: |
|
|
You can't change a reference name dynamically.
using table and pointer techniques you can simplify your code. Give us an idea of what IPxx-TABLE-LINKAGE and TABLE-LINKAGE consist: i.e. PIC clause; the context of how and why they are being used. Also, a count of the number of module names involved. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
KOUSIK Beginner
Joined: 04 Jan 2005 Posts: 26 Topics: 13
|
Posted: Tue Aug 14, 2007 11:16 pm Post subject: |
|
|
Thank you so much for your response and advise Dick!
Here is a more detailed explanation on what I am trying to do. I am attaching a piece of the code for a better picture. IPXX-TABLE-LINKAGE is a group item and it represents a DB2 table. All the elementary items under this group would a column in the table. TABLE-LINKAGE is just X(700). We populate the IPxx-TABLE-LINKAGE and then move this IPXX-TABLE-LINKAGE to TABLE-LINKAGE, Call the table I/O module as
MOVE 'PATAP08' TO AB06-MODULE-NM ( PATAP08 represents a DB2 table )
MOVE 'R' TO AB06-ACTION-IND ( 'R' refers to read the table )
MOVE IP08-TABLE-LINKAGE TO TABLE-LINKAGE
CALL AB06-MODULE-NM
USING TABLE-LINKAGE
IF RETURN-SQLCODE = +0
MOVE TABLE-LINKAGE TO IP08-TABLE-LINKAGE
END-IF
So, now the module would have read the row I wanted from the table and returned it back to me and I can go use the table data in a program. |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Wed Aug 15, 2007 12:06 am Post subject: |
|
|
each IPXX-TABLE-LINKAGE group is defined the same way?
Are you using dynamic sql?
give me an idea of what IP06-TABLE-LINKAGE and IP08-TABLE-LINKAGE looks like.
you have a unique db2 module for each db2 table?
at this point I have to make too many assumptions about what you are doing. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Aug 15, 2007 8:46 am Post subject: |
|
|
I'm just wondering why you need the moves to/from TABLE-LINKAGE in the first place. Why not just call the module referencing the data area? Instead of
MOVE IP08-TABLE-LINKAGE TO TABLE-LINKAGE
CALL AB06-MODULE-NM USING TABLE-LINKAGE
MOVE TABLE-LINKAGE TO IP08-TABLE-LINKAGE
why not
CALL AB06-MODULE-NM USING IP08-TABLE-LINKAGE ? |
|
Back to top |
|
|
KOUSIK Beginner
Joined: 04 Jan 2005 Posts: 26 Topics: 13
|
Posted: Sun Aug 19, 2007 12:09 am Post subject: |
|
|
Sharon,
This is the standard we follow normally. It could be done as you said but as of now it is considered a bad practice. We have to follow the standards. This logic is kind of universal, people don't accept changes suddenly.
Dick,
Thanks a lot and appreciate your response. I coded the logic a little bit different but structured though I couldn't do what I initially thought. |
|
Back to top |
|
|
|
|