Thursday, July 21, 2011

To Display Long Text In ALV

The purpose of this document is to provide an option of “word wrap” to ALV functionality. Other options may be possible; however, they only work around and doesn’t provide end user the flexibility to view the texts in single instance. Few of the other alternatives are listed below –  
·         You can make the column text as link and show truncated text so that even if the whole text in a column is not seen, the user can see the entire text on mouse over.
·         You can implement functionality where in on clicking on the required cell, a popup comes with the entire text.  
However, in the above alternatives, incase end user needs to take print out of the report output, he will miss out the truncated texts.

Wednesday, July 20, 2011

How To Do Implicit Enhancement

Enhancement options are positions where we can add our code, SAP has provides with these positions where we can put our code as per the requirement, we can add an implementation element without modifying the original code of SAP.
Enhancement implantation elements are stored in the package with own transport objects thus avoiding any conflict in modification in later stages.
 Explicit and Implicit Enhancement Options
 Implicit Enhancement options are for free, provided by the framework, while the explicit ones need to be inserted explicitly, as the name indicates.
How To Do Implicit Enhancement
Suppose we want to enhance Fun Mod:
We know Fun Mod 'popup_to_inform' is used to display popup message, I will add one more Fun Mod 'popup_to_confirm'.
And on selecting cancel the program should exit.
1.In SE37.
 2. Screen will look something like this.
 3. Select enhance source code  

 4.Screen will come white & fonts will come Gray, select show_implicit enhancement options.


5. Yellow lines will come, place your cursor on yellow strip & create enhancement.

6. Choose declaration type of enhancement.
7. Now place your required code in this section.

8. Here we have placed one popup to confirm

9. Activate the function module & run you will find the implemented enhancements.
 

How to do Explicit Enhancement

In case of explicit enhancement we can add our enhancements at any place as per our requirement.
Well in our case I don't have any standard program so I am using a Z program & enhancing the code.
Before starting explicit enhancement we have to create:
  •   One enhancement spot.
  •   In enhancement spot we have to implement spot.
  •   All these task to be done under one package.
  •   So I am creating one package in se80 first.
  1.   Right click & create Enhancement Spot.
 2.   Give the name of Enhancement Spot

3.   Now activate the enhancement spot
4.   Right click Enhancement Spots & implement it.
5.   Activate the implementation, Goto SE38 & place the cursor where enhancement is require.
6. Enter Enhancement implementation name in Enhancement Spot name & Package name.
  7.   Now enhancement-point will come in your code with Grey Fonts.
 8.  Select Enhance
9.   Place the cursor on enhancement-point & create enhancement.
10.    Give enhancement Implementation name.
 11.  Place your code & activate. 

 12.  Now run the program you will find the enhancement.
 

Thursday, July 14, 2011

Tuesday, July 12, 2011

Creating user exits for substitutions

Substitutions can be used for validating data at the time of entry in SAP system. This wiki can be used for creating custom user exits so that one can set his validations & conditions. User exits are user defined FORM routines that are used to calculate/replace values with in a substitution .I have shown demo for FI but same steps with some minor modifications can be used for other areas too.
What are substitutions?
Whenever a data is entered in a system, validations are invoked to check  its integrity .Once validations are done, one can substitute the entered value with some other value. This gives you the opportunity of having the system validate values that are to be substituted. A substitution value can be numeric or a string. The system first performs some validations and then substitutions.
Transactions used for substitutions are :                  
 GGB1 :  Substitutions  maintenance.                                                                                                                                                                                                                                                          
 OBBH :  Activation of FI substitutions.
 Substitutions can be performed using three ways:
 1.Constant values.
 2.Field -Field assignment.
 3.User exits.
In this wiki I have shown substitutions implemented using custom user exits.
Steps for creating user exits for  substitutions.
The exits used for  substitutions are stored in a Include program.RGGBS000 is a standard include given by SAP for user exits for substitutions. So for creating custom user exits, one has to copy this include to a 'Z' (Custom namespace) program.
Step1 : Create a copy of include RGGBS000 ,let say ZTEST000.The length of the name you choose should not exceed 8 characters.
Step2 : Define your user exit in the FORM routine GET_EXIT_TITLES with the correct exit type (EXITS-PARAM).
exits-name  = 'U111'.
exits-param = c_exit_param_none.
exits-title = text-100.       "Give any suitable text for your exit
APPEND exits.
Include the EXIT NAME , PARAM and TITLE in the form GET_EXIT_TITLES .This form GET_EXIT_TITLES contains name and titles of all available standard exits. Every new exit need to be  added to this from. One has to specify a parameter type to enable the code generation program to determine correctly how to generate the user exit call ,i.e. How many and what kind of paramter(s) are used in the user exit. The following parameter types exist:
TYPE                                                    Description            
 -------------------------------------------------------------------------------------------------------
 C_EXIT_PARAM_NONE                     Use no parameter except B_RESULT . If you do not want to substitute a field, use this parameter in the substitution .
 C_EXIT_PARAM_FIELD                     Use one field as param. Exactly one field is substituted.
 C_EXIT_PARAM_CLASS                    Use a type as parameter.
Step3: Create a FORM for your exit which will define its functionality.
In form GET_EXIT_TITLES we have define our EXIT-NAME as  'U111'. So wee need to create a FORM with name U111 which will define the functionality of our user exit. Here I am taking a simple example of populating the Item Text (BSEG-SGTXT).
*---------------------------------------------------------------------*
*       FORM U111                                                                  *
*---------------------------------------------------------------------*
*       Populate Item Text (BSEG-SGTXT)                                                             
*---------------------------------------------------------------------*
FORM U111.
  DATA: wl_awkey TYPE  bkpf-awkey.
  CONSTANTS: c_asterisk  TYPE c VALUE '*',
             c_hypen TYPE c VALUE '-'.
  CLEAR wl_awkey.
*-- Removing leading zeros
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
      input  = bkpf-awkey
    IMPORTING
      output = wl_awkey.
*-- Set the item text
  CONCATENATE c_asterisk bseg-zuonr c_hypen wl_awkey INTO bseg-sgtxt.
ENDFORM.                                                    "U111
You need to be cautious when writing code for your user exit. No dialog boxes, warning messages, information or error messages must be issued in an exit. Do not use any ABAP commands that cause you to leave the exit directly, for example LEAVE TO SCREEN. In the includes of the substitution exits, you must not use the commands MODIFY, INSERT or DELETE in the internally used structures such as BSEG or BKPF. These structures are interpreted internally as database tables because they are defined by a TABLES statement. As a result, the system writes, deletes or changes database records if you use the commands mentioned above. This can cause serious inconsistencies and problems in the document processing. If you want to change field contents in the exit type C_EXIT_PARAM_CLASS, you should make the changes in the internal table BOOL_DATA (for example BOLL_DATA-BSEG).
Step 4:Run transaction GCX2 to update IMG to use your new program instead of Standard SAP program for substitution exits.
Alternatively you can use   SPRO for  updating IMG. Run SPRO- Financial Accounting (New) - Special Purpose Ledger -Basic Settings - User Exits - Maintain Client Specific User Exits.
Update the program name RGGBR000 with your new program ZTEST000 for application area GBLS. Now you can use this user exit for substitutions.

How to use custom user exit for a substitution?
Go to transaction GGB1.Here you can create\change a substitution . I am not going in detail for creating a  substitution .Specify the user exit(Highlighted area in red) for a field that is to be substituted buy your exit .
 Also you can see the list of all the user exit on pressing F4 on the highlighted area in red. If your user exit is in active state, then it will be visible there. Once you have done the changes ,Save it. Now your user exit will be invoked automatically for that field.

Downloading internal tables as XML

This is simple program to convert Internal table into XML and download the same in local drive or to FTP.