July 08, 2008, 10:06 AM
hammo1jDEFINE FUNCTION with variable length return
Trying to write function using DEFINE FUNCTION
NOCRLF(inlen,indata) to remove CR and LF
eg CLEANSTR/A67 = NOCRLF(67,PART_NO) ;
Cannot see how to code a variable return format eg for TEMP and NOCRLF
DEFINE FUNCTION NOCRLF(INLEN, INDATA/A256) ;
TEMP/A67 = STRREP (INLEN,INDATA, 1, HEXBYT(13, 'A1'), 1, ' ',INLEN, TEMP);
NOCRLF/A67 = STRREP(INLEN,TEMP, 1, HEXBYT(10, 'A1'), 1, ' ', INLEN, NOCRLF);
END
Anybody know how to do this?
July 08, 2008, 11:15 AM
Tony AJohn,
I posted a function that managed this a while back (
here). It was in response to get the RIGHT n characters from a string but it should give you some syntactical ideas?
T
July 08, 2008, 11:33 AM
Danny-SRLJohn,
Since you don't know the length of your input string you could use a variable length string. See this example:
-* File deffunc.fex
DEFINE FUNCTION NOCRLF(INLEN/I3, INDATA/A255)
TEMP/A255 = STRREP (INLEN,INDATA, 1, HEXBYT(13, 'A1'), 1, ' ',INLEN, TEMP);
NOCRLF/A255V = STRREP(INLEN,TEMP, 1, HEXBYT(10, 'A1'), 1, ' ', INLEN, NOCRLF);
END
DEFINE FILE CAR
MODEL_BODY/A40=MODEL || HEXBYT(13,'A1') || HEXBYT(10,'A1') || BODYTYPE;
END
TABLE FILE CAR
PRINT MODEL_BODY
BY COUNTRY
BY CAR
ON TABLE HOLD
END
SAVE AS SAVECRLF
!TYPE SAVECRLF.FTM
-RUN
DEFINE FILE HOLD
TEMP/A40=NOCRLF(40, MODEL_BODY);
END
TABLE FILE HOLD
PRINT TEMP
BY COUNTRY
BY CAR
ON TABLE SAVE
END
-RUN
!TYPE SAVE.FTM