By 'identifier' do you mean 'variable'?
You can do arithmetic on any numeric variable.
By the way - your code is bad - you have 3 variables called number1. I presume this is a typo but to avoid in future you should cut and paste the real code - omitting items unrelated to the problem.
Also, use code tags so that we can read it properly.
How to handle number series logics in cobol pgm
-
- Global moderator
- Posts: 3025
- Joined: Sun Jul 04, 2010 12:13 am
- Skillset: JCL, PL/1, Rexx, Utilities and to a lesser extent (i.e. I have programmed using them) COBOL,DB2,IMS
- Referer: Google
- Location: Pushing up the daisies (almost)
Re: How to handle number series logics in cobol pgm
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
Regards
Nic
Re: How to handle number series logics in cobol pgm
Code: Select all
id division
program-id. pattern.
data division
working-storage section.
01 ws-num1 pic 9 value zero
01 ws-num2 pic 9 value zero
01 ws-num3 pic 9
procedure division
perform varying ws-num1 1 by 1 until ws-num1 < = 3.
perform varying ws-num2 1 by 1 until ws-num2 < = ws-num1.
compute ws-num3=ws-num1*ws-num2.
display 'bb' ws-num3 with no advancing. //bb - two blank spaces
end-perform.
end-perform.
stop-run.
Is this ok nicC...

Re: How to handle number series logics in cobol pgm
the code tag is ok, everything else is wrong :
1) you have . at the end of every line
2) "until ws-num1 <= 3 " you start with 1 so it is immediately <= 3
3) comments don't start with // but with * in col 7
1) you have . at the end of every line
2) "until ws-num1 <= 3 " you start with 1 so it is immediately <= 3
3) comments don't start with // but with * in col 7
Re: How to handle number series logics in cobol pgm
dude i just need the logic to be checked..
I tried nested performs similar to nested loops in C , i just need to know whether my approach is correct.
will i get the output when i use performs in this way
I think ws-num1 > 3 works , so perform runs u3 time,is it?

I tried nested performs similar to nested loops in C , i just need to know whether my approach is correct.
will i get the output when i use performs in this way
Code: Select all
perform varying ws-num1 1 by 1 until ws-num1 > 3.
perform varying ws-num2 1 by 1 until ws-num2 > ws-num1.
compute ws-num3=ws-num1*ws-num2.
display 'bb' ws-num3 with no advancing.
end-perform
end-perform.
I think ws-num1 > 3 works , so perform runs u3 time,is it?
Re: How to handle number series logics in cobol pgm
Code: Select all
perform varying ws-num1 1 by 1 until ws-num1 > 3
perform varying ws-num2 1 by 1 until ws-num2 > ws-num1
compute ws-num3=ws-num1*ws-num2
display ' ' ws-num3 with no advancing
end-perform
display ' '
end-perform.
otherwise it will display 1 2 4 3 6 9
I can explain it to you, but i can not understand it for you.
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: How to handle number series logics in cobol pgm
Hello,
We do neither kiddie chat room nor "dude". . .
Even for freshers/students/rookies/newbies/etc posting in a professional manner is good practice.
It is most difficult to "check logic" when the pseudo code is incorrect. . . Even when you reposted, you did not correct the problems. . .
Rather, You need an attitude adjustment. . .dude i just need the logic to be checked..

We do neither kiddie chat room nor "dude". . .
Even for freshers/students/rookies/newbies/etc posting in a professional manner is good practice.
It is most difficult to "check logic" when the pseudo code is incorrect. . . Even when you reposted, you did not correct the problems. . .
Hope this helps,
d.sch.
d.sch.
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: How to handle number series logics in cobol pgm
IT is a discipline which rewards attention to detail. I took your code as you posted it and ran it through the compiler -- after defining a value clause for WS-NUM3. The results are:13 errors in 3 variable definitions and 6 lines of code is quite a ratio! I recommend you take a course to learn the syntax of COBOL before attempting to post questions on this -- or any -- forum. I changed it to code that will actually compile (and added some indentation as well):Issues:
1. You will get no output from this program. PERFORM ... UNTIL defaults to WITH TEST BEFORE per section 6.2.27.4 of the COBOL Language Reference manual. Hence, the first PERFORM test is done, and WS-NUM1 has a value <= 3 (zero is less than three in COBOL) so none of the code in the outer PERFORM loop is executed. So the only thing the program has to do is exit -- which it does.
2. Your inner PERFORM loop has the same issue.
Once you get past these issues, you should be able to get some output to start figuring out if your algorithm is correct or not.
Code: Select all
000013 01 WS-NUM1 PIC 9(02) VALUE ZERO
000014 01 WS-NUM2 PIC 9(02) VALUE ZERO
==000014==> IGYDS1082-E A period was required. A period was assumed before "01
000015 01 WS-NUM3 PIC 9(10) VALUE ZERO.
==000015==> IGYDS1082-E A period was required. A period was assumed before "01
000016 PROCEDURE DIVISION
000017 PERFORM VARYING WS-NUM1 1 BY 1 UNTIL WS-NUM1 < = 3.
==000017==> IGYPS2145-E A period was required. A period was assumed before "PE
==000017==> IGYPS0088-S The "PERFORM" statement was invalid. Expected "FROM",
The statement was discarded.
==000017==> IGYPS2112-E The "PERFORM" statement did not have a matching scope t
scope terminator was assumed on line 17. The execution
be correct.
000018 PERFORM VARYING WS-NUM2 1 BY 1 UNTIL WS-NUM2 < = WS
==000018==> IGYPS0088-S The "PERFORM" statement was invalid. Expected "FROM",
The statement was discarded.
==000018==> IGYPS2112-E The "PERFORM" statement did not have a matching scope t
scope terminator was assumed on line 18. The execution
be correct.
000019 COMPUTE WS-NUM3=WS-NUM1*WS-NUM2.
==000019==> IGYPS0001-W A blank was missing before character "=" in column 27.
assumed.
==000019==> IGYPS0001-W A blank was missing before character "W" in column 28.
assumed.
==000019==> IGYPS0001-W A blank was missing before character "*" in column 35.
assumed.
==000019==> IGYPS0001-W A blank was missing before character "W" in column 36.
1PP 5655-G53 IBM Enterprise COBOL for z/OS 3.4.1 MF0147 Date 0
LineID PL SL ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6--
0 assumed.
000020 DISPLAY ' ' WS-NUM3 WITH NO ADVANCING.
000021 END-PERFORM.
==000021==> IGYPS2113-E The explicit scope terminator "END-PERFORM" was found w
verb. The scope terminator was discarded.
000022 END-PERFORM.
==000022==> IGYPS2113-E The explicit scope terminator "END-PERFORM" was found w
verb. The scope terminator was discarded.
Code: Select all
01 WS-NUM1 PIC 9(02) VALUE ZERO.
01 WS-NUM2 PIC 9(02) VALUE ZERO.
01 WS-NUM3 PIC 9(10) VALUE ZERO.
PROCEDURE DIVISION.
PERFORM VARYING WS-NUM1 FROM 1 BY 1
UNTIL WS-NUM1 <= 3
PERFORM VARYING WS-NUM2 FROM 1 BY 1
UNTIL WS-NUM2 <= WS-NUM1
COMPUTE WS-NUM3 = WS-NUM1 * WS-NUM2
DISPLAY ' ' WS-NUM3 WITH NO ADVANCING
END-PERFORM
END-PERFORM.
1. You will get no output from this program. PERFORM ... UNTIL defaults to WITH TEST BEFORE per section 6.2.27.4 of the COBOL Language Reference manual. Hence, the first PERFORM test is done, and WS-NUM1 has a value <= 3 (zero is less than three in COBOL) so none of the code in the outer PERFORM loop is executed. So the only thing the program has to do is exit -- which it does.
2. Your inner PERFORM loop has the same issue.
Once you get past these issues, you should be able to get some output to start figuring out if your algorithm is correct or not.
Re: How to handle number series logics in cobol pgm
Sorry..for the mistakes..I don't have a mainframe connected to my pc..I work at home..i try with notepads and wordpad..plz excuse me.
Robert will the problem get solved when " <= " is changed to " > "..so the outer loop condition fails and gets into inner loop is it?
Robert will the problem get solved when " <= " is changed to " > "..so the outer loop condition fails and gets into inner loop is it?
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: How to handle number series logics in cobol pgm
Hello,
http://www.zcobol.org/
or here:
http://www.cobug.com/cobug/docs/freeCompilers0098.html
I believe you would benefit from having the ability to compile/test . . .
You might consider looking here:I don't have a mainframe connected to my pc..I work at home..
http://www.zcobol.org/
or here:
http://www.cobug.com/cobug/docs/freeCompilers0098.html
I believe you would benefit from having the ability to compile/test . . .
Hope this helps,
d.sch.
d.sch.
-
- Similar Topics
- Replies
- Views
- Last post
-
-
compare number lines of two dataset
by samb01 » Wed Nov 13, 2024 8:46 pm » in DFSORT/ICETOOL/ICEGENER - 6
- 2121
-
by sergeyken
View the latest post
Fri Nov 15, 2024 12:41 pm
-
-
- 2
- 4464
-
by sergeyken
View the latest post
Sat Nov 11, 2023 3:01 am
-
- 12
- 12729
-
by Robert Sample
View the latest post
Thu Dec 15, 2022 9:28 pm
-
- 1
- 4027
-
by Leixner
View the latest post
Thu Sep 15, 2022 3:33 am
-
- 2
- 3157
-
by enrico-sorichetti
View the latest post
Mon Oct 30, 2023 6:25 pm