View previous topic :: View next topic |
Author |
Message |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Fri Oct 02, 2009 1:16 pm Post subject: Cobol variable declarations needed |
|
|
I have a report in a file and data is displayed in readable format for amount fields as below:
Code: |
-3----+----4----+----5----+----6----+----7-
******************** Top of Data **********
22.54494760- 1123.47404619
0.00000000 5.83145814
122.96465052- 587.50760573
10.04237894- 896.76768837
|
The file layout from which the report is written has first amount PIC X(20) JUSTIFIED RIGHT and second amount also PIC X(20) JUSTIFIED RIGHT.The first amount will always be either 0 or less than 0 or spaces as written by the program and the second amount will be either > 0 or spaces as written by the program.
I want to read the first value amount and second value amount and then sum up by a program only and I want to display upto maximum 18 digits with 2 decimal as fractions. Can anyone one help me how should i declare my variables in the program to take care of spaces , zeroes , minus signs and positive and negative amount. If it is spaces I want to interpret the value as 0 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Fri Oct 02, 2009 1:46 pm Post subject: |
|
|
yadav2005,
Isn't it simple with NUMVAL function?
Code: |
01 INP-VAL1 PIC X(20).
01 INP-VAL2 PIC X(20).
01 NUM-VAL1 PIC S9(10)V9(2).
01 NUM-VAL2 PIC S9(10)V9(2).
IF INP-VAL1 > ' '
COMPUTE NUM-VAL1 = FUNCTION NUMVAL(INP-VAL1)
ELSE
MOVE +0 TO NUM-VAL1
END-IF
IF INP-VAL2 > ' '
COMPUTE NUM-VAL2 = FUNCTION NUMVAL(INP-VAL2)
ELSE
MOVE +0 TO NUM-VAL2
END-IF
|
Now perform the arthimetic on num-val1 and num-val2 |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Fri Oct 02, 2009 2:12 pm Post subject: |
|
|
Thanks a lot for your reply and I am clear in my understanding . The problem is I am failing compile time of the program as FUNCTION NUMVAL is not being supported by the version of cobol compiler i have :
PP 5668-958 IBM VS COBOL II RELEASE 4.0 09/15/92
Code: |
IGYPS0086-I "FUNCTION" WAS SPECIFIED AS AN INFORMATIONAL WORD IN THE CURRENT RESERVED WORD TABLE. THE RESERVED WORD TABLE
USED MAY BE DIFFERENT FROM THE IBM-SUPPLIED DEFAULT. REFER TO VS COBOL II APPLICATION PROGRAMMING LANGUAGE
REFERENCE FOR INFORMATION ON RESERVED WORDS.
IGYPS2121-S "FUNCTION" WAS NOT DEFINED AS A DATA-NAME. THE STATEMENT WAS DISCARDED
IGYPS2072-S "NUMVAL" WAS INVALID. SKIPPED TO THE NEXT VERB, PERIOD OR PROCEDURE-NAME DEFINITION.
|
Can you tell me an alternative way to achieve this. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Fri Oct 02, 2009 3:01 pm Post subject: |
|
|
yadav2005,
Quote: | PP 5668-958 IBM VS COBOL II RELEASE 4.0 09/15/92 |
VS COBOL II has been out of service since 2001. The only way I can think of is to using perform varying reading each byte and validating it if is greater than space and moving to a numeric value byte by byte.
Good Luck
Kolusu |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri Oct 02, 2009 6:43 pm Post subject: |
|
|
If I recall correctly, de-editing a numeric edited field was introduced in COBOLII. If you defined your I/P O/P fields as: Code: | IP-FLD PIC Z(10).9(08)-.
WK-FLD PIC S9(10)V9(08). |
then Code: | MOVE IP-FLD TO WK-FLD | Now you have a true numeric field to work with.
One caveat, though: IP-FLD must always obey the rules of Numeric Edited fields. If not you'll be spending time with the Big A. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Mon Oct 05, 2009 12:17 pm Post subject: |
|
|
Thanks Slade and Kolusu,
I have used variables as defined by Slade and my input data is x(20) but I get S0C7 when i move data from input field to the variable but my file positions are correct and I have used Xpediter to debug the program but it is failing in the move statement.
Code: |
IP-FLD PIC Z(10).9(08)-.
MOVE IN-REC(225:20) TO INP-FLD
|
What would be the other way to achieve the results. |
|
Back to top |
|
 |
Anuj Dhawan Intermediate
Joined: 19 Jul 2007 Posts: 298 Topics: 7 Location: Mumbai,India
|
Posted: Mon Oct 05, 2009 1:28 pm Post subject: |
|
|
Jack is correct. But, yadav2005, the way you've posed your question only suggestion is play around with the positions used reference in modification... _________________ Regards,
Anuj |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Mon Oct 05, 2009 2:07 pm Post subject: |
|
|
Anuj,
Did you mean that my positions are incorrect in the reference modification. |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Mon Oct 05, 2009 3:01 pm Post subject: |
|
|
kolusu,
Can you please help me with the code as I have tried from my end but not getting proper results and I am not correct in my approach. Furher logic explanation will be a great help as sign is also involved and spaces all possible in the positions I am not able to progress further. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Mon Oct 05, 2009 4:02 pm Post subject: |
|
|
yadav2005,
I am just showing you the processing of first field and you can do the same for the second field too. Untested code .
Code: |
01 IP-FLD1 PIC X(20).
01 WK-FLD1.
05 WK1-INTEGER PIC 9(10).
05 WK1-DECIMAL PIC 9(08).
01 NUM-FLD1 REDEFINES WK-FLD1 PIC S9(10)V9(08).
|
Code: |
INSPECT IP-FLD1(1:19) REPLACING ALL ' ' BY '0'
INITIALIZE WK-FLD1
UNSTRING IP-FLD1(1:19) DELIMITED BY '.'
INTO WK1-INTEGER, WK1-DECIMAL
IF IP-FLD1(20 : 1) = '-'
COMPUTE NUM-FLD1 = 0 - NUM-FLD1
END-IF
|
Now you can perform the arthimetic using NUM-FLD1
Kolusu |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Mon Oct 05, 2009 4:43 pm Post subject: |
|
|
Kolusu thank you very very much for your code and explanation and I will be able to complete my task. It is great but still I end up in compile time error and this time it is for Unstring verb .
Code: |
05 INP-FLD1 PIC X(20) VALUE SPACES.
05 WK-FLD1.
10 WK1-INTEGER PIC 9(10).
10 WK1-DECIMAL PIC 9(08).
05 NUM-FLD1 REDEFINES WK-FLD1 PIC S9(10)V9(08).
05 INP-FLD2 PIC X(20) VALUE SPACES.
05 WK-FLD2.
10 WK2-INTEGER PIC 9(10).
10 WK2-DECIMAL PIC 9(08).
05 NUM-FLD2 REDEFINES WK-FLD2 PIC S9(10)V9(08).
UNSTRING INP-FLD1(1:19) DELIMITED BY '.'
INTO WK1-INTEGER, WK1-DECIMAL
UNSTRING INP-FLD2(1:19) DELIMITED BY '.'
INTO WK2-INTEGER, WK2-DECIMAL
IGYPA2213-S "INP-FLD1 (ALPHANUMERIC REFERENCE MODIFIED ITEM)" WAS REFERENCE MODIFIED AND REFERENCE MODIFICATION IS NOT
ALLOWED IN THIS CONTEXT. THE STATEMENT WAS DISCARDED.
IGYPA2213-S "INP-FLD2 (ALPHANUMERIC REFERENCE MODIFIED ITEM)" WAS REFERENCE MODIFIED AND REFERENCE MODIFICATION IS NOT
ALLOWED IN THIS CONTEXT. THE STATEMENT WAS DISCARDED.
|
I am not able to understand why it is failing in Unstring , it should work as it has '.' in INP-FLD1 or INP-FLD2 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Mon Oct 05, 2009 6:23 pm Post subject: |
|
|
yadav2005,
Just remove the reference modification or only define the first 19 bytes as inp-fld and run it _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Mon Oct 05, 2009 8:16 pm Post subject: |
|
|
Try REDEFINING INP-FLD to INP-FLD-X PIC x(20).
Then:
MOVE IN-REC(225:20) TO INP-FLD-X
MOVE IP-FLD TO WK-FLD _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
Anuj Dhawan Intermediate
Joined: 19 Jul 2007 Posts: 298 Topics: 7 Location: Mumbai,India
|
Posted: Tue Oct 06, 2009 5:00 am Post subject: |
|
|
Hi,
Reference modification provides access to a subset of the character string value stored in a USAGE IS DISPLAY data item. It is specified as: Code: | data-name (leftmost:length) | where data-name is an item whose USAGE IS DISPLAY, leftmost is an arithmetic expression providing the starting position (relative to 1 at the left-hand end of the item), and length is an arithmetic expression specifying the number of character positions to be included in the newly created data item.
As you get IGYPP2213-S, that means, the format and syntax requirements of the indicated statement do not allow reference modification to be employed, that's why I suggested respecify the indicated item in the indicated statement so that it is not reference modified. _________________ Regards,
Anuj |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Tue Oct 06, 2009 10:32 am Post subject: |
|
|
Kolusu ,
Thanks a lot for your time and your logic for the code and explanation I was able to complete my task and achieve deired results and it was appreciated by client.
Thanks Anuj and Slade for your help too. |
|
Back to top |
|
 |
|
|