View previous topic :: View next topic |
Author |
Message |
ravi.alpha Beginner
Joined: 31 Mar 2009 Posts: 18 Topics: 7
|
Posted: Mon Aug 03, 2009 1:18 pm Post subject: Get the Length of a variable String |
|
|
Input file's records contain field ORG-DESCR, defined in COBOL program as PIC X(100). Data in this field is the name of the product's issuing company, i.e. "PINE RIDGE PLANTATION CM NTY DEV DIST FLA CAP IMP", "GRUPO FINANCIERO BBVA BANCOMER S.A. DE C.V." etc.
Data has to be stored in the DB2 column, defined as VARCHAR(100), in
each case length of the company's name is required. E.g., for "PINE
RIDGE PLANTATION CM NTY DEV DIST FLA CAP IMP" it would be 49,
for "GRUPO FINANCIERO BBVA BANCOMER S.A. DE C.V." it would be
43 etc.
1) How do you find the length of the company name in the COBOL
program?
2) Which way is more efficient and why?
Note, the name can contain any type of the EBCDIC characters and
multiple spaces between words can be expected. |
|
Back to top |
|
 |
ravi.alpha Beginner
Joined: 31 Mar 2009 Posts: 18 Topics: 7
|
Posted: Mon Aug 03, 2009 1:21 pm Post subject: |
|
|
One more
COBOL program accesses two files:
1) Product pricing file, containing product's IDs that are expressed in
various currencies
2) Currency conversion rates
Program reads pricing file and must convert prices into US Dollars, using conversion rates from the currency conversion rate file.
I.e., pricing file contains approx 2,500,000 prices in following format:
34567 123456.789 AED
23456 000567.007 AUD
56783 098760.775 EUR
Rates conversion file contains rates in the following format:
AED 3.67310
AFN 47.54000
ALL 91.34000
AMD 366.03000
ANG 1.79000
AOA 77.80600
ARS 3.80950
To convert price into US Dollars, price must be divided by corresponding
rate, i.e. for the first pricing record:
usd-price = 123456.789 / 3.67310
What is the logic to calculate USD prices in the this program?
Please provide the matching logic and the calculation of the price. |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Mon Aug 03, 2009 1:35 pm Post subject: |
|
|
Please use meaningful topics next time. _________________ ....Terry |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Mon Aug 03, 2009 1:42 pm Post subject: |
|
|
ravi.alpha,
what is wrong with you? Can't you even describe the problem in your title?  _________________ Kolusu
www.linkedin.com/in/kolusu
Last edited by kolusu on Mon Aug 03, 2009 3:01 pm; edited 1 time in total |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Mon Aug 03, 2009 1:43 pm Post subject: |
|
|
One option for determining the actual size of ORG-DESC is to use an INSPECT to determine the number of trailing blanks. See REVERSE function description in the Language Reference Manual. Knowing the number of trailing blanks and the length of ORG-DESC will give you what I think you want. _________________ ....Terry |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Mon Aug 03, 2009 3:02 pm Post subject: |
|
|
ravi.alpha,
Are these interview questions?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sat Oct 10, 2009 4:05 pm Post subject: |
|
|
Hi,
For posterity, here's my offering for a less complex, but maybe slightly less efficient solution: Code: | 01 L PIC S9(03) COMP.
INSPECT FUNCTION REVERSE(ORG-DESC) TALLYING L FOR LEADING SPACES
COMPUTE VCHAR-LEN = LENGTH OF ORG-DESC - L
MOVE ORG-DESC TO VCHAR-DATA |
I forget whether the DB2 tbl variables need a leading ":", it's been a while since I've used DB2. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
|
|