Tuesday, November 23, 2010

OO ALV Event DATA_CHANGED

Download .nugg file using link below and install this to your system using SAPLink.
SAPLink Package of Application

After installing active
1. ZFSL_OO_ALV_DATA_CHANGED_EVENT Main Program
2. 9001 Screen
3. MAIN_PF_STATUS PF-STATUS
4. MAIN_TITLE TITLEBAR

* Main Program
*&---------------------------------------------------------------------*
*& Report  ZFSL_OO_ALV_DATA_CHANGED_EVENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zfsl_oo_alv_data_changed_event.

DATA: ok_code_9001  LIKE sy-ucomm,
      field         TYPE c LENGTH 50,
      line          TYPE i,
      offset        TYPE i.

DATA: alv_grid  TYPE REF TO cl_gui_alv_grid,
      alv_custom_container TYPE REF TO cl_gui_custom_container.

DATA: it_fcat TYPE lvc_t_fcat,
      wa_fcat LIKE LINE OF it_fcat.

DATA: l_valid TYPE char1.

DATA: it_t247 LIKE STANDARD TABLE OF t247,
      wa_t257 LIKE t247,
      it_outtab LIKE STANDARD TABLE OF t247,
      wa_outtab LIKE t247.

CLASS: lcl_event_receiver DEFINITION DEFERRED.
DATA: event_receiver TYPE REF TO lcl_event_receiver.

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
          handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed.
ENDCLASS.                    "lcl_event_receiver DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_data_changed.
    BREAK-POINT.
  ENDMETHOD.                    "handle_data_changed
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION


************************************************************************
*                        START-OF-SELECTION                            *
************************************************************************
START-OF-SELECTION.
  CALL SCREEN 9001.

************************************************************************
*                       PROCESS BEFORE OUTPUT                          *
************************************************************************
*&---------------------------------------------------------------------*
*&      Module  DATA_SELECTION_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE data_selection_9001 OUTPUT.

  IF it_t247[] IS INITIAL.
    SELECT *
      INTO CORRESPONDING FIELDS OF TABLE it_t247
      FROM t247
      WHERE spras = 'E'.
    it_outtab[] = it_t247[].
  ENDIF.

ENDMODULE.                 " DATA_SELECTION_9001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
  SET PF-STATUS 'MAIN_PF_STATUS'.
  SET TITLEBAR 'MAIN_TITLE'.

  IF it_fcat[] IS INITIAL.
    PERFORM fill_fcat.
  ENDIF.

  IF alv_custom_container IS INITIAL.
    PERFORM show_alv.
  ENDIF.

ENDMODULE.                 " STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  CLEAR_OK_CODE_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE clear_ok_code_9001 OUTPUT.
  CLEAR: ok_code_9001.
ENDMODULE.                 " CLEAR_OK_CODE_9001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  SET_CURSOR_FIELD_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_cursor_field_9001 OUTPUT.
  SET CURSOR FIELD field LINE line OFFSET offset.
ENDMODULE.                 " SET_CURSOR_FIELD_9001  OUTPUT

************************************************************************
*                        PROCESS AFTER INPUT                           *
************************************************************************
*&---------------------------------------------------------------------*
*&      Module  EXIT_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit_command_9001 INPUT.
  CASE ok_code_9001.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL' .
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " EXIT_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  GET_CURSOR_FIELD_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE get_cursor_field_9001 INPUT.
  GET CURSOR FIELD field LINE line OFFSET offset.
ENDMODULE.                 " GET_CURSOR_FIELD_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  IT_OPERATION_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE it_operation_9001 INPUT.

ENDMODULE.                 " IT_OPERATION_9001  INPUT

*&---------------------------------------------------------------------*
*&      Module  SAVE_DATA_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE save_data_9001 INPUT.
  CASE ok_code_9001.
    WHEN 'SAVE'.
      CALL METHOD alv_grid->check_changed_data
        IMPORTING
          e_valid = l_valid.
      IF l_valid = 'X'.
        BREAK-POINT.
      ENDIF.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " SAVE_DATA_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

ENDMODULE.                 " USER_COMMAND_9001  INPUT


************************************************************************
*                                FORMs                                 *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  SHOW_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM show_alv .
  CREATE OBJECT alv_custom_container
    EXPORTING
      container_name = 'ALV_CONTROL'.

  CREATE OBJECT alv_grid
    EXPORTING
      i_parent = alv_custom_container.

  CREATE OBJECT event_receiver.
  SET HANDLER event_receiver->handle_data_changed FOR alv_grid.

  CALL METHOD alv_grid->set_table_for_first_display
    CHANGING
      it_outtab       = it_outtab
      it_fieldcatalog = it_fcat.
ENDFORM.                    " SHOW_ALV

*&---------------------------------------------------------------------*
*&      Form  FILL_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fill_fcat .
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'T247'
    CHANGING
      ct_fieldcat            = it_fcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT it_fcat INTO wa_fcat WHERE fieldname = 'LTX'.
    wa_fcat-edit = 'X'.
    MODIFY it_fcat FROM wa_fcat INDEX sy-tabix.
  ENDLOOP.
ENDFORM.                    "FILL_FCAT

* Flow Logic of Screen 9001
*********************************************************************
*                    PROCESS BEFORE OUTPUT                          *
*********************************************************************
PROCESS BEFORE OUTPUT.
  MODULE data_selection_9001.
  MODULE status_9001.
  MODULE clear_ok_code_9001.
  MODULE set_cursor_field_9001.

*********************************************************************
*                     PROCESS AFTER INPUT                           *
*********************************************************************
PROCESS AFTER INPUT.
  MODULE exit_command_9001 AT EXIT-COMMAND.
  MODULE get_cursor_field_9001.
  MODULE it_operation_9001.
  MODULE save_data_9001.
  MODULE user_command_9001.

Monday, November 22, 2010

Filter and Search in Table Control

From last few weeks I am observing two or three threads about searching in Table Control on SDN, those threads gave me idea to develop some Filtering and Searching option in Table Control I just completed this and going to share with you Friends.

I used SELECT-OPTIONs on Screen using SUB Screen, Macros, Dynamic Search Help and Dynamic Dropdown list Filling. I think these things will help specially for beginners those who didn’t play these things before.

Download .nugg file of that Program using link below and install this to your system using SAPLink.

SAPLink Package of Application

After installing active

1. ZFSL_FS_IN_TABLE_CONTROL Main Program
2. 9001 Screen
3. MAIN_PF_STATUS PF-STATUS
4. MAIN_TITLE TITLEBAR

Main Screen (Filter)

image

From Dropdown Listbox select the Value you want to filter by, which has already field as shown in below screenshots.

image image

Select different Values from the Dropdown Listbox and Press the Filter Button it will filter the records according to the Selected value as in bellow screens.

1st

image

2nd
image

3rd
image

Main Screen (Search)
In the case of Filter you can only select the values from the Dropdown Listbox you can't do the search like all strings starting from A. and also want to search string starting with A or B we will see this in next steps. The Main Search Screen will look like below one.
image
Search Help for Both Fields will fill dynamically according to the Table Control Values, for above Table Control Values Search Help will look like below.

INT field Search Help
image

CHAR field Search Help
image


We have the following Option in the Cash of Search, Select the Search Button after every entered value.


1st
image

2nd
image

You can also use the Extension button for Multiple Values in single field like i want to show records where INT having values 1 or 2 and CHAR having value starting with A or B.

3rd
1
image

image


2
image
image


3
image

Monday, November 15, 2010

Get Name of Files from Selected Directory to Excel File

REPORT  zfsl_gdirfn.

DATA: it_file LIKE STANDARD TABLE OF sdokpath WITH HEADER LINE,
      it_dir  LIKE STANDARD TABLE OF sdokpath WITH HEADER LINE,
      file_count TYPE i,
      dir_count TYPE i.

PARAMETER:  pdirp TYPE pfeflnamel OBLIGATORY, " Directory Path from where you want to get Name of Files
            psavep TYPE string OBLIGATORY. " Excel File Path and Name in which you want to Save Name of Files

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES' " To Get the Name of Files in Internal Table of Given Directory
  EXPORTING
    directory  = pdirp
    filter     = '*.*'
  IMPORTING
    file_count = file_count " Number of File in Directory
    dir_count  = dir_count " Number of Directory in Directory
  TABLES
    file_table = it_file " Table for Name of Files
    dir_table  = it_dir " Table for Name of Directories
  EXCEPTIONS
    cntl_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.

IF file_count IS NOT INITIAL.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = psavep " Path and Name of Excel File with Extension .xls
    TABLES
      data_tab                = it_file " Internal Table having all Name of Files
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ELSE.
  MESSAGE: 'No file found in the selected Directory' TYPE 'I'.
ENDIF.

INITIALIZATION.
  pdirp = 'C:\'.
  psavep = 'C:\test.xls'.

*F4 for Getting Directory Path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pdirp.
  DATA: fname TYPE string.

  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title         = 'Select Directory'
    CHANGING
      selected_folder      = fname
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  pdirp = fname.

*F4 for Getting File Path and Name
AT SELECTION-SCREEN ON VALUE-REQUEST FOR psavep.

  DATA: filename TYPE string,
        path TYPE string.

  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = 'Select path and file name'
      default_extension    = 'XLS'
    CHANGING
      filename             = filename
      path                 = path
      fullpath             = psavep
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

HR: Employee Infotype (0000 to 9999) Change History

A few months back I got a requirement to show all changes in Employee Master. First I tried my best to search the solution, I found many of the threads with the similar requirement but solution was not there, so I tried to think about it and came to a solution, I want to share this so that it will helpful people in future.

Selection Screen :- On the Selection Screen bellow you will have to enter the date between you want to display the changes and personal numbers or you can leave it blank for display changes of all Employees.




Output :- Bellow is the Screen Shot of the First Screen it will show up all the infotypes which have changed with the Employee's Personal Number and Name




After Click on any Change Category it will show up the details of that infotype as shown bellow.




Code :-Just Copy Past Bellow Code Save, Active and ready to display changes

REPORT zfsl_hremdch NO STANDARD PAGE HEADING.

TABLES: pa0000.

************************************************************************
*                         Selection Screen                             *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001 .
SELECT-OPTIONS: soaedat FOR pa0000-aedtm OBLIGATORY NO-EXTENSION,
                sopernr FOR pa0000-pernr.
SELECTION-SCREEN END OF BLOCK main.

************************************************************************
*                          Types Defined                               *
************************************************************************
TYPES:  BEGIN OF ty_tables, " Type for All HR Master Table Name and Description
        tabname LIKE dd02l-tabname,
        ddtext LIKE dd02t-ddtext,
        END OF ty_tables.

TYPES:  BEGIN OF ty_mas. " Type for HR Master Data Change
INCLUDE: STRUCTURE pakey,
         TYPE ty_tables.
TYPES:  ename LIKE pa0001-ename,
        aedtm LIKE pa0000-aedtm,
        uname LIKE pa0000-uname,
        END OF ty_mas.

TYPES:  BEGIN OF ty_pa0001, " Type for Ename and Plans
        pernr LIKE pa0001-pernr,
        ename LIKE pa0001-ename,
        END OF ty_pa0001.

************************************************************************
*                    Declaration of Variables                          *
************************************************************************
DATA: it_tables TYPE STANDARD TABLE OF ty_tables WITH HEADER LINE,
      wa_tables TYPE ty_tables,
      it_mas    TYPE STANDARD TABLE OF ty_mas WITH HEADER LINE,
      wa1_mas   TYPE ty_mas,
      wa2_mas   TYPE ty_mas,
      it_pa0001 TYPE SORTED TABLE OF ty_pa0001 WITH HEADER LINE WITH UNIQUE KEY pernr,
      wa_pa0001 TYPE ty_pa0001,
      str_date  TYPE string,
      str_len   TYPE i,
      date_low  TYPE c LENGTH 10,
      date_high TYPE c LENGTH 10,
      flag      TYPE c LENGTH 1.

************************************************************************
*                           FIELD-SYMBOLS                              *
************************************************************************
FIELD-SYMBOLS: <wa_mas_c> TYPE ty_mas.


************************************************************************
*                    Declaration of RANGES                             *
************************************************************************
DATA: rg_pernr LIKE RANGE OF pa0000-pernr WITH HEADER LINE.


************************************************************************
*                        START-OF-SELECTION                            *
************************************************************************
START-OF-SELECTION.

*  Format Date to Display on the Screen Top of Page
  CLEAR: date_low, date_high.
  WRITE: soaedat-low TO date_low, soaedat-high TO date_high.
  IF soaedat-high <> '00000000' .
    CONCATENATE 'Date: From' date_low 'to' date_high INTO str_date SEPARATED BY space.
  ELSE.
    CONCATENATE 'Date:' date_low INTO str_date SEPARATED BY space.
  ENDIF.

*  Select All the Table Name and Description Start from PA
  SELECT dd02l~tabname dd02t~ddtext
    INTO CORRESPONDING FIELDS OF TABLE it_tables
    FROM dd02l LEFT OUTER JOIN dd02t ON ( dd02l~tabname = dd02t~tabname AND dd02t~ddlanguage = 'E' )
    WHERE dd02l~tabname LIKE 'PA%'.

*  Now Delete all other Tables name Because we Need name from PA0000 to PA9999 we are dealing with all Infotypes 0000 to 9999
  LOOP AT it_tables INTO wa_tables.
    IF wa_tables-tabname+2(4) CO '0123456789' AND STRLEN( wa_tables-tabname ) = 6 .
    ELSE.
      DELETE it_tables INDEX sy-tabix.
    ENDIF.
  ENDLOOP.

  SORT it_tables BY tabname.

**  Get all the Changed Data and Append it to Internal Table and also Append pernrs to a Range for further USE
  rg_pernr-sign = 'I'. rg_pernr-option = 'EQ'.
  LOOP AT it_tables INTO wa_tables.
    SELECT pernr subty objps sprps endda begda seqnr aedtm uname
      APPENDING CORRESPONDING FIELDS OF TABLE it_mas
      FROM (wa_tables-tabname)
      WHERE aedtm IN soaedat
        AND pernr IN sopernr.
    IF sy-subrc = 0.
      LOOP AT it_mas ASSIGNING <wa_mas_c> WHERE tabname IS INITIAL.
        <wa_mas_c>-tabname = wa_tables-tabname.
        <wa_mas_c>-ddtext = wa_tables-ddtext.
        rg_pernr-low = <wa_mas_c>-pernr.
        APPEND rg_pernr.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

*  Delete all duplicate pernrs because we Need Distinct For this First Sort by low
  SORT rg_pernr BY low.
  DELETE ADJACENT DUPLICATES FROM rg_pernr COMPARING low.

  IF rg_pernr[] IS NOT INITIAL.
*  Select Ename and Plans from PA0001 for all pernr in Range
    SELECT mandt pernr subty objps sprps endda begda seqnr ename " We need only Pernr and Ename but because me using FOR ALL ENTRIES IN so talking all Key Fields
       FROM pa0001
      INTO CORRESPONDING FIELDS OF TABLE it_pa0001
      FOR ALL ENTRIES IN rg_pernr
      WHERE pernr = rg_pernr-low
        AND endda = '99991231'.
*  Now Place Names against every pernr
    LOOP AT it_mas ASSIGNING <wa_mas_c> .
      READ TABLE it_pa0001 WITH TABLE KEY pernr = <wa_mas_c>-pernr.
      IF sy-subrc = 0.
        <wa_mas_c>-ename = it_pa0001-ename.
      ENDIF.
    ENDLOOP.
  ENDIF.

  IF it_mas[] IS INITIAL.
    MESSAGE: 'No Change History Found' TYPE 'I'.
  ENDIF.

  SORT: it_mas BY pernr tabname aedtm begda.

*  Now Write the Master Internal Table on the Screen in the Specific Format
  LOOP AT it_mas INTO wa1_mas.

*    Uncomment this code if want to see Table Description between ( )
**    Here we only need the infotype name not Prefix Before Table Description So Get only Text in “ (  ) “
*    SEARCH wa1_mas-ddtext FOR '('.
*    IF sy-subrc EQ 0.
*      str_len = 60 - sy-fdpos.
*      wa1_mas-ddtext = wa1_mas-ddtext+sy-fdpos(str_len).
*    ELSE.
*      CLEAR: wa1_mas-ddtext.
*    ENDIF.

    wa2_mas = wa1_mas.

    AT NEW pernr.
      WRITE: 1(140) sy-uline,
             /1 '|',
             2(12) wa2_mas-pernr CENTERED HOTSPOT ON,
             14(1) '|',
             15(30) wa2_mas-ename HOTSPOT ON,
             45(1) '|',
             46(60) wa2_mas-ddtext HOTSPOT ON,
             106(1) '|',
             107(20) wa2_mas-uname CENTERED HOTSPOT ON,
             127(1) '|',
             128(12) wa2_mas-aedtm CENTERED HOTSPOT ON.
      HIDE : wa2_mas.
      WRITE:  140(1) '|',
        /1(140) sy-uline.
      flag = 'X'.
    ENDAT.
    IF flag EQ 'X'.
      flag = ''.
    ELSE.
      WRITE: /1 '|',
             45(1) '|',
             46(60) wa2_mas-ddtext HOTSPOT ON,
             106(1) '|',
             107(20) wa2_mas-uname CENTERED HOTSPOT ON,
             127(1) '|',
             128(12) wa2_mas-aedtm CENTERED HOTSPOT ON,
             140(1) '|'.
      HIDE : wa2_mas.
      WRITE: /1 '|',
             45(96) sy-uline.
    ENDIF.

    AT END OF pernr.
      WRITE: 1(140) sy-uline.
    ENDAT.
  ENDLOOP.

************************************************************************
*                           AT LINE-SELECTION                          *
************************************************************************
AT LINE-SELECTION.

  DATA: it_ref TYPE REF TO data.
  DATA: lvc_title TYPE lvc_title.

*  Creation of Dynamic Internal Table
  CREATE DATA it_ref TYPE STANDARD TABLE OF (wa2_mas-tabname).
  FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
  ASSIGN it_ref->* TO <itab>.

*  Selection of Changed Data
  SELECT * FROM (wa2_mas-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <itab>
    WHERE pernr = wa2_mas-pernr
    AND aedtm <= wa2_mas-aedtm.
  IF sy-subrc = 0.
*  Show ALV for select records
    PERFORM show_alv.
  ENDIF.


************************************************************************
*                    AT SELECTION-SCREEN OUTPUT                        *
************************************************************************
AT SELECTION-SCREEN OUTPUT.
  IF soaedat[] IS INITIAL.
    soaedat-high = sy-datum.
    APPEND soaedat TO soaedat.
  ENDIF.

************************************************************************
*                           INITIALIZATION                             *
************************************************************************
INITIALIZATION.

************************************************************************
*                             TOP-OF-PAGE                              *
************************************************************************
TOP-OF-PAGE.
  WRITE: 1(140) sy-uline,
         /1 '|',
         2(139) 'HR: Master Data Change' CENTERED COLOR 1,
         140(1) '|' ,
         /1 '|',
         2(139) str_date CENTERED COLOR 1,
         140(1) '|' .
  WRITE: /1(140) sy-uline,
         /1 '|',
         2(12) 'Personal No.' CENTERED  COLOR 1,
         14(1) '|',
         15(30) 'Name of Employee' CENTERED  COLOR 1,
         45(1) '|',
         46(60) 'Changed Category' CENTERED  COLOR 1,
         106(1) '|',
         107(20) 'Changed By' CENTERED  COLOR 1,
         127(1) '|',
         128(12) 'Changed On' CENTERED  COLOR 1,
         140(1) '|',
         /1(140) sy-uline.

************************************************************************
*                               FORMs                                  *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  show_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM show_alv.
  TYPE-POOLS: slis.
  DATA: wa_layout TYPE slis_layout_alv.
  DATA: it_sort TYPE slis_t_sortinfo_alv,
        wa_sort TYPE slis_sortinfo_alv.

  CONCATENATE wa2_mas-tabname+2(4) '=>' wa2_mas-ddtext INTO lvc_title SEPARATED BY space.

*  For Sorting
  CLEAR wa_sort.
  wa_sort-fieldname = 'AEDTM'.
  wa_sort-up = 'X'.
  APPEND wa_sort TO it_sort.

*  for Layout
  wa_layout-zebra = 'X'.
  wa_layout-colwidth_optimize = 'X'.

*  Display ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-cprog
      i_structure_name   = wa2_mas-tabname
      i_grid_title       = lvc_title
      is_layout          = wa_layout
      it_sort            = it_sort
      i_default          = 'X'
      i_save             = 'X'
    TABLES
      t_outtab           = <itab>
    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.                    "show_alv

HR: Applicant Infotype (0000 to 9999) Change History

A few months back I got a requirement to show all changes in Applicant Master. First I tried my best to search the solution, I found many of the threads with the similar requirement but solution was not there, so I tried to think about it and came to a solution, I want to share this so that it will helpful people in future.

Selection Screen :- On the Selection Screen bellow you will have to enter the date between you want to display the changes and personal numbers or you can leave it blank for display changes of all Employees.




Output :- Bellow is the Screen Shot of the First Screen it will show up all the infotypes which have changed with the Employee's Personal Number and Name




After Click on any Change Category it will show up the details of that infotype as shown bellow.




Code :-Just Copy Past Bellow Code Save, Active and ready to display changes

REPORT zfsl_hremdch NO STANDARD PAGE HEADING.

TABLES: pa0000.

************************************************************************
*                         Selection Screen                             *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001 .
SELECT-OPTIONS: soaedat FOR pa0000-aedtm OBLIGATORY NO-EXTENSION,
                sopernr FOR pa0000-pernr.
SELECTION-SCREEN END OF BLOCK main.

************************************************************************
*                          Types Defined                               *
************************************************************************
TYPES:  BEGIN OF ty_tables, " Type for All HR Master Table Name and Description
        tabname LIKE dd02l-tabname,
        ddtext LIKE dd02t-ddtext,
        END OF ty_tables.

TYPES:  BEGIN OF ty_mas. " Type for HR Master Data Change
INCLUDE: STRUCTURE pakey,
         TYPE ty_tables.
TYPES:  ename LIKE pa0001-ename,
        aedtm LIKE pa0000-aedtm,
        uname LIKE pa0000-uname,
        END OF ty_mas.

TYPES:  BEGIN OF ty_pa0001, " Type for Ename and Plans
        pernr LIKE pa0001-pernr,
        ename LIKE pa0001-ename,
        END OF ty_pa0001.

************************************************************************
*                    Declaration of Variables                          *
************************************************************************
DATA: it_tables TYPE STANDARD TABLE OF ty_tables WITH HEADER LINE,
      wa_tables TYPE ty_tables,
      it_mas    TYPE STANDARD TABLE OF ty_mas WITH HEADER LINE,
      wa1_mas   TYPE ty_mas,
      wa2_mas   TYPE ty_mas,
      it_pa0001 TYPE SORTED TABLE OF ty_pa0001 WITH HEADER LINE WITH UNIQUE KEY pernr,
      wa_pa0001 TYPE ty_pa0001,
      str_date  TYPE string,
      str_len   TYPE i,
      date_low  TYPE c LENGTH 10,
      date_high TYPE c LENGTH 10,
      flag      TYPE c LENGTH 1.

************************************************************************
*                           FIELD-SYMBOLS                              *
************************************************************************
FIELD-SYMBOLS: <wa_mas_c> TYPE ty_mas.


************************************************************************
*                    Declaration of RANGES                             *
************************************************************************
DATA: rg_pernr LIKE RANGE OF pa0000-pernr WITH HEADER LINE.


************************************************************************
*                        START-OF-SELECTION                            *
************************************************************************
START-OF-SELECTION.

*  Format Date to Display on the Screen Top of Page
  CLEAR: date_low, date_high.
  WRITE: soaedat-low TO date_low, soaedat-high TO date_high.
  IF soaedat-high <> '00000000' .
    CONCATENATE 'Date: From' date_low 'to' date_high INTO str_date SEPARATED BY space.
  ELSE.
    CONCATENATE 'Date:' date_low INTO str_date SEPARATED BY space.
  ENDIF.

*  Select All the Table Name and Description Start from PA
  SELECT dd02l~tabname dd02t~ddtext
    INTO CORRESPONDING FIELDS OF TABLE it_tables
    FROM dd02l LEFT OUTER JOIN dd02t ON ( dd02l~tabname = dd02t~tabname AND dd02t~ddlanguage = 'E' )
    WHERE dd02l~tabname LIKE 'PB%'.

*  Now Delete all other Tables name Because we Need name from PA0000 to PA9999 we are dealing with all Infotypes 0000 to 9999
  LOOP AT it_tables INTO wa_tables.
    IF wa_tables-tabname+2(4) CO '0123456789' AND STRLEN( wa_tables-tabname ) = 6 .
    ELSE.
      DELETE it_tables INDEX sy-tabix.
    ENDIF.
  ENDLOOP.

  SORT it_tables BY tabname.

**  Get all the Changed Data and Append it to Internal Table and also Append pernrs to a Range for further USE
  rg_pernr-sign = 'I'. rg_pernr-option = 'EQ'.
  LOOP AT it_tables INTO wa_tables.
    SELECT pernr subty objps sprps endda begda seqnr aedtm uname
      APPENDING CORRESPONDING FIELDS OF TABLE it_mas
      FROM (wa_tables-tabname)
      WHERE aedtm IN soaedat
        AND pernr IN sopernr.
    IF sy-subrc = 0.
      LOOP AT it_mas ASSIGNING <wa_mas_c> WHERE tabname IS INITIAL.
        <wa_mas_c>-tabname = wa_tables-tabname.
        <wa_mas_c>-ddtext = wa_tables-ddtext.
        rg_pernr-low = <wa_mas_c>-pernr.
        APPEND rg_pernr.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

*  Delete all duplicate pernrs because we Need Distinct For this First Sort by low
  SORT rg_pernr BY low.
  DELETE ADJACENT DUPLICATES FROM rg_pernr COMPARING low.

  IF rg_pernr[] IS NOT INITIAL.
*  Select Ename and Plans from PA0001 for all pernr in Range
    SELECT mandt pernr subty objps sprps endda begda seqnr ename " We need only Pernr and Ename but because me using FOR ALL ENTRIES IN so talking all Key Fields
       FROM pa0001
      INTO CORRESPONDING FIELDS OF TABLE it_pa0001
      FOR ALL ENTRIES IN rg_pernr
      WHERE pernr = rg_pernr-low
        AND endda = '99991231'.
*  Now Place Names against every pernr
    LOOP AT it_mas ASSIGNING <wa_mas_c> .
      READ TABLE it_pa0001 WITH TABLE KEY pernr = <wa_mas_c>-pernr.
      IF sy-subrc = 0.
        <wa_mas_c>-ename = it_pa0001-ename.
      ENDIF.
    ENDLOOP.
  ENDIF.

  IF it_mas[] IS INITIAL.
    MESSAGE: 'No Change History Found' TYPE 'I'.
  ENDIF.

  SORT: it_mas BY pernr tabname aedtm begda.

*  Now Write the Master Internal Table on the Screen in the Specific Format
  LOOP AT it_mas INTO wa1_mas.

*    Uncomment this code if want to see Table Description between ( )
**    Here we only need the infotype name not Prefix Before Table Description So Get only Text in “ (  ) “
*    SEARCH wa1_mas-ddtext FOR '('.
*    IF sy-subrc EQ 0.
*      str_len = 60 - sy-fdpos.
*      wa1_mas-ddtext = wa1_mas-ddtext+sy-fdpos(str_len).
*    ELSE.
*      CLEAR: wa1_mas-ddtext.
*    ENDIF.

    wa2_mas = wa1_mas.

    AT NEW pernr.
      WRITE: 1(140) sy-uline,
             /1 '|',
             2(12) wa2_mas-pernr CENTERED HOTSPOT ON,
             14(1) '|',
             15(30) wa2_mas-ename HOTSPOT ON,
             45(1) '|',
             46(60) wa2_mas-ddtext HOTSPOT ON,
             106(1) '|',
             107(20) wa2_mas-uname CENTERED HOTSPOT ON,
             127(1) '|',
             128(12) wa2_mas-aedtm CENTERED HOTSPOT ON.
      HIDE : wa2_mas.
      WRITE:  140(1) '|',
        /1(140) sy-uline.
      flag = 'X'.
    ENDAT.
    IF flag EQ 'X'.
      flag = ''.
    ELSE.
      WRITE: /1 '|',
             45(1) '|',
             46(60) wa2_mas-ddtext HOTSPOT ON,
             106(1) '|',
             107(20) wa2_mas-uname CENTERED HOTSPOT ON,
             127(1) '|',
             128(12) wa2_mas-aedtm CENTERED HOTSPOT ON,
             140(1) '|'.
      HIDE : wa2_mas.
      WRITE: /1 '|',
             45(96) sy-uline.
    ENDIF.

    AT END OF pernr.
      WRITE: 1(140) sy-uline.
    ENDAT.

  ENDLOOP.

************************************************************************
*                           AT LINE-SELECTION                          *
************************************************************************
AT LINE-SELECTION.

  DATA: it_ref TYPE REF TO data.
  DATA: lvc_title TYPE lvc_title.

*  Creation of Dynamic Internal Table
  CREATE DATA it_ref TYPE STANDARD TABLE OF (wa2_mas-tabname).
  FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
  ASSIGN it_ref->* TO <itab>.

*  Selection of Changed Data
  SELECT * FROM (wa2_mas-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <itab>
    WHERE pernr = wa2_mas-pernr
    AND aedtm <= wa2_mas-aedtm.
  IF sy-subrc = 0.
*  Show ALV for select records
    PERFORM show_alv.
  ENDIF.



************************************************************************
*                    AT SELECTION-SCREEN OUTPUT                        *
************************************************************************
AT SELECTION-SCREEN OUTPUT.
  IF soaedat[] IS INITIAL.
    soaedat-high = sy-datum.
    APPEND soaedat TO soaedat.
  ENDIF.

************************************************************************
*                           INITIALIZATION                             *
************************************************************************
INITIALIZATION.

************************************************************************
*                             TOP-OF-PAGE                              *
************************************************************************
TOP-OF-PAGE.
  WRITE: 1(140) sy-uline,
         /1 '|',
         2(139) 'HR: Master Data Change' CENTERED COLOR 1,
         140(1) '|' ,
         /1 '|',
         2(139) str_date CENTERED COLOR 1,
         140(1) '|' .
  WRITE: /1(140) sy-uline,
         /1 '|',
         2(12) 'Personal No.' CENTERED  COLOR 1,
         14(1) '|',
         15(30) 'Name of Employee' CENTERED  COLOR 1,
         45(1) '|',
         46(60) 'Changed Category' CENTERED  COLOR 1,
         106(1) '|',
         107(20) 'Changed By' CENTERED  COLOR 1,
         127(1) '|',
         128(12) 'Changed On' CENTERED  COLOR 1,
         140(1) '|',
         /1(140) sy-uline.

************************************************************************
*                               FORMs                                  *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  show_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM show_alv.
  TYPE-POOLS: slis.
  DATA: wa_layout TYPE slis_layout_alv.
  DATA: it_sort TYPE slis_t_sortinfo_alv,
        wa_sort TYPE slis_sortinfo_alv.

  CONCATENATE wa2_mas-tabname+2(4) '=>' wa2_mas-ddtext INTO lvc_title SEPARATED BY space.

*  For Sorting
  CLEAR wa_sort.
  wa_sort-fieldname = 'AEDTM'.
  wa_sort-up = 'X'.
  APPEND wa_sort TO it_sort.

*  for Layout
  wa_layout-zebra = 'X'.
  wa_layout-colwidth_optimize = 'X'.

*  Display ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-cprog
      i_structure_name   = wa2_mas-tabname
      i_grid_title       = lvc_title
      is_layout          = wa_layout
      it_sort            = it_sort
      i_default          = 'X'
      i_save             = 'X'
    TABLES
      t_outtab           = <itab>
    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.                    "show_alv

Friday, November 5, 2010

How to Install SAPLink

SAPLink LOGO
Here in Part1 we are discussing about the detailed Installation process of main application and Plugins both (NUGG and SLNK type) and in Part2 we will discuss in detail working with SAPLink

Download SAPLink
Download SAPLINK_INSTALL-*.ZIP from the following link.
Click here for Download Main Installation Files
Note: * Means it can be vary release to release.

Installing SAPLink
After unzip the above downloaded file you will find the following two main file in it.

1. ZSAPLINK_INSTALLER.TXT
2. NUGG_SAPLINK-*.NUGG


Follow the following Steps for Installation.

1. Go to T-Code SE38
2. Create a new Executable Program with the name ZAPPLINK_INSTALLER. You can save this program as a local Object because we use this only for First time installing SAPLink application.
3. Copy code from ZSAPLINK_INSTALLER.TXT file and paste in the Created Program
4. Save and Activate Program
5. Now Execute the Program using F8 Key
6. Following Screen will appear

Installer Initial Screen

7. In Field Installation Nugget Press F4 or Click on the Search Help Icon on the right hand side of the Field
8. Following Dialog Box will appear from here you need to select that NUGG_SAPLINK-*.NUGG File

Note:  If you will Check Overwrite Originals Option as Shown in the Picture it will overwrite all you existing object so be careful here.

Select File for Installation

9. Selecting required NUGG_SAPLINK-*.NUGG file Click Open button, path and file name will appear in the Field
10. Now press F8 to Start Installing.
11. Following Dialog Box will appear for every Object, Select for your relevant Package name as I am Selecting ZFSL and select SAVE Button (Displaying in the box Bottom Left).

Save Dialog

12. After Selecting SAVE Button a box will appear for Transport Request as you often see, Create a Request for First Object and save all other in the same Request.
13. After a Short time following message will appear with the name of installed objects.

 Installed

In the 1st Column Installed indicate that this object installed successfully, 2nd column is showing the type of the object here CLAS mean Class and PROG mean Program, 3rd Column is displaying the name of the Object.

14. Open the all object in the relevant T-Code and Active one by one for example SE24 for Classes and SE38 for Program in this case. You also have to Active a STATUS of Program ZSAPLINK for this Open T-Code SE41 give the program name in Program text filed and Press F4 in the STATUS Text Filed it will automatically select SELOBJ activate this too.
15. After activating all the objects open program ZSAPLINK using T-Code SE38 and Press F8 for Execute.
16. The following Screen will appear

Main Screen

7. There are two Tabs Nugget and Slinkee, Nugget is for operations on .NUGG file and Slinkee for .SLNK

Now you have INSTALL SAPLINK application successfully.

Builtin Plugins
The two Plugins showing in the picture are builtin you don’t need to install these.

Builtin Plugins

Download Plugins

Click here for Download Plugins

Installing Plugins
There are two types of file available for all Plugins .NUGG and SLNK. Here we will try to install both of these.

Installing NUGG Plugins
In the following Example we are going to install Plugin for ABAP Dictionary Objects. This NUGG_SAPLINK_DDIC-0.1.0.nugg will use to install DDIC Plugins as it is a .nugg file so we will select Nugget Tab.

1. Select Radio Button Import Nugget
2. In the text field Nugget File Name Select the .NUGG file you want to install, Here we are installing NUGG_SAPLINK_DDIC-0.1.0.nugg so we will select this.
3. After Selecting the File Press F8 to Start Installation (Follow Above Installing SAPLink Steps 11 and 12)
4. After few seconds a window with the following message will appear.

Plugin DDIC Installed

5. Green icon means Installed Successfully now you just need to active all these given objects.

Note: .NUGG file can have one or more than one object but .SLNK can have only one object.

Installing SLNK Plugins
For installing .SLNK select the Slinkee Tab as shown in the following picture

Slinkee Tab

1. Select Radio Button Import Slinkee
2. In the text field Slinkee File Name Select the .SLNK file you want to install
3. After Selecting the File Press F8 to Start Installation. (Follow Above Installing SAPLink Steps 11 and 12)
4. It will display name of the Installed object this time it will be only one because we can place only one object in .SLNK file. (Open and Active this Object)

Possible Warning or Error Messages While Installing

1. If you have Check: the Overwrite Originals Check Box and you have already have some installed components than you can get the following pop up for conformation.

Overwrite Pop UP

You can select accordingly

Yes, will only overwrite current Object
Yes to all, will overwrite all Objects
Cancel, will cancel the process

2. If you didn’t check: the Overwrite Originals Check Box and you have already have some installed components than you can see the following message.

In Case of Nugget

Already Exists NUGG

In Case of Slinkee

Already Exists SLINK

Step by Step Configuration for running Web Dynpro in SAP NetWeaver 7.01 SR1 SP3 ABAP Trial Version

 >> Please Click Here <<