Sunday, March 11, 2012

Conversion exit routine for inverted date (INPUT/OUTPUT)

report ZCERINVERTDATE
data d_date(10).

call function 'CONVERSION_EXIT_INVDT_OUTPUT'
exporting
input = '79879869'
importing
output = d_date.
write d_date.

data c_date(8).

call function 'CONVERSION_EXIT_INVDT_INPUT'
exporting
input = '07102005'
importing
output = c_date.
write c_date.

HOW TO SEND AUTOMAIL


report ZSENDAUTOMAIL.

*Sample Program
*
*
*REPORT zcustom_errmsg.
data: lt_mailsubject     type sodocchgi1.
data: lt_mailrecipients  type standard table of somlrec90 with header line.
data: lt_mailtxt         type standard table of soli      with header line.

* Recipients
lt_mailrecipients-rec_type  = 'U'.
lt_mailrecipients-receiver = 's777@gmail.com'.
append lt_mailrecipients .
clear lt_mailrecipients .

* Subject.
lt_mailsubject-obj_name = 'TEST'.
lt_mailsubject-obj_langu = sy-langu.
lt_mailsubject-obj_descr = 'Mail Subject'.

* Mail Contents
lt_mailtxt = 'This is a test mail'.
append lt_mailtxt. clear lt_mailtxt.

* Send Mail
call function 'SO_NEW_DOCUMENT_SEND_API1'
  exporting
    document_data              = lt_mailsubject
  tables
    object_content             = lt_mailtxt
    receivers                  = lt_mailrecipients
  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.
if sy-subrc eq 0.
  commit work.

*   Push mail out from SAP outbox
  submit rsconn01 with mode = 'INT' and return.
endif.

HOW TO CREATE RANDOM NUMBER

*&---------------------------------------------------------------------*
*& Report  ZRANDOMNUMBER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZRANDOMNUMBER.
DATA RANINT LIKE QF00-RAN_INT.

PARAMETERS: P_MAX LIKE QF00-RAN_INT DEFAULT 100,
P_MIN LIKE QF00-RAN_INT DEFAULT 1,
P_TIMES TYPE I DEFAULT 10.

WRITE:/ 'RANDOM NUMBER'.
ULINE.

DO P_TIMES TIMES.

CALL FUNCTION 'QF05_RANDOM_INTEGER'

EXPORTING RAN_INT_MAX = P_MAX
         RAN_INT_MIN = P_MIN

IMPORTING RAN_INT = RANINT

EXCEPTIONS INVALID_INPUT = 1

OTHERS = 2.

IF SY-SUBRC EQ 0.

WRITE:/ RANINT. ELSE.
WRITE:/ 'UNABLE TO GENERATE RANDOM NUMBER'.

ENDIF.

ENDDO.