Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

This report checks if the “AVAL” status has been set more than  3 days ago,Then the program sets the user status to “ACCT” and closes the notification.

report zpm_status no standard page heading.

*Constants and Data Declaration

constants: gc_noco  type char4 value 'NOCO',"Notification Complete

           gc_nopo  type char4 value 'NOPO',"Notification postponed

           gc_e0016 type char5 value 'E0016',"AVAL

           gc_e0018 type char5 value 'E0018',"ACCT

           gc_x     type c     value 'X',"Flag

           gc_a     type c     value 'A',"Abend

           gc_e     type c     value 'E',"Error

           gc_aval  type char4 value 'AVAL',"AVAL

           gc_bt    type char2 value 'BT',"Notification type BT

           gc_an    type char2 value 'AN',"Notification type AN

           gc_ja    type char2 value 'JA'."Notification type JA

types: begin of gty_data,

       qmnum  like qmel-qmnum,

       qmart  like qmel-qmart,

       objnr  like qmel-objnr,

       aedat  like qmel-aedat,

       aezeit like qmel-aezeit,

       end of   gty_data.

data: gt_data            type standard table of gty_data,

      gt_data1           type standard table of gty_data,

      gt_jcds            type standard table of jcds,

      gv_sys_stat        type bsvx-sttxt,

      gv_user_stat       type bsvx-sttxt,

      gv_tage(200)       type c,

      gs_jcds            type jcds,

      gs_status          type bapi2080_notusrstati,

      gv_qnum            type bapi2080_nothdre-notif_no,

      gt_bapiret2        type standard table of bapiret2,

      gv_flag            type c,

      gv_sultvon         type vtbbewe-sultvon value 'X',

      gv_sultbis         type vtbbewe-sultbis value 'X',

      gs_syststat        type bapi2080_notsti.

field-symbols <gfs_data> type gty_data.

* Parameters

parameters p_days type char3 default '3'.

ago.

start-of-selection.

*Data Selection

  select qmnum

         qmart

         objnr

         aedat

         aezeit

         from qmel into corresponding fields of table gt_data

where qmart in (gc_bt , gc_ja , gc_an ).

  if sy-subrc = 0.

* check for system status <> I0072 or I0069 and user staus ne 'AVAL'

    loop at gt_data assigning <gfs_data>.

      call function 'AIP9_STATUS_READ'

        exporting

          i_objnr = <gfs_data>-objnr

          i_spras = sy-langu

        importing

          e_sysst = gv_sys_stat

          e_anwst = gv_user_stat.

      if gv_sys_stat+0(4) = gc_nopo or gv_sys_stat+0(4) = gc_noco.

        continue.

      else.

        if  gv_user_stat = gc_aval.

          call function 'FIMA_DAYS_BETWEEN_TWO_DATES'

            exporting

              i_datum_von     = <gfs_data>-aedat

              i_kz_ult_von    = gv_sultvon

              i_datum_bis     = sy-datum

              i_kz_ult_bis    = gv_sultbis

            importing

              e_tage          = gv_tage.

          condense gv_tage.

          if gv_tage < 10.

            append <gfs_data> to gt_data1.

          endif.

        else.

          continue.

        endif.

      endif.

    endloop.

    select * from jcds into corresponding fields of table gt_jcds

     for all entries in gt_data1

     where objnr = gt_data1-objnr

      and  stat  = gc_e0016.

    if sy-subrc = 0.

      sort gt_jcds

      by objnr stat chgnr usnam udate utime descending.

      loop at gt_data1 assigning <gfs_data>.

        read table gt_jcds into gs_jcds with key objnr = <gfs_data>-objnr.

        if sy-subrc = 0.

          call function 'FIMA_DAYS_BETWEEN_TWO_DATES'

            exporting

              i_datum_von     = gs_jcds-udate

              i_kz_ult_von    = gv_sultvon

              i_datum_bis     = sy-datum

              i_kz_ult_bis    = gv_sultbis

            importing

              e_tage          = gv_tage.

          condense gv_tage.

          if gv_tage >  p_days.

            clear: gs_status,gv_qnum.

            gv_qnum = <gfs_data>-qmnum.

            gs_status-status_int = gc_e0018.

            call function 'BAPI_ALM_NOTIF_CHANGEUSRSTAT'

              exporting

                number           = gv_qnum

                usr_status       = gs_status

            tables

              return             = gt_bapiret2.

            loop at gt_bapiret2 transporting no fields where type = gc_a or type = gc_e.

              gv_flag = gc_x.

            endloop.

            if gv_flag <> gc_x.

              call function 'BAPI_TRANSACTION_COMMIT'

               exporting

                 wait          = gc_x.

              clear gt_bapiret2.

              call function 'BAPI_ALM_NOTIF_CLOSE'

                exporting

                  number          = gv_qnum

                  syststat        = gs_syststat

              tables

               return             = gt_bapiret2.

              loop at gt_bapiret2 transporting no fields where type = gc_a or type = gc_e.

                gv_flag = gc_x.

              endloop.

              if gv_flag <> gc_x.

                call function 'BAPI_TRANSACTION_COMMIT'

               exporting

                 wait          = gc_x.

              endif.

            endif.

          endif.

        endif.

      endloop.

    endif.

  endif.