Skip to end of metadata
Go to start of metadata

Introduction

Standard text is used when we need the text to be reusable. We can create our own standard texts or use the existing text if it is satisfying our purpose. These texts are globally stored and we can access these texts anywhere within any program. If we find a particular text to be repeated often we can create the text in a standard text module and use it instead of typing it each and every where. Usually we create standard texts for printing documents or inserting content of the mail body in such scenarios it’s better to go for standard texts.

Now let us see the step by step process of creating a standard text and how to access it.

Steps for Creating a Text Editor

Step1: Opening the text Editor

SO10 is the transaction for creating standard text. Enter SO10 transaction in the command prompt and press enter the first screen appears as shown below.
In the Text Name field enter the name of the standard text which we are going to create.
After entering the name as shown in the above screen press on the create button available. Next screen appears as shown below.
In the space provided we can enter the text which we needed and can save the standard text as shown below.

Step2: Entering text in the Standard Text Editor

We have various options for formatting the text which we will be discussed below. We will not be able to see the preview in the same screen but we can see the preview in print preview by selecting Text-> Print Preview option in the menu bar.

We also have a different text editor. Which we can use for entering and editing the text. But the difference is that we will be able to see the alignment in the same screen where we enter the text. To see the other editor we need to click GOTO -> Change Editor. Then we will be able to see the actual output.

Now let us see the various formatting options which we can use.

Formatting Options Available with Text Editor

The figure below shows you the various formatting options available along with the standard text editor

.
Now we can see few examples for the various formatting options. The formatting options are quite familiar to the user. Now let us see how the output will look like with the formatting options.

Now we can see each of the formatting options with an example.

Explanation for the above formats

’         Default Paragraph*

Is the default paragraph we will get the output or display as we there won’t be any change in alignment it will be defaulted.

B          Paragraph Justified

Is used when the paragraph needs to be justified. The paragraph which is given with this formatting option will be justified in the output.

Space   Continuous Text

Is used to define continuous text i.e. when we need two or more lines in a same paragraph we can mention it as a continuous text by just specifying space in the format option.

We can define the format for the paragraph as shown below

 
And the preview or the text in the output will appear as shown,
C          Centered

 Is used to align the paragraph to center. So in the preview we can see the paragraph will be centre aligned.

L          Paragraph Left Aligned

Is to align the paragraph to left.

We can specify the alignment as shown below.

 
The text in the output will appear as shown below,
=          Extended Line

Is used when we need to extended the line. When we want the current line to be displayed following the preceding line we can use this. This is similar to ‘space’ formatting option but if we give space the line will get appended to the previous line at the editing mode itself. But if we need the line to be appended to the preceding line only at the output we can go for this option.

(           Raw line  

We use this formatting option when we want to follow the same paragraph format as use previously. i.e. when we need to adapt the same paragraph format of the previous paragraph used we go for this option. When we use this option the next line will also be append to the previous line.

We can specify the formatting as shown below.

 
It looks like this when we just enter the text but after we press enter or save button the screen looks as shown below .
The second line of second paragraph is appended to its previous line. (Which will be indicated using a small symbol ‘>’at the end of the first line).  Now the output will be as shown
/           Line Feed

Using this formatting option will display the text in the next line. It’s not related to formatting it performs the normal function as we use in write statement to print the statement in next line

/=         Line Feed and Extended Line

This is same line extended line option but what it does is, it displays the content of the current line in the next line.

We can specify the formatting option as shown,

 

The output will be as shown


/(          Line Feed and Raw Line

This is same like raw line but when we want the preceding line to be displayed at the next line and we want only the paragraph format of the previous paragraph to be imported we can use this option.

We can specify the formatting option as shown,

  

The output will be as shown


/:          Command Line

We use this when we use come command lines for our better understanding. These lines are not interpreted. The command line must end with in a single line. Once we specify the line in this format the contents of this line will be converted to caps.

/          Comment Line*

We use this when we need to write comments, like we write in our normal programs. These statements will not be executed or interpreted this only for our understanding.

We can specify the format as shown,

 

The output will be as shown,

Example: Using a Standard Text Editor Content in Mail Body

Now let us create a simple E-mail application of creating a standard text and read the text with a function module and use it in an E-mail body.

Now let us consider the below example

 
We can read this standard text using a function module and we can use it in an email body.

Read the text using a function module ‘READ_TEXT’. The sample code is shown below,

CALL FUNCTION 'READ_TEXT'
    EXPORTING
      client                  = sy-mandt
      id                      = 'ST'                   "Standard Text
      language                = sy-langu               "System Language
      name                    = 'Z02EXAMPLE'           “Name of Standard Text
      object                  = 'TEXT'
    TABLES
      lines                   = t_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 <> 0.
    RETURN.
  ENDIF.

  LOOP AT t_lines INTO x_lines WHERE tdformat NE '/*'.
    APPEND x_lines-tdline TO t_body.
  ENDLOOP.

 Now the table t_body will be having the contents of the standard text. This can be directly used in the email body.

The example program code for reading the standard text and using it in email is shown below,

REPORT  Z02_EXAMPLE.

DATA  : x_lines TYPE tline.
DATA  : t_lines TYPE tline_t.
data  : t_BODY  TYPE soli_tab.

  REFRESH: t_body.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      client                  = sy-mandt
      id                      = 'ST' "Standard Text
      language                = sy-langu "System Language
      name                    = 'Z02EXAMPLE'
      object                  = 'TEXT'
    TABLES
      lines                   = t_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 <> 0.
    RETURN.
  ENDIF.

  LOOP AT t_lines INTO x_lines WHERE tdformat NE '/*'.
    APPEND x_lines-tdline TO t_body.
  ENDLOOP.

  DATA: v_send_request    TYPE REF TO cl_bcs,            " E-Mail Send Request
        v_document        TYPE REF TO cl_document_bcs,   " E-Mail Attachment
        v_sender          TYPE REF TO if_sender_bcs,     " Address of Sender
        v_recipient       TYPE REF TO if_recipient_bcs,  " Distribution List
        v_bcs_exception   TYPE REF TO cx_document_bcs,   " BCS Exception
        v_send_exception  TYPE REF TO cx_send_req_bcs,   " E-Mail sending Exception
        v_addr_exception  TYPE REF TO cx_address_bcs.    " Address Exception

  DATA : v_result  TYPE  sy-binpt,
         v_message TYPE  string,
         v_sub     TYPE  so_obj_des,
         v_rec     TYPE  ad_smtpadr.

  TRY.
      v_send_request = cl_bcs=>create_persistent( ).

      v_send_request->set_status_attributes(  i_requested_status = 'E' ).
* Creating Document
      IF t_body IS NOT INITIAL.
        v_sub = 'Email using Sstandard text editor as mail body'.
        v_document = cl_document_bcs=>create_document(
                                    i_type        = 'RAW'
                                    i_importance  = '5'
                                    i_text        = t_body
                                    i_subject     = v_sub ).
      ENDIF.

* Add document to send request
      CALL METHOD v_send_request->set_document( v_document ).

* Get Sender Object
      CALL METHOD v_send_request->set_sender
        EXPORTING
          i_sender = v_sender.

* E-Mail l_recipient
        v_rec = Any email address which you need to sent.
        v_recipient = cl_cam_address_bcs=>create_internet_address( v_rec ).

        CALL METHOD v_send_request->add_recipient
          EXPORTING
            i_recipient  = v_recipient
*           i_express    = ''
            i_copy       = ' '
            i_blind_copy = ' '
            i_no_forward = ' '.

* Trigger E-Mail immediately
      v_send_request->set_send_immediately( 'X' ).

      CALL METHOD v_send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = v_result ).

      COMMIT WORK.

    CATCH cx_document_bcs INTO v_bcs_exception.
      v_message = v_bcs_exception->get_text( ).
      MESSAGE v_message TYPE 'S'.

    CATCH cx_send_req_bcs INTO v_send_exception.
      v_message = v_send_exception->get_text( ).
      MESSAGE v_message TYPE 'S'.

    CATCH cx_address_bcs  INTO v_addr_exception.
      v_message = v_addr_exception->get_text( ).
      MESSAGE v_message TYPE 'S'.

  ENDTRY.

The output of this program will be as shown below,
For better understanding of the mail program you can find the article in the SDN with the name “Step by Step Process of preparing E-mail with HTML body and HTML attachment”. This will give you a clear understanding about the Email logic used.

Thanks,

Sri Hari

  • No labels