Tuesday 31 July 2012

Idoc steps


Steps to be done in Source client

 1. Go to transaction SE11 -> create a table with entries.
 2. Go to transaction WE31 -> create segments as shown before. Here you have to mention all the fields mentioned in the database table.
 3. Go to transaction WE30 -> create basic IDOC type and release the segments and basic type.
 4. Go to transaction WE81 -> create message type.
 5. Go to transaction WE82 -> assign message type to basic Idoc type.
 6. Go to transaction BD64 -> Click on Display/change button          
 7. Click on Edit menu -> model view -> create      
 8. Specify description and technical name and press continue.                    
 9. Select your model view -> click edit -> Add message type                  
 10. In dialog box specify sender, receiver, and message type and continue.
 11. Click on environment menu -> generate partner profile               
  12. It will show the following screen. Select your model view and click on execute.      
  13. It will show the partner profile log in next screen.
  14. Click on back button 2 times it will take to distribution model screen.
  15. Click on Edit -> Model view -> Distribute
  16. In displayed dialog box select the partner system and continue.
   17. Then it will show the log of model view distribution.
   18. To check partner profile go to transaction WE20.
   19. Then write the report program in SE38 to create IDOC control records and transfer it to destination   partner system.
   20. Go to Transaction WE02 to check the generated IDOC control records. 



Steps to be done in Destination client

 

 

1.                            Go to transaction SE37 to create the function module for updating the table from IDOC segments.
2.                            Specify import, export and table parameters.
3.                            Go to transaction WE57 for assigning the FM to logical system. Click on Display/ change button.
4.                            Specify FM name, function type, basic type(IDOC ), message type and direction then save it.
5.                            Go to transaction BD51 to define input method for inbound function module and click on Display change button
6.                            Specify your function module and input type by clicking the new entries.
7.                            Go to transaction WE42 and  create process code.
8.                            Go to transaction BD64 and generate the partner profile again.
9.                            Got o transaction SE 38 and execute the transaction in source system (client100).
10.                       Check in destination system (client 800). Go to Transaction WE02 and check your table in SE11. (You can get the transferred entries in that table).

Wednesday 25 July 2012

Trafic lights using alv grid.

Trafic light using alv.
Based the select option value it display the trafic lights in alv grid.


TABLES: MARA.
TYPE-POOLS: SLIS,ICON.
TYPESBEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        ERSDA TYPE MARA-ERSDA,
        ERNAM TYPE MARA-ERNAM,
        PSTAT TYPE MARA-PSTAT,
        MATKL TYPE MARA-MATKL,
      END OF TY_MARA.

TYPES:BEGIN OF TY_MARA1,
      ICON TYPE CHAR4.
      INCLUDE TYPE TY_MARA.

TYPESEND OF TY_MARA1.

DATA: LS_MARA TYPE TY_MARA,
      LT_MARA TYPE STANDARD TABLE OF TY_MARA,
      LS_FINAL TYPE TY_MARA1,
      LT_FINAL TYPE TABLE OF TY_MARA1,
      LT_FIELDCAT TYPE  SLIS_T_FIELDCAT_ALV,
      LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
      LS_LAYOUT  TYPE SLIS_LAYOUT_ALV,
      TEMP TYPE MARA-MATNR.



CONSTANTSprogram TYPE syrepid VALUE sy-repid.


SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.


IF SY-SUBRC EQ 0.
SELECT   MATNR
         ERSDA
         ERNAM
         PSTAT
         MATKL
         FROM MARA INTO TABLE LT_MARA .
          "WHERE MATNR IN S_MATNR.

  MESSAGE 'THE DATA FOUND' TYPE 'I'.
  ELSE.
*
*  MESSAGE 'THE DATA NOT FOUND' TYPE 'I'.
  ENDIF.

  PERFORM POP_RECORD.
  PERFORM DISPLAY.
*&---------------------------------------------------------------------*
*&      FORM  POP_RECORD
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM POP_RECORD .
LOOP AT LT_MARA INTO LS_MARA.

CLEAR TEMP.

TEMP = LS_MARA-MATNR.

IF TEMP IN S_MATNR.          "checking the selection option values
  LS_FINAL-ICON = ICON_GREEN_LIGHT.

  ELSE.


      LS_FINAL-ICON = ICON_RED_LIGHT.
*    ELSE.
*
*     LS_FINAL-ICON = ICON_YELLOW_LIGHT.

   ENDIF.



   LS_FINAL-MATNR  = LS_MARA-MATNR.
   LS_FINAL-ERSDA  = LS_FINAL-ERSDA.
   LS_FINAL-ERNAM  = LS_FINAL-ERNAM.
   LS_FINAL-PSTAT  = LS_FINAL-PSTAT.
   LS_FINAL-MATKL  = LS_FINAL-MATKL.

   APPEND LS_FINAL TO LT_FINAL.

CLEAR LS_FINAL.
ENDLOOP.
REFRESH LT_MARA.
ENDFORM.    " POP_RECORD


*&---------------------------------------------------------------------*
*&      FORM  DISPLAY
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM DISPLAY .
PERFORM F_cat.

PERFORM P_LAYOUT.

PERFORM ALV.


ENDFORM.                    " DISPLAY
*
*&---------------------------------------------------------------------*
*&      FORM  P_LAYOUT
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM P_LAYOUT .
LS_LAYOUT-ZEBRA = 'X'.
LS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

ENDFORM.                    " P_LAYOUT
*&---------------------------------------------------------------------*
*&      FORM  ALV
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM ALV .


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     I_CALLBACK_PROGRAM                = program
*     I_CALLBACK_PF_STATUS_SET          = ' '
*     I_CALLBACK_USER_COMMAND           = ' '
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
     IS_LAYOUT                          =  LS_LAYOUT
     IT_FIELDCAT                        =  LT_FIELDCAT
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
*     IT_SORT                           =
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
*     I_SAVE                            = ' '
*     IS_VARIANT                        =
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
*     IS_PRINT                          =
*     IS_REPREP_ID                      =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 = 0
*     I_HTML_HEIGHT_END                 = 0
*     IT_ALV_GRAPHICS                   =
*     IT_HYPERLINK                      =
*     IT_ADD_FIELDCAT                   =
*     IT_EXCEPT_QINFO                   =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      T_OUTTAB                          = LT_FINAL
   EXCEPTIONS
     PROGRAM_ERROR                     = 1
     OTHERS                            = 2
            .
  IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM.                    " ALV
**&---------------------------------------------------------------------*
**&      Form  FIELDCAT
**&---------------------------------------------------------------------*
**       text
**----------------------------------------------------------------------*
**  -->  p1        text
**  <--  p2        text
**----------------------------------------------------------------------*
*FORM FIELDCAT .

*
*ENDFORM.                    " FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  F_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM F_CAT .


DEFINE FCAT_MERGE.

LS_FIELDCAT-COL_POS        = &1.
LS_FIELDCAT-FIELDNAME      = &2.
IF LS_FIELDCAT-FIELDNAME   = 'ICON'.
LS_FIELDCAT-ICON         = 'X'.  " DISPLAY THE FIELD AS ICON
LS_FIELDCAT-SELTEXT_M    = 'OCCUPENCY STATUS'.   " COLUMN HEADER
LS_FIELDCAT-INTTYPE      = 'C'.
LS_FIELDCAT-OUTPUTLEN    = '4'.
ENDIF.

LS_FIELDCAT-REF_FIELDNAME  = &3.
LS_FIELDCAT-REF_TABNAME    = &4.

IF LS_FIELDCAT-FIELDNAME  = 'MATNR'.
LS_FIELDCAT-CFIELDNAME  = 'MATNR'.
LS_FIELDCAT-CTABNAME    = 'LT_FINAL'.
ENDIF.

APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR LS_FIELDCAT.

END-OF-DEFINITION.

FCAT_MERGE '1' 'ICON' '' ''.
FCAT_MERGE '2' 'MATNR' 'MATNR' 'MARA'.
FCAT_MERGE '3' 'ERSDA' 'ERSDA' 'MARA'.
FCAT_MERGE '4' 'ERNAM' 'ERNAM' 'MARA'.
FCAT_MERGE '5' 'PSTAT' 'PSTAT' 'MARA'.
FCAT_MERGE '6' 'MATKL' 'MATKL' 'MARA'.



ENDFORM.                    " F_CAT

Thursday 19 July 2012

Finding Badi


Multiple ways of finding Badi 






• Finding BADI Using CL_EXITHANDLER=>GET_INSTANCE
• Finding BADI Using SQL Trace (TCODE-ST05).
• Finding BADI Using Repository Information System (TCODE- SE84).

1. Go to the Transaction, for which we want to find the BADI, take the example of Transaction VD02. Click on System->Status. Double click on the program name. Once inside the program search for ‘CL_EXITHANDLER=>GET_INSTANCE’.
Make sure the radio button “In main program” is checked. A list of all the programs with call to the BADI’s will be listed.
The export parameter ‘EXIT_NAME’ for the method GET_INSTANCE of class CL_EXITHANDLER will have the user exit assigned to it. The changing parameter ‘INSTANCE’ will have the interface assigned to it. Double click on the method to enter the source code.Definition of Instance would give you the Interface name.

2. Start transaction ST05 (Performance Analysis).
Set flag field "Buffer trace"
Remark: We need to trace also the buffer calls, because BADI database tables are buffered. (Especially view V_EXT_IMP and V_EXT_ACT)
Push the button "Activate Trace". Start transaction VA02 in a new GUI session. Go back to the Performance trace session.
Push the button "Deactivate Trace".
Push the button "Display Trace".
The popup screen "Set Restrictions for Displaying Trace" appears.
Now, filter the trace on Objects:
• V_EXT_IMP
• V_EXT_ACT

Push button "Multiple selections" button behind field Objects
Fill: V_EXT_IMP and V_EXT_ACT

All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BADI class interfaces. The BADI name is after the IF_EX_.
So the BADI name of IF_EX_CUSTOMER_ADD_DATA is CUSTOMER_ADD_DATA

3. Go to “Maintain Transaction” (TCODE- SE93).
Enter the Transaction VD02 for which you want to find BADI.
Click on the Display push buttons.
Get the Package Name. (Package VS in this case)

Go to TCode: SE84->Enhancements->Business Add-inns->Definition
Enter the Package Name and Execute.

Here you get a list of all the Enhancement BADI’s for the given package MB.
The simplese way for finding BADI is
1. Choose Tcode Program & package for that Tcode.
2. Go to Tcode se18
3. Press F4
4. Search by package or by program.



editable alv


Editable ALV through OOPS

*&---------------------------------------------------------------------*
*& Report  YKC_ALV_OOPS
*&
*&---------------------------------------------------------------------*
*& This prog will help in understanding ALV OOPS
*& EDIT on SAVE
*& Tool bar button addition
*&---------------------------------------------------------------------*
REPORT  ykc_alv_oops.

TABLES: mara.
DATABEGIN OF it_tab OCCURS 0,
      matnr LIKE mara-matnr,
      ersda LIKE mara-ersda,  "creation date
      ernam LIKE mara-ernam,  "person created
      pstat LIKE mara-pstat,  "maint stat
      lvorm LIKE mara-lvorm,  "flg for deletion
      mtart LIKE mara-mtart,  "mat type
      meins LIKE mara-meins,  "uom
      END OF it_tab.
DATA: wa_it_tab LIKE LINE OF it_tab.  "making work area
DATA: i_modified TYPE STANDARD TABLE OF mara,"For getting modified rows
      w_modified TYPE mara.
CLASS lcl_events_d0100 DEFINITION DEFERRED.
DATA: event_receiver1  TYPE REF TO lcl_events_d0100,
      i_selected_rows TYPE lvc_t_row,                "Selected Rows
      w_selected_rows TYPE lvc_s_row.

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 DEFINITION.
  PUBLIC SECTION.
    METHODS
        handle_hotspot_click
        FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
             e_row_id
             e_column_id
             es_row_no
             sender.
*---code addition for ALV pushbuttons
*--for placing buttons
    METHODS handle_toolbar_set
        FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
              e_object
              e_interactive.
*---user command on clicking a button
    METHODS handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
             e_ucomm.
ENDCLASS.                    "lcl_events_d0100 DEFINITION

TYPE-POOLS cndp.
DATA ok_code TYPE sy-ucomm.


*----------------------------------------------------------------------*
*                       FOR VARIANT
*----------------------------------------------------------------------*
DATA st_var TYPE disvariant .
DATA save TYPE c.
st_var-report = 'YKC_ALV_OOPS'.
save = 'A'.

*----------------------------------------------------------------------*
*         FOR LAYOUT
*----------------------------------------------------------------------*
DATA loyo TYPE lvc_s_layo.
loyo-zebra = 'X'.
loyo-detailinit = 'X'.
loyo-info_fname = 'RED'.

*----------------------------------------------------------------------*
*           FOR FIELD CATALOG
*----------------------------------------------------------------------*
DATA fcat TYPE lvc_t_fcat.
DATA wa_fcat LIKE LINE OF fcat.
*--Declaration for toolbar buttons
DATA : ty_toolbar      TYPE stb_button.
DATA : e_object        TYPE REF TO cl_alv_event_toolbar_set,
       io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.
*---custom container
DATA container TYPE REF TO cl_gui_custom_container.
DATA ref_grid TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT container
  EXPORTING
    container_name = 'CONTAINER'."name of container in module pool
CREATE OBJECT ref_grid
  EXPORTING
    i_parent = container.

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 IMPLEMENTATION.
*---method for hotspot
  METHOD handle_hotspot_click.
    DATA:ls_col_id   TYPE lvc_s_col.
    READ TABLE it_tab INTO wa_it_tab
                             INDEX e_row_id-index.
    IF sy-subrc = 0.
      CHECK ( wa_it_tab-matnr IS NOT INITIAL ).
      CASE e_column_id-fieldname.
        WHEN 'MATNR'.
          LEAVE PROGRAM.
*---put your own logic as per requirement on hotspot click
        WHEN OTHERS.
*       do nothing
      ENDCASE.
      CALL METHOD ref_grid->set_current_cell_via_id
        EXPORTING
          is_row_id    = e_row_id
          is_column_id = ls_col_id.
    ENDIF.
  ENDMETHOD.                    "handle_hotspot_click
**---method for handling toolbar
  METHOD handle_toolbar_set.
    CLEAR ty_toolbar.
    ty_toolbar-function = 'EDIT'"name of btn to  catch click
    ty_toolbar-butn_type = 0.
    ty_toolbar-text = 'EDIT'.
    APPEND ty_toolbar    TO e_object->mt_toolbar.
  ENDMETHOD.                    "handle_toolbar_set
  METHOD handle_user_command.
    DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    DATA: lt_rows TYPE lvc_t_row,
          lt_index TYPE  lvc_s_row-index.
    CASE e_ucomm.
      WHEN 'EDIT'.
        PERFORM save_database.
        CALL METHOD ref_grid->refresh_table_display.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command
ENDCLASS.                    "lcl_events_d0100 IMPLEMENTATION

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM field_catalog.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text : getting data into internal table
*----------------------------------------------------------------------*
FORM get_data .
  SELECT matnr ersda ernam pstat lvorm mtart meins
         INTO TABLE it_tab
         FROM mara
         WHERE matnr GE '000000000000000001'.
ENDFORM.                    " get_data

*&---------------------------------------------------------------------*
*&      Form  field_catalog
*&---------------------------------------------------------------------*
*       text  :setting field cat
*----------------------------------------------------------------------*
FORM field_catalog .
  REFRESH fcat.
  DATA: lv_pos TYPE i.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-coltext = 'Material No'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-hotspot = 'X'.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'ERSDA'.
  wa_fcat-coltext = 'Creation Date'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-edit = 'X'.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-coltext = 'Person Created'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'PSTAT'.
  wa_fcat-coltext = 'Maint Stat'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'LVORM'.
  wa_fcat-coltext = 'Flag For Deletion'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MTART'.
  wa_fcat-coltext = 'Material Type'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-coltext = 'UOM'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  CREATE OBJECT event_receiver1.
*---setting event handlers
  SET HANDLER event_receiver1->handle_toolbar_set   FOR ref_grid.
  SET HANDLER event_receiver1->handle_user_command  FOR ref_grid.
  SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.

*----------------------------------------------------------------------*
*           ALV GRID DISPLAY
*----------------------------------------------------------------------*
  CALL METHOD ref_grid->set_table_for_first_display
    EXPORTING
      is_variant      = st_var
      i_save          = save
      is_layout       = loyo
    CHANGING
      it_outtab       = it_tab[]
      it_fieldcatalog = fcat.
  CALL SCREEN 100.
ENDFORM.                    " field_catalog

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  CREATE OBJECT gr_events_d0100.
*
*  SET HANDLER gr_events_d0100->double_click
*
*                 FOR ref_grid.
  CALL METHOD ref_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified.
  SET PF-STATUS 'S100'.
  SET TITLEBAR 'XXX'.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  exit  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  CASE ok_code.
    WHEN 'EXI' .
      CLEAR ok_code.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " exit  INPUT

*&---------------------------------------------------------------------*
*&      Form  SAVE_DATABASE
*&---------------------------------------------------------------------*
*       text : saving into DDIC from internal table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM save_database .
*--- Getting the selected rows index
  CALL METHOD ref_grid->get_selected_rows
    IMPORTING
      et_index_rows = i_selected_rows.
*--- Through the index capturing the values of selected rows
  LOOP AT i_selected_rows INTO w_selected_rows.
    READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING wa_it_tab TO w_modified.
      APPEND w_modified TO i_modified.
    ENDIF.
  ENDLOOP.
  MODIFY mara FROM TABLE i_modified.
ENDFORM.                    " SAVE_DATABASE