IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

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


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jun 21, 2011 9:02 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jun 21, 2011 9:27 pm
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
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

Superior Member


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

PostPosted: Wed Jun 22, 2011 3:26 pm
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
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: 1353
Location: Israel

PostPosted: Wed Jun 22, 2011 7:00 pm
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
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jun 22, 2011 7:17 pm
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
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: 1353
Location: Israel

PostPosted: Wed Jun 22, 2011 8:44 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

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

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jun 22, 2011 10:48 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top