Welcome To My BLOG

This site is to give a brief idea for the abap learners who are looking for some real time programs .It consists of collection of programs from my side . I hope these programs are very much used for all of the learners. Please check the links for any information in ABAP.
Please vote for my Blog. And please input me on this mail addrssess.Email me

Share this link with your friends

http://www.rebtel.com/u/15163104576

For every friend who signs up using this link and makes a payment, we'll give you 8 €!


Wednesday, September 29, 2010

Creating your own SAP Customized Main Menu

You can add additional menu transaction in the SAP main menu without affecting the original SAP default area menu S000.
For example, you have created a transaction code called ( z123 - ABC Own Report ) and you want to insert it under Logistics.  The specific user will be able to access ABC Own Report by clicking Logistics -> ABC Own Report.
Steps :-
  • Goto Transaction SE43 - Area Menu
  • Click the copy button.  Copy from S000 to ZXXX
  • After copying, click Change (area menu ZXXX)
  • Double click on Logistics and add in your transaction code in the AreaMenu.
  • Remembers to Activate it.
  • Next Goto Transaction SU01 - Maintain users
  • Type in the user name and click the Defaults button
  • Type in the area menu (ZXXX) in the Start Menu field.
  • Change SAP Default Menu for User
  • Click Save
  • The user will be able to see the additional transaction on the next logon.
The CUA area menus are converted to tree navigation in Release 4.6A. The menu contents are automatically copied into a new data structure in Upgrade to Release 4.6A or higher. You can edit Area Menus with a new maintenance interface (Area Menu maintenance transaction: SE43 ). Reporting Tree Integration - Only transactions could previously be put in Area Menus. From Release 4.6A you can also put all the types of reports which are in reporting trees, in Area Menus. The system automatically assigns a transaction code to call the report from the menu. If you have already put the report in another Area Menu, no new transaction code is generated, the unique transaction code already assigned is used.
You can create Area Menus from complete reporting trees with the migration transaction RTTREE_MIGRATION . The report transaction codes are generated automatically.
Reporting trees can only be displayed. They cannot be maintained. To modify the contents of reporting trees, you must convert them with the migration transaction. You can then modify the contents with the Area Menu maintenance.

Tuesday, September 28, 2010

Download ABAP Spool to PDF

*** This program receive spool id and destination file name ***
DATA: it_pdf TYPE TABLE OF TLINE WITH HEADER LINE,
      gv_string TYPE string.


PARAMETERS: p_spool LIKE TSP01-RQIDENT,
            p_file LIKE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION ’KD_GET_FILENAME_ON_F4’
    EXPORTING
*     PROGRAM_NAME        = SYST-REPID
*     DYNPRO_NUMBER       = SYST-DYNNR
*     FIELD_NAME          = ’ ’
      STATIC              = ’X’
      MASK                = ’,*.txt,*.*’
    CHANGING
      FILE_NAME           = p_file
    EXCEPTIONS
      MASK_TOO_LONG       = 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.

START-OF-SELECTION.
  CALL FUNCTION ’CONVERT_ABAPSPOOLJOB_2_PDF’
    EXPORTING
      SRC_SPOOLID                    = p_spool
*     NO_DIALOG                      =
*     DST_DEVICE                     =
*     PDF_DESTINATION                =
*   IMPORTING
*     PDF_BYTECOUNT                  =
*     PDF_SPOOLID                    =
*     LIST_PAGECOUNT                 =
*     BTC_JOBNAME                    =
*     BTC_JOBCOUNT                   =
   TABLES
     PDF                            = it_pdf
   EXCEPTIONS
     ERR_NO_ABAP_SPOOLJOB           = 1
     ERR_NO_SPOOLJOB                = 2
     ERR_NO_PERMISSION              = 3
     ERR_CONV_NOT_POSSIBLE          = 4
     ERR_BAD_DESTDEVICE             = 5
     USER_CANCELLED                 = 6
     ERR_SPOOLERROR                 = 7
     ERR_TEMSEERROR                 = 8
     ERR_BTCJOB_OPEN_FAILED         = 9
     ERR_BTCJOB_SUBMIT_FAILED       = 10
     ERR_BTCJOB_CLOSE_FAILED        = 11
     OTHERS                         = 12
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ELSE.
    gv_string = p_file.
    CALL FUNCTION ’GUI_DOWNLOAD’
      EXPORTING
*       BIN_FILESIZE                    =
        FILENAME                        = gv_string
        FILETYPE                        = ’BIN’
*       APPEND                          = ’ ’
*       WRITE_FIELD_SEPARATOR           = ’ ’
*       HEADER                          = ’00’
*       TRUNC_TRAILING_BLANKS           = ’ ’
*       WRITE_LF                        = ’X’
*       COL_SELECT                      = ’ ’
*       COL_SELECT_MASK                 = ’ ’
*       DAT_MODE                        = ’ ’
*       CONFIRM_OVERWRITE               = ’ ’
*       NO_AUTH_CHECK                   = ’ ’
*       CODEPAGE                        = ’ ’
*       IGNORE_CERR                     = ABAP_TRUE
*       REPLACEMENT                     = ’#’
*       WRITE_BOM                       = ’ ’
*       TRUNC_TRAILING_BLANKS_EOL       = ’X’
*       WK1_N_FORMAT                    = ’ ’
*       WK1_N_SIZE                      = ’ ’
*       WK1_T_FORMAT                    = ’ ’
*       WK1_T_SIZE                      = ’ ’
*     IMPORTING
*       FILELENGTH                      =
      TABLES
        DATA_TAB                        = it_pdf
*       FIELDNAMES                      =
     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.
  ENDIF.

Monday, September 27, 2010

Download a report to excel with format (border, color cell, etc)

Try this program...it may help you to change the font ..etc. 

Code: 
REPORT ZSIRI NO STANDARD PAGE HEADING. 
* this report demonstrates how to send some ABAP data to an 
* EXCEL sheet using OLE automation. 
INCLUDE OLE2INCL. 
* handles for OLE objects 
DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object 
      H_MAPL TYPE OLE2_OBJECT,         " list of workbooks 
      H_MAP TYPE OLE2_OBJECT,          " workbook 
      H_ZL TYPE OLE2_OBJECT,           " cell 
      H_F TYPE OLE2_OBJECT.            " font 
TABLES: SPFLI. 
DATA  H TYPE I. 
* table of flights 
DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE. 

*&---------------------------------------------------* 
*&   Event START-OF-SELECTION 
*&-------------------------------------------------* 
START-OF-SELECTION. 
* read flights 
  SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS. 
* display header 
  ULINE (61). 
  WRITE: /     SY-VLINE NO-GAP, 
(3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP, 
(4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP, 
(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP, 
(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP, 
(8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP. 
  ULINE /(61). 
* display flights 
  LOOP AT IT_SPFLI. 
  WRITE: / SY-VLINE NO-GAP, 
  IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP, 
  IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP, 
  IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP, 
  IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP, 
  IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP. 
  ENDLOOP. 
  ULINE /(61). 
* tell user what is going on 
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
     EXPORTING 
*           PERCENTAGE = 0 
           TEXT       = TEXT-007 
       EXCEPTIONS 
            OTHERS     = 1. 
* start Excel 
  CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'. 
*  PERFORM ERR_HDL. 

  SET PROPERTY OF H_EXCEL  'Visible' = 1. 
*  CALL METHOD OF H_EXCEL 'FILESAVEAS'
EXPORTING #1 = 'c:\kis_excel.xls' 
. 

*  PERFORM ERR_HDL. 
* tell user what is going on 
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
     EXPORTING 
*           PERCENTAGE = 0 
           TEXT       = TEXT-008 
       EXCEPTIONS 
            OTHERS     = 1. 
* get list of workbooks, initially empty 
  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL. 
  PERFORM ERR_HDL. 
* add a new workbook 
  CALL METHOD OF H_MAPL 'Add' = H_MAP. 
  PERFORM ERR_HDL. 
* tell user what is going on 
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
     EXPORTING 
*           PERCENTAGE = 0 
           TEXT       = TEXT-009 
       EXCEPTIONS 
            OTHERS     = 1. 
* output column headings to active Excel sheet 
  PERFORM FILL_CELL USING 1 1 1 'Flug'(001). 
  PERFORM FILL_CELL USING 1 2 0 'Nr'(002). 
  PERFORM FILL_CELL USING 1 3 1 'Von'(003). 
  PERFORM FILL_CELL USING 1 4 1 'Nach'(004). 
  PERFORM FILL_CELL USING 1 5 1 'Zeit'(005). 
  LOOP AT IT_SPFLI. 
* copy flights to active EXCEL sheet 
    H = SY-TABIX + 1. 
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID. 
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID. 
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM. 
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO. 
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME. 
  ENDLOOP. 

* changes by Kishore  - start 
*  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL. 
  CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." 
EXPORTING #1 = 2. 

  PERFORM ERR_HDL. 
* add a new workbook 
  CALL METHOD OF H_MAPL 'Add' = H_MAP  
EXPORTING #1 = 2. 
  PERFORM ERR_HDL. 
* tell user what is going on 
  SET PROPERTY OF H_MAP 'NAME' = 'COPY'. 
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
     EXPORTING 
*           PERCENTAGE = 0 
           TEXT       = TEXT-009 
       EXCEPTIONS 
            OTHERS     = 1. 
* output column headings to active Excel sheet 
  PERFORM FILL_CELL USING 1 1 1 'Flug'(001). 
  PERFORM FILL_CELL USING 1 2 0 'Nr'(002). 
  PERFORM FILL_CELL USING 1 3 1 'Von'(003). 
  PERFORM FILL_CELL USING 1 4 1 'Nach'(004). 
  PERFORM FILL_CELL USING 1 5 1 'Zeit'(005). 
  LOOP AT IT_SPFLI. 
* copy flights to active EXCEL sheet 
    H = SY-TABIX + 1. 
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID. 
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID. 
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM. 
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO. 
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME. 
  ENDLOOP. 
* changes by Kishore  - end 
* disconnect from Excel 
*      CALL METHOD OF H_EXCEL 'FILESAVEAS' 
EXPORTING  #1 = 'C:\SKV.XLS'. 

  FREE OBJECT H_EXCEL. 
  PERFORM ERR_HDL. 
*-----------------------------------------------* 
*       FORM FILL_CELL                                               
*----------------------------------------------* 
* sets cell at coordinates i,j to value val boldtype bold   
*-----------------------------------------------* 
FORM FILL_CELL USING I J BOLD VAL. 
  CALL METHOD OF H_EXCEL 'Cells' = H_ZL 
EXPORTING #1 = I #2 = J. 
  PERFORM ERR_HDL. 
  SET PROPERTY OF H_ZL 'Value' = VAL . 
  PERFORM ERR_HDL. 
  GET PROPERTY OF H_ZL 'Font' = H_F. 
  PERFORM ERR_HDL. 
  SET PROPERTY OF H_F 'Bold' = BOLD . 
  PERFORM ERR_HDL. 
ENDFORM. 
*&--------------------------------------* 
*&      Form  ERR_HDL 
*&---------------------------------* 
*       outputs OLE error if any                                        
*--------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*-------------------------------------* 
FORM ERR_HDL. 
IF SY-SUBRC <> 0. 
WRITE: / 'Fehler bei OLE-Automation:'(010),SY-SUBRC. 
  STOP. 
ENDIF. 
ENDFORM.                    " ERR_HDL 


Please note that this example maybe slow at filling the 
excel table(perhaps four fields per second on a 900 MHz 
machine - almost 30 seconds for a short example). 

To get the data on properties and methods - there is a 
bit of smoke and mirrors going on here; they are EXCEL 
properties and methods, not sap ones - so you need 
to look at excel help to determine how a particular
function is structured. then build the block in sap, 
as shown in the example.
 
If you only want to transfer the data to Excel like 
when you transfer the data from ALV to Excel simply use the 
Function Modules: 

XXL_SIMPLE_API 

If you want more modifications when you transfer it to 
Excel use: 

XXL_FULL_API 

RFC call to get Server List

How to get the RFC call to get the list of SAP Servers (Different machines)?
Does such a thing exist (From SAPRFC.INI may be?) but the INI file is not a good option as I would need to check
the connection availability.
 
A list of application servers within an R/3 system can be obtained by calling function module 'TH_DISPLAY_SERVER_LIST
For example: 
REPORT ZSERVERLIST.
call function 'TH_DISPLAY_SERVER_LIST'.
*** End of Program

Program To Generate IDoc

*&---------------------------------------------------------------------*
*& Report  ZZ_Program_To_Create_Idoc                                         
*&---------------------------------------------------------------------*

report  zz_program_to_create_idoc                     .
tables: ekko,ekpo.

selection-screen skip 3.
selection-screen begin of block b1 with frame title titl.
selection-screen skip.
select-options s_ebeln for ekko-ebeln.
selection-screen skip.
selection-screen end of block b1.


data: header_segment_name like edidd-segnam value 'Z1EKKO',
      item_segment_name like edidd-segnam value 'Z1EKPO',
      idoc_name like edidc-idoctp value 'Z19838IDOC1'.

data: header_segment_data like z1ekko,
      item_segment_data like z1ekpo.

data: control_record like edidc.

data: messagetyp like edmsg-msgtyp value 'ZZ9838MESG1'.

data: i_communication like edidc occurs 0 with header line,
      i_data like edidd occurs 0 with header line.

data: begin of i_ekko occurs 0,
      ebeln like ekko-ebeln,
      aedat like ekko-aedat,
      bukrs like ekko-bukrs,
      bsart like ekko-bsart,
      lifnr like ekko-lifnr,
      end of i_ekko.

data: begin of i_ekpo occurs 0,
      ebelp like ekpo-ebelp,
      matnr like ekpo-matnr,
      menge like ekpo-menge,
      meins like ekpo-meins,
      netpr like ekpo-netpr,
      end of i_ekpo.

start-of-selection.

select  ebeln aedat bukrs bsart lifnr from ekko
          into table i_ekko where ebeln in s_ebeln.

select ebelp
       matnr
       menge
       meins
       netpr
       from ekpo
       into table i_ekpo
       where ebeln in s_ebeln.


control_record-mestyp = messagetyp.
control_record-rcvprt = 'LS'.
control_record-idoctp = idoc_name.
control_record-rcvprn = '0MART800'.

loop at i_ekko.
header_segment_data-ebeln = i_ekko-ebeln.
header_segment_data-aedat = i_ekko-aedat.
header_segment_data-bukrs = i_ekko-bukrs.
header_segment_data-bsart = i_ekko-bsart.
header_segment_data-lifnr = i_ekko-lifnr.
i_data-segnam = header_segment_name.
i_data-sdata = header_segment_data.
append i_data.

select ebelp
       matnr
       menge
       meins
       netpr
       from ekpo
       into table i_ekpo
       where ebeln = i_ekko-ebeln.

loop at i_ekpo.
item_segment_data-ebelp = i_ekpo-ebelp.
item_segment_data-matnr = i_ekpo-matnr.
item_segment_data-menge = i_ekpo-menge.
item_segment_data-meins = i_ekpo-meins.
item_segment_data-netpr = i_ekpo-netpr.
i_data-segnam = item_segment_name.
i_data-sdata = item_segment_data.
append i_data.
endloop.
clear i_ekpo.
refresh i_ekpo.
endloop.


call function 'MASTER_IDOC_DISTRIBUTE'
  exporting
    master_idoc_control                  = control_record
*   OBJ_TYPE                             = ''
*   CHNUM                                = ''
  tables
    communication_idoc_control           = i_communication
    master_idoc_data                     = i_data
 exceptions
   error_in_idoc_control                = 1
   error_writing_idoc_status            = 2
   error_in_idoc_data                   = 3
   sending_logical_system_unknown       = 4
   others                               = 5
          .
if sy-subrc <> 0.
 message id sy-msgid type sy-msgty number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.

  loop at i_communication.
    write: 'IDOC GENERATED', i_communication-docnum.
  endloop.
  commit work.

endif.

initialization.
titl = 'ENTER THE PURCHASE ORDER NUMBER'.

How to create Internal Table dynamically and display it as ALV?

Below is a simple program that create Internal Table dynamicly and display it as ALV with header and footer text. 
Type, Data and Fields-Symbols declaration:
REPORT  Z_DYNITALV.

TYPE-POOLS: slis.
DATA :
*--  VARIABLES for function REUSE_ALV_DISPLAY
* Interface consistency check log output
i_interface_check,
* Ignore all buffers?
i_bypassing_buffer TYPE  char01,
* Buffer active
i_buffer_active          VALUE space,
* Name of the calling program
i_callback_program       LIKE sy-repid VALUE space,
* Set EXIT rountine to status
i_callback_pf_status_set TYPE slis_formname VALUE space,
* EXIT routine for command handling
i_callback_user_command  TYPE slis_formname VALUE space,
* Internal output table structure name
i_structure_name      
   LIKE dd02l-tabname,
* List layout specifications
is_layout                TYPE slis_layout_alv,
* Field catalog with field descriptions
it_fieldcat              TYPE slis_t_fieldcat_alv,
* Table of inactive function codes
it_excluding             TYPE slis_t_extab,
* Grouping fields for column selection
it_special_groups        TYPE slis_t_sp_group_alv,
* Sort criteria for first list display
it_sort                  TYPE slis_t_sortinfo_alv WITH HEADER LINE,
* Filter criteria for first list output
it_filter                TYPE slis_t_filter_alv,
* Selection information modification
is_sel_hide              TYPE slis_sel_hide_alv,
* Initial variant active/inactive logic
i_default                VALUE 'X',
* Variants can be saved
i_save                 
  VALUE space,
* Variant information
is_variant               LIKE disvariant,
* Table of events to perform
it_events                TYPE slis_t_event,
* Standard fcode exit requests table
it_event_exit            TYPE slis_t_event_exit,
* Print information
is_print                 TYPE slis_print_alv,
* Initialization key for Re/Re interface
is_reprep_id             TYPE slis_reprep_id,
* Coordinates for list in dialog box
i_screen_start_column    VALUE 0,
* Coordinates for list in dialog box
i_screen_start_line      VALUE 0,
* Coordinates for list in dialog box
i_screen_end_column      VALUE 0,
* Coordinates for list
 in dialog box
i_screen_end_line        VALUE 0,
e_exit_caused_by_caller,
es_exit_caused_by_user   TYPE slis_exit_by_user,
* Temporary structure for it_fieldcat
xfield                   TYPE slis_fieldcat_alv,
* Temporary structure for it_events
xxevent                   TYPE slis_alv_event.


DATA: new_table TYPE REF TO data,
      new_line  TYPE REF TO data,
      IS_LVC_CAT type LVC_S_FCAT,
      IT_LVC_CAT type LVC_T_FCAT,
      IS_FIELDCAT type SLIS_FIELDCAT_ALV.

FIELD-SYMBOLS: <l_table> TYPE TABLE,
               <l_line>  TYPE ANY,
               <l_field> TYPE ANY.
Main Program
START-OF-SELECTION.
  PERFORM Field_Catalog.
  PERFORM SET_DATA.
  PERFORM DISPLAY_ALV.
FORM Field_Catalog.
Here we create the field catalog for dynamic internal table.
And create table dynamicly using method: create_dynamic_table from class: cl_alv_table_create.
FORM Field_Catalog .

  IS_LVC_CAT-fieldname = 'BUKRS'.
  IS_LVC_CAT-ref_field = 'BUKRS'.
  IS_LVC_CAT-ref_table = 'PA0001'.
  IS_LVC_CAT-SCRTEXT_S  = IS_LVC_CAT-SCRTEXT_M =
  IS_LVC_CAT-SCRTEXT_L  = 'Company Code'.
  APPEND IS_LVC_CAT TO IT_LVC_CAT.

  IS_FIELDCAT-fieldname     = 'BUKRS'.
  IS_FIELDCAT-ref_fieldname = 'BUKRS'.
  IS_FIELDCAT-ref_tabname   = 'PA0001'.
  IS_FIELDCAT-OUTPUTLEN     = 10.
  IS_FIELDCAT-SELTEXT_S = IS_FIELDCAT-SELTEXT_M =
                          IS_FIELDCAT-SELTEXT_L = 'Company Code'.
  APPEND IS_FIELDCAT TO IT_FIELDCAT.

  IS_LVC_CAT-fieldname = 'WERKS'.
  IS_LVC_CAT-ref_field = 'WERKS'.
  IS_LVC_CAT-ref_table =
 'PA0001'.
  IS_LVC_CAT-SCRTEXT_S  = IS_LVC_CAT-SCRTEXT_M =
  IS_LVC_CAT-SCRTEXT_L  = 'Pers.Area'.
  APPEND IS_LVC_CAT TO IT_LVC_CAT.

  IS_FIELDCAT-fieldname     = 'WERKS'.
  IS_FIELDCAT-ref_fieldname = 'WERKS'.
  IS_FIELDCAT-ref_tabname   = 'PA0001'.
  IS_FIELDCAT-OUTPUTLEN     = 10.
  IS_FIELDCAT-SELTEXT_S = IS_FIELDCAT-SELTEXT_M =
                          IS_FIELDCAT-SELTEXT_L = 'Pers.Area'.
  APPEND IS_FIELDCAT TO IT_FIELDCAT.

  IS_LVC_CAT-fieldname = 'BTRTL'.
  IS_LVC_CAT-ref_field = 'BTRTL'.
  IS_LVC_CAT-ref_table = 'PA0001'.
  IS_LVC_CAT-SCRTEXT_S  = IS_LVC_CAT-SCRTEXT_M =
  IS_LVC_CAT-SCRTEXT_L  = 'Pers.SubArea'.
  APPEND IS_LVC_CAT TO IT_LVC_CAT.

  IS_FIELDCAT-fieldname     = 'BTRTL'.
  IS_FIELDCAT-ref_fieldname = 'BTRTL'.
  IS_FIELDCAT-ref_tabname   = 'PA0001'.
  IS_FIELDCAT-OUTPUTLEN     = 10.
  IS_FIELDCAT-SELTEXT_S = IS_FIELDCAT-SELTEXT_M =
                         
 IS_FIELDCAT-SELTEXT_L = 'Pers.SubArea'.
  APPEND IS_FIELDCAT TO IT_FIELDCAT.

  IS_LVC_CAT-fieldname = 'CNAME'.
  IS_LVC_CAT-ref_field = 'CNAME'.
  IS_LVC_CAT-ref_table = 'PA0002'.
  IS_LVC_CAT-SCRTEXT_S  = IS_LVC_CAT-SCRTEXT_M =
  IS_LVC_CAT-SCRTEXT_L  = 'Name'.
  APPEND IS_LVC_CAT TO IT_LVC_CAT.

  IS_FIELDCAT-fieldname     = 'CNAME'.
  IS_FIELDCAT-ref_fieldname = 'CNAME'.
  IS_FIELDCAT-ref_tabname   = 'PA0002'.
  IS_FIELDCAT-OUTPUTLEN     = 20.
  IS_FIELDCAT-SELTEXT_S = IS_FIELDCAT-SELTEXT_M =
                          IS_FIELDCAT-SELTEXT_L = 'Name'.
  APPEND IS_FIELDCAT TO IT_FIELDCAT.

* Create a new Table
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = IT_LVC_CAT
    IMPORTING
      ep_table        = new_table.

* Create a new Line with the same
 structure of the table.
  ASSIGN new_table->* TO <l_table>.
  CREATE DATA new_line LIKE LINE OF <l_table>.
  ASSIGN new_line->* TO <l_line>.

ENDFORM.                    " CREATE_LAYOUT
Form Set_Data.
Here we input our data.
FORM SET_DATA .
* Test it...
    DO 3 TIMES.
      ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = '8369'.

      ASSIGN COMPONENT 'WERKS' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = '1000'.

      ASSIGN COMPONENT 'BTRTL' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = '0100'.

      ASSIGN COMPONENT 'CNAME' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = 'Test Employee Name'.

      INSERT <l_line> INTO TABLE <l_table>.
   
 ENDDO.
ENDFORM.                    " SET_DATA
Form Display_ALV
We display our data using FM: 'REUSE_ALV_LIST_DISPLAY'.
FORM DISPLAY_ALV .

*  SET PAGE HEADER & END LIST.
  CLEAR xxevent.
  xxevent-name = 'TOP_OF_PAGE'.
  xxevent-form = 'TOP_OF_PAGE_ALV'.
  APPEND xxevent TO it_events.

  CLEAR xxevent.
  xxevent-name = 'END_OF_LIST'.
  xxevent-form = 'END_OF_LIST_ALV'.
  APPEND xxevent TO it_events.

* Layout
  IS_LAYOUT-COLWIDTH_OPTIMIZE = ''.

* setting variant
*  is_variant-variant = p_var.
  is_variant-report = sy-repid.
  is_variant-username = sy-uname.
* others
  i_save = 'A'.
  i_callback_program = sy-repid.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            i_interface_check        = i_interface_check
            i_bypassing_buffer       =
 i_bypassing_buffer
            i_buffer_active          = i_buffer_active
            i_callback_program       = i_callback_program
            i_callback_pf_status_set = i_callback_pf_status_set
            i_callback_user_command  = i_callback_user_command
            i_structure_name         = i_structure_name
            is_layout                = is_layout
            it_fieldcat              = it_fieldcat
            it_excluding             = it_excluding
            it_special_groups        = it_special_groups
            it_sort                  = it_sort[]
            it_filter                = it_filter
            is_sel_hide              = is_sel_hide
            i_default                = i_default
            i_save                   = i_save
            is_variant               = is_variant
            it_events                = it_events
            it_event_exit            = it_event_exit
           
 is_print                 = is_print
            is_reprep_id             = is_reprep_id
*            i_screen_start_column    = i_screen_start_column
            i_screen_start_line      = i_screen_start_line
            i_screen_end_column      = i_screen_end_column
            i_screen_end_line        = i_screen_end_line
       IMPORTING
            e_exit_caused_by_caller  = e_exit_caused_by_caller
            es_exit_caused_by_user   = es_exit_caused_by_user
       TABLES
            t_outtab                 = <l_table>
       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.                    " DISPLAY_ALV
Form TOP_OF_PAGE_ALV and END_OF_LIST_ALV.
Here where we can put Report header and footer text.
FORM TOP_OF_PAGE_ALV .
  WRITE: 'Here Your Report Header'.
  WRITE:/'Sub Report Header '.
  SKIP.
ENDFORM.                    " TOP_OF_PAGE_ALV

FORM END_OF_LIST_ALV .
  WRITE:/'Here Your Report Footer'.
  WRITE:/'Sub Report Footer '.
  SKIP.
ENDFORM.                    " END_OF_LIST_ALV

To change development class of SAP script

Use Standard program “RSWBO052” to Change Development class.

Step 1: Execute the above Program.
Step 2: Give the saved Package Name and Person Responsible (SAP user Id) then execute
Step 3: Select your ‘Original Systems’ (SYSID) were the object is saved
Step 4: Then Find Your Form Name in the List.
Step 5: Double click your object  and change your ‘Development Class’ and save it.

Friday, September 24, 2010

Save and Edit in classical report

*----------------------------------------------------------*
* created by : Manikandan
* created date: 28.12.2008
* description : The sample code for editing the clssical report
* and saving after modification successfully. this is an
* example program,so that i didnt use more validations,
* this is to aviod complexicity of the coding .
*----------------------------------------------------------*
REPORT ZEDIT_CLASSICAL_REPORT.

TYPES: BEGIN OF TY_ITAB ,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
END OF TY_ITAB .

DATA: ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE,
WA TYPE TY_ITAB.

DATA: V_MEINS LIKE MARA-MEINS,
V_MEINS1 LIKE MARA-MEINS,
V_MATNR LIKE MARA-MATNR.

START-OF-SELECTION.

SET PF-STATUS 'TEST'.

PERFORM GET_DATA.

PERFORM HEADER_DATA.

PERFORM DISPLAY_DATA.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SAVE'.
PERFORM SAVE_FUNCTION.

ENDCASE.
*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM GET_DATA .

SELECT MATNR
MEINS
FROM MARA
INTO TABLE ITAB
UP TO 5 ROWS.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form header_data
*----------------------------------------------------------------------*
FORM HEADER_DATA .

WRITE:/1(30) SY-ULINE.
WRITE:/1 SY-VLINE,
2 'Material',
20 SY-VLINE,
21 'Mat Unit',
30 SY-VLINE.
WRITE:/1(30) SY-ULINE.

ENDFORM. " header_data
*&---------------------------------------------------------------------*
*& Form display_data
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .


LOOP AT ITAB INTO WA.
WRITE:/1 SY-VLINE,
2 WA-MATNR,
20 SY-VLINE.
FORMAT INTENSIFIED INPUT.
WRITE: 21 WA-MEINS.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE: 30 SY-VLINE.
ENDLOOP.
WRITE:/1(30) SY-ULINE.

ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form save_function
*----------------------------------------------------------------------*
FORM SAVE_FUNCTION .

DO .
CLEAR: V_MATNR,V_MEINS, V_MEINS1.
READ LINE SY-INDEX .
IF SY-SUBRC NE 0.
*---if there exists no line , exit the processing
EXIT.
ELSE.
*---check whether the material exitsting or not .
SELECT MATNR MEINS
FROM MARA
INTO (V_MATNR, V_MEINS)
WHERE MATNR = SY-LISEL+1(18).

ENDSELECT.
IF SY-SUBRC = 0.
*---if material existing then get the actual Unit of measure,
* and capture the value to v_meins capture the changed value
* into v_meins1, process it if it is not initial.
V_MEINS1 = SY-LISEL+20(4).
IF NOT V_MEINS1 IS INITIAL.
*----check whether the data record was changed or not .
* if the two values are same, it means there is no
* change in the data record . here we can also put
* the validation on the v_meins1 to etner a valid
* value if not display an error message.
IF V_MEINS NE V_MEINS1.
*---if changed then update table with the updated value
* dont forget to Lock the table before processing the data
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
IF SY-SUBRC = 0.
* Modify the database table with these changes
UPDATE MARA SET MEINS = V_MEINS1
WHERE MATNR = V_MATNR.
IF SY-SUBRC = 0.
*---if successfully updated then write the modification log
WRITE:/ 'the material',
V_MATNR COLOR 7,
'unit was changed with value:',
V_MEINS1,
'from value:',
V_MEINS.
ENDIF.
* Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDDO.

ENDFORM. " save_function

How to get rid of dumps

Generally if any exception occurred it will go to dump immediately in a program, then we will process this through the tcode ST22(dump analysis). Here I am trying to convert this dump into an error message or some text statement.
For this you need to call this statement...

RECEIVE RESULTS FROM FUNCTION 'function module'

Check this example program....

REPORT ztests.

PARAMETERS:p_file LIKE rlgrap-filename .

DATA: v_file TYPE string.

DATA: BEGIN OF itab OCCURS 0,
name(23) TYPE c,
END OF itab.

DATA: errormessage TYPE char50.

v_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = ' '
TABLES
data_tab = itab.


RECEIVE RESULTS FROM FUNCTION 'GUI_UPLOAD'
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17 .
.
CASE sy-subrc.
WHEN 0.
errormessage = 'Data Loaded'.
WHEN 1.
errormessage = 'FILE_OPEN_ERROR'.
WHEN 2.
errormessage = 'FILE_READ_ERROR'.
WHEN 3.
errormessage = 'NO_BATCH'.
WHEN 4.
errormessage = 'GUI_REFUSE_FILETRANSFER'.
WHEN 5.
errormessage = 'INVALID_TYPE'.
WHEN 6.
errormessage = 'NO_AUTHORITY'.
WHEN 7.
errormessage = 'UNKNOWN_ERROR'.
WHEN 8.
errormessage = 'BAD_DATA_FORMAT'.
WHEN 9.
errormessage = 'HEADER_NOT_ALLOWED'.
WHEN 10.
errormessage = 'SEPARATOR_NOT_ALLOWED'.
WHEN 11.
errormessage = 'HEADER_TOO_LONG'.
WHEN 12.
errormessage = 'UNKNOWN_DP_ERROR'.
WHEN 13.
errormessage = 'ACCESS_DENIED'.
WHEN 14.
errormessage = 'DP_OUT_OF_MEMORY'.
WHEN 15.
errormessage = 'DISK_FULL'.
WHEN 16.
errormessage = 'DP_TIMEOUT'.
WHEN 17.
errormessage = 'OTHERS'.
ENDCASE.

MESSAGE e000(00) WITH errormessage .
With this in the report program we will get an error message instead of a dump when the exception raised.

Logo in classical report

REPORT zdem_555 .

DATA: docking TYPE REF TO cl_gui_docking_container,
picture_control_1 TYPE REF TO cl_gui_picture,
url(256) TYPE c .
DATA: query_table LIKE w3query OCCURS 1 WITH HEADER LINE,
html_table LIKE w3html OCCURS 1,
return_code LIKE w3param-ret_code,
content_type LIKE w3param-cont_type,
content_length LIKE w3param-cont_len,
pic_data LIKE w3mime OCCURS 0,
pic_size TYPE i.
START-OF-SELECTION.
PERFORM show_pic.
WRITE : /'hello see the picture ........'.

*&-------------------------------------------------------------------
*& Form show_pic
*&-------------------------------------------------------------------
FORM show_pic.
DATA: repid LIKE sy-repid. repid = sy-repid.
CREATE OBJECT picture_control_1
EXPORTING parent = docking.
CHECK sy-subrc = 0.
CALL METHOD picture_control_1->set_3d_border
EXPORTING
border = 5.
CALL METHOD picture_control_1->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_stretch.
CALL METHOD picture_control_1->set_position
EXPORTING
height = 100
left = 700
top = 1
width = 200.
*CHANGE POSITION AND SIZE
IF url IS INITIAL.
REFRESH query_table.
query_table-name = '_OBJECT_ID'.
*CHANGE IMAGE NAME BELOW
query_table-value = 'BIKER'.
APPEND query_table. CALL FUNCTION 'WWW_GET_MIME_OBJECT'
TABLES
query_string = query_table
html = html_table
mime = pic_data
CHANGING
return_code = return_code
content_type = content_type
content_length = content_length
EXCEPTIONS
object_not_found = 1
parameter_not_found = 2
OTHERS = 3.
IF sy-subrc ne 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-*msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'image'
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
TABLES
data = pic_data
CHANGING
url = url
EXCEPTIONS
OTHERS = 1.
ENDIF.
CALL METHOD picture_control_1->load_picture_from_url
EXPORTING
url = url.
ENDFORM. "show_pic

Change of sign

data: a1 type i value 56,
a2 type i value 60,
res type i,
res1(10).res = a1 - a2.
res1 = res.

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' CHANGING VALUE = res1
write res1.

Transport standard text

use RSTXTRAN program

All the text elements are customizing requests.
Or else you can use scc1 between clients to copy text elements.

Insert a blank line at the end of the file using gui_upload

Try this..

To the GUI_DOWNLOAD Fm pass WRITE_LF_AFTER_LAST_LINE = ' '.

Random number creation

use one of the function modules

SYSTEM_GET_UNIQUE_ID
SDOK_UNIQUE_ID_GET
STREE_GET_UNIQUE_ID
QF05_RANDOM_INTEGER
SYSTEM_UUID_C_CREATE
NUMBER_GET_NEXT Creat a number Range object using transction SNRO.

Download code to the desktop with screens

run REPTRAN in se38.this will download the data to the desktop

Function Modules for date conversions

FM LIST WITH RESPECT TO DAY, WEEK, AND MONTH.

CALCULATE_DATE : Calculates the future date based on the input .

DATE_TO_DAY : Returns the Day for the entered date.

DATE_COMPUTE_DAY : Returns weekday for a date

DATE_GET_WEEK : Returns week for a date

RP_CALC_DATE_IN_INTERVAL : Add days / months to a date

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

MONTH_NAMES_GET : Get the names of the month

WEEK_GET_FIRST_DAY : Get the first day of the week

HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format

SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours

L_MC_TIME_DIFFERENCE : Find the time difference between two date/time

HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months

LAST_DAY_OF_MONTHS : Returns the last day of the month

DATE_CHECK_PLAUSIBILITY :Check for the invalid date.

Check box in alv program

REPORT ZTEST .

type-pools: slis.

*Table declaration
tables: vbak,vbap.

*internal table
data: begin of i_sales occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
check type c, "checkbox
end of i_sales.

data: begin of i_final occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
end of i_final.

data: v_fieldcat type slis_fieldcat_alv,
gt_fieldcat type slis_t_fieldcat_alv,
gt_layout type slis_layout_alv,
gt_sort type slis_sortinfo_alv,
fieldcat like line of gt_fieldcat.

*Selection screen
parameters: p_vkorg like vbak-vkorg.
select-options: s_vbeln for vbak-vbeln.

*start of selection.
start-of-selection.
perform get_data.
perform fill_fieldcatalog.
perform write_data.
*-----------------------------------------------------------------
* get data
*-----------------------------------------------------------------
FORM get_data .
select a~vbeln
a~erdat
a~audat
a~kunnr
a~vkorg
b~matnr
b~netpr
into corresponding fields of table i_sales
from vbak as a inner join vbap as b on a~vbeln = b~vbeln
where a~vkorg = p_vkorg
and a~vbeln in s_vbeln.

ENDFORM. " get_data
*-----------------------------------------------------------------
* write_data
*-----------------------------------------------------------------
FORM write_data .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_PF_STATUS_SET = 'GUI_SET'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = gt_layout
IT_FIELDCAT = gt_fieldcat
TABLES
T_OUTTAB = i_sales .

ENDFORM. " write_data
*-----------------------------------------------------------------
* fill catalog
*-----------------------------------------------------------------
FORM fill_fieldcatalog .

sort i_sales by vbeln.
clear v_fieldcat.
*for check box

v_fieldcat-col_pos = 1.
v_fieldcat-fieldname = 'CHECK'.
v_fieldcat-seltext_m = 'chek'.
v_fieldcat-checkbox = 'X'.
v_fieldcat-input = 'X'.
v_fieldcat-edit = 'X'.
append v_fieldcat to gt_fieldcat.

clear v_fieldcat.
v_fieldcat-col_pos = 2.
v_fieldcat-fieldname = 'VBELN'.
v_fieldcat-seltext_m = 'Sales Document'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 3.
v_fieldcat-fieldname = 'ERDAT'.
v_fieldcat-seltext_m = 'Creation Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 4.
v_fieldcat-fieldname = 'AUDAT'.
v_fieldcat-seltext_m = 'Document Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 5.
v_fieldcat-fieldname = 'KUNNR'.
v_fieldcat-seltext_m = 'Customer'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 6.
v_fieldcat-fieldname = 'VKORG'.
v_fieldcat-seltext_m = 'Sales Organization'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 7.
v_fieldcat-fieldname = 'MATNR'.
v_fieldcat-seltext_m = 'Material'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 8.
v_fieldcat-fieldname = 'NETPR'.
v_fieldcat-seltext_m = 'Net Value'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

endform.

*&---------------------------------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------------------------------*
FORM GUI_SET USING RT_EXTAB TYPE SLIS_T_EXTAB .


SET PF-STATUS 'GETDATA' .

ENDFORM. "GUI_SET
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.


CASE R_UCOMM.
WHEN 'DATA'.
CLEAR I_FINAL.
CLEAR I_SALES.
REFRESH I_FINAL.

LOOP AT i_sales .
if i_sales-check = 'X'.
i_final-vbeln = i_sales-vbeln.
i_final-erdat = i_sales-erdat.
i_final-audat = i_sales-audat.
i_final-kunnr = i_sales-kunnr.
i_final-vkorg = i_sales-vkorg.
i_final-matnr = i_sales-matnr.
i_final-netpr = i_sales-netpr.

IF NOT I_FINAL-VBELN IS INITIAL.
append i_final .
ENDIF.

endif.
ENDLOOP.
PERFORM final_display.

endcase.

ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form final_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form final_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IS_LAYOUT = gt_LAYOUT
IT_FIELDCAT = gt_fieldcat

TABLES
t_outtab = i_final .

endform. " final_display

Password program

REPORT zpassword.


SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW TITLE title.

Parameters: p_name like sy-uname,
p_pas like sy-uname lower case.
SELECTION-SCREEN skip 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(70) text-001.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF SCREEN 500.

title = 'HAI VENKAT LOGIN PLEASE'.

CALL SELECTION-SCREEN '0500' STARTING AT 10 10 ending at 70 14.


data: begin of it_user occurs 0,
name like sy-uname,
password like sy-uname,
end of it_user.

it_user-name = 'venkat'.
it_user-password = 'venkat'.
append it_user.

it_user-name = 'srinivas'.
it_user-password = 'srinivas'.
append it_user.

it_user-name = 'preethi'.
it_user-password = 'preethi'.
append it_user.

it_user-name = 'vidya'.
it_user-password = 'vidya'.
append it_user.


AT SELECTION-SCREEN OUTPUT.
loop at screen.
check screen-name eq 'P_PAS'.
move: 1 to screen-invisible.
modify screen.
endloop.

start-of-selection.

if p_pas = 'venkat'.
write:/ 'venkat this is working'.
endif.

Selection screen with radio buttons

report ztest .

TABLES: vbak, ltak.
DATA:
err_sw.
PARAMETERS: rb1 RADIOBUTTON GROUP rb1 USER-COMMAND sel DEFAULT 'X'.
PARAMETERS: rb2 RADIOBUTTON GROUP rb1.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_auart FOR vbak-auart DEFAULT 'ZRE'
NO INTERVALS MODIF ID rb1.
SELECT-OPTIONS: s_date FOR vbak-erdat MODIF ID rb1.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
SELECT-OPTIONS: s_tanum FOR ltak-tanum MODIF ID rb2.
SELECT-OPTIONS: s_bdatu FOR ltak-bdatu MODIF ID rb2.
SELECTION-SCREEN: END OF BLOCK b2.

AT SELECTION-SCREEN OUTPUT.
IF rb1 = 'X'.
PERFORM hide_rb2_options.
ELSE.
PERFORM hide_rb1_options.
ENDIF.

INITIALIZATION.

START-OF-SELECTION.
CLEAR err_sw.
IF rb1 = 'X'.
IF s_auart IS INITIAL
OR s_date IS INITIAL.
MESSAGE i208(00) WITH 'Required field not entered'.
err_sw = 'X'.
ENDIF.
ELSE.
IF s_tanum IS INITIAL
OR s_bdatu IS INITIAL.
MESSAGE i208(00) WITH 'Required field not entered'.
err_sw = 'X'.
ENDIF.
ENDIF.

CHECK err_sw NE 'X'.

WRITE:/ 'Hi!'.

*&---------------------------------------------------------------------*
*& Form hide_rb2_options
*&---------------------------------------------------------------------*
FORM hide_rb2_options.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'RB1'.
screen-active = 1.
MODIFY SCREEN.
WHEN 'RB2'.
screen-active = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
ENDFORM. " hide_rb2_options
*&---------------------------------------------------------------------*
*& Form hide_rb1_options
*&---------------------------------------------------------------------*
FORM hide_rb1_options.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'RB2'.
screen-active = 1.
MODIFY SCREEN.
WHEN 'RB1'.
screen-active = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.

ENDFORM. " hide_rb1_options

User exit in a program

REPORT ztest .
TABLES : TSTC,
TADIR,
MODSAPT,
MODACT,
TRDIR,
TFDIR,
ENLFDIR,
SXS_ATTRT ,
TSTCT.

DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.
DATA : FIELD1(30).
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.

PARAMETERS : P_TCODE LIKE TSTC-TCODE,
P_PGMNA LIKE TSTC-PGMNA .




DATA wa_tadir type tadir.

START-OF-SELECTION.

IF NOT P_TCODE IS INITIAL.
SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.

ELSEIF NOT P_PGMNA IS INITIAL.
TSTC-PGMNA = P_PGMNA.
ENDIF.

IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM TADIR
WHERE PGMID = 'R3TR'
AND OBJECT = 'PROG'
AND OBJ_NAME = TSTC-PGMNA.

MOVE : TADIR-DEVCLASS TO V_DEVCLASS.

IF SY-SUBRC NE 0.
SELECT SINGLE * FROM TRDIR
WHERE NAME = TSTC-PGMNA.
IF TRDIR-SUBC EQ 'F'.
SELECT SINGLE * FROM TFDIR
WHERE PNAME = TSTC-PGMNA.

SELECT SINGLE * FROM ENLFDIR
WHERE FUNCNAME = TFDIR-FUNCNAME.

SELECT SINGLE * FROM TADIR
WHERE PGMID = 'R3TR'
AND OBJECT = 'FUGR'
AND OBJ_NAME EQ ENLFDIR-AREA.

MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
ENDIF.
ENDIF.

SELECT * FROM TADIR INTO TABLE JTAB
WHERE PGMID = 'R3TR'
AND OBJECT in ('SMOD', 'SXSD')
AND DEVCLASS = V_DEVCLASS.


SELECT SINGLE * FROM TSTCT
WHERE SPRSL EQ SY-LANGU
AND TCODE EQ P_TCODE.

FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) P_TCODE,
45(50) TSTCT-TTEXT.
SKIP.
IF NOT JTAB[] IS INITIAL.
WRITE:/(105) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.

* Sorting the internal Table
sort jtab by OBJECT.
data : wf_txt(60) type c,
wf_smod type i ,
wf_badi type i ,
wf_object2(30) type C.
clear : wf_smod, wf_badi , wf_object2.
* Get the total SMOD.




LOOP AT JTAB into wa_tadir.
at first.
FORMAT COLOR COL_HEADING INTENSIFIED ON.

WRITE:/1 SY-VLINE,
2 'Enhancement/ Business Add-in',
41 SY-VLINE ,
42 'Description',
105 SY-VLINE.
WRITE:/(105) SY-ULINE.
endat.
clear wf_txt.
at new object.
if wa_tadir-object = 'SMOD'.
wf_object2 = 'Enhancement' .
elseif wa_tadir-object = 'SXSD'.
wf_object2 = ' Business Add-in'.

endif.
FORMAT COLOR COL_GROUP INTENSIFIED ON.

WRITE:/1 SY-VLINE,

2 wf_object2,
105 SY-VLINE.
endat.

case wa_tadir-object.
when 'SMOD'.
wf_smod = wf_smod + 1.
SELECT SINGLE MODTEXT into wf_txt
FROM MODSAPT
WHERE SPRSL = SY-LANGU
AND NAME = wa_tadir-OBJ_NAME.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

when 'SXSD'.
* For BADis
wf_badi = wf_badi + 1 .
select single TEXT into wf_txt
from SXS_ATTRT
where sprsl = sy-langu
and EXIT_NAME = wa_tadir-OBJ_NAME.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.

endcase.



WRITE:/1 SY-VLINE,
2 wa_tadir-OBJ_NAME hotspot on,
41 SY-VLINE ,
42 wf_txt,
105 SY-VLINE.
AT END OF object.
write : /(105) sy-ULINE.
ENDAT.


ENDLOOP.

WRITE:/(105) SY-ULINE.



SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No.of Exits:' , wf_smod.
WRITE:/ 'No.of BADis:' , wf_badi.

ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(105) 'No userexits or BADis exist'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(105) 'Transaction does not exist'.
ENDIF.

AT LINE-SELECTION.

data : wf_object type tadir-object.
clear wf_object.

GET CURSOR FIELD FIELD1.
CHECK FIELD1(8) EQ 'WA_TADIR'.
read table jtab with key obj_name = sy-lisel+1(20).
move jtab-object to wf_object.

case wf_object.
when 'SMOD'.
SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).

CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
when 'SXSD'.
SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20).
CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
endcase.

Input only through the f4 help

report ztest .


PARAMETERS:p_matnr(18) TYPE c MODIF ID mid.

DATA:BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
END OF itab.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_matnr.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

IF itab IS INITIAL.

itab-matnr = 'ABC123456788'.
APPEND itab.

itab-matnr = 'BCS123456788'.
APPEND itab.

itab-matnr = 'DFC123456788'.
APPEND itab.

itab-matnr = 'ASW123456788'.
APPEND itab.

ENDIF.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_MATNR'
value_org = 'S'
TABLES
value_tab = itab.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
endloop.

Icons on the selection screen

REPORT zsscrbuttons2.

TABLES: sscrfields.

DATA: gd_ucomm TYPE sy-ucomm.

SELECTION-SCREEN BEGIN OF BLOCK period WITH FRAME TITLE text-t02.
SELECT-OPTIONS: so_dates FOR sy-datum NO-EXTENSION.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 01(20) text-fy1. "= Fiscal Year
SELECTION-SCREEN POSITION 33.
PARAMETERS: p_period LIKE qppnp-pabrp.
SELECTION-SCREEN POSITION 36.
PARAMETERS: p_year LIKE qppnp-pabrj.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN PUSHBUTTON /01(29) but1 USER-COMMAND but1.
SELECTION-SCREEN PUSHBUTTON /01(29) but2 USER-COMMAND but2.
SELECTION-SCREEN END OF BLOCK period.

*INITIALIZATION.
INITIALIZATION.
* MOVE 'Fiscal Year' TO BUT1.
MOVE 'Date Period' TO but2.

DATA: icon_name TYPE iconname,
button_text(20) TYPE c,
quickinfo LIKE smp_dyntxt-quickinfo,
icon_str(255) TYPE c.

* Setup button 1 (Fiscal year)
icon_name = 'ICON_ARROW_RIGHT'. " 'ICON_DISPLAY_MORE'.
button_text = 'Fiscal Year'.
CONCATENATE button_text text-akt
INTO quickinfo
SEPARATED BY space.

CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = icon_name
text = button_text
info = quickinfo
* ADD_STDINF = 'X'
IMPORTING
RESULT = icon_str
EXCEPTIONS
OTHERS = 0. "not interested in errors

* place text and icon on button
but1 = icon_str.

* Setup button 2 (Date period)
icon_name = 'ICON_ARROW_LEFT'. " 'ICON_DISPLAY_MORE'.
button_text = 'Date Period'.
CONCATENATE button_text text-akt
INTO quickinfo
SEPARATED BY space.

CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = icon_name
text = button_text
info = quickinfo
IMPORTING
RESULT = icon_str
EXCEPTIONS
OTHERS = 0. "not interested in errors

* place text and icon on button
but2 = icon_str.


************************************************************************
*AT SELECTION-SCREEN.
AT SELECTION-SCREEN.
* Check if buttons have been
IF sscrfields-ucomm EQ 'BUT1'.
gd_ucomm = 'BUT1'.
ELSEIF sscrfields-ucomm EQ 'BUT2'.
gd_ucomm = 'BUT2'.
ENDIF.


************************************************************************
*AT SELECTION-SCREEN.
AT SELECTION-SCREEN OUTPUT.

IF gd_ucomm IS INITIAL.
LOOP AT SCREEN.
IF screen-name CS 'P_PERIOD' OR
screen-name CS 'P_YEAR' OR
screen-name CS 'FY1' OR
screen-name EQ 'BUT2'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSEIF gd_ucomm EQ 'BUT1'.
LOOP AT SCREEN.
IF screen-name CS 'P_PERIOD' OR
screen-name CS 'P_YEAR' OR
screen-name CS 'FY1' OR
screen-name EQ 'BUT2'.
screen-active = 1.
MODIFY SCREEN.
ENDIF.
IF screen-name CS 'SO_DATES' OR
screen-name EQ 'BUT1'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSEIF gd_ucomm EQ 'BUT2' .
LOOP AT SCREEN.
IF screen-name CS 'P_PERIOD' OR
screen-name CS 'P_YEAR' OR
screen-name CS 'FY1' OR
screen-name EQ 'BUT2'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
IF screen-name CS 'SO_DATES' OR
screen-name EQ 'BUT1'.
screen-active = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.

Push buttons on selection screen

REPORT zsscrbutton NO STANDARD PAGE HEADING.

TABLES: t030, skat, sscrfields.


SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME
TITLE text-001.
SELECT-OPTIONS: p_ktopl FOR t030-ktopl,
p_komok FOR t030-komok,
p_ktosl FOR t030-ktosl.
SELECTION-SCREEN SKIP.
*SELECTION-SCREEN FUNCTION KEY 1. "Adds button to application toolbar

* Declaration of sel screen buttons
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (20) w_button USER-COMMAND BUT1.
SELECTION-SCREEN PUSHBUTTON (25) w_but2 USER-COMMAND BUT2.
SELECTION-SCREEN END OF LINE.

SELECT-OPTIONS: p_konts FOR t030-konts,
p_bklas FOR t030-bklas.
PARAMETER: gd_ucomm like sy-ucomm default 'BUT1' no-display.
SELECTION-SCREEN END OF BLOCK block1.

TYPES: BEGIN OF t_t030,
ktopl TYPE t030-ktopl,
konts TYPE t030-konts,
txt20 TYPE skat-txt20,
bklas TYPE t030-bklas,
bkbez TYPE t025t-bkbez,
END OF t_t030.

DATA: it_t030 TYPE STANDARD TABLE OF t_t030 INITIAL SIZE 0,
wa_t030 TYPE t_t030.

DATA: gd_repsize TYPE i VALUE '83'.

*INITIALIZATION.
INITIALIZATION.
* Add displayed text string to buttons
w_button = 'GL account selection'.
w_but2 = 'Valuation class selection'.


*AT SELECTION-SCREEN.
AT SELECTION-SCREEN.
* Check if buttons have been
if sscrfields-ucomm eq 'BUT1'.
gd_ucomm = 'BUT1'.
clear: p_BKLAS.
refresh: p_BKLAS.
elseif sscrfields-ucomm eq 'BUT2'.
clear: p_KONTS.
refresh: p_KONTS.
gd_ucomm = 'BUT2'.
endif.


*AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN OUTPUT.
if gd_ucomm eq 'BUT1'.
loop at screen.
if screen-name CS 'P_KONTS'.
screen-active = 1.
elseif screen-name CS 'P_BKLAS'.
screen-active = 0.
endif.
modify screen.
endloop.
elseif gd_ucomm eq 'BUT2'.
loop at screen.
if screen-name CS 'P_KONTS'.
screen-active = 0.
elseif screen-name CS 'P_BKLAS'.
screen-active = 1.
endif.
modify screen.
endloop.
endif.

User exit for a transaction

REPORT z_find_userexit NO STANDARD PAGE HEADING.

TABLES : tstc, "SAP Transaction Codes
tadir, "Directory of Repository Objects
modsapt, "SAP Enhancements - Short Texts
modact, "Modifications
trdir, "System table TRDIR
tfdir, "Function Module
enlfdir, "Additional Attributes for Function Modules
tstct. "Transaction Code Texts

*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*
DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
DATA : field1(30).
DATA : v_devclass LIKE tadir-devclass.

*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK a01.

*&---------------------------------------------------------------------*
*& Start of main program
*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Validate Transaction Code
SELECT SINGLE * FROM tstc
WHERE tcode EQ p_tcode.
* Find Repository Objects for transaction code
IF sy-subrc EQ 0.
SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'PROG'
AND obj_name = tstc-pgmna.
MOVE : tadir-devclass TO v_devclass.
IF sy-subrc NE 0.
SELECT SINGLE * FROM trdir
WHERE name = tstc-pgmna.
IF trdir-subc EQ 'F'.
SELECT SINGLE * FROM tfdir
WHERE pname = tstc-pgmna.
SELECT SINGLE * FROM enlfdir
WHERE funcname = tfdir-funcname.
SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'FUGR'
AND obj_name = enlfdir-area.
MOVE : tadir-devclass TO v_devclass.
ENDIF.
ENDIF.
* Find SAP Modifactions
SELECT * FROM tadir
INTO TABLE jtab
WHERE pgmid = 'R3TR'
AND object = 'SMOD'
AND devclass = v_devclass.
SELECT SINGLE * FROM tstct
WHERE sprsl EQ sy-langu
AND tcode EQ p_tcode.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
SKIP.
IF NOT jtab[] IS INITIAL.
WRITE:/(95) sy-uline.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
WRITE:/(95) sy-uline.

LOOP AT jtab.
SELECT SINGLE * FROM modsapt
WHERE sprsl = sy-langu AND
name = jtab-obj_name.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/1 sy-vline,
2 jtab-obj_name HOTSPOT ON,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.
ENDLOOP.
WRITE:/(95) sy-uline.
DESCRIBE TABLE jtab.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , sy-tfill.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'No User Exit exists'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'Transaction Code Does Not Exist'.
ENDIF.
* Take the user to SMOD for the Exit that was selected.
AT LINE-SELECTION.
GET CURSOR FIELD field1.
CHECK field1(4) EQ 'JTAB'.
SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

Thursday, September 23, 2010

ALV sub-total and total

*&---------------------------------------------------------------------*
*& Report Z_ALV_SUBTOTAL
*&
*&---------------------------------------------------------------------
REPORT z_alv_subtotal.
*&---------------------------------------------------------------------*
*& Table declaration
*&---------------------------------------------------------------------*
TABLES: ekko.
*&---------------------------------------------------------------------*
*& Type pool declaration
*&---------------------------------------------------------------------*
TYPE-POOLS: slis. " Type pool for ALV
*&---------------------------------------------------------------------*
*& Selection screen
*&---------------------------------------------------------------------*
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
*&---------------------------------------------------------------------*
*& Type declaration
*&---------------------------------------------------------------------*
* Type declaration for internal table to store EKPO data
TYPES: BEGIN OF x_data,
ebeln TYPE char30, " Document no.
ebelp TYPE ebelp, " Item no
matnr TYPE matnr, " Material no
matnr1 TYPE matnr, " Material no
werks TYPE werks_d, " Plant
werks1 TYPE werks_d, " Plant
ntgew TYPE entge, " Net weight
gewe TYPE egewe, " Unit of weight
END OF x_data.
*&---------------------------------------------------------------------*
*& Internal table declaration
*&---------------------------------------------------------------------*
DATA:
* Internal table to store EKPO data
i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
* Internal table for storing field catalog information
i_fieldcat TYPE slis_t_fieldcat_alv,
* Internal table for Top of Page info. in ALV Display
i_alv_top_of_page TYPE slis_t_listheader,
* Internal table for ALV Display events
i_events TYPE slis_t_event,
* Internal table for storing ALV sort information
i_sort TYPE slis_t_sortinfo_alv,
i_event TYPE slis_t_event.
*&---------------------------------------------------------------------*
*& Work area declaration
*&---------------------------------------------------------------------*
DATA:
wa_ekko TYPE x_data,
wa_layout TYPE slis_layout_alv,
wa_events TYPE slis_alv_event,
wa_sort TYPE slis_sortinfo_alv.
*&---------------------------------------------------------------------*
*& Constant declaration
*&---------------------------------------------------------------------*
CONSTANTS:
c_header TYPE char1
VALUE 'H', "Header in ALV
c_item TYPE char1
VALUE 'S'.
*&---------------------------------------------------------------------*
*& Start-of-selection event
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Select data from ekpo
SELECT ebeln " Doc no
ebelp " Item
matnr " Material
matnr " Material
werks " Plant
werks " Plant
ntgew " Quantity
gewei " Unit
FROM ekpo
INTO TABLE i_ekpo
WHERE ebeln IN s_ebeln
AND ntgew NE '0.00'.
IF sy-subrc = 0.
SORT i_ekpo BY ebeln ebelp matnr .
ENDIF.
* To build the Page header
PERFORM sub_build_header.
* To prepare field catalog
PERFORM sub_field_catalog.
* Perform to populate the layout structure
PERFORM sub_populate_layout.
* Perform to populate the sort table.
PERFORM sub_populate_sort.
* Perform to populate ALV event
PERFORM sub_get_event.
END-OF-SELECTION.
* Perform to display ALV report
PERFORM sub_alv_report_display.
*&---------------------------------------------------------------------*
*& Form sub_build_header
*&---------------------------------------------------------------------*
* To build the header
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_build_header .
* Local data declaration
DATA: l_system TYPE char10 , "System id
l_r_line TYPE slis_listheader, "Hold list header
l_date TYPE char10, "Date
l_time TYPE char10, "Time
l_success_records TYPE i, "No of success records
l_title(300) TYPE c. " Title
* Title Display
l_r_line-typ = c_header. " header
l_title = 'Test report'(001).
l_r_line-info = l_title.
APPEND l_r_line TO i_alv_top_of_page.
CLEAR l_r_line.
* Run date Display
CLEAR l_date.
l_r_line-typ = c_item. " Item
WRITE: sy-datum TO l_date MM/DD/YYYY.
l_r_line-key = 'Run Date :'(002).
l_r_line-info = l_date.
APPEND l_r_line TO i_alv_top_of_page.
CLEAR: l_r_line,
l_date.ENDFORM. " sub_build_header
*&---------------------------------------------------------------------*
*& Form sub_field_catalog
*&---------------------------------------------------------------------*
* Build Field Catalog
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_field_catalog .
* Build Field Catalog
PERFORM sub_fill_alv_field_catalog USING:
'01' '01' 'EBELN' 'I_EKPO' 'L' 'Doc No'(003) ' ' ' ' ' ' ' ',
'01' '02' 'EBELP' 'I_EKPO' 'L' 'Item No'(004) 'X' 'X' ' ' ' ',
'01' '03' 'MATNR' 'I_EKPO' 'L' 'Material No'(005) 'X' 'X' ' ' ' ',
'01' '03' 'MATNR1' 'I_EKPO' 'L' 'Material No'(005) ' ' ' ' ' ' ' ',
'01' '04' 'WERKS' 'I_EKPO' 'L' 'Plant'(006) 'X' 'X' ' ' ' ',
'01' '04' 'WERKS1' 'I_EKPO' 'L' 'Plant'(006) ' ' ' ' ' ' ' ',
'01' '05' 'NTGEW' 'I_EKPO' 'R' 'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.
ENDFORM. " sub_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_fill_alv_field_catalog
*&---------------------------------------------------------------------*
*& For building Field Catalog
*&---------------------------------------------------------------------*
*& p_rowpos Row position
*& p_colpos Col position
*& p_fldnam Fldname
*& p_tabnam Tabname
*& p_justif Justification
*& p_seltext Seltext
*& p_out no out
*& p_tech Technical field
*& p_qfield Quantity field
*& p_qtab Quantity table
*&---------------------------------------------------------------------*
FORM sub_fill_alv_field_catalog USING p_rowpos TYPE sycurow
p_colpos TYPE sycucol
p_fldnam TYPE fieldname
p_tabnam TYPE tabname
p_justif TYPE char1
p_seltext TYPE dd03p-scrtext_l
p_out TYPE char1
p_tech TYPE char1
p_qfield TYPE slis_fieldname
p_qtab TYPE slis_tabname.
* Local declaration for field catalog
DATA: wa_lfl_fcat TYPE slis_fieldcat_alv.
wa_lfl_fcat-row_pos = p_rowpos. "Row
wa_lfl_fcat-col_pos = p_colpos. "Column
wa_lfl_fcat-fieldname = p_fldnam. "Field Name
wa_lfl_fcat-tabname = p_tabnam. "Internal Table Name
wa_lfl_fcat-just = p_justif. "Screen Justified
wa_lfl_fcat-seltext_l = p_seltext. "Field Text
wa_lfl_fcat-no_out = p_out. "No output
wa_lfl_fcat-tech = p_tech. "Technical field
wa_lfl_fcat-qfieldname = p_qfield. "Quantity unit
wa_lfl_fcat-qtabname = p_qtab . "Quantity table
IF p_fldnam = 'NTGEW'.
wa_lfl_fcat-do_sum = 'X'.
ENDIF.
APPEND wa_lfl_fcat TO i_fieldcat.
CLEAR wa_lfl_fcat.
ENDFORM. " sub_fill_alv_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_populate_layout
*&---------------------------------------------------------------------*
* Populate ALV layout
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_populate_layout . CLEAR wa_layout.
wa_layout-colwidth_optimize = 'X'." Optimization of Col width
ENDFORM. " sub_populate_layout
*&---------------------------------------------------------------------*
*& Form sub_populate_sort
*&---------------------------------------------------------------------*
* Populate ALV sort table
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_populate_sort .
* Sort on material
wa_sort-spos = '01' .
wa_sort-fieldname = 'MATNR'.
wa_sort-tabname = 'I_EKPO'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO i_sort .
CLEAR wa_sort.
* Sort on plant
wa_sort-spos = '02'.
wa_sort-fieldname = 'WERKS'.
wa_sort-tabname = 'I_EKPO'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO i_sort .
CLEAR wa_sort.
ENDFORM. " sub_populate_sort
*&---------------------------------------------------------------------*
*& Form sub_get_event
*&---------------------------------------------------------------------*
* Get ALV grid event and pass the form name to subtotal_text
* event
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_get_event .
CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
'SUBTOTAL_TEXT'.
DATA: l_s_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 4
IMPORTING
et_events = i_event
EXCEPTIONS
list_type_wrong = 0
OTHERS = 0.
* Subtotal
READ TABLE i_event INTO l_s_event
WITH KEY name = slis_ev_subtotal_text.
IF sy-subrc = 0.
MOVE c_formname_subtotal_text TO l_s_event-form.
MODIFY i_event FROM l_s_event INDEX sy-tabix.
ENDIF.
ENDFORM. " sub_get_event
*&---------------------------------------------------------------------*
*& Form sub_alv_report_display
*&---------------------------------------------------------------------*
* For ALV Report Display
*----------------------------------------------------------------------*
* No Parameter
*----------------------------------------------------------------------*
FORM sub_alv_report_display .
DATA: l_repid TYPE syrepid .
l_repid = sy-repid .
* This function module for displaying the ALV report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
i_callback_top_of_page = 'SUB_ALV_TOP_OF_PAGE'
is_layout = wa_layout
it_fieldcat = i_fieldcat
it_sort = i_sort
it_events = i_event
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = i_ekpo
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE i000 WITH 'Error in ALV report display'(055).
ENDIF.ENDFORM. " sub_alv_report_display
*&---------------------------------------------------------------------*
* FORM sub_alv_top_of_page
*---------------------------------------------------------------------*
* Call ALV top of page
*---------------------------------------------------------------------*
* No parameter
*---------------------------------------------------------------------*
FORM sub_alv_top_of_page. "#EC CALLED
* To write header for the ALV
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_alv_top_of_page.
ENDFORM. "alv_top_of_page
*&---------------------------------------------------------------------*
*& Form subtotal_text
*&---------------------------------------------------------------------*
* Build subtotal text
*----------------------------------------------------------------------*
* P_total Total
* p_subtot_text Subtotal text info
*----------------------------------------------------------------------*
FORM subtotal_text CHANGING
p_total TYPE any
p_subtot_text TYPE slis_subtot_text.
* Material level sub total
IF p_subtot_text-criteria = 'MATNR'.
p_subtot_text-display_text_for_subtotal
= 'Material level total'(009).
ENDIF.
* Plant level sub total
IF p_subtot_text-criteria = 'WERKS'.
p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
ENDIF.
ENDFORM. "subtotal_text

Different select statements

For all entries

The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of
entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the
length of the WHERE clause.
The plus

Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Some steps that might make FOR ALL ENTRIES more efficient:
Removing duplicates from the the driver table
Sorting the driver table
If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low and
mykey <= i_tab-high.
Nested selects

The plus:
Small amount of data
Mixing processing and reading of data
Easy to code - and understand
The minus:
Large amount of data
when mixed processing isn’t needed
Performance killer no. 1

Select using JOINS

The plus
Very large amount of data
Similar to Nested selects - when the accesses are planned by the programmer
In some cases the fastest
Not so memory critical
The minus
Very difficult to program/understand
Mixing processing and reading of data not possible

Use the selection criteria

SELECT * FROM SBOOK.
CHECK: SBOOK-CARRID = 'LH' AND
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.

Use the aggregated functions

C4A = '000'.
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.

SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.

Select with view

SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.

SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.

Select with index support

SELECT * FROM T100
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.

SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.


Select … Into table

REFRESH X006.
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT

SELECT * FROM T006 INTO TABLE X006.


Select with selection list

SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT

SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT

Key access to multiple lines

LOOP AT TAB.
CHECK TAB-K = KVAL.
" ...
ENDLOOP.

LOOP AT TAB WHERE K = KVAL.
" ...
ENDLOOP.


Copying internal tables

REFRESH TAB_DEST.
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.

TAB_DEST[] = TAB_SRC[].

Modifying a set of lines

LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.

TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.

Deleting a sequence of lines

DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.

DELETE TAB_DEST FROM 450 TO 550.


Linear search vs. binary

READ TABLE TAB WITH KEY K = 'X'.

READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
Comparison of internal tables
DESCRIBE TABLE: TAB1 LINES L1,
TAB2 LINES L2.

IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.

IF TAB_DIFFERENT = SPACE.
" ...
ENDIF.

IF TAB1[] = TAB2[].
" ...
ENDIF.

Modify selected components

LOOP AT TAB.
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.

WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.

Appending two internal tables

LOOP AT TAB_SRC.
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP

APPEND LINES OF TAB_SRC TO TAB_DEST.

Deleting a set of lines

LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP

DELETE TAB_DEST WHERE K = KVAL.


Tools available in SAP to pin-point a performance problem

The runtime analysis (SE30)
SQL Trace (ST05)
Tips and Tricks tool
The performance database

Optimizing the load of the database

Using table buffering
Using buffered tables improves the performance considerably. Note that in some cases a stament can not be used with a buffered table, so when using these staments the buffer will be bypassed. These staments are:
Select DISTINCT
ORDER BY / GROUP BY / HAVING clause
Any WHERE clasuse that contains a subquery or IS NULL expression
JOIN s
A SELECT... FOR UPDATE
If you wnat to explicitly bypass the bufer, use the BYPASS BUFFER addition to the SELECT clause.
Use the ABAP SORT Clause Instead of ORDER BY
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The datbase server will usually be the bottleneck, so sometimes it is better to move thje sort from the datsbase server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT stament to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the datbase server sort it.

Avoid ther SELECT DISTINCT Statement

As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplciate rows.