Wednesday, December 24, 2014

SAP F4 help for Standard Screen Field, F4IF_FIELD_VALUE_REQUEST,SAP Search Help


Requirement : At times there is a requirement to add the F4 help for standard screen fields where  the field has no default search help options .

Purpose : In Such cases where only option left is to go for an access key or modifying the standard , it can be achieved by using an implicit enhancement in FM HELP_START

In order to perform this task basic understanding of Implicit enhancement and and search helps.

Enhancements is technique provided by sap in order to insert the custom code inside the standard flow control. Enhancements are of different types intially we have techniques like 'user-exits', 'customer-exits', and 'BADI's' .

after the NW04 enhancement Framework has been introduced. Enhancement framework has brought all the enhancement techniques under one roof.Source code enhancement is one of technique for adding custom codes. There are two types of source code enhancements possible
 1. Implicit Enhancement Option
 2. Explicit Enhancement Option

Implicit enhancement : Almost in all the abap system Options are available by default at predefined places like At end of all the reports,includes  ,Function Pools,Module Pools and at stating and ending of Form Subroutines and At end of all FM's.

Steps :
For Demonstration purpose i have taken the Purchase order transaction and adding Collective No Field F4 help. Collective No field SUBMI Doesn't have any search help by default, now assigning list of RFQ's to SUBMI in ME21 and ME21 Transaction on clicking F4 button.

1. Go to Se37-> Help_Start-> Click on display.
2. Click on Enhance Button( Shift F4 ) 

3. Go to -> Edit->Enhancement Operations-> Show Implicit Enhancement Options ,then you will see a line like below at the starting of FM
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Function Module HELP_START, Start 

4. Right Click on the the Quoted Line -> Enhancement Operations -> Click On Create Implementation and select the option CODE and provide the name and Short text in the pop up.





Provide Meaningful Name
5. Do the following Coding .

Here in 'ZANFNR' is a custom search help which has exporting value of ANFNR is assigned to the collective No field of ME21N And ME22N.


IF sy-tcode 'ME21N' OR sy-tcode 'ME22N' AND
        help_infos-fieldname 'SUBMI' AND help_infos-dynprofld 'MEPO1229-SUBMI'
        AND help_infos-dynpprog 'SAPLMEGUI' AND help_infos-menufunct 'HC' .
  DATAtl_return TYPE STANDARD TABLE OF ddshretval,
           wl_return TYPE ddshretval.

  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
      tabname           'MEPO1229'
      fieldname         'SUBMI'
      searchhelp        'ZANFNR'  " Create a search help / use an existing one
      shlpparam         'ANFNR'
      dynpprog          sy-cprog
      dynpnr            sy-dynnr
      dynprofield       'MEPO1229-SUBMI'
      value             'X'
    TABLES
      return_tab        tl_return
    EXCEPTIONS
      field_not_found   1
      no_help_for_field 2
      inconsistent_help 3
      no_values_found   4
      OTHERS            5.
  IF sy-subrc AND linestl_return 1.
    READ TABLE tl_return INTO wl_return INDEX 1.
    selection 'X'.
    select_value wl_return-fieldval.
    EXIT.
  ENDIF.

  ENDIF.


6. After doing all these activate the enhancement .

Hope this will be helpful in case there are no options of standard search help in standard screen fields.

Any Suggestions or corrections are welcome.











Sunday, November 23, 2014

IMA11, User Exit/ Badi IMA11,AAIR0002,Appropriation Request ,CSN , Investment Management,Create Appropriation Request

Adding Customer Fields In IMA11 (Appropriation Request / CSN) Using Exit AAIR0002

Using this enhancement AAIR0002 we can add the user fields in appropriation requests in a sub screen and place it in IMA11. In order to perform the addition of adding the custom fields in IMA11 following steps needs to be done.

For Example i have a requirement to add the material no in the appropriation requests.

1. Firstly create a structure CU_IMAU in SE11







2. Create a Screen lets say 1234 in Function Group XAI1 and create an input field by clicking on F6 and give IMAK table name and select ZZ_MATNR as shown in below figure

Click on F6 and get the ZZ_matnr From IMAK Table

After creating the Screen 1234 Go the Flow Logic and Enable PBO And PAI

PROCESS BEFORE OUTPUT.
MODULE fill_data_from_imak.
PROCESS AFTER INPUT.
MODULE pai_fill_user_entered_data.

While creating the Module FILL_DATA_FROM_IMAK you will be asked to create a new include create an include and add the below code here perform GET_USERFIELD_DATA is used to supplies the values from to the transfer structure 

*&---------------------------------------------------------------------*
*&      Module  FILL_DATA_FROM_IMAK  OUTPUT
*&---------------------------------------------------------------------*
*     
*----------------------------------------------------------------------*
MODULE fill_data_from_imak OUTPUT.
*IMAK_CI_INCLUDE-x = 'X'.
PERFORM GET_USERFIELD_DATA CHANGING IMAK_CI_INCLUDE.
PERFORM READ_REQUEST_DATA.
IMAK-ZZ_IMMATNR XIMAK-ZZ_IMMATNR.
IF gd_aktyp 'A'.  "When in Display Mode 
  LOOP AT SCREEN.
    IF screen-name 'IMAK-ZZ_IMMATNR' .
      SCREEN-INPUT 0.
      SCREEN-ACTIVE 1.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
ENDIF.
ENDMODULE.                 " FILL_DATA_FROM_IMAK  OUTPUT

PAI.

*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  PAI_FILL_USER_ENTERED_DATA  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE pai_fill_user_entered_data INPUT.
IMAK_CI_INCLUDE-ZZ_IMMATNR = IMAK-ZZ_IMMATNR.
PERFORM SET_USERFIELD_DATA changing IMAK_CI_INCLUDE.
ENDMODULE.                 " PAI_FILL_USER_ENTERED_DATA  INPUT

After doing the coding in Screen 
3. Go to tcode CMOD and create a Implementation for the Exit AAIR0002 
Give the Project Name and click on create and after that assign the go to enhancement assignments
and give the exit name AAIR0002 next click on Components goto -->EXIT_SAPLAIA1_001

create include ZXAI1U01.

*&---------------------------------------------------------------------*
*&  Include           ZXAI1U01
*&---------------------------------------------------------------------*
gd_aktyp I_aktyp .
IF I_AKTYP ='H' OR I_AKTYP 'V'.  "Create Or Change
clear ET_required[].
ET_REQUIRED-gbox '1234'.
append ET_required.
ENDIF.

Activate the project .

4. After doing all this finally we need to ask our Functional to assign the tab in appropriation requests

Goto->SPRO->Investment management->Appropriate Requests->Master Data->Control Data->Specify Tab Layout For Appropriation Requests 

Here you need to copy the SAP --Standard tab layout to a custom one ZSAP(Ex.) 

now select the ZSAP row and click on Tab Page Titles and provide the title name for your Tab
Give title as per your requirement for understanding i gave customer tab
Now Select the Customer Tab Row and double click on Position of Groups and in the next screen select your screen no from the F4 list and save the customization.

After adding the screen in layout go to SPRO->Investment management.>Appropriation Request->Masterdata->Control Data->Maintain Appropriation Request Type

here you will find the Request types select the type and give your layout name in there
Request Type 
and save .

after the customization now we can check our customer screen in IMA11.

Hope this will be helpful to some extent, if any changes or corrections please suggest.


Thanks.






Friday, November 21, 2014

Excel to SAP,UPLOAD_XLS_FILE_2_ITAB,Upload Excel,ALV

Uploading Data from Excel File to SAP using The FM 'UPLOAD_XLS_FILE_2_ITAB' and display it using ALV


The Following is the sample program for using the FM 'UPLOAD_XLS_FILE_2_ITAB'.

My Excel format is


REPORT ZEXCEL_UPLOAD_TO_SAP.

**Types For Data to be uploaded
TYPES : BEGIN OF TY_ITAB,
        EBELN TYPE EBELN,
        EBELP TYPE EBELP,
        MENGE TYPE MENGE,
        DMBTR TYPE DMBTR,
        END OF TY_ITAB.
*&Create a Table Type From Types
TYPES : TITAB TYPE STANDARD TABLE OF TY_ITAB.
*&Create Table and Work Area for Data Processing.
DATA : GT_ITAB TYPE TITAB.
DATA : GS_ITAB TYPE TY_ITAB.
*Selection Screen For Getting Filename From User
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
   EXPORTING
     FIELD_NAME          = 'P_FILE'
   IMPORTING
     FILE_NAME           = P_FILE.



START-OF-SELECTION.

CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
  EXPORTING
    I_FILENAME       = P_FILE
  TABLES
    E_ITAB           = GT_ITAB
 EXCEPTIONS
   FILE_ERROR       = 1
   OTHERS           = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
CASE SY-SUBRC.
  WHEN 1.
  MESSAGE 'Something went wrong in file,Close file and upload again' TYPE 'E'.
  WHEN 2.
  MESSAGE 'Error in Uploading file,Try again' TYPE 'E'.
ENDCASE.
ENDIF.

*&Reference for CL_SALV_TABLE for Displaying the Output
DATA GR_TABLE   TYPE REF TO CL_SALV_TABLE.


CL_SALV_TABLE=>FACTORY(
  IMPORTING
    R_SALV_TABLE   = GR_TABLE
  CHANGING
    T_TABLE        = GT_ITAB ).

GR_TABLE->DISPLAY( ).