Is there an Easytrieve function to reverse the order of the characters in a string?

Document ID : KB000044591
Last Modified Date : 14/02/2018
Show Technical Document Details

Question: 

Is there an Easytrieve function to reverse the order of the characters in a string?

 

Answer: 

No, there is no Easytrieve function to reverse the order of the characters in a string.

 

Additional Information:

But perhaps a CA Easytrieve macro as follows can already meet your needs. This is no official CA solution. It's just a simple example how that could be done and it could be improved of course.

In the following Easytrieve sample source, a macro (EZTREV) will be called with a field length and a field name as parameters.

 

DEFINE TEST-FIELD1     W 20 A VALUE 'ABCDEFGHI 1234567890'  

*                                                            

JOB INPUT NULL                                              

*                                                           

DISPLAY 'BEFORE EZTREV MACRO:'                              

DISPLAY 'TEST-FIELD1: ' TEST-FIELD1                          

*  

* calling EZTREV macro with two parms -

* the length of the field and the field name:                                                        

%EZTREV 20 TEST-FIELD1                                      

*                                                           

DISPLAY ' '

DISPLAY 'AFTER EZTREV MACRO:'                                

DISPLAY 'TEST-FIELD1: ' TEST-FIELD1                         

*                                                           

STOP  

 

If compiling and running this example you'll see:

 

BEFORE EZTREV MACRO:

TEST-FIELD1: ABCDEFGHI 1234567890

 

AFTER EZTREV MACRO:

TEST-FIELD1: 0987654321 IHGFEDCBA

 

EZTREV macro source sample:

 

MACRO L1 WF1                                                           

*                                                                       

* ------------------------------------------------------------------- *

*                                                                     *

*     MACRO TO REVERSE A STRING                                       *

*                                                                     *

*     NAME: EZTREV                                                    *

*                                                                     *

* ------------------------------------------------------------------- *

*                                                                      

DEFINE IND1           W  3     N  VALUE &L1                             

DEFINE IND2           W  3     N  VALUE 1                                

*

DEFINE W-F1           S  &L1   A                            

DEFINE W-F1-ARRAY  W-F1  1     A  OCCURS &L1                            

*                          

DEFINE W-F2           S  &L1   A                                         

DEFINE W-F2-ARRAY  W-F2  1     A  OCCURS &L1                            

*                                                                      

W-F1 = &WF1

*

DO WHILE IND1 GE 1                                                    

   MOVE W-F1-ARRAY(IND1) TO W-F2-ARRAY(IND2)                          

   IND1 = IND1 - 1                                                    

   IND2 = IND2 + 1                                                    

END-DO                                                                 

*

&WF1 = W-F2

*                                                                      

MEND