Pages

Thursday, December 17, 2009

ALV to Excel - number formatting (2.0E + 11)

read a suggestion somewhere to use ' or a single code as shown below.
Not sure if it works or not but just came across so updated it.

constant: c_quote value `'`.

loop at data_tab assigning .

concatentate c_quote -ean into wa_ean.

-ean = wa_ean.

endloop.

Tuesday, December 15, 2009

Restricting Select-option field values check on Selection screen

This FM will restrict any system check on the Select option field on selection screen.
with this we can enter a low HIGH value on the then Select-option field.

*&---------------------------------------------------------------------*
*& Form NO_SEL_OPTION_CHECK
*&---------------------------------------------------------------------*
* This code restricts any check on the DATE field of the Selection
* screen. This is done so that no comparison of dates happen when User
* enters the DATE-HIGH value. DATE-LOW is dependent on DATE-HIGH which
* is calculated after DATE-HIGH is entered.
*----------------------------------------------------------------------*
FORM no_sel_option_check .
DATA: lt_s_option TYPE TABLE OF rsldbselop,
lwa_s_option TYPE rsldbselop.

lwa_s_option-name = 'S_DATE'.
APPEND lwa_s_option TO lt_s_option.


CALL FUNCTION 'RS_SELOPT_NO_INTERVAL_CHECK'
EXPORTING
program = sy-repid
TABLES
selop = lt_s_option
EXCEPTIONS
no_programname = 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. " NO_SEL_OPTION_CHECK

Sending mail from SAP + Attachment as ADOBE form

1: Call form:

TRY .
* First get name of the generated function module
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = p_formname
IMPORTING
e_funcname = lv_form_name.
CATCH cx_fp_api_repository INTO obj_root.
wa_err-person = p_mailtab-perid.
wa_err-desc = obj_root->get_text( ).
APPEND wa_err TO it_err.
CLEAR wa_err.
ENDTRY.


2: Set output params. open Job for processing:


* Set output parameters and open spool job
wa_outputparams-nodialog = c_x. " suppress printer dialog popup
wa_outputparams-preview = space. " launch print preview
wa_outputparams-getpdf = c_x.

CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = wa_outputparams
EXCEPTIONS
cancel = 0
usage_error = 0
system_error = 0
internal_error = 0
OTHERS = 0.
* Processing should continue inspite of errors
* so made Sy-Subrc as 0

* Set form language and country (->form locale)
wa_docparams-langu = lc_language.
wa_docparams-country = lc_country.


3: Call the Form. Also error from an adobe form can be caught in following way:


* Pass Data to the Form Interface
CALL FUNCTION lv_form_name
EXPORTING
/1bcdwb/docparams = wa_docparams
t_stud_data = wa_mailtab1
IMPORTING
/1bcdwb/formoutput = wa_pdfobject
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.

CLEAR wa_err.
* This FM captures any Error which has resulted during
* Form generation
CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
IMPORTING
e_adserrstr = wa_err-desc.


5: Convert PDF to SOLIX:

This is most important for PDF as an attachment


* Convert PDF Object to type SOLIX
CALL METHOD cl_document_bcs=>xstring_to_solix
EXPORTING
ip_xstring = wa_pdfobject-pdf
RECEIVING
rt_solix = it_attachment.


6: Mail sending part:

* Initialize Mail creation
TRY.
obj_send_request = cl_bcs=>create_persistent( ).

* Set sender Email address
obj_sender =
cl_cam_address_bcs=>create_internet_address( lc_id_from ).
obj_send_request->set_sender( i_sender = obj_sender ).

7: set email IDs:


* Get Recipient's Email IDs

MOVE p_mailtab-email TO lv_recv_id.
obj_recipient =
cl_cam_address_bcs=>create_internet_address( lv_recv_id ).
obj_send_request->add_recipient(
i_recipient = obj_recipient
i_express = c_x
).



8: Attaching the Doc and sending mail:


" create documents
obj_document = cl_document_bcs=>create_document(
i_type = lc_type_raw " RAW document format
i_text = it_contents
i_subject = lv_subject
).

obj_document->add_attachment(
i_attachment_type = lc_type_pdf " add PDF attachment
i_attachment_subject = 'Official Notice'(046)
i_att_content_hex = it_attachment
).
obj_send_request->set_document( obj_document ).
**********************************************************************

" send email
obj_send_request->set_send_immediately( c_x ).
lv_ret = obj_send_request->send( ). "#EC NEEDED

CATCH cx_bcs INTO obj_root.
wa_err-person = p_mailtab-perid.
wa_err-desc = obj_root->get_text( ).
APPEND wa_err TO it_err.
CLEAR wa_err.
p_return = 1.
ENDTRY.

COMMIT WORK.


* Close spool job
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 0
system_error = 0
internal_error = 0
OTHERS = 0.
* Should not throw Errors and processing should continue

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

Display ALV Grid as well as List Header using HTML Control

1: Use ALV Split container to create space at Top for header and below it for ALV Grid:
{code}
* First Main Container
CREATE OBJECT obj_container
EXPORTING
container_name = 'CC_CONTAINER'
style = cl_gui_custom_container=>ws_maximizebox.

* 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 = 30.

* 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.
{code}

2:set two diff. events for List display and Grid display
{code}
* Set Event Handler for TOP_OF_PAGE
SET HANDLER obj_event->on_top_of_page FOR obj_grid.
SET HANDLER obj_event->on_grid_top_of_page FOR obj_grid.
{code}

3: define local classes:
{code}
CLASS lcl_event_receiver DEFINITION FINAL.
* event receiver definitions for ALV actions
PUBLIC SECTION.
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.

PRIVATE SECTION.
DATA: lv_endda TYPE endda.
ENDCLASS. "lcl_event_receiver DEFINITION

CLASS lcl_event_receiver IMPLEMENTATION.

* Create the Text to be dispalyed at top of page of ALV List Output
METHOD on_top_of_page.
* Will be hit only when ALV List Display is called
PERFORM display_list_top.
ENDMETHOD. "On_top_of_page

* Create Top_Of_Page display for ALV Grid Output
METHOD on_grid_top_of_page.
* top-of-page event
PERFORM event_top_of_page USING obj_dyndoc_id.
e_dyndoc_id = obj_dyndoc_id.
ENDMETHOD. "create_top_of_page

ENDCLASS. "lcl_event_receiver IMPLEMENTATION


4:Make it know to ALV grid about the Top of page event. Code this in MODULE ALV_DISPLAY:
{code}
* 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.
{code}

5: this object "obj_dyndoc_id" will use different methods to decorate the top page.
Like adding gaps:
"Put Header in center
CALL METHOD p_dyndoc_id->add_gap
EXPORTING
width = 200.

Adding text:
"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = lv_text
sap_style = cl_dd_area=>heading.

OR
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = lv_text
sap_fontsize = cl_dd_area=>large
sap_emphasis = cl_dd_area=>strong.

Use the constructor of class: CL_DD_AREA to define style and colors.

6: Different objects use are:

obj_container TYPE REF TO cl_gui_custom_container,
obj_splitter TYPE REF TO cl_gui_splitter_container,
obj_parent_grid TYPE REF TO cl_gui_container,
obj_grid TYPE REF TO cl_gui_alv_grid,
obj_dyndoc_id TYPE REF TO cl_dd_document,"reference to document
gv_title TYPE lvc_title,
obj_event TYPE REF TO lcl_event_receiver,
obj_parent_html TYPE REF TO cl_gui_container,"reference to html container
obj_html_cntrl TYPE REF TO cl_gui_html_viewer.