Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Use of INSPECT Command

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

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Mon Jun 22, 2009 2:29 pm    Post subject: Use of INSPECT Command
Reply with quote

I have a variable defines ...
A-WS PIC X(18).

Say A-WS conatains = "ABC123 12/.123"
It can have numerals, alphabets, special characters, spaces in between.

I need to find out the complete length of the variable. starting from A to the last 3 including numerals, alphabets, special characters, spaces there in the data.

Can we use INSPECT command to find out the same. Or is there any other way any one can suggest me on this.?
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Jun 22, 2009 2:48 pm    Post subject:
Reply with quote

Quote:
I need to find out the complete length of the variable


if what you mean is:I need to find the length of the data contained in the variable then
you could use the INSPECT REVERSE(A-WS) TALLYING for LEADING SPACES statement
or

populate a binary halfword with the length of A-WS, and use that as the starting position of a REFERENCE Modification phrase, decrementing until you have a non-space. The value of the decremented binary halfword would be the length of data within A-WS.
Back to top
View user's profile Send private message
sibi Yohannan

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Mon Jun 22, 2009 3:20 pm    Post subject: Reply to: Use of INSPECT Command
Reply with quote

As I mentioned in the example

A-WS conatains = " ABC123 12/.123"
The data characteristics
1) Spaces can be in the begining and in betwwen
2) Can contain Numerals, alphabets and special chars like / " . etc

As in the abve example, the Length count is 15. This is the requirement.

The REVEERSe command is not working in our system, the compiler do not recognioze the word REVERSE

Please advice
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Jun 22, 2009 3:36 pm    Post subject:
Reply with quote

I see you took no notice of the second part of my post.

count the number of leading spaces
--number of spaces starting at the begining of your variable before a non-space character
and the number of trailing spaces
--number of spaces starting at the end of your variable before a non-space char
subtract this total from the length.

you can use reference modification (search the forum or the cobol manual for examples) to address each byte within your variable.
you would progress from left to right to obtain leading spaces (or use inspect)
and progress from right to left to count the trailing spaces.

perform varying half-word-bin from 1 by 1
until variable(half-word-bin:1) <> space

value of half-word-bin - 1 = number of leading spaces.

perform varying half-word-bin from length-of-variable by -1
until variable(half-word-bin:1) <> space

value of length-of-variable - half-word-bin = number of trailing spaces.
Back to top
View user's profile Send private message
sibi Yohannan

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Mon Jun 22, 2009 7:47 pm    Post subject: Reply to: Use of INSPECT Command
Reply with quote

Thank you!!

Its worked out.

icon_smile.gif
Back to top
View user's profile Send private message
sibi Yohannan

New User


Joined: 15 Apr 2009
Posts: 47
Location: Bangalore

PostPosted: Fri Jul 24, 2009 12:26 pm    Post subject: Variable Declaraion concerns
Reply with quote

I see a COBOl program declared as below

01 A-WS VALUE SPACES.

10 B-WS PIC X(10)
10 C-WS PIC Z(10)
10 D-WS PIC 9(10)
10 E-WS PIC S 9(10) COMP.


Compilation is succesfull, not sure whether it is a valid o declare the group variable. At the least believe it should give a compilation error as there is numeric variable under the group.
Please advice
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Jul 24, 2009 2:34 pm    Post subject: Reply to: Use of INSPECT Command
Reply with quote

Quote:
I see a COBOl program declared as below


Code:

01 A-WS VALUE SPACES.

10 B-WS PIC X(10)
10 C-WS PIC Z(10)
10 D-WS PIC 9(10)
10 E-WS PIC S 9(10) COMP.


It doesn't gives compilation error, if any character value( or spaces) is moved to numeric.

Code:
MOVE spaces TO D-WS


The above statement would also compile successfully. You will get an abend at run time when you do computation on the numeric variables containing character values.

Note: You could have started a new thread or rather searched lot of previous topics on this forum.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8167
Location: East Dubuque, Illinois, USA

PostPosted: Fri Jul 24, 2009 5:08 pm    Post subject:
Reply with quote

Which compiler are you using? Enterprise COBOL 3.4 gives
Code:
          WORKING-STORAGE SECTION.
          01  A-WS                        VALUE SPACES.


IGYDS1277-E A "VALUE" clause was specified for a group item that contained a
          subordinate item with "USAGE" other than "USAGE DISPLAY". The "VALUE"
          clause was discarded.

              10  B-WS                    PIC X(10) .
              10  C-WS                    PIC Z(10) .
              10  D-WS                    PIC 9(10) .
              10  E-WS                    PIC S9(10) COMP.
and
Code:
              MOVE SPACES                 TO  D-WS.

IGYPA3005-S "SPACES" and "D-WS (NUMERIC INTEGER)" did not follow the "MOVE" statement
          compatibility rules.  The statement was discarded.
So the VALUE SPACES on the group is invalid not because of the numeric fields in the group but because of the COMP field -- but the numeric fields would generate S0C7 abends unless the values were corrected to be entirely numbers before using them. And the COBOL manual specifically states that moving SPACES to a numeric field is not valid since spaces are not numeric, as confirmed by the compiler message (which by the way is a SEVERE not ERROR message).
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 MQ command in option 6 of ISPF! Vignesh Sid All Other Mainframe Topics 3 Tue Sep 26, 2017 6:01 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts Failure after DIR command Hank Watson All Other Mainframe Topics 2 Tue Aug 29, 2017 3:14 am
No new posts Command to find TMEMBER name for a TPIPE Siva NKK Kothamasu IMS DB/DC 0 Wed Aug 16, 2017 6:08 pm
This topic is locked: you cannot edit posts or make replies. rexx to create a tso command Bharath Vikraman CLIST & REXX 1 Tue Aug 08, 2017 3:32 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us