VALUE Clause!!



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

VALUE Clause!!

Postby sivanag » Sun Oct 03, 2010 3:13 pm

HI...

it s all abt VALUE Cluse..

i want initialize data-names as shown below

77 male pic 9(2) value '1','2'.
77 female pic 9(2) value '2','3'.
77 value pic9(1).

procedure division.

accept value.

if value='1'
display 'male'.

if value='2'
display 'male&female'
else
display 'female'.

is this code will work??

plz help me...

regard
Sivanag
sivanag
 
Posts: 2
Joined: Wed Sep 22, 2010 4:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: VALUE Clause!!

Postby Robert Sample » Sun Oct 03, 2010 5:53 pm

What you have coded will not work. Look up 88 levels in the COBOL Language Reference manual.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: VALUE Clause!!

Postby dick scherrer » Sun Oct 03, 2010 10:01 pm

Hello,

You also need to look at how the IFs are coded.

As coded, you will never see only "male". . .
When the value is 1, "male" will be displayed. Then "female" will be displayed. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: VALUE Clause!!

Postby shindeswap » Thu Oct 14, 2010 1:35 pm

01 Gender
88 male values '1','2'.
88 female value '2','3'.

procedure division.

accept gender.

if gender='1'
display 'male'.

if gender='2'
display 'male&female'
else if gender='3'
display 'female'.

Try this and confirm
shindeswap
 
Posts: 12
Joined: Sat Feb 13, 2010 1:41 pm
Has thanked: 0 time
Been thanked: 0 time

Re: VALUE Clause!!

Postby dick scherrer » Fri Oct 15, 2010 12:09 am

Hello,

Why are there 88 level entries? They are not referenced.

"Gender" needs a picture. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: VALUE Clause!!

Postby Ferrari2010 » Fri Oct 15, 2010 6:07 pm

Hi,

You can use below simple logic to check how 88 level works.
below code may have syntax errors, please take care.

01 GENDER PIC X (01).
88 MALE VALUE '1'.
88 FEMALE VALUE '1'.

PROCEDURE DIVISION.

DISPLAY " ENTER THE CODE".
ACCEPT GENDER

IF MALE
DISPLAY " ENTERED VALUE: 1"
ELSE IF FEMALE
DISPLAY " ENTERED VALUE: 2"
ELSE
DISPLAY "INVALID ENTRY"
END-IF.

Thanks,
Ferrari2010
 
Posts: 6
Joined: Fri Oct 08, 2010 8:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: VALUE Clause!!

Postby NicC » Fri Oct 15, 2010 11:22 pm

Yes - it has errors. FEMALE should have VALUE 2.

You should cut and paste from a working program.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: VALUE Clause!!

Postby dick scherrer » Sat Oct 16, 2010 1:45 am

Hello,

The code posted by Ferrari2010 does not follow the original "rules". . .

As Nic mentioned, the code is also wrong.

Please do not post "solutions" that have not been tested and meet the requirement. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: VALUE Clause!!

Postby ritikasingh » Thu Oct 21, 2010 6:22 pm

As a suggestion if you are looking at same variable in if loop many times , its better to use EVALUATE as per my opinion.As i think in 'IF' even though the first condition has met successfully it will keep going the if loop taking more time.
ritikasingh
 
Posts: 39
Joined: Wed Sep 01, 2010 9:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: VALUE Clause!!

Postby Robert Sample » Thu Oct 21, 2010 6:38 pm

Why do you think when you can read section 6.2.19.2 of the COBOL Language Reference manual and know for sure -- especially when what you think is wrong. If the first IF statement is true, and the DISPLAY 'ENTERED VAUE: ' 1 is executed, the next statement to be executed will be the statement after the period (or corresponding END-IF if one was specified -- which there wasn't in the posted example).
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post