View previous topic :: View next topic
|
Author |
Message |
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
SUPPOSE I HAVE A NUMERIC FIELD OF LEGTH 6
w-num pic 9(06)
its value may be 000009 or 000099 or 000999.
i just want to move 9 0r 99 or 999 depending on the value of input.
i just want to remove the leading zeroes part and move the remaining field to other field. no of zeroes may vary from situation to situation.
is there any shorter solution other than comparing field by field |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
Read this Link. It can help you.
I would say google is the best friend of a programmer. Try surfing once before you post. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Use reference modification:
Code: |
PERFORM
VARYING I FROM 1 BY 1
UNTIL I > 6
IF W-NUM (I : 1) > '0'
MOVE W-NUM (I : ) TO WS-B
MOVE 7 TO I
END-IF
END-PERFORM. |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I would say google is the best friend of a programmer. Try surfing once before you post. |
Yup, google has zillions of "hits".
Before going to google, i'd suggest using our forum SEARCH. The hits here will be more directed to what you are looking for.
Quote: |
i just want to remove the leading zeroes part and move the remaining field to other field. |
Do you want the result right- or left-justified? If you want the result right-justified, you might just move the pic 9(6) field to an edited field ZZZZZ9? |
|
Back to top |
|
|
nelson.pandian
Active User
Joined: 09 Apr 2008 Posts: 133 Location: Phoenix, AZ
|
|
|
|
Ajit,
Quote: |
I just want to move 9 0r 99 or 999 depending on the value of input |
If you move only the values to an other PIC 9(06) variable and try to display it or write into an file you will get the same output with leading zeros.
So i would like to suggest you to use the edited fields ZZZZZ9. |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
thanks all of you for help.
my program requirement is to use two digits out of the six digits if only two have values.
if only digit have value other than zero than just pick one digit out of six. |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Hi,I am finding your posts little confusing ,In the beginning your requirement was some thing like
Quote: |
its value may be 000009 or 000099 or 000999.
i just want to move 9 0r 99 or 999 depending on the value of input. |
And now you desire to pick only two digits
Quote: |
my program requirement is to use two digits out of the six digits if only two have values. |
So is it right-justified or left-justified, I reckon it should right. Still,if the input value is 000109 , then what you believe your output should be.Please let us know.
Cris |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
if i input is 000109 i just want to pick 109
if input is 000010 i just want to pick 10
if input is 000111 i just want to pick 111 |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Thanks Ajit,
the solutions already posted i.e. use of edited fields ZZZZZ9 should suffice your requirement(Is this field used/displayed in report generation?). My fault got little confused after reading your penultimate post .
Cris |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
using zzz wil only supress zeroes
i just want to neglect leading zeroes and take the remaining digits out
and this length may be variable
and in my cobol substring doesn't work |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is the definition of your final destination for this data?
are you having left/right justification problems?
what cobol substring (no such thing)? There is reference modification.
do you want to move only digits following a non-zero digit to another field?
provide the definition of the sending field and the receiving field.
you know what you want, but we do not.
you have half explained the first part:
Quote: |
i just want to neglect leading zeroes and take the remaining digits |
now, explain the second part: what is the definition of your final destination? |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
I have to string three fields for example as below
1st field w-A pic x(6) value abcdef
2nd field w-B pic 9(6) value 000024
3rd field w-C pic 9(6) value 000111
now at last i want output as abcdef/24/111 |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Ajit007_cool,
excellent! you will now receive some clever suggestions from our forum friends.
the process would be to determine the number of characters (and location within the field) that would be strung together with W-A.
Code: |
Move spaces to receiving-field
STRING w-A
delimited by size
w-B(<position of first non-zero/space char>:<remaining length of w-B to move>)
delimited by size
w-C(<position of first non-zero/space char>:<remaining length of w-C to move>)
delimite by size
into Receiving-field
END-STRING
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I have to string three fields for example as below
1st field w-A pic x(6) value abcdef
2nd field w-B pic 9(6) value 000024
3rd field w-C pic 9(6) value 000111
now at last i want output as abcdef/24/111 |
Please reflect on what you have finally posted versus how you began the topic.
You will get useful answers much more quickly if you post your actual requirement right away rather than some incomplete, misleading question. All this does is waste everyone's time (including yours). |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Ajit007_cool,
You can try this piece of code
Code: |
01 A PIC X(06) VALUE SPACES.
01 B PIC 9(06) VALUE ZEROES.
01 C PIC 9(06) VALUE ZEROES.
01 WS-TEMP PIC X(18) VALUE SPACES.
01 M PIC 9(02) VALUE ZEROES.
01 I PIC 9(02) VALUE ZEROES.
01 K PIC 9(02) VALUE ZEROES.
01 PTR1 PIC 99 VALUE 1.
UNSTRING A DELIMITED BY SPACE INTO WS-TEMP
POINTER PTR1
COMPUTE PTR1 = PTR1 - 1
MOVE '/' TO WS-TEMP(PTR1:1)
PERFORM
VARYING I FROM 1 BY 1
UNTIL I > 6
IF B(I : 1) > '0'
COMPUTE K = 7 - I
MOVE B (I : ) TO WS-TEMP(PTR1: K)
MOVE 7 TO I
END-IF
END-PERFORM
COMPUTE PTR1 = PTR1 + K
MOVE '/' TO WS-TEMP(PTR1:1)
COMPUTE PTR1 = PTR1 + 1
PERFORM
VARYING I FROM 1 BY 1
UNTIL I > 6
IF C(I : 1) > '0'
COMPUTE K = 7 - I
MOVE C(I : ) TO WS-TEMP(PTR1: K)
MOVE 7 TO I
END-IF
END-PERFORM |
This would fail if variable A has spaces in between e.g. A = "abc de" or "ab de " .If you believe such a scenario can occur then u need to read the string A till the end and to check for spaces. Surely reference modification can be one good option to try for this as well.
Cris |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Hi, I just checked my code ..the variable definition of field A should be taken as PIC X(7) value spaces.
Cris |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Hi,For the string A you can use the following code if you dont wish to use
unstring option
Code: |
A pic x(06) value spaces
MOVE 6 TO I
PERFORM UNTIL I = 0
IF A(I : 1) <> SPACES
MOVE A (1 :I ) TO WS-TEMP(1: I)
MOVE 0 TO I
END-IF
COMPUTE I = I - 1
END-PERFORM |
Cris |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
problem is in my cobol sustring doesnt work so i cant use some thing like this
WS-TEMP(PTR1:1)
so if can anbody tell me
if i have field A pic Z(6) value ' 6'
so can i move this field B pic X(6) and it can appear like this '6 ' |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Please tell me you're kidding about no reference modification -- it's been in the language for a long time (as in since the late 80's or early 90's -- even VS COBOL II had it)!
If you truly don't have reference modification, you can do a batch of redefines on A to isolate the right 5, 4, 3, 2, and 1 characters. Your move would be like
Code: |
IF A >= 100000
MOVE A TO B
ELSE IF A >= 10000
MOVE A-5-CHAR TO B
...
|
|
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
can i supress leading spaces in a field and move the reamining value to some other field
delimited by leading spaces is there any command for this |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Suppress leading zeros? Of course -- PIC Z works well for that.
Move the remaining value to some other field? Nope. Check the COBOL Language Reference manual: MOVE is identifier to identifier; where identifier can be a variable name, literal, reference modification, etc. But you can't selectively move parts of fields without reference modification. |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
can string help with delimited by leading zeroes |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
problem is in my cobol sustring doesnt work so i cant use some thing like this |
I suspect the problem is the code, not the compiler.
Please post the first part of the output of the compiler - it will show which version of the compiler you are using.
Also, i do not understand why you mention substring - substring is not part of the cobol language. . . |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Hi,
Not really sure why reference modification is not working for you.If you can share your error log with us then someone would surely be able to help u with this.
You can try the following code if reference modification is actually not working for you:
Code: |
01 M PIC 9(02) VALUE ZEROES.
01 I PIC 9(02) VALUE ZEROES.
01 K PIC 9(02) VALUE ZEROES.
01 WS-TEMP PIC X(18) VALUE SPACES.
01 WS-BEMP REDEFINES WS-TEMP.
02 WS-BEMP-VAL PIC X(1) OCCURS 18 TIMES.
01 B PIC 9(06).
01 B-INPUT REDEFINES B .
02 BVAL PIC X(1) OCCURS 6 TIMES.
PROCEDURE DIVISION.
PERFORM
VARYING I FROM 1 BY 1
UNTIL I > 6
IF BVAL(I) > '0'
MOVE I TO K
MOVE 7 TO I
END-IF
END-PERFORM
ADD 1 TO M
PERFORM
VARYING I FROM K BY 1
UNTIL I > 6
MOVE BVAL(I) TO WS-BEMP-VAL(M)
COMPUTE M = M + 1
END-PERFORM
MOVE '/' TO WS-BEMP-VAL(M)
*******Follow the similar pattern for other two fields and at the end *******make the final move.*****************
MOVE WS-BEMP TO WS-TEMP |
Hope this helps.
Cris |
|
Back to top |
|
|
ajit007_cool
New User
Joined: 08 Sep 2008 Posts: 14 Location: basel
|
|
|
|
when i am trying to compile my code with this
MOVE W-NUM (1 : 4) TO W-NUMA.
i am getting this error
CBL-0019 C 1492 P : IS NOT A VALID GROUP OF CHARACTERS -- IGNORED
CBL-0310 E 1492 P W-NUM HAS TOO MANY SUBSCRIPTS OR INDEXES PROVIDED
where W-NUM 9 (6)
and W-NUM X(6) |
|
Back to top |
|
|
|