Go on link..

link us with ...

Showing posts with label Selection Screen. Show all posts
Showing posts with label Selection Screen. Show all posts

Monday, January 3, 2011

Dynamic Parameter in Selection Screen

n the last post Dynamic Parameter Texts in Selection Screen (which was so many weeks ago), we discussed how we can change the selection screen parameter by changing the values of some selection screen specific variables. Greets Enno suggested to use the FM SELECTION_TEXTS_MODIFY to handle the selection screen parameters more easily and in standard way.

Some of the readers also left comment on the previous post about the use of this trick. One scenario I came in my mind: Certain Parameter Texts based on the Radio button selection. E.g. We have some radio buttons like Sales Order, Credit Memo, Debit Memo and so on. Based on this radiobutton selection, we want to display the Date's parameter text.

This code snippet will realize this scenario using the FM SELECTION_TEXTS_MODIFY.
Code Snippet to show dynamic parameter text


*&---------------------------------------------------------------------*
*& Report ZTEST_NP_HELPER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZTEST_NP_HELPER.

*----------------------------------------------------------------------*
* Selection Screen Class definition
*----------------------------------------------------------------------*
class lcl_selscr DEFINITION.

PUBLIC SECTION.
class-DATA:
f_date_Text type char30.

CLASS-METHODS:
set_text
IMPORTING
if_name type char8
if_type type char1
if_text type char30,

change_screen.

PRIVATE SECTION.
class-DATA:
t_text type STANDARD TABLE OF RSSELTEXTS.

ENDCLASS. "lcl_selscr DEFINITION

*.... Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
PARAMETERS: p_so RADIOBUTTON GROUP rd1 DEFAULT 'X' USER-COMMAND USR1,
p_cre RADIOBUTTON GROUP rd1,
p_deb RADIOBUTTON GROUP rd1.
PARAMETERS: p_date type datum.
SELECTION-SCREEN: end of BLOCK blk1.

*.... Initialization
INITIALIZATION.
aaa = 'Select an option to continue'.

*.... At Selection-Screen Output
at SELECTION-SCREEN OUTPUT.
* text for Radiobuttons
lcl_selscr=>set_text( if_name = 'P_SO' if_type = 'P' if_TEXT = 'Sales Order' ).
lcl_selscr=>set_text( if_NAME = 'P_CRE' if_type = 'P' if_text = 'Credit memo' ).
lcl_selscr=>set_text( if_NAME = 'P_DEB' if_type = 'P' if_TEXT = 'Debit memo' ).

* determine the text for the P_DATE
CASE 'X'.
WHEN p_so. lcl_selscr=>f_date_text = 'Sales Order Entry Date'.
WHEN p_cre. lcl_selscr=>f_date_text = 'Credit Memo Entry Date'.
WHEN p_deb. lcl_selscr=>f_date_text = 'Debit Memo Entry Date'.
ENDCASE.
lcl_selscr=>set_text( if_name = 'P_DATE' if_type = 'P' if_TEXT = lcl_selscr=>f_date_text ).

* Change the Selection Screen
lcl_selscr=>change_screen( ).

*.... Start of selection
START-OF-SELECTION.
WRITE: 'Date Text', lcl_selscr=>f_date_text.

*----------------------------------------------------------------------*
* Selection Screen Class definition
*----------------------------------------------------------------------*
CLASS lcl_selscr IMPLEMENTATION.

METHOD set_text.
data: la_text LIKE LINE OF t_Text.

la_text-name = if_name.
la_text-KIND = if_type.
la_text-text = if_text.
APPEND la_text to t_text.

ENDMETHOD. "set_text

METHOD change_screen.
CALL FUNCTION 'SELECTION_TEXTS_MODIFY'
EXPORTING
PROGRAM = sy-cprog
TABLES
SELTEXTS = t_text.
ENDMETHOD. "change_screen

ENDCLASS. "lcl_selscr IMPLEMENTATION


2. Selection Screen Parameter Text by coding


Sometimes, we need to dispaly the Dynamic Parameter Text for the parameters in the selection screen.

We can use %_parameter_%_APP_%-TEXT to have the parameter text from the coding.

Code Snippet to show dynamic parameter text
  
*---------------------------------------------------------------------
* Shows how to give the selection screen parameter name by
* using coding
*---------------------------------------------------------------------
REPORT ZTEST_NP_TMP.
*
DATA: w_carrid TYPE sflight-carrid.
*
** Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
SELECT-OPTIONS: s_carrid FOR w_carrid.
SELECTION-SCREEN: END OF BLOCK blk1.
*
INITIALIZATION.
* Description for the parameter
if sy-uname = 'TEST'.
%_s_carrid_%_app_%-text = 'Carrier ID'.
else.
%_s_carrid_%_app_%-text = 'Flight ID'.
endif.


Without the code, we would see the selection screen like this:



And with the code, selection screen would be like this:


We can use this trik:
* Dyanmic Parameter text
* While Sharing the example code

Display ALV report output in the SAME Selection Screen

After a lot of analysis (and of course Trials-&-Errors), I found the solution which requires minimal development. Before giving the solution, check out how it looks-

When we start running the report, it will be a normal Selection Screen:


After executing the report, our output will overlay on the Selection Screen. And it will look like this:


Doesn't it look good ?

Journey to find the solution:
After reading the problem in the thread, suddenly I got a strike: Why not to create a Docking Container and place the ALV inside it..!!

I have started with placing the docking container in the INITIALIZATION event and the code to generate the ALV in the START-OF-SELECTION event. In this try, I got the docking container on the selection screen but no ALV inside of that docking container. Than I realize that I missed on of the basics of report programming - as soon as control goes to INITALIZATION all memory allocation will be destroyed and global data will be initialized. That's why I was not getting the ALV in the docking container. Selection screen was looking like this:


So, I moved the ALV logic in the INITALIZATION event. After this try, I got the Docking container with the empty ALV - ALV with the field catalog but no Data. Here again, I have the same problem - all my data allocation got destroyed as soon as control come to INITALIZATION event. To overcome this I used the ABAP local memory. I exported my output table and imported back it into the INITALIZATION to initialize my ALV. Selection-screen was looking like this:


Here is the code which will generate the output as shown in the second picture.
Code Snippet to Display ALV output on the Selection Screen
  
*&---------------------------------------------------------------------*
*& Generates the ALV on the Selection Screen itself
*&
*&---------------------------------------------------------------------*
REPORT zalv_on_sel_screen.
*
*----------------------------------------------------------------------*
* Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
PUBLIC SECTION.
*
DATA: t_data TYPE STANDARD TABLE OF sflight, " Output dat
r_carrid TYPE RANGE OF sflight-carrid. " Select Option
*
METHODS:
get_data,
*
generate_output.
*
ENDCLASS. "lcl_report DEFINITION
*
DATA: lo_report TYPE REF TO lcl_report.
*
DATA: w_carrid TYPE sflight-carrid.
*
** Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
SELECT-OPTIONS: s_carrid FOR w_carrid.
SELECTION-SCREEN: END OF BLOCK blk1.
*
** Initialization
INITIALIZATION.
aaa = 'Selection Criteria'.
* object for the report
CREATE OBJECT lo_report.
* generate output
lo_report->generate_output( ).
*
** Start of Selection
START-OF-SELECTION.
* Get data
lo_report->r_carrid = s_carrid[].
lo_report->get_data( ).
*
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
METHOD get_data.
*
* data selection
SELECT * FROM sflight
INTO TABLE me->t_data
WHERE carrid IN s_carrid.
IF sy-dbcnt IS INITIAL.
MESSAGE s398(00) WITH 'No data selected'.
ENDIF.
*
* export to memory
EXPORT data = me->t_data TO MEMORY ID sy-cprog.
*
ENDMETHOD. "get_data
*
METHOD generate_output.
*
* local data
DATA: lo_dock TYPE REF TO cl_gui_docking_container,
lo_cont TYPE REF TO cl_gui_container,
lo_alv TYPE REF TO cl_salv_table.
*
* import output table from the memory and free afterwards
IMPORT data = me->t_data FROM MEMORY ID sy-cprog.
FREE MEMORY ID sy-cprog.
*
* Only if there is some data
CHECK me->t_data IS NOT INITIAL.
*
* Create a docking control at bottom
CHECK lo_dock IS INITIAL.
CREATE OBJECT lo_dock
EXPORTING
repid = sy-cprog
dynnr = sy-dynnr
ratio = 80
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCK_CONT'.
IF sy-subrc <> 0.
MESSAGE 'Error in the Docking control' TYPE 'S'.
ENDIF.
*
* Create a SALV for output
CHECK lo_alv IS INITIAL.
TRY.
* Narrow Casting: To initialize custom container from
* docking container
lo_cont ?= lo_dock.
*
* SALV Table Display on the Docking container
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
r_container = lo_cont
container_name = 'DOCK_CONT'
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = me->t_data.
CATCH cx_salv_msg .
ENDTRY.
*
* Pf status
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
lo_functions = lo_alv->get_functions( ).
lo_functions->set_default( abap_true ).
*
* output display
lo_alv->display( ).
*
ENDMETHOD. "generate_output
*
ENDCLASS. "lcl_report IMPLEMENTATION


Steps to create an ALV on the Selection Screen, in summary :
  • Create docking container in the INITALIZATION event
  • Create ALV on that Docking container
  • After selecting all the data, export output table to ABAP memory
  • Before generating the output, import the output table from the memroy
  • link us...

    For Visitors

    if you want to publish or Add something on ERP, SAP , SAP FUNCTIONAL, SAP ABAP then mail us along with your email-id. contain must be yours

    email-id :- avinashkr_raj@yahoo.com(any email)

    email-id :- avinaskr_raj.abap@blogger.com ( use only gmail)