You are on page 1of 4

Dynamic Changes on ALV on pressing a custom Button on ALV (OOPS

ALV)
Submitted By: Sohit Manik
Requirement:

So here in this document we are going to discuss one of the requirements where I need to Modify the
ALV output columns Dynamically based on User action on some custom button on ALV output. Basically,
the overall requirement is:

1) To add a Checkbox column in the Final Internal table with Name Shipping Status.
2) To add the Shipment Number column in the Final Internal table.
3) To add two Custom Buttons in the ALV button with Name “Change SO Qty” & “Save Changes”.
4) Now when the user executes the report, all the checkboxes for Column ‘Shipping status’ should
be disabled (Not Available for Edit) by default. And when the user clicks on Button ‘Change SO
Qty’ then based on some conditions, few checkboxes of Shipping Status which met the
validations conditions should be Enabled for User input and respective Sales Order Quantity
(KWMENG) field should also becomes editable. So basically, after user clicks on “Change SO Qty”
all the Shipping Status Checkboxes & Sales order Qty columns which met the Validation
conditions should be enabled or editable for User Action.

Solution:

To make a column editable, it will be enough to set the field “EDIT” in the field catalog. The ALV Grid
perceives if there are some editable fields and show that field Editable in the Final output however our
requirement is different. We want only two columns to become editable that too after pressing a
Custom Button in ALV.

To Achieve this Dynamic Editable & Disabled Columns functionality, below are the steps that needs to be
followed:

1) First, for any dynamic changes to any columns or specific fields in the ALV we need to add one
extra field to our Final Internal Table with type “LVC_T_STYL”.
2) We have 2 standard methods in SAP to enable or disable the Columns based on the user
command or based on any specific conditions. Those 2 methods are:

“CL_GUI_ALV_GRID=>MC_STYLE_ENABLED” to make a field editable


“CL_GUI_ALV_GRID=>MC_STYLE_DISABLED”” to make a field non-editable.

Let’s go with requirement solution step by step:

1) For 1st requirement that is to add a checkbox in the Final Internal Table, I have added a new
field in the Final Internal Table Structure in SE11 with type XFELD ( i.e. Checkbox):
Now we need to specify in the field catalogue that the above field is going to appear as
Checkbox in the Output. Without specifying this in the field Catalogue, we won’t be getting a
proper checkbox look in the final output.

So out first requirement is done now i.e. to add a checkbox field in the Final Output Table.

2) For the 2nd requirement i.e. to add the Shipping Number in the Final Output Table. Here, we
just need to add the Shipment Number from VBFA table by passing the Delivery Number to
VBFA table. So, this requirement is easy.
3) Let’s go to the main requirement now which is to enable and disable the Shipping Status
Checkbox & Sales Order Quantity based on User action on Custom Button on ALV.

Since we are using the OOPS ALV & OOPS approach in our case, so we need to register the User
command Code under REGISTER_EVENTS METHOD of our Custom class.

So now we are going to write our Button Code inside the above highlighted HANDLE_USER_COMMAND
Method.

Let’s add a Field TSTYLE of TYPE LVC_T_STYL in our final Internal table:
Now will go to the User Command Method to write our code to make the Shipment Status Checkbox &
SO Qty enable or disable.

First, loop the Final Internal Table and set value of TSYLE against each of the rows in the internal table
whether it should be enabled or disable based on the condition.
As per the conditions written at code line 190 that when Shipment Number is Blank And LV_FLAG is not
blank only then make SO Qty (lc_kwmeng) & Shipping Status Checkbox (lc_shpmntstatus) editable else
make it non-editable. So, this is how are setting the Fields Editable or Non-editable dynamically based
on some conditions.

Now we need to pass the Style name to the Layout because that is how the program will identify that a
new layout has been inserted to the Field Catalogue. Since the ALV is displayed already for the first time
when we execute the Program with the Layout so we need to call out Layout again by using
GET_FRONTEND_LAYOUT and then pass Style Name to the Layout and then again set the Layout or
update the layout by using the method SET_FRONTEND_LAYOUT.

The last condition to be met for editability, we must call the method “SET_READY_FOR_INPUT” passing
‘1’ to the parameter “I_READY_FOR_INPUT”.

Using this method, we can switch between editable and non-editable mode. Passing ‘0’ to the
parameter while calling the method, switches to non-editable mode

You might also like