Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COBOL : How to call nth digit of a field in occurs

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
riponrai

New User


Joined: 15 Jun 2005
Posts: 2
Location: Somerset

PostPosted: Tue Jun 21, 2011 8:57 pm    Post subject: COBOL : How to call nth digit of a field in occurs
Reply with quote

hello friends,

i am confused in mapping this field from an input application to my code.
You can consider my receiving field as CONTENT X

05 HELLO OCCURS 25 TIMES.
10 SAYONARA PIC 9 VALUE 0.
10 NAMASTE PIC X(03).

How to map this ??

If NAMASTE (3:1) is 'A' in any occurence then pull corresponding SAYONARA field ??

I'm confused in declaring NAMASTE field

Thanks for any help.

Ripon
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Jun 21, 2011 9:02 pm    Post subject:
Reply with quote

Code:
05 HELLO OCCURS 25 TIMES.
10 SAYONARA PIC 9 VALUE 0.
10 NAMASTE.
     15  FILLER PIC XX.
     15  NAMASTE-SAYONARA-NEEDED-CHECK PIC X.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 21, 2011 9:12 pm    Post subject:
Reply with quote

implementing CONDITION-NAMEs (Level 88)
  • makes the code easier to understand
  • removes the need for literals in PROCEDURE DIVISION.

Code:

05  HELLO OCCURS 25 TIMES.
    10  SAYONARA                             PIC 9 VALUE 0.
    10  NAMASTE.
        15  FILLER PIC XX.
        15  NAMASTE-SAYONARA-NEEDED-CHECK    PIC X.
            88 VALUE-IS-A-PULL-SAYONARA      VALUE 'A'.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Jun 21, 2011 9:27 pm    Post subject: Reply to: COBOL : How to call nth digit of a field in occurs
Reply with quote

I am certainly in agreement, dbz.

I hope no-one is going to show the TS how to subcript/index the reference modification so that they can use a literal.

1) Look it up yourself, so you know how to use it when you need to (not for occasions like this).
2) Use the 88, like dbz points out. If you are not going to reference the PIC X field, you can make it a FILLER so that no-one wonders why the field is not used.

blah, blah, blah - did you look?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 21, 2011 9:37 pm    Post subject: Re: Reply to: COBOL : How to call nth digit of a field in oc
Reply with quote

yes, i did look; couldn't help myself.
the quote button makes it very easy to read posts,
as well as find out how BBCode works.

and you certainly did not think that I would pass up a chance to respond?
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Wed Jun 22, 2011 3:26 pm    Post subject: Reply to: COBOL : How to call nth digit of a field in occurs
Reply with quote

I'm, on the other hand, thinking about the "varibale names" used to demonstrate the example:

Hello - well, we all know.
SAYONARA - Japanese way of farewell remark.
Namaste - Indian way of saying Hello or good-bye.

Sorry Dick...icon_wink.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 22, 2011 3:30 pm    Post subject:
Reply with quote

Anuj Dhawan wrote:
Sorry Dick


no problem.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Wed Jun 22, 2011 7:00 pm    Post subject:
Reply with quote

Maybe the TS is confused about using both OCCURS and reference modification.
I opened the COBOL Language Reference, looked for "reference modification". The third example provides a clear answer.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 22, 2011 7:09 pm    Post subject:
Reply with quote

excellent post Marso, as usual.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 22, 2011 7:17 pm    Post subject: Reply to: COBOL : How to call nth digit of a field in occurs
Reply with quote

Not that easy... :-)

We don't want him to use the subscripted reference modification in this case, because you can't put an 88-level on it and we don't like literals in the Procedure Division (do we, dbz?). Perfect link for him, though.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 22, 2011 8:16 pm    Post subject:
Reply with quote

ok, Bill, you win. you can have the last post.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Wed Jun 22, 2011 8:44 pm    Post subject:
Reply with quote

Last post ? hey, wait! I'm not finished! icon_smile.gif

Technically, I think I got the right answer.
But the "reference modification / 88-level / literal" issue is interesting too, and maybe to solve it there is a way around:
Code:
SPECIAL-NAMES.                 
    CLASS SAYONARA-PULL IS 'A'.


    IF NAMASTE (SUBSCR) (3:1) IS SAYONARA-PULL THEN
        pull sayonara
    ELSE
        don't pull
    END-IF
Still using reference modification, because after all it's nice not to have to cut the field into small parts,
but no need for level 88 and no literal in PD.
Is this acceptable ?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 22, 2011 9:04 pm    Post subject:
Reply with quote

Like
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 22, 2011 10:48 pm    Post subject: Reply to: COBOL : How to call nth digit of a field in occurs
Reply with quote

Have to say I do prefer dbz's solution. All the definition in the Data Division, clear what the individual field is if necessary (else FILLLER, so it is clear the field is only tested).

W-h-a-t d-o y-o-u t-h-i-n-k, dbz?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jun 23, 2011 1:01 am    Post subject:
Reply with quote

I go out of my way to generate the required data layout in order
to avoid reference modification
in modules that i release.

honestly though, my personal modules (utilities, etc...)
look like assembler - only it is compiled with a cobol compiler.

so, it is one of those do as I say, not what I do
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us