Sunday, April 16, 2017

Changing Column Names in ALV Display using SALV model (LIST or GRID display)

Data  : alv_table_obj   TYPE REF TO cl_salv_table,
     obj_columns TYPE REF TO cl_salv_columns_table,
     obj_single_column TYPE REF TO cl_salv_column.

CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table =  alv_table_obj  
        CHANGING
          t_table      = itab_final    "Internal table holding final data to display in report output


*to change the name of the column in ALV.  

obj_columns  =  alv_table_obj->get_columns().

    obj_single_column   =  obj_columns->get_column( 'CARRID' ).

   obj_single_column ->set_long_text ( 'Flight Name' ).

    obj_single_column ->set_medium_text ( 'Flight Name' ).

    obj_single_column ->set_short_text ( 'Flight' ).

obj_single_column->set_optimize().



alv_table_obj ->display( ).    "Method to display internal table  itab_final data as ALV Report(Either list or Grid                                                     based on the parameter value passed to FACTORY method)

Changing Column Names in ALV Grid Display

In a report development using set_table_for_first_display Method of  CL_GUI_ALV_GRID class.
 I am required to over write the text given in the data elements for all the fields and display customized text, for the ALV column texts.When we display the report , by default we will get the field label text (DDIC Objet )assigned to that field in report output.
Here in this post i am going to explain you, how to customize the column headers.


FM to generate  Field catalog :


FM Signature:

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'ZSTRUCT'    "DDIC object

CHANGING

CT_FIELDCAT = ITAB_FIELDCAT  "Field catalog ref to  lvc_s_fcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

Changing the default display text with customized one.

LOOP AT  itab_fieldcat ASSIGNING <fs_fieldcat>.    "Fied symbol type  lvc_s_fcat
 IF <fs_fieldcat>-fieldname = 'CARRID'.

<fs_fieldcat>-reptext       =  'Flight'.                  
<fs_fieldcat>-scrtext_l     =  'Flight Name'.
<fs_fieldcat>-scrtext_m   =  'Flight Name'.
<fs_fieldcat>-scrtext_s    =  'Flight'.
<fs_fieldcat>-outputlen    =  10.

ENDIF.


Method to display report output

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 




If you run the above report ...

For CARRID column you will get  <fs_fieldcat>-scrtext_s text i.e  'Flight'  or  Medium or Long based the length of Column output value .

If you did n't customize the column headers , you will get ID as column name in Short , in other cases Medium and Long ... it will change according to Field label of CARRID data element.


Note 1 : In order to get customized texts in report output , Short Medium and Long texts should be there.if not,you will get DDIC Reference texts only in output.

Note 2 : If Short text presents , you will get that in output. if not, reptext will get display in output.












Sunday, March 5, 2017

Field catalog not found in SAP ABAP

When we are Displaying the ALV GRID using SET_TABLE_FOR_FIRST_DISPLAY ,Some times we may get error message like 
'FIELD CATALOG NOT FOUND".
If you are using the below Function Module to create fieldcatalog, then make sure that the ZSTRUCT should be DataDictionary Object.
If you Create ZSTRUCT as local structure by using TYPES statement,You will get the error.

FM Signature:

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'ZSTRUCT'    "DDIC object

I_INTERNAL_TABNAME = ITAB_OUTPUT   "Interanal table based on your requirement

CHANGING

CT_FIELDCAT = ITAB_FIELDCAT  "Field catalog ref to  lvc_s_fcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

RFC (Remote function call) in SAP ABAP



What is RFC in SAP system?

The RFC interface system enables function calls between two SAP systems, or between an SAP system and an external system.

How to use the RFC?

Step 1: you need to have RFC connection settings should be maintained in SM59.
Example -SAP systems (system 1:AX1 system 2:AX2).
If you like to fetch the data or a data operations or checks from AX1.
Then RFC should be created in AX1 system and that RFC you should call in AX2 system as per your requirement.

 How to create RFC destination?
  1. Go to Transaction SM59 (Display and Maintain RFC Destinations).
  2. From the menu bar, click Create.
  3. Enter the RFC destination, connection type, description, and then press Enter.
  4. Select the Registered Server Program radio-button; enter the program ID, gateway host, and gateway service.
  5. Save the RFC destination.
 How to create the RFC?

it is similar to the FM in SAP and the only difference is that- In the Attributes tab, select the Remote-Enabled Module radio button. 

·  Go to Transaction SE37 (Function Builder), enter the RFC name, and click Create.
·  Enter an existing function group under which the RFC will be created, a short description for the RFC, and click Save.
·  In the Attributes tab, select the Remote-Enabled Module radio button.
·  In the Import tab, enter the import parameters. These parameters are used for passing the external data to the function module.
·  In the Export tab, enter the export parameters.
·  In the Changing tab, enter the changing parameters.
·  In the Tables tab, enter the table names.
·  In the Exceptions tab, enter the exceptions to handle errors.
·  In the Source Code tab, enter the source code (logic) for the RFC.
·  Click the Activate icon on the toolbar to activate the function module.

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.