Search This Blog

Wednesday, June 22, 2011

Comparing Source Code of 2 different ABAP Programs

SAP provide a way to compare the source code of two different
objects, similar to what is available in Version Management. It is called the split screen editor. One can use transaction SE39 to compare 2 different ABAP programs. Can
also compare programs across systems as well using this transaction.

Wednesday, June 15, 2011

SAP ABAP Consultant At Tata Technologies

Location:

Experience:

Job Description:

Company Profile:

Monday, June 13, 2011

Coloring Individual Rows in ALV Grid

Sample ABAP Code for Coloring An Entire Row in ALV Grid.
Coloring a row is a bit complicated. To enable row coloring, you should add an additional field to your list data table ( internal table ). It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “t_ekko”.

Adding the field that will contain row color data:
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
  line_color(4) type c,     "Used to store row color attributes
 END OF t_ekko.

You should fill the color code to this field.
But how will ALV Grid know that you have loaded the color data
for the row to this field. So, you make it know this by passing
the name of the field containing color codes to the field 
“INFO_FIELDNAME” of the layout structure.

Example -
gd_layout-info_fieldname =      'LINE_COLOR'.




Sample Program :
Important lines to remember are highlighted.

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
  line_color(4) type c,     "Used to store row color attributes
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
* Set layout field for row attributes(i.e. color) 
  gd_layout-info_fieldname =      'LINE_COLOR'.
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
*            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
*            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
*            IT_EVENTS                = GT_XEVENTS
            i_save                  = 'X'
*            is_variant              = z_template

       tables
            t_outtab                = it_ekko
       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_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.

*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
*           i.e. wa_ekko-line_color = 'C410'
  ld_color = ld_color + 1.

* Only 7 colours so need to reset color value
  if ld_color = 8.
    ld_color = 1.
  endif.
  concatenate 'C' ld_color '10' into wa_ekko-line_color.
 
*Instead of doing the above steps one can directly write the following statement:
*  wa_ekko-line_color = 'C410'. " This will give all the rows the same color.
  modify it_ekko from wa_ekko.
endloop.
endform.                    " DATA_RETRIEVAL
 
Output :
 

Sunday, June 12, 2011

Why is ALE used?

ALE (Application Link Enabling) provides for the integration of distributed applications.

Applications are distributed because of the following reasons :

  • System Performance:  The transaction load is too heavy for a single
    SAP system.
  • High Availability Requirements:  The Company cannot afford downtime due to backups, maintenance, upgrades, etc.
  • SAP Release Coordination:  Different units of the organization may require different releases of the SAP software.
  • Very Large Database:  Companies with very large databases may need to distribute the data across multiple SAP systems.
  • Business Structure:  Business units may require independence and autonomy for day-to-day operations, and yet still need to share some data and functionality with other units in the enterprise.
  • Interfacing with non-SAP systems:  The Company may wish to maintain certain applications on non-SAP systems, while at the same time integrate these applications and their data with the SAP system.
  • Keep development system data in sync with production data: An organization may wish to keep the data on a development system the same as on a production system.
  • Maintain configuration and master data across clients: Organizations using multiple clients may wish to maintain certain data on a client-independent basis.

ALE allows you to:
  • Distribute your applications across several SAP systems, such that centralized functions, as well as decentralized functions can operate in the same company arena.
  • Maintain and distribute master data elements from a central system, thus maintaining unique number ranges across several systems.
  • Maintain and distribute control data objects from a central system, thus synchronizing important configuration data. This is important when trying to decentralise functions, yet keep them integrated.
  • Couple R/2 and R/3 systems, in some instances
  • Couple SAP and external systems, via IDocs (Intermediate Documents) and an external translation mechanism.

Wednesday, June 8, 2011

LOOP AT SCREEN Statement | Modify Selection Screen at Run Time

Sample Code for modifying selection screen at user command :


PARAMETERS : CBOX AS CHECKBOX USER-COMMAND ACT DEFAULT ' ',
                            EBELN LIKE EKKO-EBELN MODIF ID R1.

 PARAMETERS: BLACK(10) MODIF ID A,
                            BLACK2(5) MODIF ID A,
                            WHITE1(2) MODIF ID B.

PARAMETERS: C RADIOBUTTON GROUP RAD1 USER-COMMAND ACT DEFAULT 'X',
                           D RADIOBUTTON GROUP RAD1.


AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.

IF CBOX = 'X'.
IF SCREEN-GROUP1 = 'R1'.
SCREEN-INPUT = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

LOOP AT SCREEN.
IF C = 'X'.
IF SCREEN-GROUP1 = 'B'.
SCREEN-INPUT = 0 .
ENDIF.
ELSEIF D = 'X'.
IF SCREEN-GROUP1 = 'A'.
SCREEN-INPUT = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

Thursday, June 2, 2011

Loop at Itab Assigning | Accessing Internal Table using Field Symbols

Records in internal tables in abap can be accessed using the following methods :

1) Loop at itab into work-area.
2) Loop at itab assigning <fs-itab> 

Comparison between the above methods.

The field symbol <fs> points directly to the assigned line in memory. Unlike work areas, in which the contents of the line are only available indirectly using the INTOaddition, field symbols allow you to read and change table entries directly.

When you read from an internal table, there are no overheads for copying the table line to the work area. When you change an internal table with the MODIFY statement, you must first fill a work area with values, and then assign them to the internal table. If you work with field symbols instead, you do not have this overhead. This can improve performance if you have large or complex internal tables. It also makes it easier to process nested internal tables.

If the table is small (a couple hundred records) and you are not going to modify any data in it, then the work area will be faster.

If you need to modify data within the table, then assigning a <FS> will be faster. 


Wednesday, June 1, 2011

FOR ALL ENTRIES Command in ABAP

'For All Entries' command is helpful in fetching records and is generally used with the Select statement.

Sample Program :

TABLES : EKKO, EKPO.
DATA: IT_EKKO TYPE STANDARD TABLE OF EKKO,
              WA_EKKO LIKE LINE OF IT_EKKO,

              IT_EKPO TYPE STANDARD TABLE OF EKPO,
              WA_EKPO LIKE LINE OF IT_EKPO.

SELECT *
UP TO 10 ROWS  "ONLY RETURN FIRST 10 HITS
FROM EKKO
INTO TABLE IT_EKKO.

LOOP AT IT_EKKO INTO WA_EKKO.
  WRITE : /  WA_EKKO-EBELN.
ENDLOOP.

IF SY-SUBRC EQ 0.

* THE FOR ALL ENTRIES COMAND ONLY RETRIEVES DATA WHICH MATCHES
* ENTRIES WITHIN A PARTICULAR INTERNAL TABLE.

 SELECT *
 FROM EKPO
 INTO TABLE IT_EKPO
 FOR ALL ENTRIES IN IT_EKKO
 WHERE EBELN EQ IT_EKKO-EBELN.

  WRITE:/ 'FOR ALL ENTRIES COMAND '.

 LOOP AT IT_EKPO INTO WA_EKPO.
    WRITE:/ WA_EKPO-EBELN, WA_EKPO-EBELP.
 ENDLOOP.

ENDIF.