How to handle number series logics in cobol pgm



Re: How to handle number series logics in cobol pgm

Postby NicC » Fri Sep 17, 2010 10:16 am

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

Re: Re: How to handle number series logics in cobol pgm

 

Re: How to handle number series logics in cobol pgm

Postby joseseb » Fri Sep 17, 2010 10:33 am

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... :)
joseseb
 
Posts: 7
Joined: Thu Sep 09, 2010 9:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to handle number series logics in cobol pgm

Postby GuyC » Fri Sep 17, 2010 12:35 pm

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
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: How to handle number series logics in cobol pgm

Postby joseseb » Fri Sep 17, 2010 12:43 pm

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
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?
joseseb
 
Posts: 7
Joined: Thu Sep 09, 2010 9:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to handle number series logics in cobol pgm

Postby GuyC » Fri Sep 17, 2010 6:56 pm

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.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: How to handle number series logics in cobol pgm

Postby dick scherrer » Fri Sep 17, 2010 10:59 pm

Hello,

dude i just need the logic to be checked..
Rather, You need an attitude adjustment. . . :(
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.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to handle number series logics in cobol pgm

Postby Robert Sample » Fri Sep 17, 2010 11:25 pm

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

Re: How to handle number series logics in cobol pgm

Postby joseseb » Sat Sep 18, 2010 1:20 am

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?
joseseb
 
Posts: 7
Joined: Thu Sep 09, 2010 9:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to handle number series logics in cobol pgm

Postby dick scherrer » Sat Sep 18, 2010 1:53 am

Hello,

I don't have a mainframe connected to my pc..I work at home..
You might consider looking here:
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.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Previous

Return to Interview Questions

 


  • Related topics
    Replies
    Views
    Last post