View previous topic :: View next topic
|
Author |
Message |
sibi Yohannan
New User
Joined: 15 Apr 2009 Posts: 47 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
sibi Yohannan
New User
Joined: 15 Apr 2009 Posts: 47 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
sibi Yohannan
New User
Joined: 15 Apr 2009 Posts: 47 Location: Bangalore
|
|
|
|
Thank you!!
Its worked out.
|
|
Back to top |
|
|
sibi Yohannan
New User
Joined: 15 Apr 2009 Posts: 47 Location: Bangalore
|
|
|
|
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 |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|