Thursday, May 21, 2009

How to add new fields in dynamic selection screen

Joyjit Ghosh, Kolkata.

Most of us observe that whenever a logical database is attached with a report, it automatically adds dynamic selection screen button on the report selection screen.

Ex: Transaction FBL1N



If we click on this button, it will open up a separate selection screen that can be dynamically adjusted based on the fields you choose from the left hand side folders (Function groups).

Now our requirement is to add new field in the left hand side folder (as well as in the selection screen) that is not present currently.

1st we need to know the name of the logical database that is attached with the program.

In case of FBL1N, program name is RFITEMAP.

Go to the program’s attribute screen to know the logical database name. In our case it is KDF.

Now go to transaction SE36 and choose the menu Extras → Selection Views.

In the next screen, select Origin of view: SAP and Name of view: STANDARD, and click Display button.

This is the view that SAP uses to generate the dynamic selection screen.

Here three functional groups of fields those are available in the dynamic selections.

01 Vendor Master

02 Company code

03 Document

Each functional group contains fields from the tables that are listed on the right side (LFA1, ADDR1_VAL, etc). The field which is assigned to a functional group will be available in left hand side of the dynamic selection screen under the folder with name of the function group. Notice that for every field assigned to a functional group, there is a “Preselect” checkbox on the right. This checkbox indicates whether the relevant field should be directly available for selection.

As we want to extend the SAP-delivered dynamic selections with new fields, so we must create our own selection view. This view will have CUS as the Origin, and must be named STANDARD. To create such a view, simply use the Copy button on the top of the screen, and copy the SAP delivered view to a CUS view.

Once the customer-defined view is created then go to change mode and add new fields in the functional group.

In this case we have added the field NAME1 in functional group Vendor master (01).

Now save the view , go back to the transaction and open the dynamic selection screen. You can see the new field NAME1 is added in it.

How it works?

When a selection view with origin CUS (customer) and name STANDARD exists, and is assigned to a logical database, then this view takes precedence over the SAP-defined view. When such a view does not exist for a particular logical database, then the selection view SAP – STANDARD is used to

Monday, May 18, 2009

Display table field as checkbox in transaction SM30

By Joyjit Ghosh

Scenario: To maintain a field as a checkbox in the transaction SM30 (as shown below)

Procedure:

Create a domain for the field that you want to display as checkbox in SM30, with values “X” and “ “ (blank). Or you can use an existing domain as well with the same values.

Now create a data element with this domain.

Use this data element to define the field in the actual table.

Now create table maintenance generator for this table.


Now maintain table entries from transaction SM30. In this case field ‘STATUS’ will be displayed as check box.

SE16-Table content (Before data change):

Now set the check box for any record to test that data (“X”) is updating in the underlying database table correctly.

SE16-Table content (After data change):

As shown in the above screen shot, data (“X”) is updated in the database successfully.

Debugging Active Jobs

By Joyjit Ghosh

Go to the transaction SM37 and select the background job (with job status ‘Active’) that you want to debug.

Now select ‘Capture: active job’ from menu ‘Job’,

This will open the selected active job (program) in the debugger.

Also you can do the same from transaction SM50.

Select the work process where this job is running and then choose the menu path Program/ModeàProgramàDebugging.

It will display a pop up window for confirmation, click on the ‘Yes’ button.

Then you can see the job (program) in the debugger.

ALV interface check

By Joyjit Ghosh

In ALV we have an option to check the interface parameters, which we are passing from our program. This check will identify any problem(s) that may occur during calling the ALV FM or ALV class method. It is advisable to perform this check before formal submission of the code to avoid any inconsistency that can lead to problem(s), even program termination in worst case. To enable this check interface parameter I_INTERFACE_CHECK of ALV FM(s) must contain ‘X’.

Example: 
*&-------------------------------------------------------------*
*& Report Z_ALV_INTERFACE_CHECK *
*& *
*&--------------------------------------------------------------
REPORT  z_alv_interface_check                   .
***************************************************************
* Type pool declaration for ALV
***************************************************************
TYPE-POOLS: slis.
***************************************************************
* Table
***************************************************************
TABLES: sbook.
***************************************************************
* Type declaration for SBOOK table
***************************************************************
TYPES: BEGIN OF ty_sbook,
carrid TYPE s_carr_id, " Airline Code
connid TYPE s_conn_id, " Flight Connection Number
fldate TYPE s_date, " Flight date
bookid TYPE s_book_id, " Booking number
customid TYPE s_customer," Customer Number
END OF ty_sbook.
*****************************************************************
* Table declaration for SBOOK table
*****************************************************************
DATA: i_sbook TYPE STANDARD TABLE OF ty_sbook INITIAL SIZE 0,

****************************************************************
* Table declaration for field catalog
****************************************************************
i_fcata TYPE slis_t_fieldcat_alv.
****************************************************************
* Workarea declaration for field catalog table
****************************************************************
DATA: w_fcata TYPE slis_fieldcat_alv.
****************************************************************
* Selection screen
**************************************************************
SELECT-OPTIONS: s_carrid FOR sbook-carrid.
***************************************************************
* Start-of-selection event
****************************************************************
* Fetch data from sbook table
PERFORM fetch_data.
* Populate field catalog
PERFORM populate_catalog.
* Display data in ALV
PERFORM display_alv.
*&--------------------------------------------------------------
*& Form fetch_data
*&-------------------------------------------------------------
FORM fetch_data .
  SELECT  carrid       " Airline Code
connid " Flight Connection Number
fldate " Flight date
bookid " Booking number
customid " Customer Number
FROM sbook
INTO TABLE i_sbook
WHERE carrid IN s_carrid.
  IF sy-subrc = 0.
    SORT i_sbook BY carrid.
  ENDIF.
ENDFORM.                    " fetch_data
*&-------------------------------------------------------------*
*& Form populate_catalog
*&--------------------------------------------------------------
FORM populate_catalog .
  w_fcata-fieldname = 'CARRID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Airline Code'(001).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
  w_fcata-fieldname = 'CONNID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Flight Connection Number'(002).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
* Wrong field name FIDATE
  w_fcata-fieldname = 'FIDATE'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Flight date'(003).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
* Wrong field name BOOKLD
  w_fcata-fieldname = 'BOOKLD'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Booking number'(004).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
  w_fcata-fieldname = 'CUSTOMID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Customer Number'(005).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
ENDFORM.                    " populate_catalog
*&----------------------------------------------------------
*& Form display_alv
*&-----------------------------------------------------------
form display_alv .
data: l_repid type sy-repid.
l_repid = sy-repid.
* Interface check parameter, we have to pass ‘X’ as value in this parameter
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = 'X'
I_CALLBACK_PROGRAM = l_repid
IT_FIELDCAT = i_fcata
TABLES
t_outtab = i_sbook
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.                    " display_alv

Selection screen:

Output:

Additional screen (before showing the final output) to show the error or warning or success message(s)

Also various buttons are present on the application tool bar to check contents of Fieldcatalog, Layout, Sort, Filter, Events, Variant, and Special Fieldgroup.

Fieldcatalog:

Layout:

Sort:

Filter:

Event:

Variant:

Field group:

From the initial screen if we press back button then it will display the final output.

Final output:

Note:

  1. Always remember to switch off this check before formal code delivery otherwise these extra screen(s) can confuse the end user.
  2. In ECC 5.0, I have seen that this check does not work with FM REUSE_ALV_GRID_DISPLAY, in that case we need to convert grid to list temporarily to implement this check.

Scheduling background jobs by triggering events

By Joyjit Ghosh

Step1: Create event from transaction SM62.

Give event name and description and press save button

Step2: Create a program that triggers this event by calling the FM ‘BP_EVENT_RAISE’.

*&---------------------------------------------------------------------*
*& Report Z_TRIGGER_EVENT *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT  Z_TRIGGER_EVENT                         .
CALL FUNCTION 'BP_EVENT_RAISE'
EXPORTING
eventid = 'Z_TRIGGER_JOB'
EXCEPTIONS
BAD_EVENTID = 1
EVENTID_DOES_NOT_EXIST = 2
EVENTID_MISSING = 3
RAISE_FAILED = 4
OTHERS = 5
.
IF sy-subrc <> 0.
Write: 'Event failed to trigger'.
else.
Write: 'Event triggered'.
ENDIF.

Step3: Configure the background job from transaction SM36.

In the initial screen give job name and job class and press “Start condition” button.

In the popup screen press “After event” button and give the event name and then press save button.

Now go back to the initial screen and press “Step” button

Provide program and variant name and after providing all the values press save button.

In the initial screen press save button.

Step4: Now execute the program to trigger the event and as well check the background job.

Run transaction SM37

Check the status of job defined above

Now check the spool to see the generated list