Thursday, June 3, 2010

How to find BAdi

This post is taken from http://erpgenie.com/abaptips/content/view/594/40/
I have added this here since it might be useful to me if in case I forget how to find a BADI :)

Business Add-Ins (BAdis) are a  SAP enhancement technique based on ABAP Objects. Two parts - Definition and its Implementation - definition can either be SAP provided or user may also create it.

You can look for BAdi definition in IMG and in component hierarchy. But there are some easier methods to find a BAdi. They are follows:

Method 1
These steps should enable you to find a BAdi related to any transaction in a matter of minutes.
  • 1) Go to the transaction SE37 to find your function module.
  • 2) Locate the function SXV_GET_CLIF_BY_NAME.
  • 3) Put a break-point there.
  • 4) Now open a new session.
  • 5) Go to your transaction.
  • 6) At that time, it will stop this function.
  • 7) Double click on the function field NAME.
  • 8) That will give you name of the BAdi that is provided in your transaction.

Method 2
  • 1. Goto SE80,  open CL_EXITHANDLER (Class)
  • 2. Goto Method, GET_INSTANCE
  • 3. Set a break point at 
CALL METHOD cl_exithandler=>get_class_name_by_interface
    EXPORTING
      instance                      = instance
    IMPORTING
      class_name                    = class_name
    CHANGING
      exit_name                     = exit_name
    EXCEPTIONS
      no_reference                  = 1
      no_interface_reference        = 2
      no_exit_interface             = 3
      data_incons_in_exit_managem   = 4
      class_not_implement_interface = 5
      OTHERS                        = 6.
  CASE sy-subrc.
    WHEN 1.
      RAISE no_reference.
    WHEN 2.
      RAISE no_interface_reference.
    WHEN 3.
      RAISE no_exit_interface.
    WHEN 4.
      RAISE data_incons_in_exit_managem.
    WHEN 5.
      RAISE class_not_implement_interface.
  ENDCASE.

  • 4) Now open a new session.
  • 5) Go to your transaction.
  • 6) At that time, it will stop this function.
  • 7) Double click on the function field EXIT_NAME.
  • 8) That will give you name of the BAdi that is provided in your transaction.
 
Method 3:
  • 1. Goto ST05
  • 2. Select SQL trace and buffer trace
  • 3. Activate trace
  • 4. Now run your transaction
  • 5. Deactivate trace
  • 6. Display trace7. A pop will come
  • 8. Enter V_EXT_ACT and V_EXT_IMP as the 2 objects
  • 9. Now display the trace results. It will return all the BAPI and enhancement list in order of their execution.

Friday, March 19, 2010

IDOC /AFS/WMMBID02 message type : WMMBXY

i have been stuck with the idoc /AFS/WMMBID02 message type WMMBXY giving an error when ever i try to do a movement type 122.
I was Debugging the stranded code for more than 2 days and later i Found out that this occurs since the idoc requires few more information. this was mentioned on SAP note 833603.

Symptom
You want to post goods receipt for a stock transport order using an IDoc .

More Terms
WMMBXY, WMMBID01, WMMBID02, MBGMCR, L_IDOC_INPUT_WMMBXY

Cause and Prerequisites
It is not clear how the segments are to be filled, to ensure correct
assignment and updating of the delivery if necessary.

Solution
The following sections only take into account processing with SAP core s
tandard functions and do not include industry solutions.

1. Goods receipt for delivery

a) WMMBXY (WMMBID01, WMMBID02)

The following fields in the segment E1MBXYI must be filled:
EBELN Purchase order number
EBELP Purchase order item
KZBEW Movement indicator = 'B'
POSNR Delivery item (with leading zeros)
VBELN Delivery (with leading zeros)

b) MBGMCR (MBGMCR01, MBGMCR02)
Prerequisite: Note 356665 and basic type MBGMCR02 (not MBGMCR01).
The segment E1BP2017_GM_CODE receives the value GM_CODE = '01'.
In the segment E1BP2017_GM_ITEM_CREATE, the following must be
filled:
PO_NUMBER Purchase order number
PO_ITEM Purchase order item
MVT_IND Movement indicator = 'B'
In the subordinate segment E1BP2017_GM_ITEM_CREATE1, the following
must be filled:
DELIV_NUMB Delivery (with leading zeros)
DELIV_ITEM Delivery item (with leading zeros)

2. Goods receipt for the inbound delivery

a) WMMBXY (WMMBID01, WMMBID02)
In the segment E1MBXYI, no purchase order must be assigned. The
fields EBELN and EBELP remain blank. The movement indicator (KZBEW)

receives the value 'B'.
In the subordinate segment E1MBXYJ, the following are to be filled:
VLIEF_AVIS Inbound delivery
VBELP_AVIS Inbound delivery item

b) MBGMCR
The segment E1BP2017_GM_CODE receives the value GM_CODE = '01'.
In the segment E1BP2017_GM_ITEM_CREATE, no purchase order must be
assigned. The fields PO_NUMBER and PO_ITEM remain blank. The
following must be filled:
MVT_IND Movement indicator = 'B'
DELIV_NUMB_TO_SEARCH Inbound delivery (with leading zeros)
DELIV_ITEM_TO_SEARCH Inbound delivery item (with leading zeros)

IDOCs of the message type WMMBXY are updated using the function
module L_IDOC_INPUT_WMMBXY. In this module, you can change data
using the user exit 'EXIT_SAPLLMDE_002'. Here, use Transaction CMOD
to activate the SAP enhancement MWMIDO08 and implement the required
changes in the exit function module EXIT_SAPLLMDE_002.

hope this post will help someone else who might get stuck like me

Tuesday, March 9, 2010

selection option recommended sign

 

most of the time when we develop a report program or a selection screen. We have to remove the standard validation which comes when we define a selection option as mandatory and add a custom validation. In such cases we are unable to display the selection option as a mandatory sign. To do this we can make the input field recommended which will give the sign. bellow is the code how to do it.



AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

   IF screen-name EQ 'S_WERKS-LOW'.
     screen-required = 2. "2 is recommended
   ENDIF.

  MODIFY SCREEN.

ENDLOOP. 

Monday, March 8, 2010

selection screen with tabs

This post is about selection screen with tabs. Selection screen with tabs are not that hard to implement on ABAP and I am sure if you search online you will always get the code for it.... but just to start things ill just give the code no a basic selection screen with tabs...

SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN .

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
           
SELECT-OPTIONS: s_ebeln FOR zconf_stage-ebeln,
                s_ebelp FOR zconf_stage-ebelp,
                s_bsart FOR ekko-bsart,
                s_werks FOR ekpo-werks,
                s_matnr FOR ekpo-matnr,
                s_lifnr FOR ekko-lifnr,
                s_ekgrp FOR ekko-ekgrp,
                s_budat FOR zconf_stage-budat,
                s_kunnr FOR vbpa-kunnr.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 101.


SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN .

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_ebeln1 FOR zconf_stage-ebeln,
                s_bsart1 FOR ekko-bsart,
                s_werks1 FOR ekpo-werks ,
                s_matnr1 FOR ekpo-matnr,
                s_lifnr1 FOR ekko-lifnr,
                s_ekgrp1 FOR ekko-ekgrp,
                s_budat1 FOR zconf_stage-budat,
                s_kunnr1 FOR vbpa-kunnr.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF SCREEN 102.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 24 LINES,
TAB (30) button1 USER-COMMAND on,
TAB (30) button2 USER-COMMAND auto,
END OF BLOCK mytab.


INITIALIZATION.
  button1 = text-011.
  button2 = text-012.

  mytab-prog = sy-repid.
  mytab-dynnr = 101.
  mytab-activetab = 'BUTTON1'.



AT SELECTION-SCREEN .

  IF sy-batch = 'X'.
    mytab-dynnr = 102.
    mytab-activetab = 'BUTTON2'.
    sy-ucomm = 'AUTO'.
  ENDIF.

  CASE sy-dynnr.

    WHEN 1000.
      CASE sy-ucomm.
        WHEN 'ON'.
          mytab-dynnr = 101.
          mytab-activetab = 'BUTTON1'.
        WHEN 'AUTO'.
          mytab-dynnr = 102.
          mytab-activetab = 'BUTTON2'.
      endcase.

    WHEN 0101.
      mytab-dynnr = 101.
      mytab-activetab = 'BUTTON1'.
    WHEN 'ONLI'.
          PERFORM screen_validation101.
      ENDCASE.

    WHEN 0102.
      mytab-dynnr = 102.
      mytab-activetab = 'BUTTON2'.
      case sy-ucomm.
    WHEN 'ONLI'.
          PERFORM screen_validation102.
      ENDCASE.
  ENDCASE.

START-OF-SELECTION.

  CASE mytab-activetab.
    WHEN 'BUTTON1'."online mode
   
    WHEN 'BUTTON2'." when automatic
    
  ENDCASE.

now the above code is to a selection screen with tabs that you code using a report program.( this code cannot be used in module pool program )

When a customer request to a selection screen with tabs there can be 2 reasons.

1) To group a selection on one out put ( I mean the final out-put is one but selection screen can be with tabs to make things clear for e.g on SD related report the tabs can be Material selection , SO selection like wise )

2) The user requires different kind of out comes with different tabs... for e.g tab no1 to work during online operations and tab no 2 to work on background operations.

The above requirement 1 which will be totally fine with the code given on top. But the requirement 2 will be a issue when it comes to the above code. As most of the developers know on a selection screen we will always have mandatory fields. when switching between tabs the selection screen first calls the validation and then it calls the normal screen code ( as you know the validation is automatic if me make a selection option mandatory and we have no say on it ).
  So in case if the user wants the functionality of the tab 2 he first has to fill all the mandatory fields on tab 1 so that the error wont occur. This was a error I had to face during my development for this there are 2 way outs

1) do the validation by your self ( draw back : you wont get the mandatory sign on the selection screen )
2) write a selection screen with tabs ( draw back : the user wont be able to save variants or this part has to be coded which will be a messy job ) 

for the 2nd option on above to make sure the tab switching with happen without first validating you have to do the codding as follows

PROCESS BEFORE OUTPUT.
  MODULE STATUS_0100.
  MODULE set_tabs.

  call SUBSCREEN SUB INCLUDING sy-repid gv_dynnr.
*
PROCESS AFTER INPUT.

  MODULE exit_comm.
  MODULE switch_tab.
  CALL SUBSCREEN SUB.
  MODULE screen_comm.

  MODULE USER_COMMAND_0100.


before call sub screen you have to call a module switch tabs.

on my case my customer wanted the variants to be there. Therefore they agreed to the validation by code where the mandatory sign is not displayed.

Tuesday, March 2, 2010

five months of busy work

For the past 5 moths I have been really busy that I didn't have anytime to blog or contribute to SCN on SAP. During these 5 months I was working for 1 main client on one main area it was all about Vendor confirmations. I have been so much into it that now I know a lot about the confirmation process. There were two main developments where one was on SAP user level and other was on customer level which was a web Dynpro development. During this period I gained lots of functional Exp but on technical side it was noting much same old ABAP.

but there were few limitations which I came a cross when I developed tab striped selection screen which I am hoping to blog sometime in the future.

till then enjoy reading my old post's on SAP but still there is nothing much since from the time I joined my work place I hardly had any free time.

Wednesday, September 16, 2009

when and where we can use parallel cursor


Loop AT i_primary into wa_primary.
Loop AT i_secondary into wa_secondary from lv_index.
If ( wa_primary-field1 NE wa_secondary-field1 ) or
( wa_primary-field2 NE wa_secondary-field2 ).
Lv_index = sy-tabix.
Endif.
“ your code comes here “
Endloop.
Endloop.
To use this following should be true
1)      Both tables should be sorted with the same key ( in the above case field1 and field2 )
2)      The mapping between primary to secondary tables should be
a.       one to many ( for one record in primary there are multiple records in secondary )
b.      one to one (for one record in primary there is only one in secondary )
Please note that other than the above 2 other 2 scenarios (many to many & many to one) will not work with the above logic and make sure you don’t use in such case.
3)      The secondary table should not contain a record which does not map to the primary table ( this will not happen if the secondary is fetched using for all entries from primary )
4)      Please make sure you do not delete any record from primary before using the logic which will make the point 3 false  
5)      If you were to use a 'AND' in where statement of the inner loop you should use or in the inner loop if condition in the above logic. 
 

Friday, September 11, 2009

Copy to Clipborad SAP

copy to clipborad

Bellow code is how to copy data to clipboard. This feature helps you when there is a BDC recording and you want to add selection extended options

    DATA: v_rc TYPE I,
       it_data TYPE STANDARD TABLE OF CHAR128,
       wa_data TYPE char128.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_EXPORT
    IMPORTING DATA = it_data
    CHANGING RC = v_rc      .
Google