Hi,
I was capitalising the first letter of each word multiple times and decided to stick it in a basic sub-procedure, which I don't usually use but I can't figure out how to correctly handle variables that are smaller than the sub-procedure's input variable.
The below gets stuck in a loop due to %trim() failing as "lowerText" has the day text followed by a load of jumbled characters - clearly this is memory allocated elsewhere which I shouldn't be looking at. I'm therefore wondering what's the best way to handle this? A second "data length" variable? A better way of defining capitalise? I'd rather not use a 30a workfield to do it, i.e. alpha30 = daytext; daytext = %trim(capitalise(alpha30));
Example;
I was capitalising the first letter of each word multiple times and decided to stick it in a basic sub-procedure, which I don't usually use but I can't figure out how to correctly handle variables that are smaller than the sub-procedure's input variable.
The below gets stuck in a loop due to %trim() failing as "lowerText" has the day text followed by a load of jumbled characters - clearly this is memory allocated elsewhere which I shouldn't be looking at. I'm therefore wondering what's the best way to handle this? A second "data length" variable? A better way of defining capitalise? I'd rather not use a 30a workfield to do it, i.e. alpha30 = daytext; daytext = %trim(capitalise(alpha30));
Example;
Code:
h dftactgrp(*no) d capitalise pr 30a extproc('capitalise') d lowerText 30a options(*varsize) d dayText s 3a /free dayText = 'sun'; dayText = capitalise(dayText); dsply dayText; *inlr = *on; return; /end-free p capitalise b d capitalise pi 30a d lowerText 30a options(*varsize) d char s 1a inz(*off) d forever s n inz(*off) d startPos s 2p 0 d lo c 'abcdefghijklmnopqrstuvwxyz' d up c 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /free startPos = 0; dou forever; startPos += 1; %subst(lowerText : startPos : 1) = %xlate(lo:up:%subst(lowerText : startPos : 1)); startpos = %scan(' ' : %trim(lowerText) : startPos); if startPos = 0; leave; endif; enddo; return lowerText; /end-free p capitalise e
Comment