Thursday, April 7, 2016

Editable ALV Report



We can edit an ALV report on the screen and then we can download it as per requirement. Here we are discussing about two ways to edit an ALV report.
1.       The first way is to use the field catalog manually and there we can active the EDIT field of field catalog. In this way we can manually select the fields which need to be edited. The statement is as follows.

    lv_col            = 1 + lv_col.
    wa_fcat-col_pos   = lv_col.
    wa_fcat-fieldname = 'CURRCODE'.
    wa_fcat-tabname   = 'IT_SCARR'.
    wa_fcat-edit      = 'X'.               "Editable field
    wa_fcat-seltext_l = 'Local currency of airline'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

2.       Second way is to active the EDIT field of layout. This way gets the whole report editable. We can edit each and every field. Statement is as follows.

  wa_layout-colwidth_optimize = 'X'.
  wa_layout-edit = 'X'. "This activation will let all fields editable


In the following example we have demonstrated the first approach where we are manually using the editable fields by field catalog.

REPORT  zsr_test1 NO STANDARD PAGE HEADING.

TABLES scarr.
TYPE-POOLS slis.

DATA: wa_title TYPE lvc_title VALUE 'Editable ALV Report',
      "This will show the report title

      it_scarr TYPE TABLE OF scarr,

      wa_fcat  TYPE slis_fieldcat_alv,
      it_fcat  TYPE slis_t_fieldcat_alv,

      wa_layout TYPE slis_layout_alv,

      wa_top    TYPE slis_listheader,
      it_top    TYPE slis_t_listheader.

INITIALIZATION.
  SELECT-OPTIONS s_carrid FOR scarr-carrid.

START-OF-SELECTION.
  PERFORM get_flight.      "Get data from database table
  PERFORM field_catalog.   "Creating the field catalog manually
  PERFORM layout.          "Creating the layout
  PERFORM alv_grid_display."ALV grid output

TOP-OF-PAGE.
  PERFORM top_of_page.       "Top of page of editable ALV

*&---------------------------------------------------------------------*
*&      Form  get_flight
*&---------------------------------------------------------------------*
*       Get data from database table
*----------------------------------------------------------------------*
FORM get_flight .

  IF s_carrid[] IS NOT INITIAL.
    SELECT * FROM scarr INTO TABLE it_scarr
      WHERE carrid IN s_carrid.

    IF sy-subrc = 0.
      SORT it_scarr.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_flight
*&---------------------------------------------------------------------*
*&      Form  field_catalog
*&---------------------------------------------------------------------*
*       Creating the field catalog manually
*----------------------------------------------------------------------*
FORM field_catalog .

  DATA lv_col TYPE i VALUE 0.

  IF it_scarr IS NOT INITIAL.
    lv_col            = 1 + lv_col.
    wa_fcat-col_pos   = lv_col.
    wa_fcat-fieldname = 'CARRID'.
    wa_fcat-tabname   = 'IT_SCARR'.
    wa_fcat-seltext_l = 'Airline Code'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_col            = 1 + lv_col.
    wa_fcat-col_pos   = lv_col.
    wa_fcat-fieldname = 'CARRNAME'.
    wa_fcat-tabname   = 'IT_SCARR'.
    wa_fcat-seltext_l = 'Airline Name'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_col            = 1 + lv_col.
    wa_fcat-col_pos   = lv_col.
    wa_fcat-fieldname = 'CURRCODE'.
    wa_fcat-tabname   = 'IT_SCARR'.
    wa_fcat-edit      = 'X'.               "Editable field
    wa_fcat-seltext_l = 'Local currency of airline'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_col            = 1 + lv_col.
    wa_fcat-col_pos   = lv_col.
    wa_fcat-fieldname = 'URL'.
    wa_fcat-tabname   = 'IT_SCARR'.
    wa_fcat-edit      = 'X'.               "Editable field
    wa_fcat-seltext_l = 'Airline URL'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.
  ENDIF.

ENDFORM.                    " field_catalog
*&---------------------------------------------------------------------*
*&      Form  layout
*&---------------------------------------------------------------------*
*       Creating the layout
*----------------------------------------------------------------------*
FORM layout .

  wa_layout-colwidth_optimize = 'X'.
  wa_layout-zebra = 'X'.

ENDFORM.                    " layout
*&---------------------------------------------------------------------*
*&      Form  alv_grid_display
*&---------------------------------------------------------------------*
*       ALV grid output
*----------------------------------------------------------------------*
FORM alv_grid_display .

  IF it_fcat IS NOT INITIAL.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program     = sy-repid
        i_callback_top_of_page = 'TOP_OF_PAGE'
        i_grid_title           = wa_title
        is_layout              = wa_layout
        it_fieldcat            = it_fcat
      TABLES
        t_outtab               = it_scarr
      EXCEPTIONS
        program_error          = 1
        OTHERS                 = 2.
  ENDIF.

ENDFORM.                    " alv_grid_display

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       Top of page of editable ALV
*----------------------------------------------------------------------*
FORM top_of_page.

  DATA date TYPE char10.

  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
    EXPORTING
      date_internal            = sy-datum
    IMPORTING
      date_external            = date
    EXCEPTIONS
      date_internal_is_invalid = 1
      OTHERS                   = 2.

  REFRESH it_top.

  wa_top-typ = 'H'.
  wa_top-info = 'Airline Information'.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  wa_top-typ = 'S'.
  wa_top-info = 'Date: '.
  CONCATENATE wa_top-info date INTO wa_top-info.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_top.

ENDFORM.                    "top_of_page

The output is as follows.


The basic output.


Now we can edit those two fields as per requirement.


Now we are using the second approach where we need to activate the EDIT field of layout. With this approach the whole report will be editable.

REPORT  zsr_test1 NO STANDARD PAGE HEADING.

TABLES scarr.
TYPE-POOLS slis.

DATA: wa_title TYPE lvc_title VALUE 'Editable ALV Report',
      "This will show the report title

      it_scarr TYPE TABLE OF scarr, 

      it_fcat  TYPE slis_t_fieldcat_alv,

      wa_layout TYPE slis_layout_alv,

      wa_top    TYPE slis_listheader,
      it_top    TYPE slis_t_listheader.

INITIALIZATION.
  SELECT-OPTIONS s_carrid FOR scarr-carrid.

START-OF-SELECTION.
  PERFORM get_flight.      "Get data from database table
  PERFORM field_catalog.   "Creating the field catalog
  PERFORM layout.          "Creating the layout
  PERFORM alv_grid_display."ALV grid output

TOP-OF-PAGE.
  PERFORM top_of_page.       "Top of page of editable ALV
*&---------------------------------------------------------------------*
*&      Form  get_flight
*&---------------------------------------------------------------------*
*       Get data from database table
*----------------------------------------------------------------------*
FORM get_flight .

  IF s_carrid[] IS NOT INITIAL.
    SELECT * FROM scarr INTO TABLE it_scarr
      WHERE carrid IN s_carrid.

    IF sy-subrc = 0.
      SORT it_scarr.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_flight
*&---------------------------------------------------------------------*
*&      Form  field_catalog
*&---------------------------------------------------------------------*
*       Creating the field catalog
*----------------------------------------------------------------------*
FORM field_catalog .

  IF it_scarr IS NOT INITIAL.

    "Since the whole structure is involved, we use field catalog merge
    "to create the field catalog

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        i_program_name         = sy-repid
        i_internal_tabname     = 'IT_SCARR'
        i_structure_name       = 'SCARR'
      CHANGING
        ct_fieldcat            = it_fcat
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        OTHERS                 = 3.

    IF sy-subrc <> 0.
      MESSAGE 'Internal error of field catalog merge' TYPE 'I'.
    ENDIF.
  ENDIF.

ENDFORM.                    " field_catalog
*&---------------------------------------------------------------------*
*&      Form  layout
*&---------------------------------------------------------------------*
*       Creating the layout
*----------------------------------------------------------------------*
FORM layout .

  wa_layout-colwidth_optimize = 'X'.
  wa_layout-edit = 'X'. "This activation will let all fields editable

ENDFORM.                    " layout
*&---------------------------------------------------------------------*
*&      Form  alv_grid_display
*&---------------------------------------------------------------------*
*       ALV grid output
*----------------------------------------------------------------------*
FORM alv_grid_display .

  IF it_fcat IS NOT INITIAL.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program     = sy-repid
        i_callback_top_of_page = 'TOP_OF_PAGE'
        i_grid_title           = wa_title
        is_layout              = wa_layout
        it_fieldcat            = it_fcat
      TABLES
        t_outtab               = it_scarr
      EXCEPTIONS
        program_error          = 1
        OTHERS                 = 2.
  ENDIF.

ENDFORM.                    " alv_grid_display

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       Top of page of editable ALV
*----------------------------------------------------------------------*
FORM top_of_page.

  DATA date TYPE char10.

  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
    EXPORTING
      date_internal            = sy-datum
    IMPORTING
      date_external            = date
    EXCEPTIONS
      date_internal_is_invalid = 1
      OTHERS                   = 2.

  REFRESH it_top.

  wa_top-typ = 'H'.
  wa_top-info = 'Airline Information'.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  wa_top-typ = 'S'.
  wa_top-info = 'Date: '.
  CONCATENATE wa_top-info date INTO wa_top-info.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_top.

ENDFORM.                    "top_of_page

Below is the output where we can see every field is available to edit.


We have edited one as per requirement.

19 comments:

bappa kundu said...

Sir i am learning abap from your blog.Now I am being totally dependent on your valuable tutorial.please if you can provide some tutorial on smartforms.
Above-all if you can please provide your email id or mob no.

bappa kundu said...

my email id bappakunduhere@gmail.com

Anu Reddy said...

your providing such a valuabe information about SAP ABAP ..and also have some good key points to every student.
SAPUI5 Online Training

suri amburi said...

Its very useful blog for all the ABAPes. Very valuable information.

Rahul said...

Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog on SAP SD.
SAP SD

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...


Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

sushma said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Unknown said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

sanayamohit said...

Best SAP Success Factor Training in Chennai

http://thecreatingexperts.com/sap-training-in-chennai/
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/

simashree said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Priyasekar said...

Thanks for your info...Here THE CREATING EXPERTS provide hands on training with real time scenarios

http://thecreatingexperts.com/sap-abap-training-in-chennai/

contact +91-08122241286

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

Anonymous said...

hii sir,
its not updating in the database table. plz help.

Unknown said...

hi
plz teach me how to read fs and convert fs to coding

Anonymous said...

hi, can u teach me how to make alv report editable with save functionality.\

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD

Unknown said...

Great information. the information provided is of great

use as i got to learn new things. If you are looking for

real time training by industry experts with live projects

and placement support.kindly contact the creating experts

Reach our Technical Experts @ 8122241286 / 9003085882