Application Development and Automation 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: 
Read only

Badi implementation getting error and not getting called.

arijitbarman
Participant
0 Likes
2,439

Hi Abapers,

My requirement is that when users creating PO from ME21N or changing PO from ME22N my code will check FRGSX(Release Strategy) & FRGZU(Release status) of the current PO with the 2 fields of my ztable and it will select the email from the ztable if they are equal.

I created the implementation in BADI ME_PROCESS_PO_CUST METHOD POST but its not working.

I am pasting my code with the screen shot of the error. Please someone tell me where I am going wrong.

METHOD IF_EX_ME_PROCESS_PO_CUST~POST.

   DATA: IM_TRTYP TYPE TRTYP.

   DATA: LS_MEPOHEADER TYPE MEPOHEADER.

   DATA: LS_MEPOITEM TYPE MEPOITEM.

   DATA: IM_ITEM TYPE REF TO IF_PURCHASE_ORDER_ITEM_MM.

   DATA: LV_MAILID TYPE AD_SMTPADR,

         LV_DATE TYPE CHAR10,

         LV_AMT TYPE CHAR15.

   DATA: LT_PO_MAILS TYPE STANDARD TABLE OF ZMM_PO_MAILS,

         LW_PO_MAILS TYPE ZMM_PO_MAILS.

** Declaration for mail sending.*****************************************

   DATA: T_OBJBIN   TYPE STANDARD TABLE OF SOLISTI1,   " Attachment data

         T_OBJTXT   TYPE STANDARD TABLE OF SOLISTI1,   " Message body

         T_OBJPACK  TYPE STANDARD TABLE OF SOPCKLSTI1, " Packing list

         T_RECLIST  TYPE STANDARD TABLE OF SOMLRECI1" Receipient list

         T_OBJHEAD  TYPE STANDARD TABLE OF SOLISTI1.   " Header

   DATA: WA_DOCDATA TYPE SODOCCHGI1,   " Document data

         WA_OBJTXT  TYPE SOLISTI1,     " Message body

         WA_OBJBIN  TYPE SOLISTI1,     " Attachment data

         WA_OBJPACK TYPE SOPCKLSTI1,   " Packing list

         WA_RECLIST TYPE SOMLRECI1.    " Receipient list

   DATA: W_TAB_LINES TYPE I.           " Table lines

**************************************************************************

   IF ( SY-TCODE EQ 'ME21N' OR SY-TCODE EQ 'ME22N' ).

     IF ( IM_TRTYP = 'H' OR IM_TRTYP = 'V' ).

       CALL FUNCTION 'MEPOBADIEX_POST'

         EXPORTING

           IM_EBELN = IM_EBELN.

       CALL METHOD IM_HEADER->GET_DATA

         RECEIVING

           RE_DATA = LS_MEPOHEADER.

       CALL METHOD IM_ITEM->GET_DATA

         RECEIVING

           RE_DATA = LS_MEPOITEM.

       IF ( LS_MEPOHEADER-FRGZU = '' OR LS_MEPOHEADER-FRGZU = 'X' OR  LS_MEPOHEADER-FRGZU = 'XX' ).

         SELECT * FROM ZMM_PO_MAILS

           INTO TABLE LT_PO_MAILS

           WHERE FRGSX = LS_MEPOHEADER-FRGSX

           AND   FRGZU = LS_MEPOHEADER-FRGZU.

         CALL FUNCTION 'HRGPBS_HESA_DATE_FORMAT'

           EXPORTING

             P_DATE     = LS_MEPOHEADER-AEDAT

           IMPORTING

             DATESTRING = LV_DATE.

         CALL FUNCTION 'EFG_GEN_GET_USER_EMAIL'

           EXPORTING

             I_UNAME         = LS_MEPOHEADER-ERNAM

           IMPORTING

             E_EMAIL_ADDRESS = LV_MAILID.

         LV_AMT = LS_MEPOITEM-NETWR.

*...Title

         WA_DOCDATA-OBJ_NAME  = 'Email notification'.

*...Description

         WA_DOCDATA-OBJ_DESCR = 'Pending Purchase Orders'.

*... TABLE HEADING

         WA_OBJTXT-LINE = '<p> Dear Sir, </p>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = '<p> This is to inform you that below Purchase Order has been created and subjected to release. </p>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

*   Table display

         WA_OBJTXT-LINE = '<table style="MARGIN: 10px" bordercolor="#90EE90" '.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = ' cellspacing="0" cellpadding="3" width="950" '.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = ' border="1"> <tbody><tr>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

*   Table header

         WA_OBJTXT-LINE = '<th bgcolor="#90EE90">PO Number</th>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = '<th bgcolor="#90EE90">PO Amount (INR)</th>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = '<th bgcolor="#90EE90">PO Created By</th>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = '<th bgcolor="#90EE90">PO Created On</th>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

         WA_OBJTXT-LINE = '<th bgcolor="#90EE90">PO Creator E-Mail ID</th> </tr>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

*   Table Contents

         CONCATENATE '<td>' LS_MEPOHEADER-EBELN '</td>' INTO WA_OBJTXT-LINE.

         APPEND WA_OBJTXT TO T_OBJTXT.

         CONCATENATE '<td>' LV_AMT '</td>' INTO WA_OBJTXT-LINE.

         APPEND WA_OBJTXT TO T_OBJTXT.

         CONCATENATE '<td>' LS_MEPOHEADER-ERNAM '</td>' INTO WA_OBJTXT-LINE.

         APPEND WA_OBJTXT TO T_OBJTXT.

         CONCATENATE '<td>' LV_DATE '</td>' INTO WA_OBJTXT-LINE.

         APPEND WA_OBJTXT TO T_OBJTXT.

         CONCATENATE '<td>' LV_MAILID '</td> </tr>' INTO WA_OBJTXT-LINE.

         APPEND WA_OBJTXT TO T_OBJTXT.

*   Table close

         WA_OBJTXT-LINE = '</tbody> </table>'.

         APPEND WA_OBJTXT TO T_OBJTXT.

*   HTML close

         WA_OBJTXT-LINE = '</body> </html> '.

         APPEND WA_OBJTXT TO T_OBJTXT.

* Document data

         DESCRIBE TABLE T_OBJTXT      LINES W_TAB_LINES.

         READ     TABLE T_OBJTXT      INTO WA_OBJTXT INDEX W_TAB_LINES.

         WA_DOCDATA-DOC_SIZE =

             ( W_TAB_LINES - 1 ) * 255 + STRLEN( WA_OBJTXT ).

* Packing data

         CLEAR WA_OBJPACK-TRANSF_BIN.

         WA_OBJPACK-HEAD_START = 1.

         WA_OBJPACK-HEAD_NUM   = 0.

         WA_OBJPACK-BODY_START = 1.

         WA_OBJPACK-BODY_NUM   = W_TAB_LINES.

* We will pass the HTML, since we have created the message body in the HTML

         WA_OBJPACK-DOC_TYPE   = 'HTML'.

         APPEND WA_OBJPACK TO T_OBJPACK.

         CLEAR LW_PO_MAILS.

         READ TABLE LT_PO_MAILS INTO LW_PO_MAILS INDEX 1.

         IF SY-SUBRC = 0.

           WA_RECLIST-RECEIVER = LW_PO_MAILS-EMAIL.

           WA_RECLIST-REC_TYPE = 'U'.

           WA_RECLIST-EXPRESS = 'X'.

           APPEND WA_RECLIST TO T_RECLIST.

           CLEAR: WA_RECLIST.

           CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

             EXPORTING

               DOCUMENT_DATA              = WA_DOCDATA

               PUT_IN_OUTBOX              = 'X'

               COMMIT_WORK                = 'X'

             TABLES

               PACKING_LIST               = T_OBJPACK

               OBJECT_HEADER              = T_OBJHEAD

               CONTENTS_TXT               = T_OBJTXT

               RECEIVERS                  = T_RECLIST

             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.

         ENDIF.

       ENDIF.

     ENDIF.

   ENDIF.

ENDMETHOD.

1 ACCEPTED SOLUTION
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,733

I'm wondering who gave you a specification... Don't use BADI for this, use the custom output. Tons of posts on the PO output on SCN. Also we shouldn't use FM anymore for email, use this instead: Unknown thus unloved? | SCN

7 REPLIES 7
Read only

deepak_sharma_sap
Active Participant
0 Likes
1,733

Hi ,

I believe you are trying to test the method stand alone by just passing the parameter IM_EBELN and not IM_HEADER.

Object IM_HEADER being null , would give the exception mentioned in your screenshot for line of code corresponding to call of Method GET_DATA

CALL METHOD IM_HEADER->GET_DATA

  Receiving

      RE_DATA = LS_MEPOHEADER.

When the BADI would be called from the transaction ME21N or ME22N , object IM_HEADER would already be instantiated and would not give this error.

Let  me know incase my understanding of issue is not correct.

Thanks

Deepak

Read only

0 Likes
1,733

Hi Deepak,

Thank you for your reply.

You were absolutely right.

Actually this badi triggers after the po is saved in database so i used im_ebeln to get the values from ekko and then proceeded to resolve my issue.

So no need for im_header and im_item to code in my implementation where i was getting the error..

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,733

If this is resolved then kindly close the discussion. See this blog:  http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why

Read only

0 Likes
1,733

how to get po details when po is getting created from me21n. I need those details in my current badi implementation.

At present its only getting triggered correctly from me22n or you can say change mode.

Message was edited by: arijit barman

Read only

0 Likes
1,733

Hi Arijit,

I don't think you will be able to get newly created PO into BADI of Me21 itself. Once Me21 will be completed then it will be updated and also Table will show at that time.

Regards,

Amit Soni.

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,734

I'm wondering who gave you a specification... Don't use BADI for this, use the custom output. Tons of posts on the PO output on SCN. Also we shouldn't use FM anymore for email, use this instead: Unknown thus unloved? | SCN

Read only

0 Likes
1,733

Hi All,

Can someone tell me how to get the total value of a PO which is getting created from me21n.

I need it bcoz as it is saved my requirement is to send a email to releaser with the po total amount.

Arijit