Admiral
Admiral
921 views

How make a text with variables

Jump to solution

Hello again.

At the end of a process of booking a hotel need to send a mail to the end customer with the booking confirmation.
I have a pre-defined text (but can be changed) with the following format:
Booking nº @numres
Check-in: @datent
Check-out: @datsai

Is there any way I can replace the variables for their content?
The objective is the text look like this:
Booking nº 2748
Check-in: 05/20/2016
Check out: 05/25/2016

I have tried in various ways using the STRING comand and UNSTRING with the INSPECT but still could not reach the final format

Thanks

Best Regards

Alberto Ferraz

0 Likes
2 Solutions

Accepted Solutions
Admiral
Admiral

Hi,

Again a clear shot, It works perfectly.

Thank you very much.

Best Regards

Alberto Ferraz

View solution in original post

0 Likes
Admiral
Admiral

Thank you.

It also works well. Now I see what the best option will be.

View solution in original post

0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

Something like this:

      01 mytext    string  value "This is booking: @numres for checkin on @dateent and checkout on @datsai".
      01 resnum    pic 9(4) value 2748.
      01 checkin   pic x(10) value "05/20/2016".
      01 checkout  pic x(10) value "05/25/2016".
      procedure division.
          set mytext to mytext::Replace("@numres", resnum::ToString)::Replace("@dateent", checkin)::Replace("@datsai", checkout)
          display mytext

0 Likes
Admiral
Admiral

Hi,

Again a clear shot, It works perfectly.

Thank you very much.

Best Regards

Alberto Ferraz

View solution in original post

0 Likes
Micro Focus Expert
Micro Focus Expert

Another approach is to use the String::Format method with replacement variable numbers instead.

working-storage section.

01 mytext    string  value"This is booking: {0} checkin on {1} and checkout on {2}".

01 resnum    pic 9(4) value 2748.

01 checkin   pic x(10) value "05/20/2016".

01 checkout  pic x(10) value "05/25/2016".

procedure division.

     set mytext to type String::Format(mytext, resnum, checkin, checkout)

     display mytext

0 Likes
Admiral
Admiral

Thank you.

It also works well. Now I see what the best option will be.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.