Friday, June 15, 2007

Removing leading zeroes from a non zero character variable

I have a character variable which accepts numeric data. If this data is non-zero, we will have to take out any leading zeroes and then pass the resulting data to an SQL statement for further processing. This is how I acheived it using free form RPG.

InUpc is the character variable.

If %Trim(InUpc) <> *Zeros; // if data is non-zero
DoW %SubSt(%Trim(InUpc):1:1) = '0'; // take out first digit if it is zero
InUpc = %SubSt(%Trim(InUpc):2);
EndDo;
EndIf;

Wednesday, June 13, 2007

Recursion example - RPG, i5

Here is an example of recursion using a procedure in RPG:


P CrtDataQ B Export

D CrtDataQ Pi

D DtaQNam 10A Const
D KeyLen 10i 0 Const
D DtaQLen 10i 0 Const Options(*NoPass)
D LibName 10A Const Options(*NoPass)
D CmdStr S 300A Inz Varying
D Library S 10A Inz('QTEMP')
D DtaQLn S 10i 0 Inz(256)

/Free
// set default values for DtaQLen and LibName...
Select;
When %Parms() = 3;
DtaQLn = DtaQLen;
When %Parms() = 4;
DtaQLn = DtaQLen;
Library = LibName;
EndSl;
CmdStr = 'CRTDTAQ DTAQ(' + %Trim(Library) + '/' + %Trim(DtaQNam) + ') MAXLEN(' + %Trim(%Char(DtaQLn)) + ') SEQ (*KEYED) KEYLEN(' + %Trim(%Char(KeyLen)) + ')';

// Monitor for the possiblity of Data queue already present
// If data queue is already present, delete it and then create.
Monitor;
ExcClCmd(CmdStr:%Len(CmdStr));
On-Error;
DltDataQ(DtaQNam);
CrtDataQ(DtaQNam:KeyLen:DtaQLn:Library); // recursion example
EndMon;

/End-Free

P CrtDataQ E

Convert date into numeric format - RPG free

StrDt is a date field into which a date is being updated. PlHBeg is a julian date in the form yyyyddd.

The code block - %SubSt(%Char(PlHBeg - 1900000):2) gets us the Julian date that is recognized by i5.

StrDt = %Date(%SubSt(%Char(PlHBeg - 1900000):2):*Jul0);

PxHBeg is an 8 digit numeric field into which we are trying to feed a date in Iso (yyyymmdd) format. We use the built in function SubDt to extract each portion of the date and with some basic calculations, we have the date converted to numeric form.

PxHBeg = %SubDt(StrDt:*Y) * 10000 + %SubDt(StrDt:*M) * 100
+ %SubDt(StrDt:*D);

Where change seems to be the only constant

A first hand account

For the first time ever, I had to visit India under rather tragic and gloomy conditions, so I had neither the inclination nor the time to indulge in the usual fun activities. But observe I did, and what a dramatic change it has been since my last visit two years back! during my last visit, I saw an attitude shift in general with people not backing off from spending and patiently lining up in front of ATM machines waiting for their chance to withdraw (spend?) some of their hard earned money. Gone were the days of trying to save for a rainy day! Just when I thought that I have seen it all, this time around, it looked like change was the only real constant. Though change was all-pervasive, it was all the more visible in the suburbia and the smaller two tier centers.

The first surprise was Bombay (Mumbai) airport. They really turned it around. What was a murky, dirty, cramped up place on my last encounter has now turned into a spacious, spick and span, well lighted airport on par with the best that India has to offer. The new immigration counters are more spacious with minimal waiting times. It took us more time waiting at the expanded and more roomy baggage claim area than in immigration. Though customs also was more streamlined, this is one area where the officers will have to be more courteous. I couldn’t help but observe that there was also a baggage re-check area for domestic connections. It is amazing what a little bit of private enterprise can do.

The once ubiquitous Ambassador seems to have all but been relegated to the history books nowadays. It looks like that tag now belongs to the Marutis and the Tatas. And it looks like the Tatas might well get hold of that tag ultimately with their Indicas and their Indigos. The once popular Sumo had already yielded to the Qualis but after Toyota decided to replace the Qualis with the Innova, it looks like the Innova is well on the way to take over that segment. You still do see the odd Camry, Accord or Civic, but they are few and far between. People perceive them to be overpriced, as they know that they are about half the cost here in the US.

And then, there is fast food. While the McDonalds, Pizza huts, Dominos and Subways are making inroads everywhere, Indian fast food has not lost its appeal. In south India, the idlis, vadas, dosas, indo-chinese and thali still hold sway, though people don’t mind venturing into a subway or a pizza hut now and then. I couldn’t help but notice that while people fret over the price of onions touching 16 rupees a kilo, they don’t care for the price when they order a foot long sub for 200 bucks or a plate of (five) fried jumbo shrimp (served on the seashore) for 300 bucks. I suppose it is the experience of dining on the sand with the waves crashing nearby that people are willing to pay for!

Retail is exploding like never before with national chains like Reliance, Subhiksha and Spencers competing with the more regional chains like Trinethra or TruMart for the same customers. Finally, more power to the customers, though at the cost of displacing a few smaller hitherto cramped stores. With Walmart and Bharti teaming up, the retail landscape can only get spicier.

It looks like real estate is also going hand in hand with the retail boom. In some places, land that used to go for 20,000 a square yard two years ago is now going for 50,000 a square yard. The immediate suburbs of Vizag, for example, are going for about 2 crores an acre (provided you can find a chunk of land that size). With the stretch of the golden quadrilateral that passes through Vizag completed, distances are no longer an issue and people are willing to go as far as 40 to 50 Kms in search of land. The result? 30 kms from Vizag, land costs near the highway range from 15 to 60 lakhs per acre depending on how far the land is from the highway. Farmers in the suburbs are benefiting from this uptick in prices as more and more of them are not being able to refuse the offers being doled out for their lands.

Almost everybody in the average family now has a cell phone. Cell phones have become the preferred choice and landlines are very rarely used. So much so that, people are even having their news delivered to their mobiles and are even starting to pay bills using SMS. Some are not backing off from buying the more expensive models. I could not believe my eyes when I saw huge lines in front of an ATM in Guntakal at 7pm. What was more surprising was that the line didn’t seem to dissipate even at 9pm!

Be it a low profile center like Guntakal or the high profile centers like Pune or Hyderabad, change is certainly in the air. No matter where I have been to in India, there is this positive outlook that permeates all sections giving way to a perception that India’s time has finally arrived. Granted that IT is still the driving force, but other sectors like pharma, tourism, biotech and entertainment are making inroads into this once exclusive club of growth drivers. It sure looks like India is all set to embark upon one more golden period.

And finally, the one bright spot on the way back to the US on Air India was that we were on time and each and every landing (Delhi, Heathrow and JFK) was perfect, without any bumps, jerks or jolts. Should say that those were among the best landings I have ever experienced.

Calculating Time difference using Free form RPG

This is how I calculate the difference between two times in minutes...

TimeDiff = %Int(%Diff(%Time(CurTime:*Hms):%Time(OrdTime:*Hms):*mn));

where Curtime and OrdTime are numeric and *mn denotes that we need the difference in minutes to be put in the TimeDiff field.