Supported by
Supported by Inetum

Slash O

images/thumbnail.jpg - Thumbnail

Throughout all my “SAP life” I’ve used the command /olalala to initiate the lalala transaction in a new GUI window. Until now I had never tried just writing /o. I did today. The result was interesting. Meaning, it’s the same as going to SM04 and then choosing our user. But much easier. Greetings from Abapinho

Gregarious constants

images/thumbnail.jpg - Thumbnail

If you are one of those who insert the values directly in code instead of using constants, then read no more and go and stand over there in the corner on punishment for 1 hour to learn not to be lazy. If you’ve come back from punishment or you usually use constants, then please continue reading.

Your password has expired. Change it 5 times.

images/thumbnail.jpg - Thumbnail

It is not uncommon for us to be emotionally attached to our passwords. Therefore, it is always rather painful to receive those despicable threatening notices that say “your password is going to expire”. Soon followed by the blow we receive to our heart on the appearance of the inevitable vile invective that “your password has expired.” At such times, the hurt is so great that all the muses leave us, we have imagination cramp and remain stuck there, staring and drained, emptied of any idea to help us choose our next password.

Insert variables in standard texts

images/thumbnail.jpg - Thumbnail

Everyone uses standard texts. But did you know that standard texts can have dynamic fields in the middle? SAP calls them “text symbols”. The way to do it is identical to that of the old forms of the harmful SE71, in other words wrapping them in the & symbol. Thus: &KNA1-NAME1;&. It’s really handy. I’ll show you how it’s done.

Client or Customer?

images/thumbnail.jpg - Thumbnail

Wherever you use the data element KUNNR, its descriptions is “Client”. And what if we wanted to change this field description from “Client” to “Customer”? “Customer" is so much nicer! Or let’s suppose that the company you work for is trafficking in drugs and tells you that they want “Dealer” rather than “Supplier” to appear in the LIFNR field. Obviously we can label it as we wish on screens and Z reports but what about standard transactions?

Adding buttons to the selection screen

images/thumbnail.jpg - Thumbnail

Normally, when buttons must be generated for users to click, Screen Painter is used to create a screen which is then invoked by the report using CALL SCREEN. But, unless the screen being designed is already quite complex it is pointless creating a screen which will have no further use. Screens have always annoyed me.

I will demonstrate an example of using buttons on a completely normal selection screen resorting to a button called PUSHBUTTON and a very clever trick called ONLI.

Fill up the selection screen with cartoons

images/thumbnail.jpg - Thumbnail

Was SAP born miserable or are SAP-users simply unable to cheer it up?

The truth is that SAP GUI is no rainbow and neither does looking at it bring happiness. Even so, it puts at our disposal a bunch of cartoons that we may use to make it just a little more uplifting.

And take a look at just how easy it is.

Oh time turn back

images/thumbnail.jpg - Thumbnail

“Oh time turn back Give me everything I have lost Take pity and give me the life The life I have already lived Oh time turn backward Kill off my futile hopes Look how even the sun itself Returns every morning” – António Mourão

Hey Tony, right away. I will show you how you can turn back time.

Search object attributes in an internal table

images/thumbnail.jpg - Thumbnail

There are increasingly more objects in ABAP, gradually less fear of them and, lo and behold, more and more people are writing and using them. It is normal and desirable, if objects begin to appear everywhere, to start to stuff them into internal tables. I also stored a load of objects in tables a while back, unfortunately I did not know at that time what I am going to teach you here. It could have come in handy.

So, what exactly am I going to teach you here?

Implementing private methods in BADIs

images/thumbnail.jpg - Thumbnail

A little while ago I had an idea as eccentric as it was amazing that today I have decided to share here, namely, how to create private methods in BADI classes.

Let me explain.

How to sabotage tables

images/thumbnail.jpg - Thumbnail

Another article to help those who are into sneaky subversion Spies, take note on how to edit a table that cannot be (and probably shouldn’t be) edited. I’ll show you three techniques. The first stopped being useful a few years ago, the second is about to become obsolete and the third, well, we’ll just have to see for how long it will work. 1. SE16 /H OK_CODE EDIT The first technique dates back to the twentieth century and uses the old transaction SE16.

F1 + F9 = Technical Information

images/thumbnail.jpg - Thumbnail

In a functional screen I often feel the need to see technical information about a particular field. I place the cursor on the field I want, then I click on F1 and a dialog screen will appear with help for that field. Then I click on the button that says “technical information”.But there is a quick way to do the same thing using only the keyboard. There are two possible ways for F1 to display the help for one specific field:

When an internal table is not structured

images/thumbnail.jpg - Thumbnail

When you want to select some lines in an internal table you normally do something like this: DATA: BEGIN OF itbl, campo1 TYPE c, campo2 TYPE c, END OF itbl. READ TABLE itbl WITH KEY campo1 = 'X' campo2 = 'Y'. LOOP AT itbl WHERE campo1 = 'X' and campo2 = 'Y'. COISO. ENDLOOP. But what if the table is not structured and you want to search on the line as a whole?

Create test variants within functions from the debugger

images/thumbnail.jpg - Thumbnail

Imagine that you are debugging a transaction, you enter into a function and find something interesting. So interesting that you have to debug it several times. The conventional way is to start the debug of the transaction again from the beginning. How tedious.

But there is a more direct route. When you are debugging a function you can create test data for this function directly from the debugger, using the values with which the function had been called at that time. For instance:

Sending a report or spool job by email

images/thumbnail.jpg - Thumbnail

This post inaugurates a new category in Abapinho: Code. Posts in this category will present useful programs that are ready to execute.

This one is used for sending the result of any report or spool order by e-mail. This program makes use of the new BCS (Business Communication Services) through the CL_BCS class instead of the tired and old SO_DOCUMENT_SEND_API1, may its soul rest in peace.

The content can be sent in the body of the email, as a TXT attachment or as an HTML attachment, with the latter being sent nice and neat with all the colours. Enjoy it. Blindly copy it and use it or dissect it and learn how to use CL_BCS. On the way, you can still learn, if you feel like it, how to use local classes and exception classes.

A local class is simpler to show here in Abapinho but if you want you can transform it into a global class through SE24 as Abapinho already explained some time ago so that you can use it anywhere.

*&---------------------------------------------------------------------*
*& Report ZZZ_NFG_SEND_REPORT_BY_EMAIL
*&
*&---------------------------------------------------------------------*
*& Author: Nuno Godinho
*& Date:   03 January 2012
*& Description: Sends an abap list (generated by a submitted program or
*&              read from an existing spool) by email. The list can be
*&              sent either in the email body, as a text attachment or
*&              as an HTML attachment.
*&---------------------------------------------------------------------*
REPORT zzz_nfg_send_list_by_mail MESSAGE-ID so.

***************************************************************************

* Exception classes
CLASS zcx_zs_no_receivers
  DEFINITION FINAL INHERITING FROM cx_static_check.
ENDCLASS.
CLASS zcx_zs_spool_error
  DEFINITION FINAL INHERITING FROM cx_static_check.
ENDCLASS.
CLASS zcx_zs_invalid_parameters
  DEFINITION FINAL INHERITING FROM cx_static_check.
ENDCLASS.
CLASS zcx_zs_objectlist_error
  DEFINITION FINAL INHERITING FROM cx_static_check.
ENDCLASS.

*----------------------------------------------------------------------*
*       CLASS cl_send_list_by_mail DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_send_list_by_mail DEFINITION.
  PUBLIC SECTION.
    TYPES: ty_send_mode TYPE char4,
           ty_source    TYPE char6.

    CONSTANTS:
      k_send_mode_text        TYPE ty_send_mode VALUE 'TEXT',
      k_send_mode_text_attach TYPE ty_send_mode VALUE 'TXTA',
      k_send_mode_html_attach TYPE ty_send_mode VALUE 'HTMA',
      k_send_mode_attachment  TYPE ty_send_mode VALUE space,

      k_source_submit         TYPE ty_source    VALUE 'SUBMIT',
      k_source_spool          TYPE ty_source    VALUE 'SPOOL'.

    METHODS:
      constructor
        RAISING
          cx_send_req_bcs,

      add_recipient
        IMPORTING
          i_smtp_address TYPE ad_smtpadr
        RAISING
          cx_send_req_bcs
          cx_address_bcs,

      submit_and_send_mail
        IMPORTING
          i_report       TYPE program
          i_variant      TYPE raldb_vari
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          cx_bcs
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          zcx_zs_spool_error,

      read_spool_and_send_mail
        IMPORTING
          i_spool_number TYPE rspoid
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          cx_send_req_bcs
          cx_bcs
          zcx_zs_spool_error.

  PRIVATE SECTION.
    DATA: go_send_request       TYPE REF TO cl_bcs.

    METHODS:
      get_objectlist_and_send_mail
        IMPORTING
          i_source       TYPE ty_source
          i_report       TYPE program OPTIONAL
          i_variant      TYPE raldb_vari OPTIONAL
          i_spool_number TYPE rspoid OPTIONAL
          i_send_mode    TYPE ty_send_mode
          i_subject      TYPE so_obj_des
          i_smtp_address TYPE ad_smtpadr OPTIONAL
        RAISING
          zcx_zs_no_receivers
          zcx_zs_invalid_parameters
          zcx_zs_objectlist_error
          cx_bcs
          zcx_zs_spool_error,

      submit_report_to_memory
        IMPORTING
          value(i_report)     TYPE program
          value(i_variant)    TYPE raldb_vari
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_objectlist_error,

      read_spool_to_memory
        IMPORTING
          i_spool_number     TYPE rspoid
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_spool_error,

       get_objectlist
        IMPORTING
          i_source       TYPE ty_source
          value(i_report)     TYPE program
          value(i_variant)    TYPE raldb_vari
          i_spool_number     TYPE rspoid
        RETURNING
          value(ot_listobject) TYPE table_abaplist
        RAISING
          zcx_zs_spool_error
          zcx_zs_objectlist_error,

       create_text_document
         IMPORTING
           i_report       TYPE program
           i_variant      TYPE raldb_vari
           i_spool_number TYPE rspoid
           i_subject      TYPE so_obj_des
           it_listobject  TYPE table_abaplist OPTIONAL
         RETURNING
           value(o_document)    TYPE REF TO cl_document_bcs
         RAISING
           zcx_zs_objectlist_error
           cx_document_bcs,

       add_header_to_body
         IMPORTING
           i_report       TYPE program
           i_variant      TYPE raldb_vari
           i_spool_number TYPE rspoid
         CHANGING
           xt_soli TYPE soli_tab,

      add_abaplist_text_attach
        IMPORTING
          it_listobject   TYPE table_abaplist
          i_name          TYPE so_obj_des
        CHANGING
          x_document      TYPE REF TO cl_document_bcs
        RAISING
          zcx_zs_objectlist_error
          cx_document_bcs,

      add_abaplist_html_attach
        IMPORTING
          it_listobject   TYPE table_abaplist
          i_name          TYPE so_obj_des
        CHANGING
          x_document      TYPE REF TO cl_document_bcs
        RAISING
          cx_document_bcs,

      send_mail
        IMPORTING
          value(it_listobject) TYPE table_abaplist
          i_report      TYPE program OPTIONAL
          i_variant     TYPE raldb_vari OPTIONAL
          i_spool_number TYPE rspoid OPTIONAL
          i_send_mode   TYPE ty_send_mode
          i_subject     TYPE so_obj_des
        RAISING
          zcx_zs_objectlist_error
          zcx_zs_invalid_parameters
          cx_bcs,

      build_attach_name
        IMPORTING
          i_report    TYPE program
          i_variant   TYPE raldb_vari
          i_spool_number TYPE rspoid
          i_extension TYPE so_obj_des OPTIONAL
        RETURNING value(o_name) TYPE so_obj_des.

ENDCLASS.                    "cl_send_list_by_mail DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_send_list_by_mail IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_send_list_by_mail IMPLEMENTATION.

  METHOD constructor.
*   Create the send request
    go_send_request = cl_bcs=>create_persistent( ).
    go_send_request->set_send_immediately( 'X' ).
  ENDMETHOD.                    "constructor

  METHOD add_recipient.
    DATA: recipient TYPE REF TO if_recipient_bcs.
    recipient = cl_cam_address_bcs=>create_internet_address( i_smtp_address ).
    go_send_request->add_recipient( recipient ).
  ENDMETHOD.                    "add_receiver

  METHOD submit_and_send_mail.
    get_objectlist_and_send_mail(
              i_source       = k_source_submit
              i_send_mode    = i_send_mode
              i_report       = i_report
              i_variant      = i_variant
              i_subject      = i_subject ).
  ENDMETHOD.                    "submit_report_and_sendmail

  METHOD read_spool_and_send_mail.
    get_objectlist_and_send_mail(
              i_source       = k_source_spool
              i_send_mode    = i_send_mode
              i_spool_number = i_spool_number
              i_subject      = i_subject ).
  ENDMETHOD.                    "read_spool_and_send_mail

  METHOD get_objectlist_and_send_mail.
    DATA: t_recipients TYPE bcsy_re,
          t_listobject TYPE table_abaplist.

*   Check parameters
    IF ( i_source = k_source_spool AND i_spool_number IS INITIAL ) OR
       ( i_source = k_source_submit AND i_report IS INITIAL ).
      RAISE EXCEPTION TYPE zcx_zs_invalid_parameters.
    ENDIF.

*   Add recipient if supplied
    IF i_smtp_address IS SUPPLIED.
      add_recipient( i_smtp_address ).
    ENDIF.

*   It should only run if there is at least one recipient
    t_recipients = go_send_request->recipients( ).
    IF t_recipients[] IS INITIAL.
      RAISE EXCEPTION TYPE zcx_zs_no_receivers.
    ENDIF.

*   Get objectlist either from submit or from spool
    t_listobject = get_objectlist(
      i_source       = i_source
      i_report       = i_report
      i_variant      = i_variant
      i_spool_number = i_spool_number ).

*   Send email
    CALL METHOD send_mail
      EXPORTING
        it_listobject  = t_listobject
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        i_send_mode    = i_send_mode
        i_subject      = i_subject.
  ENDMETHOD.                    "get_objectlist_and_send_mail

  METHOD get_objectlist.
*   Get abap list into memory (either from spool or submit)
    IF i_source = k_source_submit.
      submit_report_to_memory( i_report  = i_report i_variant = i_variant ).
    ELSE.
      read_spool_to_memory( i_spool_number = i_spool_number ).
    ENDIF.

*   Import the list from memory and store it in table listobject
    REFRESH : ot_listobject.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = ot_listobject
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

*   Free memory
    CALL FUNCTION 'LIST_FREE_MEMORY'
      TABLES
        listobject = ot_listobject
      EXCEPTIONS
        OTHERS     = 1.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

  ENDMETHOD.                    "get_objectlist

  METHOD submit_report_to_memory.
    TRANSLATE: i_report  TO UPPER CASE,
               i_variant TO UPPER CASE.
*   Submit report
    SUBMIT (i_report) USING SELECTION-SET i_variant EXPORTING LIST TO MEMORY AND RETURN.
  ENDMETHOD.                    "submit_report

  METHOD read_spool_to_memory.
*   Adapted from FM RSPO_RETURN_ABAP_SPOOLJOB. This FM converts the list to ASCII
*   and I needed it as an ABAPLIST so I just copied the code and adapted it
    DATA: data_is_otf TYPE c.

    CALL FUNCTION 'RSPO_CHECK_JOB_ID_PERMISSION'
      EXPORTING
        rqident       = i_spool_number
        access        = 'DISP'
      EXCEPTIONS
        no_such_job   = 1
        no_permission = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ENDIF.

    CALL FUNCTION 'RSPO_GET_TYPE_SPOOLJOB'
      EXPORTING
        rqident        = i_spool_number
      IMPORTING
        is_otf         = data_is_otf
      EXCEPTIONS
        can_not_access = 1.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ENDIF.

    IF data_is_otf = 'X'.
      RAISE EXCEPTION TYPE zcx_zs_spool_error.
    ELSE.
      SUBMIT rspolist EXPORTING LIST TO MEMORY AND RETURN
                      WITH rqident = i_spool_number
                      WITH first = 1
                      WITH last = 0
                      WITH pages = space.
    ENDIF.
  ENDMETHOD.                    "read_spool

  METHOD send_mail.

    DATA: document       TYPE REF TO cl_document_bcs,
          sent_to_all    TYPE os_boolean,
          bcs_exception  TYPE REF TO cx_bcs,
          name           TYPE so_obj_des.

    IF i_send_mode = k_send_mode_text.
      document = create_text_document(
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        it_listobject  = it_listobject
        i_subject      = i_subject ).
    ELSE.
*     Create text document without adding listobject to the body (it will be attached)
      document = create_text_document(
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
        i_subject      = i_subject ).
*     Add attachment to document
      IF i_send_mode = k_send_mode_text_attach.
        name = build_attach_name(
          i_report       = i_report
          i_variant      = i_variant
          i_spool_number = i_spool_number
          i_extension    = 'TXT' ).
        add_abaplist_text_attach(
           EXPORTING
             it_listobject = it_listobject
             i_name        = name
          CHANGING
            x_document = document ).
      ELSEIF i_send_mode = k_send_mode_html_attach.
        name = build_attach_name(
          i_report       = i_report
          i_variant      = i_variant
          i_spool_number = i_spool_number ).
        add_abaplist_html_attach(
           EXPORTING
             it_listobject = it_listobject
             i_name        = name
          CHANGING
            x_document = document ).
      ENDIF.
    ENDIF.

*   Add document to send request
    go_send_request->set_document( document ).

*   Send
    sent_to_all = go_send_request->send( i_with_error_screen = 'X' ).
*    IF sent_to_all NE 'X'.
*      RAISE EXCEPTION TYPE zcx_zs_mail_not_sent.
*    ENDIF.

  ENDMETHOD.                    "send_mail

  METHOD create_text_document.
    DATA: t_listasci   TYPE STANDARD TABLE OF solisti1,
          t_listobject LIKE it_listobject,
          t_soli       TYPE soli_tab,
          w_soli       LIKE LINE OF t_soli.

*   Add header
    add_header_to_body(
      EXPORTING
        i_report       = i_report
        i_variant      = i_variant
        i_spool_number = i_spool_number
      CHANGING
        xt_soli = t_soli ).

*   Add abap list
    IF it_listobject IS SUPPLIED.

      CLEAR w_soli.
      APPEND w_soli TO t_soli.
      w_soli = '------------------------------------------------------'.
      APPEND w_soli TO t_soli.
      CLEAR w_soli.
      APPEND w_soli TO t_soli.

      t_listobject[] = it_listobject[].
      CALL FUNCTION 'LIST_TO_ASCI'
        TABLES
          listasci           = t_listasci
          listobject         = t_listobject
        EXCEPTIONS
          empty_list         = 1
          list_index_invalid = 2
          OTHERS             = 3.
      IF sy-subrc <> 0.
        RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
      ENDIF.
      APPEND LINES OF t_listasci TO t_soli.
    ENDIF.

*   Create text document
    o_document = cl_document_bcs=>create_document(
                            i_type    = 'RAW'
                            i_text    = t_soli
                            i_subject = i_subject ).
  ENDMETHOD.                    "create_text_document

  METHOD add_header_to_body.
    DATA: w_soli LIKE LINE OF xt_soli.

    IF i_report IS NOT INITIAL.
      CONCATENATE 'Report:' i_report INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    IF i_variant IS NOT INITIAL.
      CONCATENATE 'Variant:' i_variant INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    IF i_spool_number IS NOT INITIAL.
      MOVE i_spool_number TO w_soli.
      CONCATENATE 'Spool number:' w_soli INTO w_soli SEPARATED BY space.
      APPEND w_soli TO xt_soli.
    ENDIF.

    CONCATENATE 'Date:' sy-datum sy-uzeit INTO w_soli SEPARATED BY space.
    APPEND w_soli TO xt_soli.

    CONCATENATE 'User:' sy-uname INTO w_soli SEPARATED BY space.
    APPEND w_soli TO xt_soli.

  ENDMETHOD.                    "build_header

  METHOD add_abaplist_text_attach.
    DATA: t_solix TYPE solix_tab.

*   It's always necessary to compress the table. SAPconnect will decompress it
    CALL FUNCTION 'TABLE_COMPRESS'                          "#EC *
      TABLES
        in             = it_listobject
        out            = t_solix
      EXCEPTIONS
        compress_error = 1
        OTHERS         = 2.
    IF sy-subrc <> 0.
      RAISE EXCEPTION TYPE zcx_zs_objectlist_error.
    ENDIF.

    x_document->add_attachment(
      i_attachment_type    = 'ALI'
      i_attachment_subject = i_name
      i_att_content_hex    = t_solix ).

  ENDMETHOD.                    "add_abaplist_text_attach

  METHOD add_abaplist_html_attach.
    DATA: t_soli       TYPE soli_tab,
          t_listobject LIKE it_listobject.

    t_listobject[] = it_listobject[].

    CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
      TABLES
        html       = t_soli
        listobject = t_listobject.

    x_document->add_attachment(
      i_attachment_type    = 'HTM'
      i_attachment_subject = i_name
      i_att_content_text   = t_soli ).

  ENDMETHOD.                    "add_abaplist_html_attach

  METHOD build_attach_name.
    IF i_report IS NOT INITIAL.
      o_name = i_report.
      IF i_variant IS NOT INITIAL.
        CONCATENATE o_name '-' i_variant INTO o_name.
      ENDIF.
    ELSE.
      MOVE i_spool_number TO o_name.
      SHIFT o_name LEFT DELETING LEADING space.
    ENDIF.
    CONCATENATE o_name '-' sy-datum '-' sy-uzeit INTO o_name.
    IF i_extension IS NOT INITIAL.
      CONCATENATE o_name '.' i_extension INTO o_name.
    ENDIF.
  ENDMETHOD.                    "build_attach_name

ENDCLASS.                    "cl_send_list_by_mail IMPLEMENTATION

***************************************************************************
TABLES: adr6.

*------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_subj TYPE so_obj_des OBLIGATORY.
SELECT-OPTIONS: s_rec  FOR adr6-smtp_addr NO INTERVALS LOWER CASE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_submit RADIOBUTTON GROUP typ USER-COMMAND typ.
SELECTION-SCREEN BEGIN OF BLOCK b2a WITH FRAME.
PARAMETERS:     p_rep  TYPE program MODIF ID ty1,
              p_var  TYPE raldb_vari MODIF ID ty1.
SELECTION-SCREEN END OF BLOCK b2a.
PARAMETERS: p_spool RADIOBUTTON GROUP typ.
SELECTION-SCREEN BEGIN OF BLOCK b2b WITH FRAME.
PARAMETERS:   p_rspoid TYPE rspoid MODIF ID ty2.
SELECTION-SCREEN END OF BLOCK b2b.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_text  RADIOBUTTON GROUP opt,
            p_texta RADIOBUTTON GROUP opt,
            p_htmla RADIOBUTTON GROUP opt DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b3.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-group1 = 'TY1'.
      IF p_submit IS NOT INITIAL.
        screen-input = 1.
      ELSE.
        screen-input = 0.
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
    IF screen-group1 = 'TY2'.
      IF p_spool IS NOT INITIAL.
        screen-input = 1.
      ELSE.
        screen-input = 0.
      ENDIF.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.

  DATA: go_sender TYPE REF TO cl_send_list_by_mail,
        send_mode TYPE cl_send_list_by_mail=>ty_send_mode,
        exc_ref   TYPE REF TO cx_root,
        text      TYPE string.

  IF ( p_submit IS NOT INITIAL AND p_rep IS INITIAL ) OR
     ( p_spool IS NOT INITIAL AND p_rspoid IS INITIAL ).
    MESSAGE s622 DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

  CREATE OBJECT go_sender.

* Determine send mode
  CASE 'X'.
    WHEN p_texta.
      send_mode = cl_send_list_by_mail=>k_send_mode_text_attach.
    WHEN p_htmla.
      send_mode = cl_send_list_by_mail=>k_send_mode_html_attach.
    WHEN OTHERS.
      send_mode = cl_send_list_by_mail=>k_send_mode_text.
  ENDCASE.

* Add recipients
  LOOP AT s_rec.
    CALL METHOD go_sender->add_recipient
      EXPORTING
        i_smtp_address = s_rec-low.
  ENDLOOP.

  TRY.
      CASE 'X'.
        WHEN p_submit.
          CALL METHOD go_sender->submit_and_send_mail
            EXPORTING
              i_send_mode = send_mode
              i_report    = p_rep
              i_variant   = p_var
              i_subject   = p_subj.
        WHEN p_spool.
          CALL METHOD go_sender->read_spool_and_send_mail
            EXPORTING
              i_send_mode    = send_mode
              i_spool_number = p_rspoid
              i_subject      = p_subj.
      ENDCASE.
      WRITE: / 'Mail message sent'.
    CATCH cx_root INTO exc_ref.
      text = exc_ref->get_text( ).
      WRITE: / text.
  ENDTRY.

* It will not work without this commit
  COMMIT WORK.

Texts for selection screen:

P_SUBJ Subject

S_REC| Recipients

P_SUBMIT| Send report

P_REP| Report

P_VAR| Variant

P_SPOOL| Send spool job

P_RSPOID| Spool job ID

P_TEXT| Email body

P_TEXTA| TXT attachment

P_HTMLA| HTML attachment

Greetings from Abapinho.