Pages

Wednesday, October 6, 2010

MM02 - navigating directly to MRP1 data

Often it is needed to display a default view while navigating from a report output to MM02 or any other Tcode with different views.

Use below code:
SET PARAMETER ID 'MAT' FIELD p_mat-matnr.
SET PARAMETER ID 'WRK' FIELD p_mat-werks.
SET PARAMETER ID 'MXX' FIELD 'D'.
CALL TRANSACTION c_mm02 AND SKIP FIRST SCREEN.

this is basically down based on the following information:

Status (MARA-VPSTA) contains the combination of the View indicator. You can find the relation of the status indicator and view name in the documentation of the data element PSTAT_D or follow this table:

User department Maintenance status

Work scheduling A
Accounting B
Classification C
MRP D
Purchasing E
Production resources/tools F
Costing G
Basic data K
Storage L
Forecasting P
Quality management Q
Warehouse management S
Sales V
Plant stocks X
Storage location stocks Z

Tuesday, October 5, 2010

MM02 BDC – Select Specific Material Master View

Creating a BDC of the MM02 will not be an easy task. As soon as we enter the material and hit enter it will ask us to choose the required Material master views. This popup contains the available material master views and they are not constant. Sometimes MRP1 comes at the 12th line and sometimes it comes to 6th line. This dynamic of the views are solely depended on the Status (MARA-VPSTA).

MM02 BDC

To overcome of this dynamics we need to get to know where exactly our required view will appear e.g. line 6 or line 10 or line 15. We will use the FM SELECTION_VIEWS_FIND to find out which view will come at which position.

In our BDC, we will follow these steps:
1. Always select the Basic Data 1
2. Get the respective user command for the tab by Executing the FM SELECTION_VIEWS_FIND.

Status (MARA-VPSTA) contains the combination of the View indicator. You can find the relation of the status indicator and view name in the documentation of the data element PSTAT_D or follow this table:

User department Maintenance status

Work scheduling A
Accounting B
Classification C
MRP D
Purchasing E
Production resources/tools F
Costing G
Basic data K
Storage L
Forecasting P
Quality management Q
Warehouse management S
Sales V
Plant stocks X
Storage location stocks Z

In this my test BDC, I want to update the MRP type. MRP type comes under the “MRP 1″ view of the material master. So, I will first select the Basic Data and than move to MRP 1 view and update the MRP type.

BDC Code:

REPORT ztest_np_mm02
NO STANDARD PAGE HEADING LINE-SIZE 255.
*
* Local data
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*
* Selection Screen
PARAMETERS: p_matnr TYPE mara-matnr OBLIGATORY,
p_werks TYPE marc-werks OBLIGATORY,
p_lgort TYPE rmmg1-lgort OBLIGATORY,
p_dismm TYPE marc-dismm OBLIGATORY.
*
*
START-OF-SELECTION.
*
* Material views …………………………………………….
DATA: l_vpsta LIKE t130m-pstat.
*
SELECT SINGLE vpsta
INTO l_vpsta
FROM mara
WHERE matnr = p_matnr.
*
* Get View sequence ………………………………………….
DATA: l_bild LIKE t133a-bilds,
lt_bild LIKE mbildtab OCCURS 0 WITH HEADER LINE.
*
* Screen Sequence for Standard Industry tab pages in material master
l_bild = ’21′.
*
* Get screen sequence
CALL FUNCTION ‘SELECTION_VIEWS_FIND’
EXPORTING
bildsequenz = l_bild
pflegestatus = l_vpsta
TABLES
bildtab = lt_bild
EXCEPTIONS
call_wrong = 1
empty_selection = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*
* Get the Tab page for MRP1 …………………………………..
DATA: l_tab_mrp1 TYPE sy-ucomm.
*
* reading table with MRP view
READ TABLE lt_bild WITH KEY pstat = ‘D’.
IF sy-subrc = 0.
l_tab_mrp1 = lt_bild-guifu.
ENDIF.
*
* make ok code for the MRP1
CONCATENATE ‘=’ l_tab_mrp1 INTO l_tab_mrp1.
*
* BDC ………………………………………………………
PERFORM bdc_dynpro USING ‘SAPLMGMM’ ’0060′.
PERFORM bdc_field USING ‘RMMG1-MATNR’
p_matnr.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=ENTR’.
*
PERFORM bdc_dynpro USING ‘SAPLMGMM’ ’0070′.
PERFORM bdc_field USING ‘MSICHTAUSW-KZSEL(01)’
‘X’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=ENTR’.
*
PERFORM bdc_dynpro USING ‘SAPLMGMM’ ’4004′.
PERFORM bdc_field USING ‘BDC_OKCODE’
l_tab_mrp1.
*
PERFORM bdc_dynpro USING ‘SAPLMGMM’ ’0081′.
PERFORM bdc_field USING ‘RMMG1-WERKS’
p_werks.
PERFORM bdc_field USING ‘RMMG1-LGORT’
p_lgort.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=ENTR’.
*
PERFORM bdc_dynpro USING ‘SAPLMGMM’ ’4000′.
PERFORM bdc_field USING ‘MARC-DISMM’
p_dismm.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=BU’.
*
PERFORM bdc_transaction USING ‘MM02′.
*
*&———————————————————————*
*& Form BDC_DYNPRO
*&———————————————————————*
FORM bdc_dynpro USING p_program
p_screen.
*
MOVE: p_program TO bdcdata-program,
p_screen TO bdcdata-dynpro,
‘X’ TO bdcdata-dynbegin.
*
APPEND bdcdata.
CLEAR bdcdata.
*
ENDFORM. ” BDC_DYNPRO
*
*&———————————————————————*
*& Form BDC_FIELD
*&———————————————————————*
FORM bdc_field USING p_field_name
p_field_value.
*
MOVE: p_field_name TO bdcdata-fnam,
p_field_value TO bdcdata-fval.
*
APPEND bdcdata.
CLEAR bdcdata.
*
ENDFORM. ” BDC_FIELD
*
*
*&———————————————————————*
*& Form BDC_TRANSACTION
*&———————————————————————*
FORM bdc_transaction USING tcode.
DATA: l_mstring(480).
DATA: l_subrc LIKE sy-subrc.
* batch input session
REFRESH messtab.
CALL TRANSACTION tcode USING bdcdata
MODE ‘A’
“A: show all dynpros
“E: show dynpro on error only
“N: do not display dynpro
*
UPDATE ‘L’
MESSAGES INTO messtab.
REFRESH bdcdata.
ENDFORM. “BDC_TRANSACTION

Thursday, September 9, 2010

Display Top of page in ALV Function Module

Display top of page in ALV Function module method using the same code as in ALV OOPs method:

Basically we need to use the HTML call back TOP OF PAGE for this. This form uses the CL_DD_DOCUMENT object to publish the top of page. So we just need to create this form and use the same logic we use for OOPs approach.

Usual Code for OOPS approach:

*******************CODE*********************************
*******************CODE*********************************
FORM f_event_top_of_page USING p_dyndoc_id TYPE REF TO cl_dd_document.

* Design the Layout
PERFORM f_design_top_new USING p_dyndoc_id.

* populating data to html control
PERFORM f_html_header USING p_dyndoc_id.


ENDFORM. " EVENT_TOP_OF_PAGE


FORM f_design_top_new USING p_dyndoc_id TYPE REF TO cl_dd_document.

* populating header to top-of-page
PERFORM f_date_to_external USING sy-datum
CHANGING l_ext_date.

* add gap
CALL METHOD p_dyndoc_id->add_gap
EXPORTING
width = 150.

MOVE ' '(001) TO l_text.
"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = l_text
sap_style = cl_dd_area=>heading.

CALL METHOD p_dyndoc_id->underline.

ENDFORM.

FORM f_html_header USING p_dyndoc_id TYPE REF TO cl_dd_document.

* creating html control
IF obj_html_cntrl IS INITIAL.
CREATE OBJECT obj_html_cntrl
EXPORTING
parent = obj_parent_html.
ENDIF.
* reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
document = p_dyndoc_id
bottom = space.
* get top->htmobj_table ready
CALL METHOD p_dyndoc_id->merge_document.
* set wallpaper
CALL METHOD p_dyndoc_id->set_document_background
EXPORTING
picture_id = space.
* connect top document to html-control
p_dyndoc_id->html_control = obj_html_cntrl.
* display top document
CALL METHOD p_dyndoc_id->display_document
EXPORTING
reuse_control = c_x
parent = obj_parent_html
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
MESSAGE i000 WITH 'Error in displaying top-of-page'(035).
ENDIF.

ENDFORM. " F_HTML_HEADER

*******************CODE*********************************
*******************CODE*********************************


Simple ALV FM approach:

*******************CODE*********************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_prog_name
i_callback_user_command = lc_user_cmd
it_fieldcat = gt_fieldcat
i_default = lc_default
I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE'
TABLES
t_outtab = gt_alvrpt
EXCEPTIONS
program_error = 1
OTHERS = 2.

*** Here I have used my own Utility class to create CL_DD_DOCUMENT object
*** The main intension is to develop this Object. It can be done in any way

FORM TOP_OF_PAGE USING p_dyndoc_id TYPE REF TO CL_DD_DOCUMENT.

DATA: obj_sel_opt TYPE REF TO zcl_alv_header_utility,
l_text1 TYPE string.

CREATE OBJECT obj_sel_opt
EXPORTING
p_dyndoc_obj = p_dyndoc_id.

CALL METHOD obj_sel_opt->read_selection_screen
EXPORTING
repid = sy-repid
.

CALL METHOD obj_sel_opt->set_grid_top
EXPORTING
title1 = 'Scheduling Agreement or Contract vs Receipt Tracking'
* title2 =
* title3 =
* title4 =
.
ENDFORM.

*******************CODE*********************************
*******************CODE*********************************

I found out that displaying TOPOFPAGE with ALV FM is much easier than OOPs method.
Like OOPS we need not create any SPLITTER container in FM nor do we need to design the CL_DD_DOCUMENT object and fit it to the top split container.

But as it is said, its always better to hone the latest technique of coding so that our jobs are never at stake; and here OOPs is what SAP will continue polishing as development goes forward.

Friday, September 3, 2010

View on SAP Certification

http://www.jonerp.com/pdf/sap_certification_from_cert5.pdf


http://www.zdnet.com/blog/btl/can-sap-certifications-join-the-big-leagues/33369

Wednesday, September 1, 2010

ALV design Header with Selection screen elements

*----------------------------------------------------------------------*
FORM event_top_of_page USING p_dyndoc_id TYPE REF TO cl_dd_document.

* Design the Layout
PERFORM f_design_top_new USING p_dyndoc_id.

* populating data to html control
PERFORM f_html_header USING p_dyndoc_id.


ENDFORM. " EVENT_TOP_OF_PAGE

************************************************************************

FORM f_design_top_new USING p_dyndoc_id TYPE REF TO cl_dd_document.

DATA obj_area1 TYPE REF TO cl_dd_area.
DATA obj_area2 TYPE REF TO cl_dd_area.
DATA obj_table TYPE REF TO cl_dd_table_element.
DATA obj_col_key TYPE REF TO cl_dd_area.
DATA obj_col_info TYPE REF TO cl_dd_area.
DATA l_text TYPE sdydo_text_element.
DATA:l_ext_date TYPE char10."Date

* populating header to top-of-page
PERFORM f_date_to_external USING sy-datum
CHANGING l_ext_date.

* add gap
CALL METHOD p_dyndoc_id->add_gap
EXPORTING
width = 150.

MOVE 'Tree House Foods'(001) TO l_text.
"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = l_text
sap_style = cl_dd_area=>heading.

CALL METHOD p_dyndoc_id->underline.

* add gap
CALL METHOD p_dyndoc_id->add_gap
EXPORTING
width = 150.

MOVE sy-title TO l_text.
"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

CLEAR l_text.

CALL METHOD p_dyndoc_id->new_line.
* Report Type***********************
IF rb_md06 EQ c_x.
MOVE 'Report based on MRP (MD06)'(s04) TO l_text.
ELSEIF rb_md04 EQ c_x.
MOVE 'Report based on Stock Requirements (MD04)'(032) TO l_text.
ENDIF.

"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'
sap_style = 'SUCCESS'.

CLEAR l_text.

* split of document into up/below
CALL METHOD p_dyndoc_id->horizontal_split
EXPORTING
split_area = p_dyndoc_id
IMPORTING
below_area = obj_area1.

l_text = 'Selection Screen Parameters'(040).
CALL METHOD obj_area1->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'
sap_style = 'TABLE_HEADING'.

* split of below into below_left/below_right
CALL METHOD p_dyndoc_id->horizontal_split
EXPORTING
split_area = obj_area1
IMPORTING
below_area = obj_area2.

CALL METHOD obj_area2->add_table
EXPORTING
no_of_columns = 2
with_heading = ' '
border = '0'
IMPORTING
table = obj_table.

CALL METHOD obj_table->add_column
IMPORTING
column = obj_col_key.

CALL METHOD obj_table->add_column
IMPORTING
column = obj_col_info.


CALL METHOD obj_table->new_row.

l_text = 'Exception message number:'(041).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_auskt.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_auskt-option s_auskt-low s_auskt-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'Plant:'(042).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_plwrk.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_plwrk-option s_plwrk-low s_plwrk-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'Material Number:'(043).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_matnr.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_matnr-option s_matnr-low s_matnr-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'Number of Excp. per Material:'(044).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.

IF p_numex EQ 0.
l_text = 'Unlimited'(045).
ELSE.
l_text = p_numex.
ENDIF.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.

CALL METHOD obj_table->new_row.

l_text = 'Procurement Type:'(046).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_beskz.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_beskz-option s_beskz-low s_beskz-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'MRP Type:'(047).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_dismm.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_dismm-option s_dismm-low s_dismm-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'MRP Controller:'(048).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_dispo.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_dispo-option s_dispo-low s_dispo-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

CALL METHOD obj_table->new_row.

l_text = 'Material Type:'(049).
CALL METHOD obj_col_key->add_text
EXPORTING
text = l_text
sap_emphasis = 'Strong'.

LOOP AT s_mtart.
CALL METHOD obj_col_info->add_gap
EXPORTING
width = 5.
CONCATENATE s_mtart-option s_mtart-low s_mtart-high c_colon INTO l_text
SEPARATED BY space.
CALL METHOD obj_col_info->add_text
EXPORTING
text = l_text.
ENDLOOP.

ENDFORM. " F_DESIGN_TOP_NEW
****************************************************************************

*----------------------------------------------------------------------*
FORM f_html_header USING p_dyndoc_id TYPE REF TO cl_dd_document.

* creating html control
IF obj_html_cntrl IS INITIAL.
CREATE OBJECT obj_html_cntrl
EXPORTING
parent = obj_parent_html.
ENDIF.
* reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
document = p_dyndoc_id
bottom = space.
* get top->htmobj_table ready
CALL METHOD p_dyndoc_id->merge_document.
* set wallpaper
CALL METHOD p_dyndoc_id->set_document_background
EXPORTING
picture_id = space.
* connect top document to html-control
p_dyndoc_id->html_control = obj_html_cntrl.
* display top document
CALL METHOD p_dyndoc_id->display_document
EXPORTING
reuse_control = c_x
parent = obj_parent_html
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
MESSAGE i000 WITH 'Error in displaying top-of-page'(035).
ENDIF.



ENDFORM. " F_HTML_HEADER
*****************************************************************

Tuesday, August 31, 2010

ALV background display as well as foreground

MODULE alv_display OUTPUT.

IF sy-batch NE c_x.

* First Main Container
CREATE OBJECT obj_container
EXPORTING
container_name = 'CC_CONTAINER'.
* Splitter Container
CREATE OBJECT obj_splitter
EXPORTING
parent = obj_container
rows = 2
columns = 1.

* Set the height of Top of page
CALL METHOD obj_splitter->set_row_height
EXPORTING
id = 1
height = 29.

* Place obj_parent_html in First row First column
* for Top_of_page
CALL METHOD obj_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = obj_parent_html.

* Place ALV grid display in Second row First column
CALL METHOD obj_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = obj_parent_grid.

* Create ALV grid Object
CREATE OBJECT obj_grid
EXPORTING
i_parent = obj_parent_grid.

ELSE. "For Background run
* Create ALV grid Object
CREATE OBJECT obj_grid
EXPORTING
i_parent = obj_dock.
ENDIF.

* Create Event handler Object
CREATE OBJECT obj_event.
*
** Set Event Handler for List TOP_OF_PAGE
SET HANDLER obj_event->on_top_of_page FOR obj_grid.
** Set Event Handler for Grid TOP_OF_PAGE
SET HANDLER obj_event->on_grid_top_of_page FOR obj_grid.
** Set Event Handler for Grid END_OF_PAGE
SET HANDLER obj_event->on_END_OF_PAGE FOR obj_grid.
** Set Event Handler for Double Click
SET HANDLER obj_event->handle_double_click FOR obj_grid.

* Call Grid method to display ALV Table
CALL METHOD obj_grid->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'X'
is_layout = wa_layo
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = gt_mat
it_fieldcatalog = gt_fcat
it_sort = gt_sort
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE i000 WITH 'Error in Report Display'(003).
ENDIF.

* Create top-document
CREATE OBJECT obj_dyndoc_id
EXPORTING
style = 'ALV_GRID'.

* Initializing document
CALL METHOD obj_dyndoc_id->initialize_document.

* Processing events
CALL METHOD obj_grid->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = obj_dyndoc_id.

* Refresh ALV object before next display
CALL METHOD obj_grid->refresh_table_display
EXPORTING
is_stable = c_stable.

CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = obj_grid.


ENDMODULE. " ALV_DISPLAY OUTPUT

Normal ALV class Design-Events double click and top-end of page

********************************************************************
* ABAP Name: ZZSCPR044_INMRP_EXCP_CLASS
* Created by: Agnihotro Sinha
* Created on: 08/12/2010.
* Version: 1.0
*------------------------------------------------------------------*
* Modification Log:
* Date Programmer Correction Description
*
********************************************************************

************************************************************************
* Class declarations
************************************************************************
CLASS lcl_event_handler DEFINITION FINAL.
* event receiver definitions for ALV actions
PUBLIC SECTION.
*** Any Event with PREFIX as 'PRINT' is connected to ALV List Display
*** and also gthe event need not be registered with ALV Object
METHODS:
* Handle List output Top-Of-Page
on_top_of_page
FOR EVENT print_top_of_page OF cl_gui_alv_grid,
*Handle grid Top_Of_Page
on_grid_top_of_page
FOR EVENT TOP_OF_PAGE OF cl_gui_alv_grid
IMPORTING
e_dyndoc_id,
* Handle List End of Page
on_end_of_page
FOR EVENT print_END_OF_LIST OF cl_gui_alv_grid,
* Handle Double Click
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
ENDCLASS. "lcl_event_receiver DEFINITION
************************************************************************

CLASS lcl_event_handler IMPLEMENTATION.

* Create the Text to be dispalyed at top of page of ALV List Output
METHOD on_grid_top_of_page.
* top-of-page event for grid Display
PERFORM event_top_of_page USING e_dyndoc_id.
ENDMETHOD. "On_top_of_page

* Create Top_Of_Page display for ALV Grid Output
METHOD on_top_of_page.
* Will be hit only when ALV List Display is called
PERFORM display_list_top.
* e_dyndoc_id = obj_dyndoc_id.
ENDMETHOD. "create_top_of_page
* Create End of Page for List Display
METHOD on_end_of_page.
PERFORM display_list_end.
ENDMETHOD.
* Handle user command for Double Click
METHOD handle_double_click.

* read selected row from internal table gt_sflight
READ TABLE gt_mat INDEX e_row-index INTO wa_mat.
IF sy-subrc eq 0.
PERFORM f_drill_down USING wa_mat e_column.
ENDIF.


ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_receiver IMPLEMENTATION

Thursday, August 5, 2010

Publishing HTML data on Module pool or SAP report screen

1: Create a container in your module pool screen with name "HTML_CONTROL".

2: Create object as below:Point this object to the module pool control using its name
data: html_control TYPE REF TO cl_gui_html_viewer,
my_container TYPE REF TO cl_gui_custom_container.

CREATE OBJECT my_container
EXPORTING
container_name = 'HTML_CONTROL'.

CREATE OBJECT html_control
EXPORTING
parent = my_container.
3: You can load image or text to module pool screen using this OBJECT reference only. An exaple for loading graphics is shown below:

CALL METHOD html_control->load_mime_object
EXPORTING
object_id = 'HTMLCNTL_TESTHTM2_SAPLOGO'
object_url = 'SAPLOGO.GIF'
EXCEPTIONS
OTHERS = 1.


****************
Example program: SAPHTML_EVENTS_DEMO

SAP Marketplace access

Wednesday, August 4, 2010

ALV consistency check

On the grid itself where there is no display, use CTRL+SHIFT+left click.

Sunday, May 9, 2010

An example of how one company, Robert Bosch GmbH, implemented SAP R/3 over 10 years

http://books.google.co.in/books?id=ckHsZUu85VkC&printsec=frontcover&dq=Implementation+Strategies+for+SAP+R/3+in+a+Multinational+Organization&source=bl&ots=Ye4uYvp3B5&sig=_INuLhWsfXlaFyzsVMUeFFetIS0&hl=en&ei=xKnnS8ehCo61rAeIluCGAw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBYQ6AEwAA#v=onepage&q&f=false

Tuesday, May 4, 2010

ALV cell coloring

In this procedure, again we must tell the control the name of the inner table containing color data. The field “CTAB_FNAME” of the layout structure is used for this purpose.
Code Part 14 – Adding inner table that will contain cell color data
*--- Internal table holding list data
DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
DATA rowcolor(4) TYPE c .
DATA cellcolors TYPE lvc_t_scol .
DATA END OF gt_list .
DATA ls_cellcolor TYPE lvc_s_scol .
...
READ TABLE gt_list INDEX 5 .
ls_cellcolor-fname = 'SEATSOCC' .
ls_cellcolor-color-col = '7' .
ls_cellcolor-color-int = '1' .
APPEND ls_cellcolor TO gt_list-cellcolors .
MODIFY gt_list INDEX 5 .
Code Part 15 – A sample code to make the cell at row 5 and column ‘SEATSOCC’ colored
A juicy-brained guy may ask what happens if all these three procedures applied for coloring at

Sunday, April 4, 2010

Download Internal Table to Excel with headers

lv_del = cl_abap_char_utilities=>horizontal_tab.

lv_file = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = lv_file
filetype = c_ftype_asc
* APPEND = ' '
write_field_separator = lv_del
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* trunc_trailing_blanks_eol =
* IMPORTING
* FILELENGTH =
TABLES
data_tab = p_table
fieldnames = p_heading
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE i003 WITH 'File downloaded successfully:'(i04) lv_file.
ENDIF.
***********************************

Header Part.
We need to populate header data just like field catalog and pass the header details internal table to the Download FM above. Here we have passed P_HEADER which has been built in the following ways:

wa_header-fname = 'Reason'(r16).
APPEND wa_header TO p_header.
CLEAR wa_header.

wa_header-fname = 'ZPID'(r02).
APPEND wa_header TO p_header.
CLEAR wa_header.
*****************************

Do Varying usage

DATA: lv_subty TYPE subty,
lv_lgaxx TYPE lgart,
lv_betxx TYPE pad_amt7s.

* Extract PERNR Wage-type details from IT9027
**********************************************
lv_subty = '0'."Read SUBTYPE 0 only as it hold the valid record
"Read Infotype Table
SELECT * FROM pa9027
INTO TABLE it_9027
WHERE pernr EQ p0008-pernr
AND subty EQ lv_subty. "#EC CI_SGLSELECT
"If data found in IT9027
IF sy-subrc EQ 0.
"Delete all other reason code entries from Table
DELETE it_9027 WHERE preas NE c_prog_reason.
"Bring the latest record at top
SORT it_9027 BY endda DESCENDING.
"Read latest record
READ TABLE it_9027 INTO wa_9027 INDEX 1.
"If data found
IF sy-subrc EQ 0.
"Read work area row for all Wage type values
DO 40 TIMES VARYING lv_lgaxx FROM wa_9027-lga01 NEXT wa_9027-lga02
VARYING lv_betxx FROM wa_9027-bet01 NEXT wa_9027-bet02.
"Read only Annual Salary Wage types (Refer view V_T539J)
"NOTE: As of now 1000,2NPY and 1NPY make up the Annual Salary
wa_wage_tab-pernr = p0008-pernr.
CASE lv_lgaxx.
WHEN c_wage_type_1.
gv_1000 = lv_betxx. "Store Amount per Wage-Type
WHEN c_wage_type_2.
gv_2npy = lv_betxx."Store Amount per Wage-Type
WHEN c_wage_type_3.
gv_1100 = lv_betxx."Store Amount per Wage-Type
WHEN c_wage_type_4.
gv_1npy = lv_betxx."Store Amount per Wage-Type
WHEN c_wage_type_5.
gv_1005 = lv_betxx."Store Amount per Wage-Type
WHEN c_wage_type_6.
gv_mf02 = lv_betxx."Store Amount per Wage-Type
WHEN c_wage_type_7.
gv_mf04 = lv_betxx."Store Amount per Wage-Type
WHEN OTHERS.
"do nothing as only previous Wate-Type should be considered
ENDCASE.
ENDDO.
ENDIF.

* Calculate share of Annual Salary Amount per Wage-Type
*******************************************************

PERFORM get_wagetype_share USING p_oldsal p_newsal c_wage_type_1
CHANGING gv_1000.
PERFORM get_wagetype_share USING p_oldsal p_newsal c_wage_type_2
CHANGING gv_2npy.

Convert Date to external format

FORM date_to_external CHANGING p_input TYPE sy-datum
p_output TYPE char10.

IF p_input+4(2) GE '13'.
p_input+0(4) = p_input+0(4) + 1."Increment Year
ENDIF.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = p_input
IMPORTING
date_external = p_output
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
p_output = p_input.
ENDIF.


ENDFORM. " DATE_TO_EXTERNAL

Date FM: to get difference between 2 dates in different formats

* Check difference between Input Date and current date

*Program should pay attention to only the month and the year
************************************************************
CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
EXPORTING
begda = p_input_dt
endda = p_check_dt
* TAB_MODE = ' '
IMPORTING
* DAYS =
* C_WEEKS =
c_months = lv_months
c_years = lv_years
* WEEKS =
* MONTHS =
* YEARS =
* D_MONTHS =
* MONTH_TAB =
.