For Programmers: Free Programming Magazines  


Home > Archive > Cobol > November 2005 > cobol condition problem (prob. a newbie question)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cobol condition problem (prob. a newbie question)
seoj

2005-11-07, 6:56 pm

Hi,

I met a problem in writing a cobol condition statement. In C or many of
the languages used these days, you can easily say that (in pseudocode)

if (xxx contains 1 or 0) then do-something....

using a library function or some user-defined function.

But, if I would like to say a similar thing in COBOL, that (more
specifically, for example)

IF (XXX contains only X'00 and X'01) THEN PERFORM SOMETHING.......

Do I need a seperate function (as in C)? If yes, then how?

or should I take a completely different approach to it?

Richard

2005-11-07, 6:56 pm

> IF (XXX contains only X'00 and X'01) THEN PERFORM
> SOMETHING.......


You could use a class condition by setting up your own class-name in
special-names for the characters that you want to check for.

You could use examine to tally various characters and then check this
against the size of the field.

MOVE ZERO TO some-count
EXAMINE some-field TALLYING some-count FOR ALL x"00"
EXAMINE some-field TALLYING some-count FOR ALL x"01"
IF ( some-count = some-size )
PERFORM something
END-IF

2005-11-07, 6:56 pm

In article <1131325290.990956.58430@o13g2000cwo.googlegroups.com>,
seoj <seojungmin@gmail.com> wrote:
>Hi,
>
>I met a problem in writing a cobol condition statement. In C or many of
>the languages used these days, you can easily say that (in pseudocode)
>
>if (xxx contains 1 or 0) then do-something....


[snip]

>IF (XXX contains only X'00 and X'01) THEN PERFORM SOMETHING.......
>
>Do I need a seperate function (as in C)? If yes, then how?
>
>or should I take a completely different approach to it?


The manual - the 'M' in RTFM - has some interesting things to say about
such conditions. Which one do you have access to?

DD

Rick Smith

2005-11-07, 6:56 pm

> EXAMINE some-field TALLYING some-count FOR ALL x"00"
> EXAMINE some-field TALLYING some-count FOR ALL x"01"


Use INSPECT instead of EXAMINE for COBOL 85.



Judson McClendon

2005-11-07, 6:56 pm

"seoj" <seojungmin@gmail.com> wrote:
> Hi,
>
> I met a problem in writing a cobol condition statement. In C or many of
> the languages used these days, you can easily say that (in pseudocode)
>
> if (xxx contains 1 or 0) then do-something....
>
> using a library function or some user-defined function.
>
> But, if I would like to say a similar thing in COBOL, that (more
> specifically, for example)
>
> IF (XXX contains only X'00 and X'01) THEN PERFORM SOMETHING.......
>
> Do I need a seperate function (as in C)? If yes, then how?
>
> or should I take a completely different approach to it?


77 XXX PIC X(??).
77 Ptr PIC 9(06) COMP.

PERFORM VARYING Ptr
FROM 1 BY 1 UNTIL (Ptr > FUNCTION LENGTH(XXX))
IF (XXX(Ptr:1) NOT = X"00" AND X"01")
<do whatever you want>
MOVE FUNCTION LENGTH(XXX) TO Ptr
END-IF
END-PERFORM.
--
Judson McClendon judmc@sunvaley0.com (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Richard

2005-11-07, 6:56 pm

>> IF (XXX contains only X'00 and X'01) THEN PERFORM SOMETHING.......

> PERFORM VARYING Ptr
> FROM 1 BY 1 UNTIL (Ptr > FUNCTION LENGTH(XXX))
> IF (XXX(Ptr:1) NOT = X"00" AND X"01")
> <do whatever you want>


That's the wrong way around.

Judson McClendon

2005-11-07, 6:56 pm

"Richard" <riplin@Azonic.co.nz> wrote:
>
>
> That's the wrong way around.



You're correct, sorry. Do I get half credit? :-)
--
Judson McClendon judmc@sunvaley0.com (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Judson McClendon

2005-11-07, 6:56 pm

"Richard" <riplin@Azonic.co.nz> wrote:
>
> You could use a class condition by setting up your own class-name in
> special-names for the characters that you want to check for.
>
> You could use examine to tally various characters and then check this
> against the size of the field.
>
> MOVE ZERO TO some-count
> EXAMINE some-field TALLYING some-count FOR ALL x"00"
> EXAMINE some-field TALLYING some-count FOR ALL x"01"
> IF ( some-count = some-size )
> PERFORM something
> END-IF



INSPECT some-field TALLYING some-count FOR ALL x"00" x"01"
--
Judson McClendon judmc@sunvaley0.com (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Rick Smith

2005-11-07, 6:56 pm


"Judson McClendon" <judmc@sunvaley0.com> wrote in message
news:6TNbf.15488$td.10141@bignews3.bellsouth.net...
[snip]
> INSPECT some-field TALLYING some-count FOR ALL x"00" x"01"


INSPECT some-field TALLYING some-count FOR ALL x"00" ALL x"01"



Rick Smith

2005-11-07, 6:56 pm


"Rick Smith" <ricksmith@mfi.net> wrote in message
news:11mvbuhk7djdia8@corp.supernews.com...
>
> "Judson McClendon" <judmc@sunvaley0.com> wrote in message
> news:6TNbf.15488$td.10141@bignews3.bellsouth.net...
> [snip]
>
> INSPECT some-field TALLYING some-count FOR ALL x"00" ALL x"01"


It seems I was off on my counting of braces and brackets.
Either will work.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com