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

Problem having a length check in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Sun Jun 24, 2012 1:48 pm
Reply with quote

I have a a requirement of a lenghth check..

FIELDA = X(800)

FIELDA has data varying 3 to 10.

IF FIELDA is less and equal to X(10)
perform para-100
else
perform para-200
end-if.

How to meet the above requirement.Thanks for any suggestion.
Thanks
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sun Jun 24, 2012 2:11 pm
Reply with quote

jeesh! And with your daily reading of the forum nothing came to mind as to previous topis on this subject?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Jun 24, 2012 3:50 pm
Reply with quote

Hello,

I suspect that different people will have different understandings of what you have asked.

Personally, i do not understand at all. How can FIELDA be compared to X(10)?

Maybe if you show some samples of the "input" and the result of the IF statement for each of the input samples it will help clarify.
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: Sun Jun 24, 2012 4:44 pm
Reply with quote

I'm not sure what you actually want either.

Code:
01  a-nice-name-which-describes-the-field pic x(10).

MOVE FIELDA TO a-nice-name-which-describes-the-field

IF FIELDA EQUAL TO a-nice-name-which-describes-the-field
    perform para-100
ELSE
    perform para-200
END-IF


This assumes trailing spaces in your FIELDA.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Sun Jun 24, 2012 6:30 pm
Reply with quote

Assuming that I understood your requirement

maxsubrat wrote:
FIELDA has data varying 3 to 10.


Do you mean the actual data of 3 to 10 bytes apart from spaces ,low-values ??

Code:
If FIELDA(11:790) NOT = SPACES OR LOW-VALUES
   perform para-100
Else
   perform para-200
End-if
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sun Jun 24, 2012 6:39 pm
Reply with quote

COBOL does not have strings in the same way other languages have strings (variables whose length changes at run time). FIELDA, if you defined it as PIC X(800) in WORKING-STORAGE, has a length of 800. It will have a length of 800 no matter what the data is in the variable. A variable in WORKING-STORAGE is fixed length -- even variables with OCCURS DEPENDING ON have the maximum possible amount of storage reserved for them, no matter how many occurrences exist at any given time.

If a variable is defined in LINKAGE SECTION, with OCCURS DEPENDING ON, then the length can vary at run time -- but the memory for the variables is not local to the executing program.

Variables in an 01 in the FILE SECTION can also use OCCURS DEPENDING ON to have varying length, but in this case the length is based upon what the file record contains.

As others have said, perhaps if you explain what you need to accomplish, rather than how you're trying to do it, we can provide more assistance.
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: Sun Jun 24, 2012 9:44 pm
Reply with quote

Pandora-Box wrote:
Assuming that I understood your requirement

maxsubrat wrote:
FIELDA has data varying 3 to 10.


Do you mean the actual data of 3 to 10 bytes apart from spaces ,low-values ??

Code:
If FIELDA(11:790) NOT = SPACES OR LOW-VALUES
   perform para-100
Else
   perform para-200
End-if


Code:
01  FIELDA.
    05  FILLER PIC X(10).
    05  FILLER PIC X(790).
        88  FIELDA-TRAILING-VALUE-ONLY VALUE SPACE.

If FIELDA-TRAILING-VALUE-ONLY
   perform para-100
Else
   perform para-200
End-if


Your solution, Pandora-box, just not encouraging the reference-modification.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Sun Jun 24, 2012 10:48 pm
Reply with quote

Thanks Bill :-)

I get that :-)
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 Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
Search our Forums:

Back to Top