Wednesday, December 13, 2017

Neue Berechtigungsgruppen für Tabellen anlegen

Einer Datenbanktabelle (transparenten Tabelle) kann ein Berechtigungsgruppe zugeordnet werden. Wenn eine neue Berechtigungsgruppe angelegt werden soll, kann dies über die Transaktion SE54 "Generierung Tabellensicht" durchgeführt werden. Auf dem Einstiegsbild wird über den Radio Button "Berechtigungsgruppe" ausgewählt. Durch den Button "Anlegen/Ändern" gelangt man in den Pflege-Dialog zum Anlegen von Berechtigungsgruppen für Tabellen.


Siehe auch: SAP Dokumentation "Berechtigungsgruppen pflegen"

Monday, December 4, 2017

Default Full Screen Container

mr_alv NEW #i_parent cl_gui_container=>screen0 ).

Thursday, May 18, 2017

Using HTML in Dynpro an react on user interactions

The report needs dynpro 2000 with a custom container 'CC' for the HTML control.

REPORT zjso_html_in_dynpro_event.

CLASS lcl_html DEFINITION.

  PUBLIC SECTION.
    CLASS-DATAmo_cc TYPE REF TO cl_gui_custom_container.
    CLASS-DATAmo_html TYPE REF TO cl_gui_html_viewer.
    CLASS-METHODSpbouser_commandleave_screen.
    CLASS-METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
      IMPORTING action frame getdata postdata query_table.

ENDCLASS.


START-OF-SELECTION.
  CALL SCREEN 2000.


*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
  SET PF-STATUS '2000'.
  SET TITLEBAR '2000'.
  lcl_html=>pbo).
ENDMODULE.


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
  lcl_html=>user_command).
ENDMODULE.


CLASS lcl_html IMPLEMENTATION.

  METHOD pbo.
    DATA lv_url TYPE text1024.
    DATA lt_html TYPE STANDARD TABLE OF text1024 WITH DEFAULT KEY.
    DATA lt_event TYPE cntl_simple_events.

    CHECK mo_cc IS NOT BOUND.
    lt_html VALUE #(
      |<!DOCTYPE html><head>| )
      |  <meta charset="utf-8">| )
      |  <title>HTML in Dynpro</title>| )
      |  <style>| )
      '    body { font-family:segoe ui, arial, helvetica; }' )
      |  </style>| )
      |<script>| )
      |function onClick(source\{| )
      |  window.location.href 'SAPEVENT:'+source.innerHTML;| )
      |\}| )
      |</script>| )
      |</head>| )

      |<body>| )
      |  <p>Helloworld!</p>| )
      |  <a href="SAPEVENT:Hyperlink">Request SAP AS</a>| )
      |  <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ef0000">red</div>| )
      |  <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ffdd00">yellow</div>| )
      |  <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#00ee00">green</div>| )
      |</body></html>| )
    ).
    mo_cc NEW #'CC' ).
    mo_html NEW #mo_cc ).

    " setup event handler for SAPEVENT from HTML control
    INSERT VALUE #eventid mo_html->m_id_sapevent  appl_event abap_true INTO TABLE lt_event.
    mo_html->set_registered_eventslt_event ).
    SET HANDLER on_sapevent FOR mo_html.

    " populate HTML control with HTML page
    mo_html->load_data(
      IMPORTING assigned_url lv_url
      CHANGING data_table lt_html
    ).
    mo_html->show_urllv_url ).

  ENDMETHOD.


  METHOD user_command.
    CASE sy-ucomm.
      WHEN 'BACK' OR 'EXIT'leave_screen)LEAVE TO SCREEN 0.
      WHEN 'BACK' OR 'EXIT'leave_screen)LEAVE PROGRAM.
    ENDCASE.
  ENDMETHOD.


  METHOD leave_screen.
    IF mo_cc IS BOUND.
      mo_cc->free).
    ENDIF.
  ENDMETHOD.

  METHOD on_sapevent.
    MESSAGE |onClick { action }| TYPE 'I'.
    " check contents of { postdata } and { query_table } in debugger
  ENDMETHOD.

ENDCLASS.

Tuesday, May 9, 2017

Update IDoc Status

    DATA ls_edi_ds TYPE edi_ds.

    CLEAR es_edidc.

    CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'
      EXPORTING
        document_number          iv_docnum
      IMPORTING
        idoc_control             es_edidc
      EXCEPTIONS
        document_foreign_lock    1
        document_not_exist       2
        document_number_invalid  3
        document_is_already_open 4
        OTHERS                   5.
    IF sy-subrc <> 0.
      CLEAR es_edidc.
      RETURN.
    ENDIF.

    ls_edi_ds VALUE #(
      docnum iv_docnum
      status iv_status
      uname  sy-uname
      logdat sy-datum
      logtim sy-uzeit
    ).

    CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
      EXPORTING
        document_number         iv_docnum
        idoc_status             ls_edi_ds
      IMPORTING
        idoc_control            es_edidc
      EXCEPTIONS
        document_number_invalid 1
        other_fields_invalid    2
        status_invalid          3
        OTHERS                  4.
    IF sy-subrc <> 0.
      CLEAR es_edidc.
      RETURN.
    ENDIF.

    CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'
      EXPORTING
        document_number     iv_docnum
      IMPORTING
        idoc_control        es_edidc
      EXCEPTIONS
        document_not_open   1
        failure_in_db_write 2
        parameter_error     3
        status_set_missing  4
        OTHERS              5.

    IF sy-subrc <> 0.
      CLEAR es_edidc.
      RETURN.
    ENDIF.

Monday, March 27, 2017

SAP Tables for Status Handling (in ABAP)

Some important tables concerning status:

JEST  Individual Object Status
JCDS  Change Documents for System/User Statuses (Table JEST)
JSTO  Status object information
TJ02    System Status
TJ02T System status texts
TJ20T Texts for Status Profiles
TJ30T  Texts for User Status

Wednesday, January 25, 2017

Sending emails from ABAP / E-Mail mit ABAP versenden

* https://wiki.scn.sap.com/wiki/display/Snippets/Sending+mail+with+attachment+using+Object+Oriented+Approach
report zjso_send_email.

class lcl_email definition final.
  public section.
    class-methods send
      importing
                iv_subject      type so_obj_des
                it_message_body type bcsy_text
                it_attachment   type rmps_t_post_content optional
                iv_sender_email type adr6-smtp_addr
                it_recipient    type uiyt_iusr
      raising   cx_send_req_bcs cx_document_bcs cx_address_bcs.
endclass.

start-of-selection.
  try.

      lcl_email=>send(
        iv_subject 'Betreff der E-Mail'(001)
        it_message_body value #(
          line 'Hallo,'(002)
          line '  diese E-Mail wurde aus einem SAP-System verschickt.'(003)
          line '' )
          line 'Mit freundlichen Grüßen'(004)
        )
        iv_sender_email 'marvin.maybe@p1zz4.com'
        it_recipient value #(
          mandt sy-mandt
          email 'michael.laender@deutsch.de' )
          email 'ablink@usa.com' )
        )
      ).
      write 'E-Mail erfolgreich versendet'(005).
    catch cx_send_req_bcs cx_document_bcs cx_address_bcs into data(go_x).
      write / go_x->get_text).
  endtry.

class lcl_email implementation.
  method send.
    data lo_send_request type ref to cl_bcs.
    data lo_document type ref to cl_document_bcs.
    data lo_sender type ref to if_sender_bcs.
    data lv_attachment_subject type so_obj_des.
    data lo_recipient type ref to if_recipient_bcs.

    lo_send_request cl_bcs=>create_persistent).
    lo_document cl_document_bcs=>create_document(
      i_type 'RAW'
      i_text it_message_body
      i_subject iv_subject
    ).
    loop at it_attachment into data(ls_attachment).
      lv_attachment_subject ls_attachment-subject.
      lo_document->add_attachment(
          i_attachment_type    ls_attachment-objtp
          i_attachment_subject lv_attachment_subject
          i_att_content_hex    ls_attachment-cont_hex
      ).
    endloop.
    lo_send_request->set_documentlo_document ).
    lo_sender cl_cam_address_bcs=>create_internet_addressiv_sender_email ).
    lo_send_request->set_senderlo_sender ).
    loop at it_recipient into data(ls_recipientwhere email is not initial.
      lo_recipient cl_cam_address_bcs=>create_internet_addressls_recipient-email ).
      lo_send_request->add_recipientexporting
        i_recipient lo_recipient
        i_express 'X'
      ).
    endloop.
    lo_send_request->sendabap_true ).
  endmethod.
endclass.


Check transaction SOST after sending an email. 

SAP ABAP: Determine Timezone for Plant

    DATA:       lt_tzone TYPE STANDARD TABLE OF tznzone WITH DEFAULT KEY,       l_tzone  TYPE tznzone.     " get time zone for plant   ...