Friday, March 25, 2011

Automatically populating the search hlep values into different fields on the selection screen by using search help exit

Requirement overview:

I have a selection screen with some fields. For scheduling agreement field I have given the F4 help by using search help exit.

When user clicks on F4 for scheduling agreement, in the search results along with the scheduling agreement I’m giving Item, date, and some other fields.

Now, the requirement is when ever user selects a scheduling agreement from F4 help I need to populate the corresponding item automatically from the search help on to the Item field on the selection screen.

Solution:

In the above screen shot if I select 30000018 and click enter, corresponding item (000020) should get populated into the Item field on the selection screen.

After displaying the search help values, when CALLCONTROL-STEP = ‘RETURN’ we need to call the function module ‘DYNP_UPDATE_FIELDS’.

IF callcontrol-step = 'RETURN'.
DATA : i_dynp TYPE STANDARD TABLE OF dynpread.
DATA : w_dynp TYPE dynpread.
w_dynp-fieldname = 'S_POSNR-LOW'.
w_dynp-fieldvalue = gv_posnr.
APPEND w_dynp TO i_dynp.
CLEAR : w_dynp.
CALL FUNCTION 'DYNP_UPDATE_FIELDS'
EXPORTING
dyname = 'SAPMZKLIM_HUREPORT'
dynumb = '0300'
request = 'A'
TABLES
dynpfields = i_dynp
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
EXIT.
ENDIF.

Result:

When I select the agreement, corresponding item (20) will get populate into item field in the selection screen.



Providing multiple selection options in Search help

This document specifies how to include multiple select options for the given fields in the search help. For example below we can see that for material we have single selection possible.

So to convert it in the select option we need to follow certain steps.

We need to create a “Search Help Exit” in search help. Search help exit is a function module with the same interface like “F4IF_SHLP_EXIT_EXAMPLE”.

Double click in the search help exit name and paste the following code lines:

DATA:type_info LIKE dfies.

callcontrol-no_maxdisp =
'X'.

IF callcontrol-step EQ 'SELECT'.
callcontrol-step =
'DISP'.
ENDIF.

CHECK: callcontrol-step
EQ 'DISP'.

CALL FUNCTION 'TABCONTROL_VISIBLE'
EXPORTING
visible =
'F'
tab_id =
1.

SUBMIT zmat_search VIA SELECTION-SCREEN AND RETURN.
IMPORT record_tab TO record_tab FROM MEMORY ID 'REC1'.

READ TABLE shlp-fielddescr INDEX 1 INTO type_info.
type_info-leng =
18.
CLEAR type_info-offset .
MODIFY shlp-fielddescr INDEX 1 FROM type_info
TRANSPORTING leng offset.

callcontrol-step =
'RETURN'.

Create a executable program and paste code lines like this:

REPORT zmat_search.

TABLES: mara,makt.
TYPE-POOLS: slis.
DATA: gs_fcat
TYPE slis_fieldcat_alv ,
gt_fcat
TYPE STANDARD TABLE OF slis_fieldcat_alv ,
gs_layout
TYPE slis_layout_alv .

DATA: record_tab
TYPE STANDARD TABLE OF seahlpres,
gs_record
TYPE seahlpres.

DATA:BEGIN
OF gs_output,
matnr
TYPE matnr,
brand_id
TYPE mara-brand_id,
saiso
TYPE mara-saiso,
saisj
TYPE mara-saisj,
saity
TYPE mara-saity,
maktx
TYPE makt-maktx,
chk
TYPE c,
END OF gs_output,
gt_output
LIKE STANDARD TABLE OF gs_output.

SELECT-OPTIONS:matkl
FOR mara-matkl matchcode object wwg1,
brand
FOR mara-brand_id,
saiso
FOR mara-saiso NO INTERVALS NO-EXTENSION,
saisj
FOR mara-saisj NO INTERVALS NO-EXTENSION,
saity
FOR mara-saity NO INTERVALS NO-EXTENSION.

START-OF-SELECTION.

SELECT mara~matnr
mara~matkl
mara~brand_id
mara~saiso
mara~saisj
mara~saity
makt~maktx
FROM mara INNER JOIN makt ON mara~matnr = makt~matnr AND makt~spras EQ sy-langu
INTO CORRESPONDING FIELDS OF TABLE gt_output
WHERE mara~matkl IN matkl AND
mara~brand_id
IN brand AND
mara~saiso
IN saiso AND
mara~saisj
IN saisj AND
mara~saity
IN saity .

PERFORM build_fcat USING : 'MATNR' 'Article' 'X' ,
'BRAND_ID' 'Brand Id' '' ,
'SAISO' 'Season Category' '' ,
'SAISJ' 'Season Year' '' ,
'SAITY' 'Rollout' '' ,
'MAKTX' 'Description' '' .

gs_layout-box_fieldname =
'CHK'.
gs_layout-colwidth_optimize =
'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set =
'PF_STATUS_ALV'
i_callback_user_command =
'USER_COMMAND_ALV'
is_layout = gs_layout
it_fieldcat = gt_fcat
TABLES
t_outtab = gt_output
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.

*&---------------------------------------------------------------------*
*& Form build_fcat
*&-------------------------------------------------------------------FORM build_fcat USING us_fieldname TYPE c
us_seltext_m
TYPE c
us_key
TYPE c.

gs_fcat-fieldname = us_fieldname .
gs_fcat-seltext_l = us_seltext_m .
gs_fcat-key = us_key .
APPEND gs_fcat TO gt_fcat .
CLEAR gs_fcat .

ENDFORM.
" build_fcat

*&---------------------------------------------------------------------*
*& Form pf_status_alv
*&-------------------------------------------------------------------

FORM pf_status_alv USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'YSTANDARD' EXCLUDING rt_extab.
ENDFORM.
"pf_status_alv

*&---------------------------------------------------------------------*
*& Form user_command_alv
*&-------------------------------------------------------------------
FORM user_command_alv USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
CASE r_ucomm.
WHEN 'EXC'.


LOOP AT gt_output INTO gs_output WHERE chk EQ 'X'.

WRITE gs_output-matnr
TO gs_record-string(18).

APPEND gs_record TO record_tab.

ENDLOOP.

EXPORT record_tab TO MEMORY ID 'REC1'.

LEAVE PROGRAM.

WHEN '&IC1'.

READ TABLE gt_output INTO gs_output INDEX rs_selfield-tabindex.
IF sy-subrc EQ 0.

WRITE gs_output-matnr
TO gs_record-string(18).

APPEND gs_record TO record_tab.

EXPORT record_tab TO MEMORY ID 'REC1'.

LEAVE PROGRAM.

ENDIF.

WHEN '&FB03'.

SET SCREEN 0 .
LEAVE SCREEN.

ENDCASE.

ENDFORM.
"user_command_alv

Save and activate both Search help and Search help exit and run the search help.

Screen – 1

Press enter,

Screen – 2

Press Enter.

Screen - 3

Give the selection values and press F8. Output will show in ALV. Select any line and find the values in the corresponding selection box.

This search help can be attached to the standard search help say MATNR search help in MM01. BASIS will perform this action.

Creating a projection view

We use projection view to mask unwanted fields and display only relevant fields in a table. Basically View acts like a database table only, the difference is view will not occupy storage space.

1. Creating Projection View

2. Choose Projection View in the pop up which appears when you click on create

3. Give Description & base Table name(In this example we have taken KNA1)



4. After giving table name click on Table fields button

5. Choose the fields which you want to be displayed in output and click copy

6. Now Save, Activate & execute it, output will be

Summary

In standard SAP tables we will have many fields, of which we will use only few fields. whenever we go and view the data we have to come across unwanted data, to avoid this and get display of field which relevant to scenario we use this projection view.

Comparison of Transparent, Pool and Cluster tables

Transparent

Pool

Cluster

Contain a single table. Used to store master data

They are used to hold a large number of very small tables(stores customizing data or system data)

They are used to hold data from a few number of large tables.(stores system data)

It has a one-to-one relationship with a table in the database

It has a many-to-one relationship with a table in the database

It has a many-to-one relationship with table in the database

For each transparent table there is one associated table in the database

It is stored with other pooled tables in a single table called table pool in the database

Many cluster tables are stored in a single table in the database called a table cluster

The database table has the same name, same number of fields and the fields have the same names

The database table has different name, different number of fields and fields have different names

The database table has different name, different number of fields and fields have different names

There is only a single table

Table pools contain more tables than table clusters

Contains less tables than table pools

Single table can have one or more primary key

Primary key of each table does not begin with same fields or fields

Primary key of each table begins with same fields or fields

Secondary indexes can be created

Secondary indexes cannot be created

Secondary indexes cannot be created

They can be accessed using open and native SQL

They can be accessed using open SQL only

They can be accessed using open SQL only

USE: They are used to hold master data e.g. Table vendors or table of customers. Example of transaction data is orders placed by customers

USE: They reduce the amount of database resources needed when many small tables have to be opened at the same time

USE: They would be used when the tables have primary key in common and data in these tables are all accesses simultaneously

Adding new values in Standard Domain

Open any domain in which you want to add new values.

In Menu, Goto->Fixed Values Append and click OK for information message.

Give Append Name and ok.

Then add new values in the value append.

Save and Activate it. If you go back to Domain, you can view your values.



Creation of a table pool and pooled table

In this Tutorial, we create a Table pool first and then create/ (add a table to Table pool) a Pooled Table.

Step 1:

Go to transaction SE11. Go to Utilities à Other Dictionary Objects

Step 2:

Select Radio button Table pool/Cluster Give table Pool Name: ZTBL_POOL.

Then press F5 or choose Create.

Step 3:

Then Select Radio button Table Pool. Press Enter.

Step 4:

Then you go to maintain Poll Screen there give Short Description.

Step 5:

Then go to Technical settings.

Step 6:

In the “Maintain technical Settings” screen Provide Size category.



Save and activate the table Pool. Go back to SE11.

Step 7:

Go to SE11 ABAP Dictionary: Initial Screen.

Create a Z table.

Step 8:

Maintain Delivery and Maintenance attributes for the Z table.

Add fields to the Z table.

Maintain Technical settings and Enhancement Category.

Step 9:

Then Go to Extrasà Change table category

Step 10:

Choose Table type.

In our Example it is Pooled table.

Step 11:

Go back to Delivery and Maintenance tab and provide Pool/Cluster value.

We have successfully created Table pool and Pooled table.

Row level locking of database tables

Normally if a person opens table maintenance generator and tries to maintain the table, no one else can maintain the same table at the same time. This is because of table level lock by default in SAP. Only one user can maintain any table at a time through SM30 or any transaction that calls table maintenance generator. In the tutorial below we will see how to remove table level lock and apply row level lock. This way any number of users can modify the table at same time. But any particular row can be modified by only one user at a time. We will create a transaction for this purpose. The transaction will call our custom report. This custom report will call the table maintenance generator of the table after deleting table level lock.

In current example let’s create following:

Report: ZREP_SHUKS3

Transaction: ZTEST_SHUKS3

Table: ZTEST_SHUKS3 with table maintenance generator.

Using transaction ZTEST_SHUKS3 we will delete the table level lock and put row level lock so that multiple users can maintain table at same time. Rows locked by one user will not be editable by other user.

1. Create table ZTEST_SHUKS3.

2. Create table maintenance generator for the table.

We will make single screen maintenance for this table. Save it. So finally we have table maintenance code automatically generated in function group ZTEST_SHUKS3.

3. Create lock object EYTSS_E433SH in SE11. Give it name as EZTEST_SHUKS3.

Now save and activate the Lock object. SAP creates two function modules corresponding to lock object for enqueue and dequeue of the table.

4. Now create a report ZREP_SHUKS3 and transaction code ZTEST_SHUKS3 to call this report. This tcode will call table maintenance generator of table ZTEST_SHUKS3 .

5. Normally if a person opens table maintenance generator and tries to maintain the table, no one else can maintain table at the same time. This is because of table level lock by default in SAP. Only one user can maintain any table at a time. In report ZREP_SHUKS3 we will delete the table level lock and put row level lock so that multiple users can maintain table at same time. Rows locked by one user will not be editable by other user. Check the report and comments given below.

*&---------------------------------------------------------------------*
*& Report ZREP_SHUKS3
*&
*&---------------------------------------------------------------------
*& Author : Swetabh Shukla
*& Date : 05/22/2009
*& Description : To delete table level lock from table.
*&---------------------------------------------------------------------*
REPORT zrep_shuks3.

**Selection range for view maintenance
DATA:
BEGIN OF selekttab OCCURS 1. "Selektionsbereich
INCLUDE STRUCTURE vimsellist.
DATA: END OF selekttab,

**Table of inactive CUA functions for view maintenance
BEGIN OF excl_cua_funct OCCURS 1. "inaktive CUA-Fkt bei View-Pflege
INCLUDE STRUCTURE vimexclfun.
DATA: END OF excl_cua_funct.

DATA: lt_enq_del TYPE STANDARD TABLE OF seqg3,
lt_enq_read
TYPE STANDARD TABLE OF seqg7,
lw_enq_read
TYPE seqg7,
lw_enq_del
TYPE seqg3,
lv_subrc
TYPE sy-subrc.

*Read all the lock details in system
CALL FUNCTION 'ENQUE_READ2'
EXPORTING
gclient = sy-mandt
gname =
' '
guname =
'*'
TABLES
enq = lt_enq_read.

*We will search entry for table level lock for our table
LOOP AT lt_enq_read INTO lw_enq_read
WHERE gname EQ 'RSTABLE'
AND garg CS 'ZTEST_SHUKS3'.
MOVE-CORRESPONDING lw_enq_read TO lw_enq_del.
APPEND lw_enq_del TO lt_enq_del.
ENDLOOP.

*Delete table level lock entry for our table
CALL FUNCTION 'ENQUE_DELETE'
EXPORTING
check_upd_requests =
1
IMPORTING
subrc = lv_subrc
TABLES
enq = lt_enq_del.

*Now call the table maintenace generator.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action =
'U'
view_name =
'ZTEST_SHUKS3'
show_selection_popup =
'X'
TABLES
dba_sellist = selekttab
excl_cua_funct = excl_cua_funct.

6. Just one more change in table maintenance screen. Now open table maintenance function group(ZTEST_SHUKS3) in SE80.We know for table maintenance SAP automatically creates code in the function group. Now we will make some modification in that existing code to change the behavior. Open the screen you created through table maintenance and add one module.

Open the screen 0001 and add one module in PBO of the screen as shown in figure below.

Check the code below to be added in the module m_change_locking.

MODULE m_change_locking OUTPUT.
*Call the function module corresponding to the lock object we created
CALL FUNCTION 'ENQUEUE_EZTEST_SHUKS3'
EXPORTING
matnr = ztest_shuks3-matnr
werks = ztest_shuks3-werks
EXCEPTIONS
foreign_lock =
1
system_failure =
2
OTHERS = 3.
IF sy-subrc NE 0.
* row is locked..hence gray..
LOOP AT SCREEN.
screen-input = 0.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
ENDMODULE. " m_change_locking OUTPUT

7. Now we are ready for testing. Call the transaction once and make some entries in table. In below screenshot I have entered some random values. Since we have not maintained any check tables etc, so values may be invalid. That can be taken care in real scenario.

Save data.

Let’s call two sessions of the transaction ZTEST_SHUKS3.

Session 1

In first session we will call the transaction ZTEST_SHUKS3 and try to open some existing values for table maintenance.

Let’s open an existing value material = MAT1 and Plant = 0678.

So the entry opens in change mode.

Now open a second session of the transaction and see. Now the same material and plant combination can not be changed by any other user or session.

Session 2

Open transaction ZTEST_SHUKS3

So we can see that our transaction is able to achieve a row level locking and has removed table level locking.

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

goodsites