In this example, I will show you on how to use the %trim built in function, which will remove the trailing blanks.

Due to the length of my fields, I am using IBM QUILNGTX to display the text.

At the end I will have two screens, one which depicts on how the fields will display WITHOUT using %trim; and the other which displays on how the fields will display WITH using %trim.

The syntax for using %trim is:
%trim(AlphaField) ;

Program example:

*free ctl-opt dftactgrp(no) actgrp(*new);

dcl-s FirstName char(35) Inz(‘Mickey ‘) ;
dcl-s LastName char(35) Inz(‘Mouse ‘) ;
dcl-s FullName char(70) ;
dcl-s text char(150) ;
dcl-s len int(10) ;

Text = (‘First Name: ‘ + %trim(FirstName)) ;
len = %len(%trim(Text)) ;
display_Window (Text) ;

Text = (‘Last Name: ‘ + %trim(LastName)) ;
len = %len(%trim(Text)) ;
display_Window (Text) ;

Text = (‘Full Name : ‘ + %trim(FirstName) + ‘ ‘ + %trim(LastName)) ;
len = %len(%trim(Text)) ;
display_Window (text) ;

*inlr = *on ;

// ======================================================================
// Display window prototype
// Use IBM i API ‘QUILNGTX’ to dynamically show messages in a // window format rather than on the // error message line.
// ======================================================================

dcl-proc Display_Window export;
dcl-pi Display_Window ;
p_Text varchar(8192)
const; p_MsgId char(7)
Options(nopass:omit); p_MsgFile char(21)
Options(nopass:*omit);
end-pi;

dcl-ds myApiError inz qualified;
Bytes int(10) inz(%size(myApiError));
BytesAvailable int(10) inz;
ErrorID char(7) inz;
MessageData char(128) inz;
end-ds;

dcl-pr QUILNGTX extpgm(‘QUILNGTX’);
*n char(8192) const; // MsgText
*n int(10) const; // MsgLength
*n char(7) const; // MessageId
*n char(21) const; // MessageFile
*n options( *omit: *varsize ) like( MYapierror ); // ErrorDS
end-pr;
Dcl-S Msgid like(p_MsgId) ;
Dcl-S MsgFile like(p_MsgFile) ;
If %Parms = 1;
MsgId = ‘CAE0103’; // ‘Press Enter to continue.’
MsgFile = ‘QCPFMSG *LIBL’;
Elseif %Parms = 2;
MsgId = p_MsgId;
MsgFile = ‘QCPFMSG *LIBL’;
Elseif %Parms = 3;
MsgId = p_MsgId;
MsgFile = p_MsgFile;
Endif;

// Call the program
QUILNGTX(Text : len : MsgId : MsgFile : MyApiError) ;
End-Proc ;

Posted in

Leave a Reply

Discover more from Candy Hein Consulting

Subscribe now to keep reading and get access to the full archive.

Continue reading