Thursday, July 31, 2008

Simple ALV GRID (Full screen)

By Joyjit Ghosh,
Kolkata, India.

REPORT z_alv_object_1.

DATA: i_mara TYPE STANDARD TABLE OF mara.
DATA: dref TYPE REF TO cl_salv_table.


*&---------------------------------------------------------------------*
*& Start-of-selection event
*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Fetch data from database
SELECT * FROM mara
INTO TABLE i_mara
UP TO 100 ROWS.

CHECK sy-subrc = 0.

* Get the ALV instance
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>TRUE
* r_container =
* container_name =
IMPORTING
r_salv_table = dref
CHANGING
t_table = i_mara
.
CATCH cx_salv_msg .
MESSAGE i000(z_zzz_ca_messages)
WITH 'Error in ALV processing'(001).

LEAVE LIST-PROCESSING.
ENDTRY.

IF dref IS BOUND.

* Display AlV report
CALL METHOD dref->display( ).

ENDIF.

Wednesday, July 30, 2008

Execute report from sap mail

By Joyjit Ghosh,
Kolkata, India.

*&---------------------------------------------------------------------*
*& Report Z_DEMO_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z_demo_mail.


*&---------------------------------------------------------------------*
*& Global data declaration
*&---------------------------------------------------------------------*

DATA:
w_document_data LIKE sodocchgi1.

DATA:
i_object_header TYPE STANDARD TABLE OF solisti1,
w_object_header TYPE solisti1,

i_object_content TYPE STANDARD TABLE OF solisti1,
w_object_content TYPE solisti1,

i_contents_hex TYPE STANDARD TABLE OF solix,
w_contents_hex TYPE solix,

i_object_para TYPE STANDARD TABLE OF soparai1,
w_object_para TYPE soparai1,

i_object_parb TYPE STANDARD TABLE OF soparbi1,
w_object_parb TYPE soparbi1,

i_receivers TYPE STANDARD TABLE OF somlreci1,
w_receivers TYPE somlreci1.

*&---------------------------------------------------------------------*
*& Selection screen
*&---------------------------------------------------------------------*
PARAMETER : uname TYPE syuname DEFAULT sy-uname.

*&---------------------------------------------------------------------*
*& Start-of-selection event
*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Populate receiver info
clear: w_receivers.
w_receivers-receiver = uname.
w_receivers-rec_type = 'B'.
append w_receivers to i_receivers.

* Populate header data
w_document_data-obj_name = 'Your action required'.
w_document_data-obj_descr = 'Pl. press execute button'.
w_document_data-sensitivty = 'O'.
w_document_data-proc_type = 'R'.
w_document_data-proc_name = 'RSINCL00'.


* Populate mail content
clear: w_object_content.
concatenate 'Please execute report: '
w_document_data-proc_name
into w_object_content-line separated by space.
append w_object_content to i_object_content.


CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_document_data
DOCUMENT_TYPE = 'RAW'
* PUT_IN_OUTBOX = ' '
* COMMIT_WORK = ' '
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
tables
* OBJECT_HEADER =
OBJECT_CONTENT = i_object_content
* CONTENTS_HEX =
OBJECT_PARA = i_object_para
* OBJECT_PARB =
receivers = i_receivers
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF sy-subrc = 0.
message s000(z_zzz_ca_messages)
with 'Mail send successfully'(001).
ENDIF.

Sunday, July 27, 2008

Changing font style in ALV

By Joyjit Ghosh,
Kolkata, India.

By using the Function Module REUSE_ALV_GRID_DISPLAY_LVC we can change the font style in ALV report.

Example:

*&---------------------------------------------------------------------*

*& Report Z_DEMO_ALV_JG *

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------

REPORT z_demo_alv_jg .

* Include for all style values

INCLUDE <cl_alv_control>.

* Internal table for final output data

DATA: i_flight TYPE STANDARD TABLE OF sflight.

* Internal table for field catalog info

DATA: i_fields TYPE lvc_t_fcat.

* Field symbol for field catalog

FIELD-SYMBOLS: <wa_fields> TYPE lvc_s_fcat.

* Select data

SELECT * FROM sflight

INTO TABLE i_flight

UP TO 100 ROWS.

IF sy-subrc = 0.

* Get field catalog

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = i_fields

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3

.

IF sy-subrc = 0.

* Changing the style of field catalog

LOOP AT i_fields ASSIGNING <wa_fields>.

IF sy-tabix > 4.

<wa_fields>-style = ALV_STYLE_FONT_ITALIC.

ELSE.

<wa_fields>-style = ALV_STYLE_FONT_BOLD.

ENDIF.

ENDLOOP.

ENDIF.

* Calling the FM to display ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

i_structure_name = 'SFLIGHT'

i_grid_title = 'Style demo'(001)

it_fieldcat_lvc = i_fields

TABLES

t_outtab = i_flight

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.

ENDIF.

Output:



Saturday, July 26, 2008

Add custom sub-menu in ALV context menu

By Joyjit Ghosh,
Kolkata
, India
.

Code:

REPORT z_alv_context_menu NO STANDARD PAGE HEADING.

***********************************************************************
* Type pool declaration
***********************************************************************

TYPE-POOLS: slis.

***********************************************************************
* Internal table declaration
***********************************************************************

DATA: BEGIN OF gt_outtab OCCURS 0.

INCLUDE STRUCTURE sflight.

DATA: END OF gt_outtab.

data: gt_events TYPE slis_t_event.

**********************************************************************
* Structure / Variable declaration
**********************************************************************

DATA: g_repid LIKE sy-repid,

event TYPE slis_alv_event.

**********************************************************************
* Event: START-OF-SELECTION
**********************************************************************

START-OF-SELECTION.

* Storing the program name
g_repid = sy-repid.

* Building ALV event table
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 4

IMPORTING

et_events = gt_events

EXCEPTIONS

list_type_wrong = 1

OTHERS = 2.

IF sy-subrc = 0.

REFRESH gt_events.

* Adding records for CONTEXT_MENU event
event-name = 'CONTEXT_MENU'.

event-form = 'CONTEXT_MENU'.

APPEND event TO gt_events.

ENDIF.

* Data Selection
SELECT * FROM sflight INTO CORRESPONDING FIELDS

OF TABLE gt_outtab

UP TO 00030 ROWS.

* Display ALV grid
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'

i_callback_program = g_repid

i_callback_user_command = 'USER_COMMAND'

i_structure_name = 'SFLIGHT'

it_events = gt_events

TABLES

t_outtab = gt_outtab

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 html_top_of_page
***********************************************************************

FORM html_top_of_page USING top TYPE REF TO cl_dd_document.

CALL METHOD top->add_text

EXPORTING

text = 'Hello world '

sap_style = 'heading'.

CALL METHOD top->add_gap

EXPORTING

width = 200.

CALL METHOD top->add_picture

EXPORTING

picture_id = 'ENJOYSAP_LOGO'.

ENDFORM. "html_top_of_page

***********************************************************************
* Form context_menu
***********************************************************************

FORM context_menu USING e_object TYPE REF TO cl_ctmenu.

DATA: l_smenu TYPE REF TO cl_ctmenu.

IF e_object IS BOUND.

* Create custom Sub-menu to hide column on which right
* mouse button will be clicked

CREATE OBJECT l_smenu.

CALL METHOD l_smenu->add_function

EXPORTING

fcode = 'ZFN1'

text = 'Hide Column'(001).

CALL METHOD e_object->add_submenu

EXPORTING

menu = l_smenu

text = 'Hide'(002).

ENDIF.

ENDFORM. "CONTEXT_MENU

***********************************************************************
* Form user_command
***********************************************************************

FORM user_command USING r_ucomm TYPE sy-ucomm

ls_selfield TYPE slis_selfield.

DATA: g_grid TYPE REF TO cl_gui_alv_grid,

t_catalog TYPE lvc_t_fcat,

w_catalog TYPE lvc_s_fcat,

l_repid TYPE sy-repid.

CASE r_ucomm.


* When 'hide column' sub-menu is clicked from the context menu
* then hide the column from where this is happened

WHEN 'ZFN1'.

* Get the global instance of the ALV grid as well as
* it's field catalog info.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING

e_callback_program = l_repid

e_grid = g_grid

et_fieldcat_lvc = t_catalog.

CHECK l_repid = g_repid.

IF g_grid IS BOUND AND t_catalog[] IS NOT INITIAL.

* Set the 'NO_OUT' attribute of the catalog to 'X'
w_catalog-no_out = 'X'.

* Modify the field with this above value
* on which right click occured

MODIFY t_catalog FROM w_catalog TRANSPORTING no_out

WHERE fieldname = ls_selfield-fieldname.

IF sy-subrc = 0.

* Set the field catalog with this modified one
CALL METHOD g_grid->set_frontend_fieldcatalog

EXPORTING

it_fieldcatalog = t_catalog.

ENDIF.

ENDIF.

WHEN OTHERS.

* Do nothing

ENDCASE.

ls_selfield-refresh = 'X'.

ENDFORM. "USER_COMMAND

Output:



Problem with ALV grid Top of Page

By Joyjit Ghosh,
Kolkata, India.


Problem:

Normally in ALV grid TOP_OF_PAGE, we cannot display information of more than 60 characters long. This is due to the limitation of the FM REUSE_ALV_COMMENTARY_WRITE. Usually we call this FM from the subroutine that is linked with TOP_OF_PAGE event.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary =

i_logo =

i_end_of_list_grid =

.

*"----------------------------------------------------------------------

*"*"Lokale Schnittstelle:

*" IMPORTING

*" VALUE(IT_LIST_COMMENTARY) TYPE SLIS_T_LISTHEADER

*" REFERENCE(I_LOGO) OPTIONAL

*" REFERENCE(I_END_OF_LIST_GRID) OPTIONAL

*"----------------------------------------------------------------------

In this above FM, exporting parameter ‘IT_LIST_COMMENTARY’ contains a field ‘INFO’ that is only 60 characters long. And it is responsible for displaying the information in the TOP_OF_PAGE area.

Solution:

To overcome this limitation we can use dynamic document which can be implemented through the class CL_DD_DOCUMENT. As dynamic documents use HTML viewer control so instead of triggering the TOP_OF_PAGE event we should trigger event of HTML TOP_OF_PAGE.

First create a subroutine for top of page in HTML format and send that name in I_CALLBACK_HTML_TOP_OF_PAGE parameter of ALV function module. The input parameter for this subroutine will be a variable of class CL_DD_DOCUMENT.

*---------------------------------------------------------------------*
* FORM html_top_of_page *
*---------------------------------------------------------------------*

FORM html_top_of_page USING top TYPE REF TO cl_dd_document.

data: l_text(255) type c.

do 180 times.

l_text+sy-index(1) = '*'.

enddo.

CALL METHOD top->add_text EXPORTING text = 'Hello world '

sap_style = 'heading' .

CALL METHOD top->add_gap EXPORTING width = 200.

CALL METHOD top->add_picture EXPORTING picture_id = 'ENJOYSAP_LOGO'.

CALL METHOD top->NEW_LINE( ).

CALL METHOD top->add_text EXPORTING

text = l_text.

ENDFORM.

* Display ALV grid

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'

i_callback_program = g_repid

i_structure_name = 'SFLIGHT'

TABLES

t_outtab = gt_outtab.


Output:

Limitations:

As dynamic documents use SAP HTML Viewer control internally, so whatever limitations exist for SAP HTML Viewer, same limitations hold true for dynamic documents also.


Display total text in ALV using class

By Joyjit Ghosh,
Kolkata, India
.

We had one requirement where we need to display Total text in ALV grid using oops concept. To achieve it we did following things:

1. Added one extra field in the ALV output table and populated it with a constant value (This is nothing but the text that need to be displayed as Total text) for all the records.

2. Hide this field in field catalog level

3. Populated the sort table for ALV with this field and enable subtotal display for it.

4. Hide total line display in ALV by passing appropriate value in the Layout structure.

As this extra field contains constant value for all the records so subtotal on it is equivalent to total for rest of the fields.

Ex:


Code:

*&---------------------------------------------------------------------*
*& Report Z_ALV_DEMO_TOTAL_TEXT
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*

REPORT z_alv_demo_total_text.

* Type declaration for final table to display the output
TYPES: BEGIN OF ty_mara,

srno TYPE char40, " Storing the total text

matnr TYPE matnr, " Material

ersda TYPE ersda, " Creation date

ernam TYPE ernam, " Created by

laeda TYPE laeda, " Last change date

aenam TYPE aenam, " Last change by

vpsta TYPE vpsta, " Maintenance status

brgew TYPE brgew, " Gross weight

ntgew TYPE ntgew, " Net weight

gewei TYPE gewei, " Weight Unit

END OF ty_mara.

* Type declaration for table storing temp. data
TYPES: BEGIN OF ty_mara_tmp,

matnr TYPE matnr, " Material

ersda TYPE ersda, " Creation date

ernam TYPE ernam, " Created by

laeda TYPE laeda, " Last change date

aenam TYPE aenam, " Last change by

vpsta TYPE vpsta, " Maintenance status

brgew TYPE brgew, " Gross weight

ntgew TYPE ntgew, " Net weight

gewei TYPE gewei, " Weight Unit

END OF ty_mara_tmp.

* Internal table for storing final data
DATA: i_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 0.

* Work area for final table
DATA: w_mara TYPE ty_mara.

* Internal table for storing temp. data
DATA: i_mara_tmp TYPE STANDARD TABLE OF ty_mara_tmp INITIAL SIZE 0.

* Work area for temp. table
DATA: w_mara_tmp TYPE ty_mara_tmp.

* Object variable for ALV grid
DATA: oref1 TYPE REF TO cl_gui_alv_grid.

* Field catalog table for ALV grid
DATA: fieldcat TYPE lvc_t_fcat.

* Workarea for field catalog table
DATA: w_field TYPE lvc_s_fcat.

* Internal table for storing info. for ALV grid
data: i_sort2 TYPE STANDARD TABLE OF lvc_s_sort INITIAL SIZE 0.

* Workarea for sort table
DATA: wa_sort2 TYPE lvc_s_sort.

* Workarea for ALV layout
data: wa_layout TYPE lvc_s_layo.

START-OF-SELECTION.

* Fetch data
SELECT matnr " Material

ersda " Creation date

ernam " Created by

laeda " Last change date

aenam " Last change by

vpsta " Maintenance status

brgew " Gross weight

ntgew " Net weight

gewei " Weight Unit

FROM mara

INTO TABLE i_mara_tmp

UP TO 100 ROWS.

CHECK sy-subrc = 0.

* Populate final table
LOOP AT i_mara_tmp INTO w_mara_tmp.

* Storing the Total text need to be displayed in
* ALV

w_mara-srno = 'Total weight (Gross & Net)'.

w_mara-matnr = w_mara_tmp-matnr.

w_mara-ersda = w_mara_tmp-ersda.

w_mara-ernam = w_mara_tmp-ernam .

w_mara-laeda = w_mara_tmp-laeda.

w_mara-aenam = w_mara_tmp-aenam.

w_mara-vpsta = w_mara_tmp-vpsta.

w_mara-brgew = w_mara_tmp-brgew.

w_mara-ntgew = w_mara_tmp-ntgew.

w_mara-gewei = w_mara_tmp-gewei.

APPEND w_mara TO i_mara.

ENDLOOP.

* Calling the screen to display ALV

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* Display ALV report
*----------------------------------------------------------------------*

MODULE status_0100 OUTPUT.

IF oref1 IS INITIAL.

* Create ALV grid object

* In this case we have not created any custom container in the screen,

* Instead of that dummy container name is passed

* ADVANTAGE: we can run this report in background without any problem

CREATE OBJECT oref1

EXPORTING

i_parent = cl_gui_custom_container=>screen0

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5
.

CHECK sy-subrc = 0.

* Preparing the field catalog

* ZDEMO: Defined in DDIC, it's structure is same as TYPE ty_mara

* defined in the program

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'ZDEMO'

CHANGING

ct_fieldcat = fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc = 0.

LOOP AT fieldcat INTO w_field.

IF w_field-fieldname = 'BRGEW' OR

w_field-fieldname = 'NTGEW'.

* Summation for Gross & Net weight

w_field-do_sum = 'X'.

MODIFY fieldcat FROM w_field TRANSPORTING do_sum.

ENDIF.

IF w_field-fieldname = 'SRNO'.

* Hide this field so that it can display it's content i.e.

* Total text in Subtotal level

w_field-tech = 'X'.

w_field-no_out = 'X'.

MODIFY fieldcat FROM w_field TRANSPORTING tech no_out.

ENDIF.

CLEAR w_field.

ENDLOOP.

ENDIF.

* Populate Sort table with SRNO field so that we can display the total

* text in it's subtotal level

wa_sort2-spos = 1.

wa_sort2-fieldname = 'SRNO'.

wa_sort2-up = 'X'.

wa_sort2-subtot = 'X'.

APPEND wa_sort2 TO i_sort2.

* Hide the total line

wa_layout-no_totline = 'X'.

* Display the ALV grid

CALL METHOD oref1->set_table_for_first_display

EXPORTING

is_layout = wa_layout

CHANGING

it_outtab = i_mara[]

it_fieldcatalog = fieldcat

it_sort = i_sort2

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

* Set the focus on the grid

CALL METHOD cl_gui_alv_grid=>set_focus

EXPORTING

control = oref1

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

ENDIF.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

Output:

Wednesday, July 23, 2008

How to maintain Pattern

By Joyjit Ghosh,
Kolkata, India.


From transaction SE38 follow the menu path as shown in the screen shot and click on Create pattern sub menu .

Note: You can change, display or delete a pattern from the same menu path as shown here.

Next enter the pattern name.

Now in the next screen enter the pattern content that you want to define and press save button.

Now go back to the program editor and press pattern button for inserting the newly created pattern in the program.

In the next popup screen choose the Other pattern radio button and press enter.

Now from the generated list double click on the pattern that we have created above.

Pattern content will be inserted in the program.

Tuesday, July 22, 2008

Adding custom context menu in classical list

By Joyjit Ghosh,
Kolkata
, India
.

Code:

*&---------------------------------------------------------------------*
*& Report Z_CONTEXT_MENU_DEMO
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

REPORT z_context_menu_demo.

* Table declaration
DATA: i_vbak TYPE STANDARD TABLE OF vbak INITIAL SIZE 0,
i_vbap TYPE STANDARD TABLE OF vbap INITIAL SIZE 0.

* Workarea declaration
DATA: w_vbak TYPE vbak,
w_vbap TYPE vbap.

START-OF-SELECTION.

* Set custom status
SET PF-STATUS 'BASIC'.

* Fetch header data
SELECT * FROM vbak

INTO TABLE i_vbak

UP TO 50 ROWS.

IF sy-subrc = 0.

* Fetch line item data

SELECT * FROM vbap

INTO TABLE i_vbap

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln.

CHECK sy-subrc = 0.

* Display basic list

LOOP AT i_vbak INTO w_vbak.

FORMAT COLOR COL_HEADING.

WRITE : /10 w_vbak-vbeln,

20 w_vbak-erdat,

35 w_vbak-erzet,

55 w_vbak-ernam.

HIDE: w_vbak-vbeln.

ENDLOOP.

ENDIF.

AT USER-COMMAND.

* Handle user command
CASE sy-ucomm.

WHEN 'DETAIL'.

CHECK NOT w_vbak IS INITIAL.

* Display detail list

LOOP AT i_vbap INTO w_vbap WHERE vbeln =

w_vbak-vbeln.

FORMAT COLOR COL_HEADING.

WRITE : /10 w_vbap-vbeln,

25 w_vbap-posnr,

35 w_vbap-matnr,

55 w_vbap-matwa.

ENDLOOP.

WINDOW STARTING AT 20 20

ENDING AT 120 110.

ENDCASE.

*&---------------------------------------------------------------------*
*& Form on_ctmenu_request
*&---------------------------------------------------------------------*
* Creation of custom context menu- It is called dynamically
* by ABAP runtime
*----------------------------------------------------------------------*
* -->L_MENU Handle for context menu
*----------------------------------------------------------------------*

FORM on_ctmenu_request USING l_menu TYPE REF TO cl_ctmenu.


DATA lin TYPE i.

GET CURSOR LINE lin.

IF lin > 2 AND sy-lsind = 0.

* Add menu
CALL METHOD l_menu->add_function
EXPORTING
fcode = 'DETAIL'
text = text-001.

ENDIF.

* Add menu
CALL METHOD l_menu->add_function

EXPORTING

fcode = 'BACK'

text = text-002.

ENDFORM. "on_ctmenu_request

How SAP calls the routine ON_CTMENU_REQUEST:

Whenever user presses right mouse button or shift + F10 key combinations sap triggers system event and calls the method DISPATCH_SYSTEM_EVENTS of class CL_GUI_CFW. Within it, it calls the method DISPATCH of class LCL_DYNPRO_PROXY (defined within the class pool of CL_GUI_CFW).




From this method (DISPATCH) it calls the routine ON_CTMENU_REQUEST which is defined in our program.




Output:

Basic list:

Detail list:


Monday, July 21, 2008

Maintain LSMW object from its own transaction

By Joyjit Ghosh,
Kolkata, India.

Step: 1

Create a report and insert the code block given below.

* Type pools

TYPE-POOLS: tumls. " LSM Workbench: Type-Pool

* Data declaration

DATA: project TYPE tumls_project, " Project

subproj TYPE tumls_subproj, " Subproject

object TYPE tumls_objectnew. " Object

START-OF-SELECTION.

* Store project

project = 'TPISP - DC'.

* Store subproject

subproj = 'VARIANT_MAT'.

* Store object

object = '6GSC022_TS3'.

* Call the function module to display object (LSMW) maintenance screen

CALL FUNCTION '/SAPDMC/LSM_OBJ_STARTER'

EXPORTING

project = project

subproj = subproj

object = object

EXCEPTIONS

no_such_object = 1

OTHERS = 2.

Basically from LSMW’s initial screen whenever you press enter or continue button it calls the FM /SAPDMC/LSM_OBJ_STARTER and there is no authorisation check prior to do this, only LSMW checks for authorisation when you press Administration from GOTO menu using the FM /SAPDMC/LSM_AUTHORIZATN_CHECK. That means any body can access any object and can do any unwanted change. And it is really hard to track the changes as LSMW does not have any inbuilt version management. So to avoid this before calling the FM we can do the authorisation check based on certain conditions (not necessary to do authority check, but can be achieved by maintaining parameter ID in the user profile or through maintaining custom table) and by this way we can restrict unwanted user access.

Step: 2

Create a transaction for the report from SE93.

Now execute the program or the transaction. It will show you the maintenance screen of the LSMW object.


Sunday, July 13, 2008

Download document server image

By Joyjit Ghosh,
Kolkata, India.

*&---------------------------------------------------------------------

*& Report Z_DOWNLOAD_BDS_GRAPHICS

*&---------------------------------------------------------------------

*& Download image stored in document server

*&---------------------------------------------------------------------

REPORT z_download_bds_graphics .

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

* Variable declaration

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

DATA: v_graphic_size TYPE i,

v_graphic_xstr TYPE xstring,

v_graphic_conv TYPE i,

v_graphic_offs TYPE i,

v_file TYPE string.

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

* Table declaration

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

DATA: BEGIN OF i_graphic_table OCCURS 0,

line(255) TYPE x,

END OF i_graphic_table.

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

* Structure declaration

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

DATA: st_stxbitmaps TYPE stxbitmaps.

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

* Selection screen

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

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_object LIKE st_stxbitmaps-tdobject DEFAULT 'GRAPHICS'

MODIF ID abc ,

p_name LIKE st_stxbitmaps-tdname,

p_id LIKE st_stxbitmaps-tdid DEFAULT 'BMAP'

MODIF ID abc ,

p_type LIKE st_stxbitmaps-tdbtype,

p_dir TYPE localfile.

SELECTION-SCREEN END OF BLOCK b1.

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

* At Selection-screen output event

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

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF screen-group1 = 'ABC' .

screen-input = '0'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

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

* At Selection-screen on value-request event

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.

DATA: l_folder TYPE string.

CALL METHOD cl_gui_frontend_services=>directory_browse

EXPORTING

window_title = 'Select Folder'

initial_folder = 'C:\'

CHANGING

selected_folder = l_folder

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

not_supported_by_gui = 3

OTHERS = 4.

IF sy-subrc = 0.

p_dir = l_folder.

ENDIF.

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

* Start-of-selection event

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

START-OF-SELECTION.

st_stxbitmaps-tdobject = p_object.

st_stxbitmaps-tdname = p_name.

st_stxbitmaps-tdid = p_id.

st_stxbitmaps-tdbtype = p_type.

* Get the bmp image from BDS in hex string format

CALL METHOD cl_ssf_xsf_utilities=>get_bds_graphic_as_bmp

EXPORTING

p_object = st_stxbitmaps-tdobject

p_name = st_stxbitmaps-tdname

p_id = st_stxbitmaps-tdid

p_btype = st_stxbitmaps-tdbtype

RECEIVING

p_bmp = v_graphic_xstr

EXCEPTIONS

not_found = 1

internal_error = 2

OTHERS = 3.

IF sy-subrc = 0.

* Find the length of hex string

v_graphic_size = xstrlen( v_graphic_xstr ).

CHECK v_graphic_size > 0.

v_graphic_conv = v_graphic_size.

v_graphic_offs = 0.

* Populate internal table from this hex string

WHILE v_graphic_conv > 255.

i_graphic_table-line = v_graphic_xstr+v_graphic_offs(255).

APPEND i_graphic_table.

v_graphic_offs = v_graphic_offs + 255.

v_graphic_conv = v_graphic_conv - 255.

ENDWHILE.

i_graphic_table-line = v_graphic_xstr+v_graphic_offs(v_graphic_conv).

APPEND i_graphic_table.

* Prepare file name and file path

CONCATENATE p_dir '\' p_name '.BMP' INTO v_file.

* Download image

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = v_graphic_size

filename = v_file

filetype = 'BIN'

TABLES

data_tab = i_graphic_table

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.

WRITE: 'File downloaded successfully'(002).

ELSE.

WRITE: 'Error during file download'(003).

ENDIF.

ELSE.

CASE sy-subrc.

WHEN 1.

WRITE: 'Image not found'(004).

WHEN OTHERS.

WRITE: 'Error in Image retrieval'(005).

ENDCASE.

ENDIF.