Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Get the system status of a notification in PM after a change

Former Member
0 Kudos
968

Hello,

I' m using a copy of BTE event FM 'SAMPLE_INTERFACE_PM000010' to build some modifications in case of create/update of a notification in PM (transaction IW21 and IW22). I want to do some actions depending on the change of the system status and on the new values of the system status (i don't want to find out which status is active). I'm not able to find a standard FM/BAPI/Method to do that.

Can someone help me?

Kind regards,

Yan Cazarelly

1 ACCEPTED SOLUTION

Former Member
0 Kudos
161

Below is an example of how I've done it in the past. So maybe there is a better way. Of course it is specific for the company I work at, so I deleted some irrelevant coding...

FUNCTION z_ep_get_status_from_notif.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(NOTIFICATION) LIKE  VIQMEL-QMNUM
*"  TABLES
*"      Z_USERSTATUS STRUCTURE  ZUSERSTATUS_NOTIF OPTIONAL
*"      Z_SYSTEMSTATUS STRUCTURE  ZUSERSTATUS_NOTIF OPTIONAL
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
*  DATA: zstsma  LIKE  tj30-stsma VALUE 'NOTEEB'.
  DATA: status  LIKE TABLE OF jstat WITH HEADER LINE.
  DATA: h_type  LIKE bapiret2-type,
        h_text  LIKE bapiret2-message,
        h_lines TYPE i.
  DATA: h_stsma LIKE  tq80-stsma.
  DATA: i_user_parms LIKE usparam OCCURS 10 WITH HEADER LINE.

...

 * Go through the object number to the status
  SELECT SINGLE objnr FROM viqmel
                      INTO viqmel-objnr
                     WHERE qmnum = notification.

  IF sy-subrc <> 0.
    CONCATENATE 'Notification' notification 'not found'
                          INTO h_text
                          SEPARATED BY space.
    add_to_return 'E' h_text.
    EXIT.
  ENDIF.

  CALL FUNCTION 'STATUS_READ'
       EXPORTING
            objnr            = viqmel-objnr
            only_active      = 'X'
       TABLES
            status           = status
       EXCEPTIONS
            object_not_found = 1
            OTHERS           = 2.

  CASE sy-subrc.
    WHEN 0.
      h_type = 'S'.
      h_text = 'Status read successfully'.
      add_to_return h_type h_text.
    WHEN 1.
      h_type = 'E'.
      h_text = 'Object not found'.
      add_to_return h_type h_text.
    WHEN OTHERS.
      h_type = 'E'.
      h_text = 'Unexpected error while retrieving status'.
      add_to_return h_type h_text.
  ENDCASE.

  DESCRIBE TABLE status LINES h_lines.
  IF h_lines = 0.
    CONCATENATE 'No status found for notification' notification
                          INTO h_text
                          SEPARATED BY space.
    h_type = 'I'.
    add_to_return h_type h_text.
  ELSE.
* Select all required info for the retrieved user status's
    SELECT stsma estat spras txt04 txt30
                             FROM ent5854
                             INTO (z_userstatus-stsma,
                                   z_userstatus-estat,
                                   z_userstatus-spras,
                                   z_userstatus-txt04,
                                   z_userstatus-txt30)
               FOR ALL ENTRIES IN status
                            WHERE estat = status-stat
                              AND spras = sy-langu.
      APPEND: z_userstatus.
      CLEAR:  z_userstatus.
    ENDSELECT.
* Select all required info for the retrieved system status's
    SELECT istat spras txt04 txt30
                             FROM tj02t
                             INTO (z_systemstatus-estat,
                                   z_systemstatus-spras,
                                   z_systemstatus-txt04,
                                   z_systemstatus-txt30)
               FOR ALL ENTRIES IN status
                            WHERE istat = status-stat
                              AND spras = sy-langu.
      APPEND: z_systemstatus.
      CLEAR:  z_systemstatus.
    ENDSELECT.

...

  ENDIF.

2 REPLIES 2

Former Member
0 Kudos
162

Below is an example of how I've done it in the past. So maybe there is a better way. Of course it is specific for the company I work at, so I deleted some irrelevant coding...

FUNCTION z_ep_get_status_from_notif.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(NOTIFICATION) LIKE  VIQMEL-QMNUM
*"  TABLES
*"      Z_USERSTATUS STRUCTURE  ZUSERSTATUS_NOTIF OPTIONAL
*"      Z_SYSTEMSTATUS STRUCTURE  ZUSERSTATUS_NOTIF OPTIONAL
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
*  DATA: zstsma  LIKE  tj30-stsma VALUE 'NOTEEB'.
  DATA: status  LIKE TABLE OF jstat WITH HEADER LINE.
  DATA: h_type  LIKE bapiret2-type,
        h_text  LIKE bapiret2-message,
        h_lines TYPE i.
  DATA: h_stsma LIKE  tq80-stsma.
  DATA: i_user_parms LIKE usparam OCCURS 10 WITH HEADER LINE.

...

 * Go through the object number to the status
  SELECT SINGLE objnr FROM viqmel
                      INTO viqmel-objnr
                     WHERE qmnum = notification.

  IF sy-subrc <> 0.
    CONCATENATE 'Notification' notification 'not found'
                          INTO h_text
                          SEPARATED BY space.
    add_to_return 'E' h_text.
    EXIT.
  ENDIF.

  CALL FUNCTION 'STATUS_READ'
       EXPORTING
            objnr            = viqmel-objnr
            only_active      = 'X'
       TABLES
            status           = status
       EXCEPTIONS
            object_not_found = 1
            OTHERS           = 2.

  CASE sy-subrc.
    WHEN 0.
      h_type = 'S'.
      h_text = 'Status read successfully'.
      add_to_return h_type h_text.
    WHEN 1.
      h_type = 'E'.
      h_text = 'Object not found'.
      add_to_return h_type h_text.
    WHEN OTHERS.
      h_type = 'E'.
      h_text = 'Unexpected error while retrieving status'.
      add_to_return h_type h_text.
  ENDCASE.

  DESCRIBE TABLE status LINES h_lines.
  IF h_lines = 0.
    CONCATENATE 'No status found for notification' notification
                          INTO h_text
                          SEPARATED BY space.
    h_type = 'I'.
    add_to_return h_type h_text.
  ELSE.
* Select all required info for the retrieved user status's
    SELECT stsma estat spras txt04 txt30
                             FROM ent5854
                             INTO (z_userstatus-stsma,
                                   z_userstatus-estat,
                                   z_userstatus-spras,
                                   z_userstatus-txt04,
                                   z_userstatus-txt30)
               FOR ALL ENTRIES IN status
                            WHERE estat = status-stat
                              AND spras = sy-langu.
      APPEND: z_userstatus.
      CLEAR:  z_userstatus.
    ENDSELECT.
* Select all required info for the retrieved system status's
    SELECT istat spras txt04 txt30
                             FROM tj02t
                             INTO (z_systemstatus-estat,
                                   z_systemstatus-spras,
                                   z_systemstatus-txt04,
                                   z_systemstatus-txt30)
               FOR ALL ENTRIES IN status
                            WHERE istat = status-stat
                              AND spras = sy-langu.
      APPEND: z_systemstatus.
      CLEAR:  z_systemstatus.
    ENDSELECT.

...

  ENDIF.

0 Kudos
161

Hello Edwin,

I can use some of your coding. My problem at this moment is that in the user-exit there is still no change of the status of the notification. I need to find another UE where the status has been already changed.

Thanks,

Yan