SAP ABAP SystemID ve Long App Server Name Çeken Fonksiyon

DATA: SERVER_NAME TYPE MSXXLIST-NAME.

CALL FUNCTION 'GENERAL_GET_APP_SERVER_NAME' "Get long app server name
 IMPORTING
   SERVER_NAME              = SERVER_NAME "msxxlist-name  Local app server name
* EXCEPTIONS
*   ERROR_READING_NAME       = 1
*   OTHERS                   = 2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

DATA: SYSID TYPE SY-SYSID.
SYSID = SY-SYSID.

*display
cl_demo_output=>display( SERVER_NAME ).
cl_demo_output=>display( SYSID ). 

SAP ABAP Send Email Program (HMTL Formatted)

PARAMETERS: psubject(40) type c default 'MERHABA',
            p_email(40)  type c default 'receiver@test.com' .

data:   it_packing_list like sopcklsti1 occurs 0 with header line,
        it_contents like solisti1 occurs 0 with header line,
        it_receivers like somlreci1 occurs 0 with header line,
        it_attachment like solisti1 occurs 0 with header line,
        gd_cnt type i,
        gd_sent_all(1) type c,
        gd_doc_data like sodocchgi1,
        gd_error type sy-subrc.

data:   it_message type standard table of SOLISTI1 initial size 0
                with header line.

DATA: gf_doc_chng    TYPE sodocchgi1,
      gf_objtxt      TYPE solisti1.

*html kodlarıyla mail içeriğini oluştur
PERFORM populate_message_table.

*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.

*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*       Adds text to email text table
*----------------------------------------------------------------------*
form populate_message_table.

    gf_doc_chng-obj_name  = 'HTML Format Email from SAP'.
    gf_doc_chng-obj_descr = psubject.
    gf_objtxt-line = '<body bgcolor = "#E6E6FA">'.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    CONCATENATE '<FONT COLOR = "#191970" face="Garamond">' '<b>' INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    CONCATENATE '<p>' 'Merhaba,' '</p>' INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    gf_objtxt-line = space.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    CONCATENATE '<p>' 'Bu bir HTML formatlı örnek maildir.' '</p>' INTO gf_objtxt-line SEPARATED BY space.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    gf_objtxt-line = '<center>'.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    gf_objtxt-line = '<TABLE  width= "100%" border="1">'.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<TR><td align = "LEFT" BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>Başlık1</B> </FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"> <B>Başlık2</B> </FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>Başlık3</B> </FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>Başlık4</B> </FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">' '<FONT COLOR = "BLUE"><B>Başlık5</B> </FONT>' '</td></tr>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
CONCATENATE '<TR><td align = "LEFT">' '<FONT COLOR = "BLUE">' 'Satır1Kolon1' '</FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' 'Satır1Kolon2' '</FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' 'Satır1Kolon3' '</FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' 'Satır1Kolon4' '</FONT>' '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">' '<FONT COLOR = "BLUE">' 'Satır1Kolon5' '</FONT>' '</td></tr>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    gf_objtxt-line = '</center>'.
    APPEND gf_objtxt TO it_message.
    CLEAR  gf_objtxt.
    gf_objtxt-line = 'İyi çalışmalar.<br />'.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    gf_objtxt-line = '<br><br><b><center><i><font color = "RED">Sistem tarafından gönderildi.'.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.
    gf_objtxt-line = '</FONT></body>'.
    APPEND gf_objtxt TO it_message.
    CLEAR gf_objtxt.

endform.                    " POPULATE_MESSAGE_TABLE

*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*       Send email message
*----------------------------------------------------------------------*
form send_email_message.
* Fill the document data.
  gd_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
  clear it_packing_list.
  refresh it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  describe table it_message lines it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  append it_packing_list.

* Add the recipients email address
  clear it_receivers.
  refresh it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  append it_receivers.

* Call the FM to post the message to SAPMAIL

**Removed because code does not seem to work in current version of SAP but may work in older versions
*  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
*       exporting
*            document_data              = gd_doc_data
*            put_in_outbox              = 'X'
**
  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = gd_doc_data
            document_type              =  'HTM'
*            put_in_outbox              = 'X'
*            sender_address             = 'sender@test.com'
*            sender_address_type        = 'INT'
*            commit_work                = 'X'
*       importing
*            sent_to_all                = gd_sent_all
       tables
*            packing_list               = it_packing_list
*            contents_txt               = it_message
            object_content             = it_message
            receivers                  = it_receivers
       exceptions
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            others                     = 8.

** Store function module return code
*  gd_error = sy-subrc.
*
** Get it_receivers return code
*  loop at it_receivers.
*  endloop.

if sy-subrc eq 0.
  COMMIT WORK.
  submit rsconn01 with mode ='INT' AND RETURN.
  else.
    endif.
endform.                    " SEND_EMAIL_MESSAGE

*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
form initiate_mail_execute_program.
  wait up to 2 seconds.
  if gd_error eq 0.
      submit rsconn01 with mode = 'INT'
                    with output = 'X'
                    and return.
  endif.
endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

SAP ABAP Send Email Program (Text)

PARAMETERS: psubject(40) type c default 'Hello',
            p_email(40)  type c default 'receiver@test.com' .

data:   it_packing_list like sopcklsti1 occurs 0 with header line,
        it_contents like solisti1 occurs 0 with header line,
        it_receivers like somlreci1 occurs 0 with header line,
        it_attachment like solisti1 occurs 0 with header line,
        gd_cnt type i,
        gd_sent_all(1) type c,
        gd_doc_data like sodocchgi1,
        gd_error type sy-subrc.

data:   it_message type standard table of SOLISTI1 initial size 0
                with header line.

*mail içeriğini hazırla
PERFORM populate_message_table.

*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.


*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*       Adds text to email text table
*----------------------------------------------------------------------*
form populate_message_table.
  Append 'Email line 1' to it_message.
  Append 'Email line 2' to it_message.
  Append 'Email line 3' to it_message.
  Append 'Email line 4' to it_message.
endform.                    " POPULATE_MESSAGE_TABLE


*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*       Send email message
*----------------------------------------------------------------------*
form send_email_message.
* Fill the document data.
  gd_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
  clear it_packing_list.
  refresh it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  describe table it_message lines it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  append it_packing_list.

* Add the recipients email address
  clear it_receivers.
  refresh it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  append it_receivers.

* Call the FM to post the message to SAPMAIL

**Removed because code does not seem to work in current version of SAP but may work in older versions
*  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
*       exporting
*            document_data              = gd_doc_data
*            put_in_outbox              = 'X'
**
  call function 'SO_DOCUMENT_SEND_API1'
       exporting
            document_data              = gd_doc_data
            put_in_outbox              = 'X'
            sender_address             = 'sender@test.com'
            sender_address_type        = 'INT'
            commit_work                = 'X'
       importing
            sent_to_all                = gd_sent_all
       tables
            packing_list               = it_packing_list
            contents_txt               = it_message
            receivers                  = it_receivers
       exceptions
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            others                     = 8.

* Store function module return code
  gd_error = sy-subrc.

* Get it_receivers return code
  loop at it_receivers.
  endloop.
endform.                    " SEND_EMAIL_MESSAGE


*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
form initiate_mail_execute_program.
  wait up to 2 seconds.
  if gd_error eq 0.
      submit rsconn01 with mode = 'INT'
                    with output = 'X'
                    and return.
  endif.
endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

SAP ABAP MB to GB Çeviren Fonksiyon

*&---------------------------------------------------------------------*
*&      Form  MB_TO_GB
*&---------------------------------------------------------------------*
*       1024mb üzeri değerleri GB cinsinden gösterir
*----------------------------------------------------------------------*
FORM mb_to_gb USING     db_size TYPE any
              CHANGING  size    TYPE C.
  data: info(2) type c,
        mbsize(4) type c,
        tempsize type p decimals 2.
  constants: db_mbsize type i value 1024.
  if db_size >  db_mbsize.
    info = 'GB'.
    tempsize = ( db_size / 1024 ).
    size(18) = tempsize.
    CONCATENATE size(18) info INTO size SEPARATED BY SPACE .
  else.
    info = 'MB'.
    mbsize = db_size.
    CONCATENATE mbsize info INTO size SEPARATED BY SPACE .
  endif.

ENDFORM.    " MB_TO_GB