Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Mailtext (SAPscript) enrichment with program variables

ralf_wenzel_heuristika
Active Participant
0 Kudos

Hi,

I have a SAPscript text, which contains an email text, I have to send via bcs-classes. Email sending is working fine, but now I am supposed to translate some program variables within the SAPscript text.

I think "program symbols" and the FM text_symbol_replace are the right way, but which attributes such a program variable has to have to be determined?

I have to say, that my mail is sent by a method, not by a report (so, no "global" fields are available).

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Thinking aloud....

If you call a function from your method...

In the function group at the top you put your variable data.

And my test: (very crud)

Function group top include


FUNCTION y_r_eitan_tests_06.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------

   DATA: st_thead TYPE thead .

   DATA: it_lines TYPE tline_tab .

   st_thead-tdobject = 'TEXT' .
   st_thead-tdname   = 'Y_R_EITAN_01' .
   st_thead-tdid     = 'ST' .
   st_thead-tdspras  = 'E'  .

   CALL FUNCTION 'READ_TEXT'
     EXPORTING
       id                      = st_thead-tdid
       language                = st_thead-tdspras
       name                    = st_thead-tdname
       object                  = st_thead-tdobject
     IMPORTING
       header                  = st_thead
     TABLES
       lines                   = it_lines
     EXCEPTIONS
       id                      = 1
       language                = 2
       name                    = 3
       not_found               = 4
       object                  = 5
       reference_check         = 6
       wrong_access_to_archive = 7
       OTHERS                  = 8.

   IF sy-subrc NE 0 .
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
   ENDIF.

   st_makt-matnr = '1234567890' .
   st_makt-maktx = 'I am a description !!!' .

* Not used !!!!!!!!!!
*  CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
*    EXPORTING
*      header                 = st_thead
*     INIT                   = ' '
*      option_dialog          = abap_true
*      program                = sy-repid
*     REPLACE_PROGRAM        = 'X'
*     REPLACE_STANDARD       = 'X'
*     REPLACE_SYSTEM         = 'X'
*     REPLACE_TEXT           = 'X'
*     STARTLINE              = 1
*     ENDLINE                = 99999
*   IMPORTING
*     CHANGED                =
*     NEWHEADER              =
*    TABLES
*      lines                  = it_lines .

   DATA: st_options TYPE itcpo.

   st_options-tdprogram = sy-repid .

   CALL FUNCTION 'PRINT_TEXT'
     EXPORTING
       OPTIONS                  = st_options
       dialog                   = abap_true
       header                   = st_thead
     TABLES
       lines                    = it_lines
     EXCEPTIONS
       canceled                 = 1
       device                   = 2
       form                     = 3
       OPTIONS                  = 4
       unclosed                 = 5
       unknown                  = 6
       format                   = 7
       textformat               = 8
       communication            = 9
       bad_pageformat_for_print = 10
       OTHERS                   = 11.

   IF sy-subrc NE 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.




ENDFUNCTION.

Note that the use of PRINT_TEXT .

You can suspend the dialog and get your OTFDATA from there.

Regards.

33 REPLIES 33

Juwin
Active Contributor
0 Kudos

The same concept is used in POPUP_TO_CONFIRM, where the function replaces variables from a text object, using the values passed by the calling program.

Thanks,

Juwin

0 Kudos

No, POPUP_TO_CONFIRM uses a very different concept.

Jelena
Active Contributor
0 Kudos

I used READ_TEXT followed by TEXT_CONTROL_REPLACE in one of the programs, but it was a report, so no such issues. Have a look at the FM documentation. There is parameter PROGRAM that might be helpful (although I didn't quite get the documentation text, seems like a bad translation).

Also take a look at 'where used' -> Classes for this FM.

0 Kudos

Unfortunately not. I call TEXT_SYMBOL_REPLACE with parameter PROGRAM = 'ZCL.....CP', it searches in global variables (which does not exist in a class) and for that reason, my text symbol is deleted. I do have tried:

* using a local variable of the same name in my method

* using a class-data public variable of the same name in my global   class

What can I do, now?

raymond_giuseppi
Active Contributor
0 Kudos

You could use in sequence

  • DOCU_GET (message long text) or READ_TEXT (sapscript text)
  • SET_TEXTSYMBOL
  • REPLACE_TEXTSYMBOL
  • CONVERT_ITF_TO_HTML.

and send the final html in mail body

Regards,

Raymond

0 Kudos

This is the same Calling Chain, TEXT_SYMBOL_REPLACE uses.... What could I win by calling them manually?

0 Kudos

You can "manually" get yourself the fields required and pass them to sapscript using SET_TEXTSYMBOL.

0 Kudos

As you can see, the following code row shows, that TEXT_SYMBOL_REPLACE can not used in any type of classes - because a dirty assign will never run into a class:

If THIS is the way, SAP wants to power OO coding, it will fail. According to the coding, it detects ONLY "tables" (which are forbidden in classes) and "global variables" (which are also forbidden in classes). This results into the fact, that this FB will NEVER run properly, if it's called from a method.

So, I have to write a procedural function module, just for transporting my variables to this TEXT_SYMBOL_REPLACE.

I won't write here, what I shouted through the room, when I saw this, SCN would ban me.

0 Kudos

Hi,

Provided you can pass the text lines on to mail processing dynamically, and the subsequent text processing is "SapScript conform", the easiest to quickly put something together (while staying in OO) would probably be to use the trick CL_SAPSCRIPT_LONGTEXT->ADD_PLACEHOLDER_VALUES is using. Namely, prepend the text with the lines containing SapScript symbol and formatted value pair definitions.

One could verify if the subsequent processing is "SapScript conform" by adding some symbol definitions to the text manually; something like this:

The symbol table can be collected using FM TEXT_SYMBOL_COLLECT, and it's entirely up to you where the values are gonna come from. There are limitations on the length of formatted values: 60 characters, or 80 - when the value contains another symbol.

cheers

Janis

0 Kudos

I'll try this tomorrow. Thanks for your Posting.

0 Kudos

The problem is, that this method adds the DEFINEs into the text, but I don't believe, that the CL_BCS-classes will replace the symbols by the values (which you called "SAPscript conformity"

0 Kudos

The symbol replacement kind of "works" for both the attachment (I_ATTACHMENT_TYPE = 'SCR'; see TSOTD entry) and the body (I_TYPE = 'SCR'):

but:


- the result is IMO unusable, because there is no way to supply the style definition to BCS (formatting lost in SAPConnect) or the layout information;

- our SAPConnect settings would turn SapScript body into pdf anyway,

- SOST display is not correct (line breaks around variable):


However, the text so prepared can be converted using FM 'CONVERT_ITF_TO_HTML' (I_REPLACE = 'X', I_PRINT_COMMANDS = space), and would display properly in SOST (would preserve at least basic formatting):

What I have problem with is that the html (apart from the opening <html> tag) would  apparently get taken out both from the body and the attachment somewhere during sending... (I believe this is SAPConnect setup problem at our place). There are discussions on SCN about this, but, as with so many topics on SCN, I wasn't able to find a solution thus far...


"Fazit": SapScript symbol replacement would work properly on a text so prepared. How useful SapScript text would be in mail or other processing, considering the meager "API" for these texts that can be found in SAP (I would not use word "offered" here...), is... *ahem* open for debate.


Frankly, I'd be messing with SapScript text only if it's processed via PWB Application Form (or at least "naked" Smartform)...


cheers

Jānis


0 Kudos

It seems to work - with a litte problem:

CONVERT_ITF_TO_HTML creates a HTML text with surplus paragraph-tags:

How can I avoid this? There is no reason to create a special paragraph for '12345'....

0 Kudos

Hi,

No idea where the extra paragraph comes from. The TEXT_SYMBOL_REPLACE would work on a text with DEFINEs - that's what the CONVERT_ITF_TO_HTML calls internally (among other stuff; see Form REPLACE_ITF_TEXT in LSTXNF05).

cheers

Jānis

0 Kudos

The problem is, that each symbol is included in <P>-tags, which results into separate paragraphs for each symbol.

Example:

This is an example text with a symbol &xmpl&

Result from CONVERT_ITF_TO_HTML:

<P>This is an example text with a symbol</P>

<P> &xmpl&</P>

This kind of text is unusable......

Jelena
Active Contributor
0 Kudos

Ralf, I'm not sure how complex your standard text is, but maybe a simple solution would be to just read the text and do some kind of DIY symbol replacement? If it's just a few variables then simple string search/replace would do.

Or consider using something else entirely (again - depends on how complex the text is).

former_member220028
Active Contributor
0 Kudos

Hi Ralf,

i have done some replacements using CONVERT_ITF_TO_HTML.

your HTLM can just have simple formatings. as far as i know floating-text should work, never tried more than just simple symbol replacements.  i dont think something like "DEFINE" or "IF" gets translatet correctly. in this case its no sap-script, its just a simple SO10-Text that can be used for your email-Body. if you need something more complex you will have to "build" your own HTML-Code.

Maybe you can call "TEXT_SYMBOL_REPLACE" befor CONVERT_ITF_TO_HTML. looking to the interface of TEXT_SYMBOL_REPLACE looks like it would also translate SAP-SCRIPT-Statements.

Regards

Stefan Seeburger

0 Kudos

As I wrote: TEXT_SYMBOL_REPLACE does not work properly in methods, because it makes a dirty assign into the main program (which does not exist for a method).

See my posting above (  Sep 29, 2015 11:02 AM )

0 Kudos

Hi,

there is always a main programm... maybe support it to your method via interface-parameter, or do an external assign.

regards

Stefan Seeburger

0 Kudos

there is now way to make a dirty assign into a method.....

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Thinking aloud....

If you call a function from your method...

In the function group at the top you put your variable data.

And my test: (very crud)

Function group top include


FUNCTION y_r_eitan_tests_06.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------

   DATA: st_thead TYPE thead .

   DATA: it_lines TYPE tline_tab .

   st_thead-tdobject = 'TEXT' .
   st_thead-tdname   = 'Y_R_EITAN_01' .
   st_thead-tdid     = 'ST' .
   st_thead-tdspras  = 'E'  .

   CALL FUNCTION 'READ_TEXT'
     EXPORTING
       id                      = st_thead-tdid
       language                = st_thead-tdspras
       name                    = st_thead-tdname
       object                  = st_thead-tdobject
     IMPORTING
       header                  = st_thead
     TABLES
       lines                   = it_lines
     EXCEPTIONS
       id                      = 1
       language                = 2
       name                    = 3
       not_found               = 4
       object                  = 5
       reference_check         = 6
       wrong_access_to_archive = 7
       OTHERS                  = 8.

   IF sy-subrc NE 0 .
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
   ENDIF.

   st_makt-matnr = '1234567890' .
   st_makt-maktx = 'I am a description !!!' .

* Not used !!!!!!!!!!
*  CALL FUNCTION 'TEXT_SYMBOL_REPLACE'
*    EXPORTING
*      header                 = st_thead
*     INIT                   = ' '
*      option_dialog          = abap_true
*      program                = sy-repid
*     REPLACE_PROGRAM        = 'X'
*     REPLACE_STANDARD       = 'X'
*     REPLACE_SYSTEM         = 'X'
*     REPLACE_TEXT           = 'X'
*     STARTLINE              = 1
*     ENDLINE                = 99999
*   IMPORTING
*     CHANGED                =
*     NEWHEADER              =
*    TABLES
*      lines                  = it_lines .

   DATA: st_options TYPE itcpo.

   st_options-tdprogram = sy-repid .

   CALL FUNCTION 'PRINT_TEXT'
     EXPORTING
       OPTIONS                  = st_options
       dialog                   = abap_true
       header                   = st_thead
     TABLES
       lines                    = it_lines
     EXCEPTIONS
       canceled                 = 1
       device                   = 2
       form                     = 3
       OPTIONS                  = 4
       unclosed                 = 5
       unknown                  = 6
       format                   = 7
       textformat               = 8
       communication            = 9
       bad_pageformat_for_print = 10
       OTHERS                   = 11.

   IF sy-subrc NE 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.




ENDFUNCTION.

Note that the use of PRINT_TEXT .

You can suspend the dialog and get your OTFDATA from there.

Regards.

0 Kudos

And now tell me how to get the two fields into one row

0 Kudos

Hi,

If you are not joking there it is:

Regards.

0 Kudos

I am not joking - as you can see in my Posting at Oct 5, 2015 4:33 PM there are surplus <p>-Tags, that cuts my rows....

0 Kudos

After passing PRINT_TEXT, my OTFDATA-table is empty....

0 Kudos

Hi,

DATA: st_options TYPE itcpo. 

st_options-TDGETOTF = abap_true .

CALL FUNCTION 'PRINT_TEXT' 

      EXPORTING 

        OPTIONS                  = st_options 

        dialog                   = abap_false

        header                   = st_thead 

      TABLES 

       lines                    = it_lines 

      

      

See:

PRINT_TEXT - BC SAPscript: Printing with Forms - SAP Library

      

Regards.

0 Kudos

Finally, this worked very well. This was a long way to get the solution and I want to thank all of you.

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

I just noticed that you keep HTML in your standard text (I am getting old ) .

HTML is a long string (the rendering is done by the client) see CLASS cl_htm here

So in your case try:

FUNCTION y_r_eitan_tests_06.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  EXPORTING

*"     REFERENCE(EX_RESULT_STRING) TYPE  STRING

*"----------------------------------------------------------------------

  DATA: st_thead TYPE thead .

  DATA: it_lines TYPE tline_tab .

  st_thead-tdobject = 'TEXT' .

  st_thead-tdname   = 'Y_R_EITAN_01' .

  st_thead-tdid     = 'ST' .

  st_thead-tdspras  = 'E'  .

  CALL FUNCTION 'READ_TEXT'

    EXPORTING

      id                      = st_thead-tdid

      language                = st_thead-tdspras

      name                    = st_thead-tdname

      object                  = st_thead-tdobject

    IMPORTING

      header                  = st_thead

    TABLES

      lines                   = it_lines

    EXCEPTIONS

      id                      = 1

      language                = 2

      name                    = 3

      not_found               = 4

      object                  = 5

      reference_check         = 6

      wrong_access_to_archive = 7

      OTHERS                  = 8.

  IF sy-subrc NE 0 .

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .

  ENDIF.

  st_makt-matnr = '1234567890' .

  st_makt-maktx = 'I am a description !!!' .

  CALL FUNCTION 'TEXT_SYMBOL_REPLACE'

    EXPORTING

      header  = st_thead

      program = sy-repid

    TABLES

      lines   = it_lines.

  FIELD-SYMBOLS: <st_lines> LIKE LINE OF it_lines .

  ex_result_string = '' .

  LOOP AT it_lines ASSIGNING <st_lines> .

    CONCATENATE ex_result_string <st_lines>-TDLINE INTO ex_result_string SEPARATED BY ' ' .

  ENDLOOP.

ENDFUNCTION.

EX_RESULT_STRING can be converted to SOLI using CL_BCS_CONVERT .

Regards.

0 Kudos

Edited (wrong thread):

As I said: TEXT_SYMBOL_REPLACE does not work, called from a method, because it works with a dirty assign. The main program of a method is it's class, which does not allow dirty assigns.

0 Kudos

Hi,

The idea is to create an environment where TEXT_SYMBOL_REPLAC can work.

You need to pass your variable to the function as import parameters .

Those parameters needs to go to data statements defined at the top include .

A function is a program.

So

CALL FUNCTION 'TEXT_SYMBOL_REPLACE'

    EXPORTING

      header  = st_thead

      program = sy-repid (the FunctionPool name )

    TABLES

      lines   = it_lines.

   

And TEXT_SYMBOL_REPLACE will have no problem to find the variables it needs .

There is no need to do any dirty stuff .

Regards.

0 Kudos

Is this the concept of ABAP OO? That I have to call a function module from my method, using global variables?

Could it be possible, that there is NO WAY to replace text symbols within a method w/o using a function module with global (=obsolete!) variables?

0 Kudos

Hi,

I assume that SAP is not your first and only career experience .

SAP is far for being perfect .

I started programing 1973.

I started with SAP at 2006 and I am still under culture shock....

When SAP will allow for more then one line of headings in “CL_GUI_ALV_GRID”

there will be a special holiday on this planet......

Enjoy.

0 Kudos

YMMD!