Sunday, February 26, 2017

Reset or clear input Fields in Web Dynpro

I  have created a View with several Input Fields.Now i wanted to give the User the ability to clear his input on click of button for example say RESET button.

(Code wizard icon )
We can simply do this task by using code wizard
.......
Example :
I have a MAIN view with Login and Password I/O fields(LOGIN and PASSWORD fields are attributes of LOGIN Node present in MAIN View) .Now on click of RESET button values present in Login and Password I/O fields need to get clear.
In ON-ACTION method of RESET button do as follows.
Click on Code Wizard Icon. Then you will get one popup screen where you will have options like Read,Set,Append etc..
Select SET Radio Button then Click on Context Button... Select the Context Node LOGIN.
Now Check the functionality.

Note : Clearing the values are nothing but making the values as null(Blank).The importance of SET in the code wizard is , it will set the values for the context node.Here i have selected the LOGIN context node to set the values which is mapped to Login and Password fields.


Tuesday, February 14, 2017

Remove Horizontal and Vertical lines from ALV Grid in SAP ABAP

We can display ALV GRID report either by using FM 'REUSE_ALV_GRID_DISPLAY' or by using 'SET_TABLE_FOR_FIRST_DISPLAY' method. there are few more ways are there to display ALV GRID.
In this post I am considering only 'SET_TABLE_FOR_FIRST_DISPLAY' method to explain how to  Remove Horizontal and Vertical lines from ALV Grid Display.

CALL METHOD obj_grid->set_table_for_first_display
            EXPORTING i_structure_name = 'ZSTRUCTURE'    "Global Struct
                                    is_layout               =  wa_layout             " Layout
            CHANGING
                                  it_outtab       =  itab_output            "Final Internal Table refer to struct
                                  it_fieldcatalog  =   itab_fieldcatalog            "Field catalog 

Note : Errors you may get when you are using above method to display ALV Report
1.Field catalog not found . For Solution Click Here.

By using above piece of code , we can display ALV Grid. If you want to remove Horizontal/Vertical Lines from the Report do make the changes as done below before passing wa_layout to the method.

Layout Settings :
------------------

wa_layout-no_hgridln = 'X'.

wa_layout-no_vgridln  = 'X'.



Changing Column names in ALV GRID REPORT based on user requirement Click Here




Saturday, February 4, 2017

Total and Subtotal in ALV Hierarchical report using SAP ABAP OOPS

Cl_salv_hierseq_table : Basic Class for hierarchical sequential tables.

By Using Cl_salv_hierseq_table class methods we can display hierarchical report.

Procedure :

Cl_salv_hierseq_table contains Factory method(static method). By using this method ,Will get instance for ALV table object.

1 . 
TRY.
cl_salv_hierseq_table=>factory(
Exporting
  t_binding_level1_level2  =  itab_binding.
Importing
 r_hierseq = obj_hierseq
Changing
 t_table_level1  = itab_header[]
 t_table_level2  = itab_item[]
).

Catch .....

Endtry.

Declaration for Factory Method parameters:

DATA : itab_binding  TYPE  salv_t_hierseq_binding,
             wa_binding    TYPE salv_s_hierseq_binding,
             obj_hierseq   TYPE REF TO cl_salv_hierseq_table,
            itab_header  TYPE STANDARD TABLE OF (required database table/user defined structure),
           itab_item  TYPE STANDARD TABLE OF (required database table/user defined structure).

Data Fill :

Fill header and item tables based on your requirement.

wa_binding-master = 'XYZ' .   "  (Field common to header and item table)
wa_binding-slave = 'XYZ' .      " (Field common to header and item table)
Append wa_binding to itab_binding.


2.
PERFORM calculate_sub_total.

3.

obj_hierseq->display( ).


---------------------------------------------------------------------------------------------------------------
*in order to do subtotals.. first we have to perform the sort based on the column on which we are going to
*calculate subtotals

*cl_salv_sorts :  class used for sorting..

Note 1: Sub totals will work on header level fields only

Note 2 : Level 1 : Header , Level 2 : Item 



FORM  calculate_sub_total.

DATA : obj_sorts TYPE REF TO cl_salv_sorts.

CREATE OBJECT obj_sorts
   Exporting
       r_columns         =   obj_columns  "Alv Column  (TYPE REF TO cl_salv_columns)
       r_aggregations  =   obj_sum        "Alv Aggeregation (TYPE REF TO cl_salv_aggregations)
.


"Calculating  Sub Totals 

obj_sorts  =  obj_hierseq->get_sorts( level = 1 ).

CALL METHOD obj_sorts->add_sort
Exporting
Columnname  = 'XYZ'     "Sort column always key field
Position = 1
subtotal  = if_salv_c_bool_sap=>true     "" Subtptal = 'X'
group  =  if_salv_c_sort=>sort_up

Receiving
  Value = obj_sort_column     "Sorted column   (TYPE REF TO cl_salv_sort )
.


CALL METHOD obj_sort_column->set_subtotal   "Setting subtotal for returned column name from add_sort
Exporting
  Value = if_salv_c_bool_sap=>true
.


"Calculating Total

obj_sum  =  obj_hierseq->get_aggregations( level = 2 ).

obj_sum->add_aggregation(
Exporting

columnname  =  'TOTAL'    "Column name present in ITAB  itab_item
aggregation =  if_salv_c_aggregation=>total
Receiving
  Value = obj_total       "Obj contains total   ( TYPE REF TO cl_salv_aggregation )
).


ENDFORM.






Read statement failure in sap abap

Internal Table name : itab_final.

work area   name : wa_final

itab_final having 4 records as follows.

S.NO      UID    UNAME  

1            A1       AUDI

2            B1       BMW

3            R1       RENAULT

4            H1       HONDA

I have one variable CID holding  value R1.


In my program I have a READ statement like

READ TABLE itab_final  INTO wa_final WITH KEY uid = cid BINARY SEARCH.

we have R1 in itab_final but still will  get SY-SUBRC as 8 (READ statement failure) when we execute the above READ statement.


Solution 1 :

READ TABLE itab_final  INTO wa_final WITH KEY uid = cid .

Solution 2:

SORT itab_final by uid.

READ TABLE itab_final  INTO wa_final WITH KEY uid = cid BINARY SEARCH.

Sort the internal table based on the field which is used in READ statement as WITH KEY .


Conclusion : Both Solution 1 and Solution 2 will work fine. But when compare to Solution 1 , Solution 2 is better in performance wise.