ALV with an Editable Row

Edit ALV Row in SAP Report
Share on Facebook7Share on LinkedIn25Tweet about this on TwitterShare on Google+0
Please Share!!

Introduction

Almost all of us are quite aware of ALVs with an editable column. If asked about an editable row, we might see perplexed faces. Although the concept has been discussed in different forums many times before, no entire code was found to implement that on the go. The following discussion will explain in and out of creating an ALV with editable rows. Also, find the entire working code at the end which can be downloaded and re-used.

Requirement

Let’s assume the requirement is to display purchase orders given as an input in the selection screen. Purchase orders will be displayed with all item numbers and material numbers. In our output screen, we want Purchase Order Number, Plant, Storage, Company Code, Document Type, Item No and Material. Additionally, we should have a hotspot enable field on Purchase order number upon clicking on which system should navigate to the ME21N screen. When clicked on back from ‘ME21N’ transaction all the rows of that particular purchase order should become editable.

Program Construct

  1. Types and Structure Declarations
  2. Work Areas and Internal Tables
  3. Declare Local Class For Event Handling
  4. Class Implementation
  5. Selection Screen Design
  6. Start Of Selection
  7. Call Screen
  8. PBO
  9. Module DISPLAY_ALV
  10. PAI

Did you know? You can check the consistency of an ALV report by pressing the SHIFT + Right Double Click.

1. Types and Structure Declarations

OOPS ALV Reports in ABAP

Note – Apart from the required types, in our final types structure we used ‘fstyl’ of type lvc_t_styl to control the editable settings. This plays the actual role to make the final ALV output table rows editable or display only.

2. Work Areas and Internal Tables OOPs ReportNote– LS_STYLEROW and LT_STYLEROW are used for holding the style information we will create later in this article.

3. Declare Local Class for Event Handling

Hot Spot in ALV

For hotspot event, we have created this class-method.

4. Class Implementation

ALV Report to make Row Editable

This section will handle the major tasks required in our program. First of all, we need to have the hotspot navigation functionality. This has been achieved with ‘Call Transaction’ statement after reading the row_id and corresponding PO number for that. Also note, for that particular PO number, we have collected all the line items into the GT_FINAL table which we will make editable.

Now we should take care of the row editing logic.

SAP ALV report

Make note of the use of this section (cl_gui_alv_grid=>mc_style_enabled). This actually makes a particular field of your ALV editable. For this requirement, I used all the fields. Alternatively, if you have a requirement to make 2 fields of a particular row editable you can simply pass only those two field names and you will find those editable.

Not only you have to make fields editable but also have to take care of making those disabled if the editing condition is not met.

Editable Field in ALV

Now you should be good with the editable row functionality. Let’s move on to the basic body of our program.

Also Read: Alternative to ‘REUSE_ALV_GRID_DISPLAY’.

5. Selection Screen Design

6. Start Of Selection

Create a subroutine for fetching the basic data for grid display. The flow logic for the custom screen created will look like below.

custom screen in SAP

6.a. Refer the full code.

6.b. Refer the full code.

6.c. Module Display_ALV

This section contains logic to identify whether the program has been executed in foreground/background. Depending on that, it uses a particular class reference. Remember, if you have created an object of a custom container (i.e. if you have used CL_GUI_CUSTOM_CONTAINER), background execution of the report will fail and job status will be cancelled. Always use docking container reference in such cases. We use CL_GUI_ALV_GRID_OFFLINE to identify whether the program is executed on foreground/background.

Docking Container

6.d. Refer the full code.

Let’s see how correctly it was designed.

Selection Screen

SAP OOPs Report

List Screen

Click on any Purchasing Document no in list screen and navigate back to the report. You should be able to see all associated lines of the purchasing document editable.

Tried with other PO number and it worked seamlessly!

Why ALV Report is dumping in Background

Execute the program in background

Background Job Status should be “Finished”

You might also like: Just 4 Versions of the same program to understand OOPs ABAP.

Further Reading

For similar functionality and better understanding refer BCALV_EDIT_02 program.

Please download the entire code from Here.

Updated: 31st July 2017

Additional Reading

The user will obviously want some editing operation with change-save functionality. Once the rows are in the editable mode, the user will change some data and hit save button. This will eventually trigger the PAI section of the custom screen and to handle the save we need to use ‘SPOS’ function-code. Changes can be saved to respective standard tables/custom tables(depending on the requirement). To make our article simple I did not introduce any such save operation but displayed the changed data in another ALV format using the factory method.

Code for the PAI section is attached below.

The final output after incorporating this operation will look something like below.

The user will edit something in the ALV output (I have changed the ‘Material’ as WL-test and DG-test).

After change hit the ‘SAVE’ button and see the changed tuples in final ALV.

So…What Do You Think?

Now we want to hear from you.

What do you think of this method? Do you have a better approach?

Whether you have had the requirement to make some ALV fields editable or not, in either case, please leave a quick comment below.

 

Share on Facebook7Share on LinkedIn25Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

Saswata
I hold a Bachelor's Degree in Information Technology and into SAP technical consulting for approximately 4 years. I have worked with overseas clients for domains like Pharmaceuticals and Forestry Equipment Manufacturers etc. I am presently a consultant in an MNC located in Pune, India. Apart from being a voracious technology learner I spend quality time in reading books, sketching, watching movies and listening music. Find more about him on LinkedIn.

Be the first to comment on "ALV with an Editable Row"

Leave a comment

Your email address will not be published.


*