Showing posts with label BADI. Show all posts
Showing posts with label BADI. Show all posts

Thursday, October 1, 2020

What are the differences between Classic (Old) BADI and New (Kernel) BADI?

 

What are the differences between Classic (Old) BADI and New (Kernel) BADI?



Ans :-

Classic or Old BADI

New or Kernel BADI

1. The standard method GET_INSTANCE of the standard class CL_EXIT_HANDLER is used to call

1. The ABAP statements GET BADI & CALL BADI are used to work with New BADI’s.

2. An interface of a BADI referred to create the Reference object

2. The definition of a BADI is referred to create the Reference object

3. It is not faster as like the Kernel BADI

3. It is faster than the Classic BADI 

4. It can be a multiple use BADI

4. It must be a single use BADI

5. The Fall back class can’t be defined

5. The Fall back class can be defined

6. It can be a Filter Dependent BADI

6. It is not possible to maintain the Filter values

What are the ways to find BADIs

 What are the ways to find BADIs.



How to find BADIs in SAP ABAP.

Ans :-

ü  Most of the Standard BADI’s are classic BADI’s.

ü  They are used to add the additional customer specific functionality/business logic to the standard programs/T-codes.

ü  There are 4 ways to find the BADI’s

                      I.        Using the standard class CL_EXITHANDLER

Ø  Execute the T-code: SE24 to maintain the global class.

Ø  Enter the standard class name CL_EXITHANDLER

Ø  Click on display button.

Ø  Double click on the method GET_INSTANCE

Ø  Set a session break point on the method GET_CLASS_NAME_BY_INTERFACE

Ø  Execute the required functional T-code Ex: MM02

Ø  Perform the required action Ex: save material

Ø  Double click on a passing parameter (EXT_NAME) to list out the corresponding BADI. Ex: BADI_MATERAIL_CHECK

                    II.        Using the T-code SE84

                   III.        Using the T-code ST05 (SQL Tracer)

                  IV.        Using the T-code SPRO

Details About BADI's in SAP ABAP.

Details About BADI's in SAP ABAP.

What are the Transaction Codes associated with BADIs?

Ans :-

           T-code SE18 & SE19: are used to work with the BADI’s

           T-code SE18: used to define the BADI’s

           T-code SE19: used to implement the BADI’


What are the types & sub types of BADIs and explain about them?

Ans :- It is used to add the additional customer specific business logic to the standard programs.

1.    Classic/Old BADI: These are mostly used in the functional areas like SD, MM, FI/CO. The standard method “GET_INSTANCE” of the standard class “CL_EXIT_HANDLER” is used to work with the classic BADI’s.

2.    Kernel/New BADI: The ABAP statements “GET BADI & CALL BADI” are used to work with New BADI’s. It is faster than Classical BADI’s.

GET BADI: This statement is used to generate a New BADI object & sets the BADI reference to the objects in the BADI reference variables.

CALL BADI: This statement is used to call the Methods of the New BADI’s.

         Subtypes:

a.    Single use BADI: The single use BADI can’t be implemented for multiple times. This BADI can have only one implementation.

b.    Multiple use BADI: The multiple use BADI’s can’t be implemented for the multiple times.

c.    Filter Dependent BADI: It is used to control the BADI implementation based on the specified filter value. The system generates an Import parameter ‘FLT_VAL’ to pass the filter values for controlling the business logic of the BADI implementation.

Thursday, July 23, 2020

MB_MIGO_BADI BADI USED TO POSTING DATA VALIDATION FOR MIGO

MB_MIGO_BADI BADI



method IF_EX_MB_MIGO_BADI~POST_DOCUMENT.

  BREAK-POINT.

  IF is_mkpf-budat < is_mkpf-BLDAT.

    sy-ucomm 'ENT1'.

    MESSAGE 'Posting Date Should Not Less Than Document Date'  TYPE 'E' .

    SET SCREEN syst-dynnr.

    LEAVE SCREEN.

  ENDIF.

endmethod.

Send Mail Excel attachment program in SAP ABAP

Send Mail Excel attachment program in SAP ABAP.




DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,

      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE,

      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,

      lt_mailsubject     TYPE sodocchgi1,

      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

      gv_cnt             TYPE i.


Add Recipients


lt_mailrecipients-rec_type  = 'U'.

lt_mailrecipients-com_type  = 'INT'.

lt_mailrecipients-RECEIVER  = 'someone@erpdb.info'.

APPEND lt_mailrecipients .

CLEAR lt_mailrecipients .


Put in the Mail Contents


lt_mailtxt = 'Hi How are you'.      APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Here is a test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.


Create the attachment


  DATA: BEGIN OF lt_po_data_cons OCCURS 0,

         ebeln LIKE ekpo-ebeln,

         ebelp LIKE ekpo-ebelp,

        END OF lt_po_data_cons.


  SELECT ebeln ebelp INTO TABLE lt_po_data_cons

  UP TO 10 ROWS

  FROM ekpo. 


  CLASS cl_abap_char_utilities DEFINITION LOAD.

  CONCATENATE 'PO' 'PO Line'

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=&GT;horizontal_tab.

  APPEND lt_attachment. CLEAR lt_attachment.


  LOOP AT lt_po_data_cons.

  CONCATENATE lt_po_data_cons-ebeln lt_po_data_cons-ebelp

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=&GT;horizontal_tab.


  CONCATENATE cl_abap_char_utilities=&GT;newline lt_attachment

              INTO lt_attachment.


  APPEND lt_attachment. CLEAR lt_attachment.

 ENDLOOP.

Pack the mail contents and attachment

 lt_packing_list-transf_bin  = SPACE.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 0.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_mailtxt ).

  lt_packing_list-doc_type    = 'RAW'.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_packing_list-transf_bin  = 'X'.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 1.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_attachment ).

  lt_packing_list-doc_type    = 'XLS'. " You can give RAW incase if you want just a txt file.

  lt_packing_list-obj_name    = 'data.xls'.

  lt_packing_list-obj_descr   = 'data.xls'.

  lt_packing_list-doc_size    = lt_packing_list-body_num * 255.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_mailsubject-obj_name     = 'MAILATTCH'.

  lt_mailsubject-obj_langu    = sy-langu.

  lt_mailsubject-obj_descr    = 'You have got mail'.

  lt_mailsubject-sensitivty   = 'F'.

  gv_cnt = LINES( lt_attachment ).

  lt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + STRLEN(

  lt_attachment ).

Finally, send the mail out.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data              = lt_mailsubject

    TABLES

      packing_list               = lt_packing_list

      contents_bin               = lt_attachment

      contents_txt               = lt_mailtxt

      receivers                  = lt_mailrecipients

    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 sy-subrc EQ 0.

    COMMIT WORK.

    SUBMIT rsconn01 WITH MODE = 'INT' AND RETURN.

  ENDIF.

Wednesday, March 18, 2020

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 .

Implement BADI BADI_ACC_DOCUMENT for Enabling Parameter Extension2 in BAPI_ACC_DOCUMENT_POST.


Implement BADI BADI_ACC_DOCUMENT.




BAPI_ACC_DOCUMENT_POST is meanly used to create FI documents like as GL, AP, and AR (TCode F-02). This BAPI, there are EXTENTION2 table parameters that can be used to throw data for which fields are not provided by BAPI BAPI_ACC_DOCUMENT_POST, such as the Ref field. Key 1 Header (BKPF-XREF1_HD), or even for the need to change the key post from the journal to be made.

However, this EXTENTION2 parameter will only function if BADI_ACC_DOCUMENT has been implemented. Following are the steps for implementing BADI_ACC_DOCUMENT:

Copy class CL_EXM_IM_ACC_DOCUMENT to custome class YCL_EXM_IM_ACC_DOCUMENT via SE24. Activate.
Run TCode SE19 and create BADI_ACC_DOCUMENT in the Create Implementation >> New BAdI section.

Write the name of the BAdI Enhancement Implementation along with the Composite Enhancement Implementation (if there is no composite yet, create it first.


• Enter the name of the BAdI custome in step 3 and the name of the custom class in step 1, and select the name BAdI Definitioan = BADI_ACC_DOCUMENT.

1.Save & Activate.



1.On the Technical Tab, double click the custom class for BAdI custom coding according to the requirement.



1.Double click the ~ CHANGE method to start coding.

  • Save & Activate
  • ABAP program, the passing parameter extension2 is as follows


  DATA:  ld_header LIKE bapiache09,
         ld_objkey LIKE bapiache09-obj_key,
         lt_gl     LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
         lt_ap     LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
         lt_amt    LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
         lt_ext    LIKE bapiparex OCCURS 0 WITH HEADER LINE,
         lt_ret    LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
         ld_itemno LIKE bapiacgl09-itemno_acc,

  CONSTANT: c_struct TYPE TE_STRUC VALUE 'XREF1_HD'.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

    CLEAR lt_ext.
    ADD 1 TO ld_itemno.
    lt_ext-structure   = c_struct.
    lt_ext-valuepart1  = ld_itemno.
    lt_ext-valuepart2  = 'Test Ref Key Header'.
    APPEND lt_ext.

*isi parameter ld_header, lt_gl, lt_amt sesuai requirement.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = ld_header
      IMPORTING
        obj_key        = ld_objkey
      TABLES
        accountgl      = lt_gl
        accountpayable = lt_ap
        currencyamount = lt_amt
        return         = lt_ret
        extension2     = lt_ext
      EXCEPTIONS
        OTHERS         = 1.

    IF ld_objkey IS INITIAL OR ld_objkey EQ '$'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.
 The CHANGE method does the following coding:
  DATA: wa_extension   TYPE bapiparex,
        wa_accit       TYPE accit,
        ld_posnr       TYPE posnr_acc.

  LOOP AT c_extension2 INTO wa_extension.
    ld_posnr = wa_extension-valuepart1.
    READ TABLE c_accit WITH KEY posnr = ld_posnr
          INTO wa_accit.
    IF sy-subrc IS INITIAL.
      IF wa_extension-structure = 'XREF1_HD'.
        wa_accit-xref1_hd = wa_extension-valuepart2.
        MODIFY c_accit FROM wa_accit index sy-tabix TRANSPORTING xref1_hd.
      ENDIF.
    ENDIF.
  ENDLOOP.




Thursday, February 28, 2019

BADI For Material check In SAP ABAP.

BADI FOR MATERIAL CHECK

The Requirement for information message .When you creating a material if material group is A10 and division is: 05.
(This is only use for: As it needs two information for the material and user wants information message while saving the material. we can’t use field exit for this).
First step:
How to find appropriate BADI for this requirement??
Go to T-Code:--SE24
PUT:-- CL_EXITHANDLER.
NEXT:-Click display button.
Add the break- point into Class CL_EXITHANDLER’s GET_INSTANCE method.
Next:-Go to T-code MM01, After that you create a material and try to save it. it stops at many locations with different values of EXIT_NAME. (After checking into Se18 we got the BADI_MATERIAL_CHECK which can be used for our requirement.
    §  It has a method CHECK_DATA which is called before saving the material.
    §  It also has WMARA table as input data (Material Group and Division comes in MARA table).
Step 2:
Go to Transaction code SE18.
Open BADI: BADI_MATERIAL_CHECK.
Go to menu option Implementation  Create.
Step 3:
Put the name of implementation as ZMM_MAT_CHECK.
Step 4:
Double click on the method CHECK_DATA.If you notice the input parameters we have many data related to batch, material and storage location etc.
For our requirement we need material group and division which exist in WMARA. Put the below code inside the method then activate the class and method.

IF WMARA-MATKL EQ
‘A10’
AND WMARA-SPART EQ
’05’.
message
‘Material creation for this Group should be avoided for animal products!!’
TYPE
‘I’.

ENDIF.
This code is just checks the material group and division.
Step 5:
Go back and activate the implementation.
Step 6:
For this go to transaction MM01 and try to create a material.
(if you are confused use material name as CH004 ,
Industry sector as Animal Health and
Material Type as Beverages )
Click on the ENTER Button and from the view select BASIC DATA 1.