Solution: SAP SD Userexit - Screen Gets Grayed Out after Error Message

Most of the times when you are working on SD User Exit, for example ( MV45AFZZ, UserExit (USEREXIT_SAVE_DOCUMENT_PREPARE)), you get a requirement to display eror messages based on some validations and conditions. When you write something as MESSAGE e001(ZV), the error message shows up in the status bar, but the screen gets completely grayed out or say un-editable.

To solve such issues what you can do is, replace the message statement



 IF ( vbak-vbtyp = 'H' OR vbak-vbtyp = 'K' ) AND vbak-vgbel IS NOT INITIAL
                                                                        AND t180-trtyp NE 'A'.
    TYPES: BEGIN OF lty_vbrp,
             vbeln TYPE vbrp-vbeln,
             posnr TYPE vbrp-posnr,
             netwr TYPE vbrp-netwr,
             vgbel TYPE vbrp-vgbel,
             vgpos TYPE vbrp-vgpos,
             vgtyp TYPE vbrp-vgtyp,
             aubel TYPE vbrp-aubel,
             aupos TYPE vbrp-aupos,
           END OF lty_vbrp.

    DATA: gt_vbrp  TYPE TABLE OF lty_vbrp,
          gwa_vbrp TYPE lty_vbrp.

    SELECT vbeln posnr netwr vgbel vgpos vgtyp aubel aupos
      FROM vbrp
      INTO TABLE gt_vbrp
      FOR ALL ENTRIES IN xvbap
      WHERE vbeln = xvbap-vgbel
        AND posnr = xvbap-vgpos.

    SORT gt_vbrp BY vbeln posnr .

    LOOP AT xvbap WHERE ( updkz EQ 'I' OR updkz EQ 'U' ).
      IF xvbap-abgru IS NOT INITIAL.

      READ TABLE gt_vbrp INTO gwa_vbrp WITH KEY vbeln = xvbap-vgbel
                                                                                             posnr = xvbap-vgpos BINARY SEARCH.
      IF sy-subrc EQ 0.
        IF xvbap-netwr GT gwa_vbrp-netwr.
          MESSAGE s999(zv) WITH xvbap-posnr DISPLAY LIKE 'E'.
          PERFORM folge_gleichsetzen(saplv00f).
          fcode = 'ENT1'.
          SET SCREEN syst-dynnr.
          LEAVE SCREEN.
      IF xvbap-vgbel IS INITIAL AND xvbap-vgpos IS INITIAL.
        MESSAGE s989(zv) WITH xvbap-posnr DISPLAY LIKE 'E'.
        PERFORM folge_gleichsetzen(saplv00f).
        fcode = 'ENT1'.
        SET SCREEN syst-dynnr.

The above scenario helps to validate return orders created with reference to billing documents.The above code can be implemented in USEREXIT_SAVE_DOCUMENT_PREPARE.

Never display message directly as error rather mention it as Success and then use DISPLAY LIKE error as shown above. For making the screen editable, you can use fcode = 'ENT1' just after the message statement.

Check the usage of UPDKZ field available in XVBAP and XVBAK structures. Whenever you are trying to validate line items always validate for items which has status Insert ('I') or Update('U'). Never validate for items for deleted items or items with UPDKZ as Delete('D') .

The other things to note here is the usage of T180-TRTYP. You might not want the validations for display transactions. Hence when you set T180-TRTYP NE 'A', this code will skip the validations for display transactions.

Do's & Dont's while working on SD UserExits:

  • Don't use keyword CHECK.
  • Dont use Loop at Screen...Endloop in SCREEN MODIFICATION Userexit.
  • Never hardcode transaction codes in UserExits.


Also Read...