Add SRV_STR Stuff

This commit is contained in:
SJLennon
2020-10-03 15:18:23 -04:00
parent 8daf3e8953
commit 74f2e263d1
6 changed files with 146 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
//==============================================================
//=== SRV_STR service program contains procedures working
//=== with strings
//==============================================================
// CRTRPGMOD MODULE(SRV_STR)
// CRTSRVPGM SRVPGM(SRV_STR) EXPORT(*ALL)
// ADDBNDDIRE BNDDIR(UTIL_BND) OBJ((SRV_STR *SRVPGM *DEFER))
//=== CenterStr ================================================
// Return the centered string. The input string is normally
// fixed length and RPG will promote it to varying on the
// call. A varying string is returned which RPG will reset
// to fixed if needed.
// It will also execute with a varying string input but the
// result may not be what you expect.
//
// Conceptual call:
//=================
// H BndDir('UTIL_BND')
// /include Demo,Srv_Str_P
// d Head S 20A inz('Inquiry')
// Head = CenterStr(Head);
// Notes:
// CenterStr is small, but it is convenient.
// Could add left and right justify, but...
// Left justify is simple in RPG:
// str = %trim(str);
// Right justify is also simple:
// evalr str = %trim(str);
h nomain option(*NoDebugIo: *srcstmt)
/include Demo,SRV_STR_P
p CenterStr b export
d CenterStr pi 256a varying
d InStr 256a varying const
d
d blanks s 256a varying inz
d trimInStr s 256a varying
/free
trimInStr = %trim(InStr);
// Set length to materialize required leading blanks.
%len(blanks) = %int((%len(inStr) - %len(trimInStr))/2);
return blanks + trimInStr;
/end-free
p CenterStr e