View previous topic :: View next topic |
Author |
Message |
chandu Beginner
Joined: 18 Dec 2003 Posts: 15 Topics: 6
|
Posted: Tue May 11, 2004 9:45 am Post subject: To access literals in IF conditions |
|
|
Hi,
I wanted to try out a situation something like this
Code: |
WORKING-STORAGE SECTION.
05 A PIC 9 VALUE 9.
05 CC PIC X(20) VALUE 'A IS EQUAL TO 9'.
PROCEDURE DIVISION.
0000-MAIN.
DISPLAY '*** TOP OF PROGRAM ***'.
IF CC
DISPLAY 'GREAT'.
DISPLAY '*** END OF PROGRAM ***'.
STOP RUN.
|
Now what i wanted to achieve is that the condition should be dynamically populated ie CC would be substituted with
Code: |
IF A IS EQUAL TO 9
DISPLAY 'GREAT'.
|
I have a situation where i need to get the conditions from an IAM file and hence i am trying out this scenario, which is not working , I wanted to know if such a thing is possible and what could be the other ways of achieving the same thing.
Any help would be appreciated
Thanks |
|
Back to top |
|
|
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Tue May 11, 2004 1:34 pm Post subject: |
|
|
Chandu,
Read the file and have an 88 level for your variable.
Like
05 A PIC 9 VALUE 0.
88 CC PIC 9(1) VALUE 9.
88 ZZ PIC 9(1) VALUE 0.
When the data is moved into the layout, CC will be initialized. Do your DD for all combinations and test it. Thanks |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue May 11, 2004 3:24 pm Post subject: |
|
|
Suresh kumar,
I don't think your suggestion will work. If I understand Chandu's question correctly, he wants the program to dynamically check for the conditions. I can't think of a way without compiling the program.
One way is to read all the conditions and create a copy of cobol code from the conditions( which will be like paragraph) and the next step will be compilation of the main program which will then include the copybook with all the conditions.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Wed May 12, 2004 12:03 am Post subject: |
|
|
If there are only a few conditions then probably you can handle it by multiple if's. But if there are a lot then probably REXX INTERPRET might help.
Give a sample of few records and the if conditions you would like to generate. |
|
Back to top |
|
|
chandu Beginner
Joined: 18 Dec 2003 Posts: 15 Topics: 6
|
Posted: Wed May 12, 2004 5:57 am Post subject: |
|
|
Hi
Thanks for the replies
Dibakar , there are quite a few conditions which have to be generated , these conditions would be part of a VSAM ( IAM file) , and i wanted to take these conditions in a variable depending upon the kay match like
123 HOMEPHONE IS GREATER THAN 200
124 HOMECITY IS NOT 'ABC'
[The above would be in a VSAM file where 123 is the key field so for that key the if conditon would take the condition like for the key 123 the condition to be applied would be "HOMEPHONE IS GREATER THAN 200"]
Also if we can do this to one condition i think we can replicate it to others as well,
Kindly let me know in case of any more details required,
If i am not able to do it dynamically then i would be putting in more details in the VSAM file by breaking the conditions,
Thanks |
|
Back to top |
|
|
neilxt Beginner
Joined: 01 Mar 2004 Posts: 23 Topics: 1
|
Posted: Wed May 12, 2004 2:34 pm Post subject: |
|
|
Quote: |
Dibakar , there are quite a few conditions which have to be generated , these conditions would be part of a VSAM ( IAM file) , and i wanted to take these conditions in a variable depending upon the kay match like
123 HOMEPHONE IS GREATER THAN 200
124 HOMECITY IS NOT 'ABC'
[The above would be in a VSAM file where 123 is the key field so for that key the if conditon would take the condition like for the key 123 the condition to be applied would be "HOMEPHONE IS GREATER THAN 200"]
|
I don't know of any compiled language that can handle this sort of structure.
The one time I had to do something like this I broke the field into 3 parts. The Data item, the comapre value and the comparison to be made. I then had three modules...
The first extracted the data item to be compared, determined whether it was alpha or numeric and stored it - one big EVALUATE basically.
The second stored the comparand based on the numeric decision from part 1.
The third compared the 2 using whichever comparator was specified and returned true or false.
I know it isn't what you wanted but in the long run I think you'll find it works out better than trying to call a run time parser from a compiled program. |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Thu May 13, 2004 5:26 am Post subject: |
|
|
chandu,
to me it appears that you have cobol program and you want to generate dyanamic if conditions in cobol. In this case REXX would not work. But if it is possible to change your program to REXX than you can read and create dyanamic if conditions in REXX, using INTERPRET. |
|
Back to top |
|
|
chandu Beginner
Joined: 18 Dec 2003 Posts: 15 Topics: 6
|
Posted: Thu May 13, 2004 5:36 am Post subject: |
|
|
Hi,
Thanks for the replies
Dibakar i was not having any other language in mind as i was not aware of other possibilities, If you could show me some code in REXX for the same , then i can try that out and decide if i could go for such an option,
can REXX read a VSAM (KSDS) and also generate conditions dynamically,
If you could show me such a solution then it would be very kind.
Thanks |
|
Back to top |
|
|
superk Advanced
Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Thu May 13, 2004 7:15 am Post subject: |
|
|
When this was first posted, I too considered that REXX might be able to provide the solution. To test the theory, I made this little test exec up:
/* REXX */
A = 9
EQU = 'If A = 9'
Interpret(EQU) Then Say 'OK'
This does work. Try it. |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Mon May 17, 2004 5:21 am Post subject: |
|
|
Chandu,
Rexx will not support VSAM(KSDS), which is not a big deal, put a 'Tso Repro' to copy to sequential file and then read sequentially. If you want to read for a particular key, then you can do 'Repro' for that key too but doing this in a loop will decrease performance.
This is my input file (testfile)
Code: |
123 HOMEPHONE IS GREATER THAN 200
124 HOMECITY IS NOT 'ABC'
125 NAME IS 'DIBAKAR BISWAS'
126 TO CHECK ERROR CONDITION
|
This is my rexx
Code: |
/* REXX to test Chandu's requirement */
parse pull HOMEPHONE HOMECITY NAME
"alloc f(testfile) da(UTILITY.CLIST(TESTFILE)) shr reuse"
do forever; "execio 1 diskr testfile"
if (rc > 0) then leave
pull t_line; t_line = strip(t_line)
t_wrds = words(t_line); t_var1 = word(t_line,2)
select
when (subword(t_line,3,3) = 'IS GREATER THAN') then
do
t_oper = '>'; t_var2 = subword(t_line,6,t_wrds-5)
end
when (subword(t_line,3,2) = 'IS NOT') then
do
t_oper = '<>'; t_var2 = subword(t_line,5,t_wrds-4)
end
when (subword(t_line,3,1) = 'IS') then
do
t_oper = '='; t_var2 = subword(t_line,4,t_wrds-3)
end
otherwise t_oper = 'Err'
end
if (t_oper = 'Err') then
say 'Could not extract input condition from:' t_line else
do
interpret 'testcond =' t_var1 t_oper t_var2
condmet = 'False'
interpret 'if' testcond 'then condmet = "True"'
if (condmet = 'True') then say 'Condition Met: ' t_line
else say 'Condition Not Met:' t_line
end
end
"execio 0 diskr testfile (FINIS"
"free f(testfile)"
exit
|
This is my output when I give blank input
Code: |
Condition Not Met: 123 HOMEPHONE IS GREATER THAN 200
Condition Met: 124 HOMECITY IS NOT 'ABC'
Condition Not Met: 125 NAME IS 'DIBAKAR BISWAS'
Could not extract input condition from: 126 TO CHECK ERROR CONDITION
|
|
|
Back to top |
|
|
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Tue May 18, 2004 12:47 am Post subject: |
|
|
Thanks mike, hopefully next time i won't get scared of using vsam in rexx. |
|
Back to top |
|
|
chandu Beginner
Joined: 18 Dec 2003 Posts: 15 Topics: 6
|
Posted: Tue May 25, 2004 8:13 am Post subject: |
|
|
Thanks a lot Dibakar. |
|
Back to top |
|
|
|
|