Skip to Content

Hello Guys,

I have created one abap program which will send the information in mail to requisite receiver giving details about the status and object included in that TR send betweeen nth day to today date. This program is created to give the information in below format.

Transport      Date          Author        System    ProgramID   ObjectType  Object Id

XX0K9932XX  15.05.2013  0906XXXX   QXX         R3TR            MPRO          ZMRPXXX

This information is stored in TPALOG(DB Buffer for ALOG File) and E071(Change & Transport System: Object Entries of Requests/Tasks). There will be parameter for Number Of Days(old we want to see the data), Program ID, Receiptents, Object ID and Object Name.

If we give Number Of days as 1 and Program ID as CORR then data should come for date range Today Date – 1 to Today Date and PGMID as CORR.

Logic : It will hit table TPALOG and fetch Transport Number, Author, target System, Time into internal table  with condition Systemdate-Number of days<=TRTIME 

>=system date.

Then we will read E071 table to fetch Object ID , Object Name and Program ID where Transport number is wat we have fecth above and Program ID which is passed by user in parameter.

Below is the sample code for this:

   REPORT  ZTRAN***** MESSAGE-ID 00.
tables : BALHDR.
TABLES: e071 ,tpalog.

DATA: BEGIN OF it_tpalog OCCURS 0,
      trtime TYPE tpalogtrtime,
      trkorr TYPE tpalogtrkorr,
      trstep TYPE tpalogtrstep,
      truser TYPE tpalogtruser,
      tarsystem TYPE tpalogtarsystem,
      retcode TYPE tpalogretcode,
      END OF it_tpalog.

DATA: BEGIN OF it_e071 occurs 0,
      trkorr TYPE e071trkorr,
      object TYPE e071object,
      pgmid TYPE  e071pgmid,
      obj_name TYPE e071obj_name,
END OF it_e071.

DATA: BEGIN OF it_final OCCURS 0,
      trkorr TYPE tpalogtrkorr,
      truser TYPE tpalogtruser,
      tarsystem TYPE tpalogtarsystem,
      retcode TYPE tpalogretcode,
      object TYPE e071object,
      pgmid TYPE  e071pgmid,
      obj_name TYPE e071obj_name,
      trtime TYPE tpalogtrtime,
  END OF it_final.

DATA: date1(14) TYPE n,
      date2(14) TYPE n,
      date TYPE sydatum,
      stamp(6) TYPE c value ‘000000’.

PARAMETERS: Days(2) TYPE n DEFAULT ’01’.
SELECT-OPTIONS: Prog_ID FOR e071pgmid,
                Obj_Type FOR e071object,
                Obj_Name FOR e071obj_name.

date = sydatum days.
CONCATENATE date stamp INTO date1.
CONCATENATE sydatum syuzeit INTO date2.

************************************************************
* For Mail Sending                  
************************************************************

data : gv_title(255).
data : l_sysid type xuvalue.

* Email data
DATA: v_recv              LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
      v_document_data     LIKE sodocchgi1.
DATA: object_id           LIKE  sofolenti1object_id,
      objcont             LIKE  soli OCCURS 10 WITH HEADER LINE,
      OBJECT_HEADER       like  SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: gv_receiver TYPE somlreci1receiver.

INITIALIZATION.
clear gv_title.

Concatenate ‘The following objects have been imported by transports below. Please review’ ‘*****’ into gv_title SEPARATED BY space.
SELECTION-SCREEN BEGIN OF BLOCK B.
SELECT-OPTIONS: s_mail FOR gv_receiver LOWER CASE NO INTERVALS.
SELECTION-SCREEN end of block B.

AT SELECTION-SCREEN.
    READ TABLE s_mail INDEX 1.
    IF sysubrc <> 0.
      MESSAGE e001 WITH ‘Please enter at least one email address’.
    ENDIF.
* Reciever’s email Id should be valid
  LOOP AT s_mail.
    IF NOT s_mailhigh IS INITIAL.
      MESSAGE e001 WITH s_mailhigh ‘is not valid. Please enter with no intervals’.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.
* Select data from the Broadcast table for the selection
  PERFORM Z_SELECTDATA.
END-OF-SELECTION.

FORM Z_SELECTDATA.

SELECT   trkorr trstep truser tarsystem trtime  INTO  CORRESPONDING FIELDS OF TABLE it_tpalog FROM tpalog
WHERE  retcode IN (‘0004’, ‘0000’, ‘0008’, ‘0012’AND trstep = ‘I’ AND trtime GE date1 AND trtime LE date2.

*WRITE:/ date1.
*write:/ date2.

LOOP AT it_tpalog.
      SELECT trkorr object pgmid obj_name  INTO CORRESPONDING FIELDS OF TABLE it_e071 FROM e071 WHERE trkorr = it_tpalogtrkorr AND pgmid IN Prog_ID.
*        WRITE:/ it_tpalog-trkorr, it_tpalog-trstep, it_tpalog-truser, it_tpalog-tarsystem.
ENDLOOP.

LOOP AT it_e071.
    READ TABLE it_tpalog WITH KEY trkorr = it_e071trkorr.

  IF sysubrc = 0.
      it_finaltrkorr = it_tpalogtrkorr.
      it_finaltruser = it_tpalogtruser.
      it_finaltarsystem = it_tpalogtarsystem.
      it_finalretcode = it_tpalogretcode.
      it_finalobject = it_e071object.
      it_finalpgmid it_e071pgmid.
      it_finalobj_name = it_e071obj_name.
      it_finaltrtime = it_tpalogtrtime.

ENDIF.
      APPEND it_final.
      CLEAR it_final.

ENDLOOP.

PERFORM Z_DISPLAY.

ENDFORM.

   FORM Z_DISPLAY.
   data: l_message(300).
* Display Broadcast status as a list.
OBJECT_HEADERline = gv_title.
    append OBJECT_HEADER.

    CONCATENATE ‘*********’ ‘The following objects have been imported by transports below. Please review’ ‘********’ INTO objcontline SEPARATED BY space.
    APPEND objcont.

    WRITE: syuline(66) TO objcontline.
    APPEND objcont.
    CONCATENATE syvline ‘ Transport ‘ syvline ‘Date   ‘ syvline
    ‘Author ‘ syvline ‘System ‘ syvline ‘Program ID ‘ syvline ‘Object Type ‘ syvline ‘Object Id  ‘ INTO objcontline.
    APPEND objcont.
    WRITE: syuline(66) TO objcontline.
    APPEND objcont.

    REFRESH v_recv.
    CLEAR v_recv.
    LOOP AT s_mail.
* receivers
      v_recvreceiver = s_maillow.                    “recipient
      v_recvexpress = ‘X’.
      v_recvrec_type = ‘U’.                           “internet email
      APPEND v_recv.
    ENDLOOP.
LOOP AT it_final.
      WRITE: syuline(66) TO objcontline.
      CLEAR objcont.
      CONCATENATE syvline it_finaltrkorr syvline it_finaltrtime+0(8) syvline  it_finaltruser syvline
       it_finaltarsystem syvline  it_finalpgmid syvline it_finalobject syvline
        syvline it_finalobj_name syvline  into objcontline.
      APPEND objcont.
ENDLOOP.

    v_document_dataobj_descr = gv_title.

*    clear p_title.
* send mail message
    CALL FUNCTION ‘SO_NEW_DOCUMENT_SEND_API1’
      EXPORTING
        document_data              = v_document_data
        document_type              = ‘RAW’
        put_in_outbox              = ‘X’
        commit_work                = ‘X’
      IMPORTING
        new_object_id              = object_id
      TABLES
        OBJECT_HEADER              = OBJECT_HEADER
        object_content             = objcont
        receivers                  = v_recv
      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 sysubrc <> 0.
      MESSAGE s001 WITH ‘Email was not sent’.
    ELSE.
      MESSAGE s001 WITH ‘Email was successfully sent’.
    ENDIF.

ENDFORM.

When You execute the program the output will be like:

Program1.jpg

Mail output LIke this:

Program2.jpg

Thanks

P.S –> Form ZSELECT_DATA can also be written like this in fewer lines:

FORM Z_SELECTDATA.
*
SELECT tp~trkorr tp~trstep  tp~truser tp~tarsystem e7~object e7~pgmid e7~obj_name


FROM tpalog AS tp INNER JOIN e071 AS e7 ON e7~trkorr = tp~trkorr INTO CORRESPONDING FIELDS OF TABLE it_final
WHERE tp~retcode IN (‘0004’, ‘0000’, ‘0008’, ‘0012’)  AND tp~trstep = ‘I’ AND tp~trtime GE date1 AND tp~trtime LE date2 AND e7~pgmid IN Prog_ID.

IF sy-subrc = 0.
** Display data of Broadcast status
*  PERFORM Z_DISPLAY.
ELSEIF sy-subrc <> 0.
MESSAGE s001 WITH ‘No Errors Occurred.’.
ENDIF.

*ENDFORM.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    This is a very useful document to get the transport status daily.

    The code is very optimized and easy to understand.

    Keep it up buddy!!!!

    (0) 

Leave a Reply