Tuesday, 30 December 2014

What are the technical prerequisites to use Adobe Forms in SAP

  • Configuration
    • SAP NetWeaver 6.40
    • Java Stack installed
    • Adobe Document Services (ADS) installed on the Java Stack
    • If using ABAP, RFC communication must be established between ABAP and Java stacks
  • Developers
    • Adobe LiveCycle Designer 7.1 is installed on your machine ( Desktop / Laptop)
    • Adobe Reader 7.* is installed
    • SAP GUI (see Note 864634)
      • 620 Patch level 56 or higher
      • 640 Patch level 12 or higher
      • 710 any patch level
  • Users
    • Adobe Reader 7.*

How to retrieve filled in data from an Interactive Form?

depends if the interactive form is offline or online (web dynpro)
  • Offline :
    • The interactive form is either sent to the user by email, or downloaded by the user from a portal on his laptop
    • So, the user is (usually) not connected to SAP at the time he fills in data using Adobe Reader. Some interaction with the SAP system may still be achieved using Web Services.
    • When he has finished with the Adobe form, he sends it back to the SAP system, or he/any user connects to the SAP system and uploads the adobe form. A Java or ABAP program reads the form and extracts filled in data using Adobe Document Services.
  • Online :
    • The user displays and fills the interactive form via a Web Dynpro (which itself may be accessed via a portal or Web Application Server)
    • The Web Dynpro interacts with the Adobe form using the Context nodes and Bindings

What are the steps to develop an Adobe Form on ABAP stack?

  • Start transaction code SFP, create an interface
  • With this same transaction, create the Adobe Form
  • From your ABAP, call the interactive form as follows (see also SAP Library - PDF-Based Forms - Calling Forms in an Application Program, which contains an example)
    1. Data retrieval and processing : SELECT ... FROM ... etc.
    2. Find out name of generated function module from the Adobe form name : CALL FUNCTION 'FP_FUNCTION_MODULE_NAME' ...
    3. Start form processing : CALL FUNCTION 'FP_JOB_OPEN' ...
    4. Call function module dynamically: CALL FUNCTION <generated function module> ...
    5. End form processing : CALL FUNCTION 'FP_JOB_CLOSE' ...

Monday, 29 December 2014

Demo program to color particular row or column or cell of an ALV list using 'REUSE_ALV_LIST_DISPLAY'

REPORT ZALV_LIST1.
TABLES: SPFLI.

TYPE-POOLS:SLIS.


PARAMETERS:P_COL TYPE I ,

                             P_ROW TYPE I,
                             P_COLOR(4) TYPE C .


DATA:T_FIELDCAT    TYPE SLIS_T_FIELDCAT_ALV,
                 FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
                 FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
                 W_COLOR(4) ,
                 W_ROW TYPE I,
                 W_FIELDNAME(20),
                 W_PROG TYPE SY-REPID.


DATA:BEGIN OF T_SPFLI OCCURS 0,
            COLOR(4),
            CHECKBOX ,
            CELL TYPE SLIS_T_SPECIALCOL_ALV,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
CITYFROM TYPE SPFLI-CITYFROM,
CITYTO TYPE SPFLI-CITYTO,
DISTANCE TYPE SPFLI-DISTANCE,
END OF T_SPFLI.


DATA:
FS_CELL LIKE LINE OF T_SPFLI-CELL.


SELECT *
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.


W_COLOR = P_COLOR.

T_SPFLI-COLOR = P_COLOR.


IF P_COL IS INITIAL AND P_ROW GT 0.
MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.
ENDIF.

FS_FIELDCAT-FIELDNAME = 'CARRID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 1.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'CONNID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 2.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 3.
FS_FIELDCAT-KEY = ' '.
FS_FIELDCAT-EDIT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT.
FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 4.
FS_FIELDCAT-KEY = ' '.
APPEND FS_FIELDCAT TO T_FIELDCAT.

LOOP AT T_FIELDCAT INTO FS_FIELDCAT.
IF FS_FIELDCAT-COL_POS EQ P_COL.
FS_FIELDCAT-EMPHASIZE = P_COLOR.
W_FIELDNAME = FS_FIELDCAT-FIELDNAME.
IF P_ROW IS INITIAL AND P_COL GT 0.
MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.
ENDIF.
ENDIF.
ENDLOOP.

FS_CELL-FIELDNAME = W_FIELDNAME .
FS_CELL-COLOR-COL = 6.
FS_CELL-NOKEYCOL = 'X'.
APPEND FS_CELL TO T_SPFLI-CELL.

IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.
MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.
ENDIF.

FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
FS_LAYOUT-F2CODE = '&ETA'.

W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IS_LAYOUT = FS_LAYOUT
IT_FIELDCAT = T_FIELDCAT
TABLES
T_OUTTAB = T_SPFLI
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.

NOTE
 Column and Row are colored with a coded color ‘Cxyz’.

    Where C: Color (coding must begin with C)

                 X: Color Number

                 Y: Bold

                 Z: Inverse.
 The Selection Screen will be as follows. 
     
In the Selection screen if we enter only the Column Number and color the whole column will be colored as follows.

 
In the Selection screen if we enter only the row Number and color, the whole column will be colored as follows.
   
 In the Selection screen if we enter both the Row number and the Column Number then that particular cell will be colored as follows (this color is not picked from selection screen, it is already written in the program itself) 

SAP ALV row colour change and making each individual row a different color

The follow program demonstrates how to change the colour of individual rows of an ALV grid. Changes required from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with color attribute and adding an entry to layout control table.

cover



REPORT  zdemo_alvgrid                 .

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'.
  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.
*  wa_ekko-line_color = 'C410'.
  modify it_ekko from wa_ekko.
endloop.
endform.                    " DATA_RETRIEVAL

Change colour of individual SAP ALV cells within an ALV grid report

The below abap program shows how to change the colour of individual ALV cells /fields. Only a small number of changes are required from a basic ALV grid which include adding a new field to ALV data declaration table(it_ekko), populating this field with the field name identifier and colour attributes and finally adding an entry to layout control work area. These changes are highlighted in bold below.



cover


REPORT  ZALV_CELLCOLOR.

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,
  CELLCOLOR TYPE LVC_T_SCOL,

 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,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


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

  perform data_retrieval.
  perform build_fieldcatalog.
  perform build_layout.
  perform set_cell_colours.
  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-do_sum      = 'X'.
  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).
  gd_LAYOUT-coltab_fieldname = 'CELLCOLOR'.  "CTAB_FNAME
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_events
*           is_print                = gd_prntparams
            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.

  select ebeln ebelp statu aedat matnr menge meins netpr peinh
   up to 10 rows
    from ekpo
    into CORRESPONDING FIELDS OF TABLE it_ekko.
endform.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
  data: t_header type slis_t_listheader,
        wa_header type slis_listheader,
        t_line like wa_header-info,
        ld_lines type i,
        ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.                    "top-of-page


*&---------------------------------------------------------------------*
*&      Form  SET_CELL_COLOURS
*&---------------------------------------------------------------------*
*       Set colour of individual ALV cell, field
*----------------------------------------------------------------------*
FORM SET_CELL_COLOURS .
  DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.
  DATA: ld_index TYPE SY-TABIX.

  LOOP AT IT_EKKO into wa_ekko.
    LD_INDEX = SY-TABIX.

*   Set colour of EBELN field to various colors based on sy-tabix value
    WA_CELLCOLOR-FNAME = 'EBELN'.
    WA_CELLCOLOR-COLOR-COL = sy-tabix.  "color code 1-7, if outside rage defaults to 7
    WA_CELLCOLOR-COLOR-INT = '1'.  "1 = Intensified on, 0 = Intensified off
    WA_CELLCOLOR-COLOR-INV = '0'.  "1 = text colour, 0 = background colour
    APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
    MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.

*   Set colour of NETPR field to color 4 if gt 0
    if wa_ekko-netpr gt 0.
      WA_CELLCOLOR-FNAME = 'NETPR'.
      WA_CELLCOLOR-COLOR-COL = 4.  "color code 1-7, if outside rage defaults to 7
      WA_CELLCOLOR-COLOR-INT = '0'.  "1 = Intensified on, 0 = Intensified off
      WA_CELLCOLOR-COLOR-INV = '0'.  "1 = text colour, 0 = background colour
      APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
      MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.
    endif.

*   Set colour of AEDAT field text to red(6)
    WA_CELLCOLOR-FNAME = 'AEDAT'.
    WA_CELLCOLOR-COLOR-COL = 6.  "color code 1-7, if outside rage defaults to 7
    WA_CELLCOLOR-COLOR-INT = '0'.  "1 = Intensified on, 0 = Intensified off
    WA_CELLCOLOR-COLOR-INV = '1'.  "1 = text colour, 0 = background colour
    APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
    MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.
  ENDLOOP.

ENDFORM.                    " SET_CELL_COLOURS

Sunday, 28 December 2014

Reports

How can we display multiple alv's without using containers?


You can use blocked alv to achieve this.
  CALL FUNCTION REUSE_ALV_BLOCK_LIST_INIT
    EXPORTING
      i_callback_program = l_repid.
*Adding First Block to the List
  CALL FUNCTION REUSE_ALV_BLOCK_LIST_APPEND
    EXPORTING
      is_layout                  = w_layo
      it_fieldcat                = it_fcat
      i_tabname                  = text-064
      it_events                  = it_events
      it_sort                    = it_sort
    TABLES
      t_outtab                   = it_mainalv
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 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.
  CALL FUNCTION REUSE_ALV_BLOCK_LIST_APPEND
    EXPORTING
      is_layout                  = w_layo
      it_fieldcat                = it_fcat1
      i_tabname                  = text-094
      it_events                  = it_events1
      it_sort                    = it_sort1
    TABLES
      t_outtab                   = it_field_change
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 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.
  • Displaying the list
  CALL FUNCTION REUSE_ALV_BLOCK_LIST_DISPLAY
    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


How many blocks can create in a ALV BLOCK LIST in ABAP

Yes u can append max 19 block:
The fm REUSE_ALV_BLOCK_LIST_APPEND has the exception MAXIMUM_OF_APPENDS_REACHED, it will be triggered as soon as the max (19) will be reached

 How to set a button in ALV grid


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM       = V_REPID
            I_CALLBACK_PF_STATUS_SET = 'F_SET_PF_STATUS' <--FORM NAME we have to give here
            I_CALLBACK_USER_COMMAND  = C_USER_COMMAND
            IS_LAYOUT                = WA_LAYOUT
            IT_FIELDCAT              = IT_FIELDCAT[]
            IT_EXCLUDING             = IT_EXTAB[]
            IT_SORT                  = IT_SORT[]
       TABLES
            T_OUTTAB           = IT_ZBCAR50[]
       EXCEPTIONS
            PROGRAM_ERROR      = 1
            OTHERS             = 2.
*&---------------------------------------------------------------------*
*&      Form  F_SET_PF_STATUS
*&---------------------------------------------------------------------*
*       Set PF_STATUS STANDARD modifying the standard toolbar
*       by excluding some buttons
*----------------------------------------------------------------------*
*      -->P_IT_EXTAB  -- TABLE OF EXCLUDING FUNCTIONS
*----------------------------------------------------------------------*
FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

  CLEAR : WA_EXTAB,
          IT_EXTAB.

*--Set the Modified PF status for the ALV.
  SET PF-STATUS 'STATUS_01' EXCLUDING RT_EXTAB.

ENDFORM.                               " SET_PF_STATUS 
 
Suppose in an ALV report in grid we have to disply matnr, ernam,ebeln,ebelp etc. 
But when we bring the cursor on that specified field, it will show "material number" for matnr, 
"purchase Document Number" for ebeln etc. how do you achieve this? 
By Using Fieldcat-Seltext_m 

Wednesday, 24 December 2014

Delivery Class

You use the delivery class to control the transport of table data for an installation, upgrade, or client copy and transports between customer systems. The delivery class is also used in the extended table maintenance.

Features

There are the following development classes:
  A- Application table (master and transaction data).
  C- Customer table, data is only maintained by the customer.
  L- Table for storing temporary data.
  G- Customer table, SAP can insert new data records but cannot overwrite or delete existing ones. The customer namespace must be defined in table TRESC. To define the customer namespace use report RDDKOR54. You can start it directly from the table maintenance by choosing Maintain Customer Namespace on the Delivery and Maintenance tab.
  E- System table with its own namespace for customer entries. The customer namespace must be defined in table TRESC. To define the customer namespace use report RDDKOR54. You can start it directly from the table maintenance by choosing Maintain Customer Namespace on the Delivery and Maintenance tab.
  S- System table, data changes have the status of program changes.
  W- System table (for example table of the development environment) whose data is transported with its own transport objects (such as R3TR PROG, R3TR TABL and so on).

Behavior During Client Copy

Only the data of client-dependent tables is copied.
  Class C, G, E, S- The data records of the table are copied to the target client.
  Class W, L- The data records of the table are not copied to the target client.
  Class A- Data records are only copied to the target client if explicitly requested (parameter option). It is not sensible to transport such data, but this is supported nevertheless to allow the entire client environment to be copied.

Behavior During Installation, Upgrade and Language Import

The behavior of client-dependent tables differs from that of cross-client tables.
Client-Dependent Tables
  Class A and C- Data is only imported into client 000. The system overwrites the existing data records.
  Class E, S and W- Data is imported into all clients. The system overwrites the existing data records.
  Class G- The system overwrites the existing data records in client 000. In all other clients, the system inserts new data records, but existing data records are not overwritten.
  Class L- No data is imported.
Cross-Client Tables
  Classes A, L and C- No data is imported.
  Classes E, S, and W- Data is imported. The system overwrites the existing data records with the same key.
  Class G- The system inserts non-existent data records, but does not overwrite existing data records.

Behavior During Transport Between Customer Systems

Data records of tables having delivery class L are not imported into the target system. Data records of tables having delivery classes A, C, E, G, S and W are imported into the target system (for client-dependent tables this is done for the target clients specified in the transport).

Use of the Delivery Class in the Extended Table Maintenance

The delivery class is also used in the Extended Table Maintenance (transaction code SM30). The maintenance interface generated for a table performs the following checks:
  It is not possible to transport the entered data using the transport connection of the generated maintenance interface for tables having delivery classes W and L.
  Data that is entered is checked to see if it violates the namespace defined in table TRESC. If the data violates the namespace, the system rejects the input.

How to create table maintenance generator?

Go to Se11, give the table name and click on change. Then Go to utilities--> Table maintenance generator.
In the table maintenance generator screen, we should give Authorization Group, Function Group name (Function Group name can be same as table name), Maintenance type can be one step or two step, usually we will create with one step. we should give maintenance screen number.
Authorization Group  used to group the logically related objects. It helps us to group dictionary tables for the purpose of authorization checking (Table TDDAT contains its list) . To create go to SE54, give the table name and choose authorization group and then click on create/change.
Function Group name is the name of the group to which the generated maintainence would belong.
Package if you want to assign it to a particular package.
After clicking on create button, a table maintenance generator will be created.
To check it go to SM30 . In SM30, we find display, Maintain options.
We can view the table contents by choosing Display and we can create table entries by choosing Maintain.

Single step and Two step in TMG

You can select either one step or two step. Assign Screen numbers (To assign Screen numbers click on the button 'Find Scr no'. It will propose screen no's)

Then Create. Save 

Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records. 
Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.

Tuesday, 23 December 2014

Extended Table Maintenance Events

Events allow you to change the generated table maintenance dialog at predefined positions, which cannot be reached by user modules in the screen flow logic.

The user routines are called dynamically at runtime. For this reason, the routines must be in a user include in the table/view maintenance dialog function group. All extended table maintenance global data is available. An interface is only required for events 22 and AF.
The events can be additions or replacements.
 

Additional events

Event 01 before saving the data in the database

Event 02 after saving the data in the database

Event 03 before deleting data in the display

Event 04 after deleting data in the display

Event 05 when inserting a new entry

Event 06 after completely performing the function 'Get original'

Event 07 before correcting the contents of a selected field

Event 08 after correcting the contents of a selected field

Event 09 after 'Get original' for one entry

Event 10 after creating the change request header entry  

Event 11 after changing a key entry in the change request  

Event 12 after changing the key entries in the change request

Event 13 end processing (leave main function module)

Event 14 after lock/unlock in main function module  

Event 15 before retrieving deleted entries  

Event 16 after retrieving deleted entries

Event 17 before printing entries  

Event 18 after the data change check  

Event 19 after initializing global variables, field symbols, etc.

Event 20 after input in date subscreen (time-dep.tables/views)

sapurl_link_0001_0020_0034

 Event 21 fill hidden fields  

Event 22 go to long text maintenance for other languages  

Event 23 before calling address maintenance screen

Event 25 at start of maintenance dialog

Event 26 before displayed data is output in a list  

Event 27 after filling a GUID field


Replacement events

Event AA instead of the standard data read routine

 Event AB instead of the standard database change routine

Event AC instead of the standard 'Get original' routine  

Event AD instead of the standard RO field read routine  

Event AE instead of the standard positioning code  

Event AF instead of reading texts in other languages

Event AG instead of 'Get original' for texts in other languages

Event AH instead of database changes for texts in other languages  

Event ST GUI menu main program name



Create table event

Validation on table maintenance

While creating the tables, sometimes we may need to update the table fields in the background. For example, if we create a table with 10 fields and in those 10 fields there are 2 fields which are User name and the Date, these 2 fields should update automatically when a record Inserted/Updated in the table. It also can be used when we want provide various validations on creating, changing or saving entries in a table.

Event Handling

When we provide event handling on table maintenance, table fields will be updated automatically when a new record inserted into the table or an existed record changes through the table maintenance generator.
To achieve the event handling in table maintenance, we need to create a table maintenance generator and then create events. Process is as follows:

Create a table ZTAB with the following fields:



Create a table maintenance generator for the table:

To create table maintenance generator go Utilities -> Table Maintenance Generator and provide following information:
Authorization Group: &NC&
Function group: Any suitable FC Eg: ZBC420XX
Maintenance type: Two Step
Maint. screen no: Overview screen 8005
                             Single screen    8006
Click on Create.

Create Events for table Maintenance:

To create events on table maintenance go to Environment -> Modification -> Events -> New Entries


List of events available:

Choose maintenance event 05-Creating New Entry and provide a name of the event (This will become perform/subroutine).
Click on Editor Button to provide event handling code.

A popup will be appear, It will ask to create an include program, in which we'll write the event handling code.
Click on continue.


Write the following code in include for this event.
FORM new_entry.
  DATA: v_nchar TYPE i.
  CONSTANTS: c_conlimit TYPE i VALUE 3.
  ztab-changed_by = sy-uname.         " current user
  ztab-create_date = sy-datum.        " current date
  ztab-create_time = sy-uzeit.        " current time
* Validation on Country Field
  v_nchar = STRLEN( ztab-country ).
  IF v_nchar NE c_conlimit.
    MESSAGE i536.
  ENDIF.
ENDFORM.                    "New_Entry

Create Transaction Code:

Create a transaction code to run the table maintenance generator.
Go to Tcode SE93
Transaction code: ZTAB
Short text: Test Table Maintenance Events
Start Object: Transaction with parameters (Parameter Transaction)

Transaction: SM30
Skip first Screen: Check ON
Default Values:
View Name      ZTAB
Update           X


Execute the transaction code:

Execute the transaction code ZTAB and click on New Entries button.


Now provide a valid value in country field and remain blank another fields.

Click Enter (NEW_ENTRY event will trigger) and current User, date and time will be automatically filled in respective fields.

Save the entry and check in table.

One more entry by table maintenance:
Write country code as US in place of USA and press Enter
Information message shown that entry was not saved.

Now provide USA as country code and save entry.

Monday, 22 December 2014

current execution is a batch job (background) or a dialog job(foreground)

SY-BATCH indicates if the current execution is a batch job (background) or a dialog job(foreground). If sy-batch is 'X', then the execution is in the background.

Suppose if you want to write logic for 2 diff. situations.

1. when program runs in foreground output shold be in excel

2.  when program runs in background output shold store in application server as a file.

To determine whether program is running forground or background we will can
use  SY-BATCH

IF SY-BATCH =  'X'.

  Background.

ELSE.

FOREground
ENDIF.

Different behviour in background processing from foreground processing

BDC for table control is totally depending upon the screen resolution.

if you try it on background it will show different behavior than foreground. It will also behave differently for different PC .

So my suggestion is go for BAPI.   

Many SAP transactions behave differently in online mode and in Batch mode and this mode is determined by the SY-BINPT variable that can be controlled using the OPTIONS command in addition to the CALL TRANSACTION.
 For example, the error message that usually comes in status bar while you are running the transaction online might appear in a popup window when you are running that in batch. This will make your fields disabled for input. This OPTIONS addition will remove this problem
The way to use the OPTIONS addition.
Declare a work area of type CTU_PARAMS
Fill the fields of CTU_PARAMS The field NOBINPT should be set to ‘X’.
This will set the SY-BINPT to space. So now the transaction which you will be calling will run in online mode.
Example.
clear X_OPTIONS.
X_OPTIONS-DISMODE = 'E'.
X_OPTIONS-UPDMODE = 'S'.
X_OPTIONS-CATTMODE = ' '.
X_OPTIONS-DEFSIZE = ' '.
X_OPTIONS-RACOMMIT = ' '.
X_OPTIONS-NOBINPT = 'X'.
X_OPTIONS-NOBIEND = ' '.
call transaction 'BP' using T_BDCDATA[] options from X_OPTIONS.
Note:
Do not use the MODE & UPDATE additions when you are using OPTIONS. The mode & update values are passed in the CTU_PARAMS structure.

Display two or more ALVs on one screen using Splitter Control

 

Output:-
Code:-

DATA: CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
      GRAPHIC_PARENT1 TYPE REF TO CL_GUI_CONTAINER,
      GRAPHIC_PARENT2 TYPE REF TO CL_GUI_CONTAINER.
DATA REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA REF_GRID1 TYPE REF TO CL_GUI_ALV_GRID.
**   create container in which to place splitter
**   (place it in the custom control named CONTAINER
**   defined using screenpainter in dynpro 100)
CREATE OBJECT CUSTOM_CONTAINER
EXPORTING
 CONTAINER_NAME = 'CONTAINER'. "use uppercase letters!
*
**   create splitter container in which to place graphics
CREATE OBJECT SPLITTER
 EXPORTING
   PARENT  = CUSTOM_CONTAINER
    ROWS    = 2
   COLUMNS = 1
   ALIGN   = 15. " (splitter fills the hole custom container)
**   get part of splitter container for 1st table
CALL METHOD SPLITTER->GET_CONTAINER
  EXPORTING
    ROW       = 1
    COLUMN    = 1
  RECEIVING
    CONTAINER = GRAPHIC_PARENT1.
**   get part of splitter container for 2nd table
CALL METHOD SPLITTER->GET_CONTAINER
  EXPORTING
    ROW       = 2
    COLUMN    = 1
  RECEIVING
    CONTAINER = GRAPHIC_PARENT2.
CREATE OBJECT  REF_GRID EXPORTING I_PARENT = GRAPHIC_PARENT1.
**  Display first ALV
PERFORM SET_DISPLAY.
CREATE OBJECT  REF_GRID1 EXPORTING I_PARENT = GRAPHIC_PARENT2.
**  Display second ALV
PERFORM SET_DISPLAY1.
*&amp;--------------------------------------------------------------------*
*&amp;      Form  set_display
*&amp;--------------------------------------------------------------------*
*       text  Display first ALV
*---------------------------------------------------------------------*
FORM SET_DISPLAY.
  CALL METHOD REF_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      IS_VARIANT      = ST_VAR
      I_SAVE          = SAVE
      IS_LAYOUT       = LOYO
    CHANGING
      IT_OUTTAB       = ITAB_FINAL[]
      IT_FIELDCATALOG = FCAT.
ENDFORM.                    "set_display
*&--------------------------------------------------------------------*
*&      Form  set_display1
*&--------------------------------------------------------------------*
*       text Display second ALV
*---------------------------------------------------------------------*
FORM SET_DISPLAY1.
  CALL METHOD REF_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      IS_VARIANT      = ST_VAR
      I_SAVE          = SAVE
      IS_LAYOUT       = LOYO1
    CHANGING
      IT_OUTTAB       = ITAB_FINAL1[]
      IT_FIELDCATALOG = FCAT1.
ENDFORM.                    "set_display1

VERSION MANAGEMENT IN SMARTFORMS




The purpose of this document is to compare the versions of smart forms in different servers. This document is highly beneficial for Developers in ABAP which explains a step by step procedure to compare the versions of the forms.

INTRODUCTION:

Smartform has only one active version, in the form of function module which is regenerated once you change and activate it. Since smartform is client Independent, it can be easily transported to other systems. There may be cases where we would require to compare the versions of the forms across different systems. Though it is not possible to compare the forms directly, it can be achieved to some extent by comparing the generated Function modules line by line, thereby capturing the changes. This can be done via the Transaction SE39-Split Screen editor.
Note that the generated Function Module names will not be same across all systems.

PROCEDURE:
Once the smartform is created and activated, a Function Module gets generated.
P1.png

To open the Function Module in display mode, either execute the Smartform or go via Transaction SE37 by fetching the FM name from Environment menu.FM will be opened in display mode as follows.
P2.png
Select the Attributes tab and double click on the program name.
P3.png
The following screen appears with the list of file names. Select the required Include name under User defined Files.
p4.png

Similarly, the include name is fetched from the other server that needs to be compared.
Now, go to transaction code SE39.The following screen appears.
p6.png
Click on the option ‘Compare different Systems’.
Enter appropriate include names and details of the systems that needs to be compared.
p7.png
Enter the logon details of the system to be compared.
Comparison screen appears. Click on the ‘Comparison On’ button to initiate the process.
p10.png
Select ‘Next Difference from cursor ‘, Next Identical section from cursor’ options to analyze the variations and the same procedure is carried out till the end.           
There is no option to compare the forms directly. But, the entire list of requests available for a smartform can be obtained from which the number of changes done can be captured.
Go to transaction SE03. Select the option ‘Objects in Requests’.  Double click on Search for objects in Requests/Task.
p11.png

The screen appears as below. In the Object Selection type, enter the Object type as ‘SSFO’ and give the smartform name and then Execute.
p12.png
List of all the Requests related to that smartform are displayed from which the changes can be traced.

You can also check this link http://www.geekface.in/2012/10/version-management-and-comparison-for.html