Sunday, December 31, 2017

How to Change ALV Standard toolbar button text in SAP ABAP

Scenario : As per the requirement we need to display SAP ALV standard tool bar export button text as 'SAVE EXCEL' .By default the button text is 'Export'.

Solution :

All ALV standard toolbar buttons (Function Codes ) are available in SAP standard internal table

e_object->mt_toolbar.

here e_object is the one of the importing parameter of ALV TOOLBAR Event ( Toolbar Event : where we add customizing buttons to the ALV standard toolbar using the same internal table).

Customizing the standard text display :

In side the ALV Toolbar event handler , write the below mentioned piece of code .

LOOP AT e_object->mt_toolbar ASSIGNG <fieldsymbol>.

   IF <fieldsymbol>-function EQ '&MB_EXPORT' .  " (&MB_EXPORT is the FCODE of export                                                                                                button)
 
   <fieldsymbol>-text  = 'SAVE EXCEL' .   "User's customizing text

 ENDIF.
ENDLOOP.


Sunday, December 10, 2017

How to Increase length of Selection Texts ( Parameter/Select-options ) display text in sap ABAP


Limitation :

 If you declare any Selection screen elements (Parameter or Select - options ) , Corresponding displaying we will provide it in Selection texts.

Path -- GOTO --> Text Elements --> Selection Texts.

Ex :  SELECTION-SCREEN BEGIN OF BLOCK b1.
        PARAMETERS : p_rad1 RADIO BUTTON GROUP g1,
                                     p_rad2  RADIO BUTTON GROUP g1.

       SELECTION-SCREEN BEGIN OF BLOCK b1.

Here corresponding Display text of Radio buttons will provide in Selection Texts.But the Maximum length we can provide is 30.

But here in my requirement i need to provide display text as 40 for p_rad1 Radio Button . By using Selection texts , it's not possible.

Solution : 

       SELECTION-SCREEN BEGIN OF BLOCK b1.
       SELECTION-SCREEN BEGIN OF LINE.
       PARAMETERS : p_rad1 RADIO BUTTON GROUP g1.
       SELECTION-SCREEN COMMENT (50) text-001 FOR FIELD p_rad1.
       SELECTION-SCREEN END OF LINE.
       PARAMETERS :   p_rad2  RADIO BUTTON GROUP g1.
       SELECTION-SCREEN BEGIN OF BLOCK b1.


Maintain display text for text-001.

Path : GOTO-->Text Elements --> Text Symbols.

Wednesday, November 29, 2017

How to Remove/Delete or Hide CLOSE ( X ) Button in Model Dialog Box

Problem : How to Remove/Delete or Hide CLOSE ( X ) Button in Model Dialog Box





Example :  i have a screen 100 which is designed as Model Dialog box.I am displaying this screen from FM.

Ex code :

FUNCTION Fun_name.

CALL SCREEN 100 STARTING AT 10 01
                                   ENDING AT 50 05.

ENDFUNCTION.


Screen 100:

PBO :

MODULE Status_100.

CODE in O01 Include:

MODULE status_100.
SET PF-STATUS 'Z100'.
ENDMODULE.

GUI Status Creation  for model dialog box:
Double click on Z100 and select Model dialog box radio button from pop up screen by providing meaningful description.

After that Create your Application Tool bar Buttons as per the requirement, while creating buttons we have to provide function keys to the buttons.
If you provide function key as ENTER to any Function code of button , It will automatically enable CLOSE (X) button in Model Dialog box.

Solution :

1. SET PF-STATUS 'Z100'. EXCLUDING 'FC_CLOSE'.
      Here 'FC_CLOSE' is the function code assigned to ENTER function key.

2.Remove the Function code Assigned to ENTER function key .


Sunday, September 10, 2017

OOP Report : Backgroung job cancelled in SAP ABAP


Problem : When we are running ALV OOP report as background job , Sometimes will get status as cancelled in SM37.


Solution :

Step 1 : Check the container used for holding the ALV Report . If the container used is CL_GUI_CUSTOM_CONTAINER , then it is not possible to run report in background.

Solution : Replace CL_GUI_CUSTOM_CONTAINER object reference with CL_GUI_DOCKING_CONTAINER. Now it's possible to run report as background job.


Note : If you are using CL_GUI_DOCKING_CONTAINER , no need of creating object .Just pass the referece to CL_GUI_ALV_GRID object creation.

Signature :

CREATE OBJECT obj_grid
Exporting

i_parent  = obj_docking_container
.

Sunday, May 28, 2017

PF STATUS for Selection Screen

In this post we are going to learn , how to set PF-STATUS for standard selection screen ( SCREEN #: 1000)

i will explain this by taking small example.


Report Zvenky_pfstatus.

Tables : MARA.

SELECT-OPTIONS :   s_matnr FOR mara-matnr.



If you execute the above piece of code, you will get a selection screen with s_matnr as select option.
Here in output you will get GUI status with Back,Exit and Cancel button.This status automatically provided by SAP.

Now here my requirement is , i want to display my own PF-STATUS for Standard Selection screen.

we can implement this very easily with help of SAP Standard FM 'RS_SET_SEL_SCREEN_STATUS'.

Example.

Report Zvenky_pfstatus.

Tables : MARA.

SELECT-OPTIONS :   s_matnr FOR mara-matnr.

AT SELECTION-SCREEN OUTPUT.   " Event which will trigger before Selection screen display

CALL FUNCTION 'RS_SET_SEL_SCREEN_STATUS'
EXPORTING
p_status = 'ZSTATUS'    " user created status
*p_program = ' '

TABLES
p_exclude = itab_exclude .   " itab_exclude type standard table of rsexfcode


By Using above piece of code we can display our own GUI Status.

Note : In Standard gui status Back,Exit,Cancel Buttons will work automatically ,as the button functionality will take by SAP. But if you display your own GUI status ,You have to write code for Button action.


P_EXCLUDE : Table of OK codes to be excluded.






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.






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.






Friday, January 13, 2017

Error in module RSQL of the database interface Example

I have declared one local structure as follows,

TYPES : BEGIN OF struct_mara,

               matnr    TYPE   mara-matnr,
               vpsta     TYPE  mara-vpsta,
               matkl     TYPE  mara-matkl,
               bismt     TYPE  mara-bismt,
               meins    TYPE  mara-meins,

END OF struct_mara.

I have declared an internal table and a work area for the corresponding structure as follows,

DATA : itab_mara TYPE STANDARD TABLE OF struct_mara,
            wa_mara LIKE LINE OF itab_mara.

now i have fetched data from MARA table into the internal table itab_mara

SELECT matnr vpsta matkl meins FROM mara INTO TABLE itab_mara
                                                UP TO 10 ROWS.

When we run the above select query, it will end up with a run-time error  Error in module RSQL of the database interface .

Reason for Runtime Error :
-----------------------------
In the STRUCTURE declaration bismt field is there in 4th position but where as in the select query meins field is there in 4th position. Because of this field mismatch we are getting this runtime error.

Solution 1:
-----------
SELECT matnr vpsta matkl meins FROM mara INTO CORRESPONDIG FIELDS OF TABLE itab_mara
                                                UP TO 10 ROWS.

   As per performance issue we are not suppose to use CORRESPONDIG FILEDS keyword.

Solution 2:
------------
TYPES : BEGIN OF struct_mara,

               matnr    TYPE   mara-matnr,
               vpsta     TYPE  mara-vpsta,
               matkl     TYPE  mara-matkl,
               meins    TYPE  mara-meins,
               bismt     TYPE  mara-bismt,
             

END OF struct_mara.

As per the SELECT query fields sequence ,declare the fields inside the structure.
If you need additional fields in the internal table which are not there in select query but you need those for future purpose, in that case declare those fields after SELECT query fields sequence like bismt field which is shown above.


Saturday, January 7, 2017

how to use the BADI checks on tcode SU01 in SAP


What is BADI?

badi : Business add-ins are enhancements to the standard version of the SAP system. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery. Since specific industries often require special functions, SAP allows you to predefine these points in your software.

You can differentiate between single-use and multiple use Business Add-Ins. The distinction is based on the procedure or event character of an enhancement. In the first case, the program waits for the enhancement to return something, usually a return code. A typical example could be a benefit calculation in HR. Depending on the implementation, alternative calculations can be executed. With multiple use add-ins, an event that may be of interest to other components is processed in program flow. Any number of components could use this event as a “hook” to hang their own additional actions on to.

In addition to importing parameters, you can also use changing parameters for multiple-use Business Add-Ins. There is no sequence control for multiple-use implementations of BadIs. Therefore, using changing parameters can cause problems. There is no guarantee that implementations will not overwrite the results of previous implementations. Sequence control is technically impossible, since at the time of the definition the interface does not know which implementations there will be and which parameters will be changed by implementations. It is not possible to have a decision as to which implementation should be executed before which other (future) implementation.


Example related to SAP BADI

To validate the roles during change or create of user master data in SU01, BADI à
BADI_IDENTITY_CHECK can be implemented. Importing Parameter IO_BADI_MSG_BUFFER can be usedto add the error message and this error message will be displayed during save. We can display pop to the
user asking to enter the comments in case of any conflicts in the user roles.


Enhancement spot   SUID_IDENTITY

GoTo SE19.
Enter enhancement spot
click on create impl.






Sunday, January 1, 2017

Error in module RSQL of the database interface

DATA var_sum type n LENGTH 3.



SELECT sum( col ) from ztable INTO  var_sum
  WHERE (filter condition).


Here in above query i try to store the sum of col into a variable of type numc.Due to this i got the error (Error in module RSQL of the database interface).


Solution in this case :
DATA var_sum TYPE i.


FOR more details with example Click HERE

how to hide an ui element in web dynpro

Declare one Attribute in Context node(under CONTEXT tab of view or CONTEXT tab of COMPONENT CONTROLLER) which is of type WDUI_VISIBILITY.
Now bind the above declared attribute with the VALUE property of your UI element(Which element you want to hide).

Now By using CODE wizard ... select the SET radio button and then choose the attribute which is created in Context node...it will generate some predefined code which is shown below.

For Ex:
node->set_attribute(
------
value = lv_attribute
).



Visibility Criteria:


If you want to hide the UI element use
lv_attribute = 01.  (value for hiding)


If you want to show the UI element use
lv_attribute = 02. (value to show UI element) .

You can use this procedure based on button clicks; Like, On click of BUTTON you can display some text elements or I/O fields etc....

Happy New Year - 2017

Bill Gates
----------
1.Don't Compare yourself with anyone in this World. If YOU do so , you are insulting yourself.

2.If you BORN poor it's not your mistake , If you DIE poor it's your mistake.

3.When you have MONEY in hand only you forget who  are you , BUT when you don't have any money in your hand , the whole world forget who you are. IT'S LIFE!...


Abdul Kalam
-----------------

1.Success is when your 'SIGNATURE' changes to 'AUTOGRAPH'.

2.Man need his difficulties because they are necessary to enjoy SUCCESS.

3.DREAM is not that which you see while SLEEPING, it is something that does not let you SLEEP.