|
YPRACTICE_302 |
Home | ||||
|
Previous Next | |||||
|
*&---------------------------------------------------------------------* *& Report YPRACTICE_302 * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------*
REPORT ypractice_302 .
*----------------------------------------------------------------------* * Tables *----------------------------------------------------------------------* TABLES : mara, makt, t006a.
*----------------------------------------------------------------------* *GLOBAL VARIABLE DECRALATION *----------------------------------------------------------------------* TYPES: BEGIN OF ty_header, matkl LIKE mara-matkl, " Material Group matnr LIKE mara-matnr, " Material Number maktx LIKE makt-maktx, " Material Descriptiop bismt LIKE mara-bismt, " Old material number meins LIKE mara-meins, " Base Unit of Measure mseht LIKE t006a-mseht, " Unit of Measurement Text END OF ty_header.
DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE, gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE, gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.
DATA: gv_width TYPE i. " Width of list
DATA: ok_code LIKE sy-ucomm, save_ok TYPE sy-ucomm.
* Html Report Required TYPES: BEGIN OF gy_html_code, line_code(1000), END OF gy_html_code. DATA: gi_html_code TYPE TABLE OF gy_html_code WITH HEADER LINE.
DATA: cc_report_display TYPE REF TO cl_gui_html_viewer, web_container TYPE REF TO cl_gui_custom_container.
DEFINE write_code1. clear gi_html_code. gi_html_code-line_code = &1. append gi_html_code. END-OF-DEFINITION.
DEFINE write_code2. clear gi_html_code. concatenate &1 &2 into gi_html_code-line_code. append gi_html_code. END-OF-DEFINITION.
DEFINE write_code3. clear gi_html_code. concatenate &1 &2 &3 into gi_html_code-line_code. append gi_html_code. END-OF-DEFINITION.
*----------------------------------------------------------------------* *INCLUDE PROGRAM *----------------------------------------------------------------------* *You can put the include program at the bottom of code
INCLUDE ypractice_302_classes.
*----------------------------------------------------------------------* *Input Screen/Selection *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101. "Declare Group Box 1
SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(14) text_102 FOR FIELD so_matkl. SELECT-OPTIONS so_matkl FOR mara-matkl OBLIGATORY DEFAULT '001'. SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(14) text_103 FOR FIELD so_matnr. SELECT-OPTIONS so_matnr FOR mara-matnr. SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox1. "End Group Box 1
SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201. "Declare Group Box 2
SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname. PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT 'C:\abap_report_01.html'. SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline . PARAMETERS p_mline TYPE n DEFAULT 20 LENGTH 4. SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox2. "End Group Box 2
*----------------------------------------------------------------------* *EVENT *----------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. text_101 = 'Selection Parameter'. text_102 = 'Material Group'. text_103 = 'Material Number'.
text_201 = 'Save Html File'. text_202 = 'File Location'. text_203 = 'Max. Line per Page'.
*----------------------------------------------------------------------* *INITIALIZATION *----------------------------------------------------------------------* INITIALIZATION. PERFORM fm_initialization.
*======================================================================* *MAIN PROGRAM *Execute after Input Screen *======================================================================* START-OF-SELECTION. gv_width = 113. PERFORM fm_collect_data. PERFORM fm_process_data. PERFORM fm_display_data.
END-OF-SELECTION.
*======================================================================* *SUB PROGRAM / SUB ROUTINE *======================================================================*
*&--------------------------------------------------------------------* *& Form fm_collect_data *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM fm_collect_data. * Collect Master Material SELECT matnr matkl bismt meins INTO CORRESPONDING FIELDS OF TABLE gi_header FROM mara WHERE matkl IN so_matkl AND matnr IN so_matnr.
* "For SAP 4.6C * DATA : lv_total_data type i. * DESCRIBE TABLE gi_header LINES lv_total_data. * IF lv_total_data > 0.
IF LINES( gi_header ) > 0." For SAP 4.7 above * Collect Material Decription SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE gi_makt FROM makt FOR ALL ENTRIES IN gi_header WHERE matnr = gi_header-matnr AND spras = sy-langu.
* Collect Measurement Text SELECT msehi mseht INTO CORRESPONDING FIELDS OF TABLE gi_t006a FROM t006a FOR ALL ENTRIES IN gi_header WHERE msehi = gi_header-meins AND spras = sy-langu. ENDIF.
* Notes : * Avoid using inner join
ENDFORM. "FM_COLLECT_DATA
*&--------------------------------------------------------------------* *& Form FM_PROCESS_DATA *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM fm_process_data. *Get other requirement information LOOP AT gi_header. * Get Material Description READ TABLE gi_makt WITH KEY matnr = gi_header-matnr. IF sy-subrc = 0. gi_header-maktx = gi_makt-maktx. ENDIF.
* Get Measurement Text READ TABLE gi_t006a WITH KEY msehi = gi_header-meins. IF sy-subrc = 0. gi_header-mseht = gi_t006a-mseht. ENDIF.
MODIFY gi_header. ENDLOOP.
ENDFORM. "FM_PROCESS_DATA
*&--------------------------------------------------------------------* *& Form fm_display_data *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM fm_display_data. DATA : lv_active_page_no TYPE n LENGTH 4, lv_limit_top TYPE i, lv_limit_bottom TYPE i, lv_total_page LIKE lv_active_page_no, lv_remainder LIKE lv_active_page_no.
* Calculate Total Page lv_total_page = ( LINES( gi_header ) DIV p_mline ). lv_remainder = LINES( gi_header ) MOD p_mline.
IF lv_remainder > 0. lv_total_page = lv_total_page+1. ENDIF.
* Calculate Page Limit IF LINES( gi_query_table ) > 0 AND gv_action = 'SUBMIT_PAGE_NO'. READ TABLE gi_query_table WITH KEY name = 'PAGE_NO'. IF sy-subrc = 0. lv_active_page_no = gi_query_table-value.
lv_limit_top = lv_active_page_no * p_mline. ENDIF. ELSE. lv_active_page_no = 1. lv_limit_top = 1. ENDIF.
lv_limit_bottom = lv_limit_top + p_mline.
REFRESH gi_html_code. PERFORM fm_create_css.
write_code1 '<body>'.
write_code1 '<table width="100%" border="0" cellspacing="2" cellpadding="0">'. PERFORM fm_create_paging_menu USING lv_total_page lv_active_page_no.
* Create Header Text write_code1 ' <tr bgcolor="#999999" class="styleHeader">'. write_code1 ' <td>Mat. Group</td>'. write_code1 ' <td>Mat. No.</td>'. write_code1 ' <td>Description</td>'. write_code1 ' <td>Old Mat. No.</td>'. write_code1 ' <td>Base Unit of Measure</td>'. write_code1 ' <td>Measure</td>'. write_code1 ' </tr>'.
* Display Data to Screen LOOP AT gi_header FROM lv_limit_top TO lv_limit_bottom. write_code1 ' <tr bgcolor="#EBEBEB">'. write_code3 ' <td class="style1">' gi_header-matkl '</td>'. write_code3 ' <td class="style1">' gi_header-matnr '</td>'. write_code3 ' <td class="style2">' gi_header-maktx '</td>'. write_code3 ' <td class="style2">' gi_header-bismt '</td>'. write_code3 ' <td class="style1">' gi_header-meins '</td>'. write_code3 ' <td class="style2">' gi_header-mseht '</td>'. write_code1 ' </tr>'.
ENDLOOP.
* End of Line write_code1 ' <td bgcolor="#999999" class="styleHeader" colspan="6"> </td>'. PERFORM fm_create_paging_menu USING lv_total_page lv_active_page_no. write_code1 '</table>'. write_code1 '</body>'.
PERFORM fm_create_html_file TABLES gi_html_code USING p_fname. PERFORM fm_load_html USING p_fname.
CALL SCREEN 2000.
ENDFORM. "fm_display_data
*&--------------------------------------------------------------------* *& Form fm_create_paging_menu *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->FV_TOTAL_PAtext * -->FV_ACTIVE_PtextNO *---------------------------------------------------------------------* FORM fm_create_paging_menu USING fv_total_page fv_active_page_no. DATA : lv_counter TYPE n LENGTH 4, lv_item(256). lv_counter = 0.
write_code1 ' <form name="form1" method="post" action="SAPEVENT:SUBMIT_PAGE_NO">'. write_code1 ' <tr colspan="6" class="style2">'. write_code1 ' <td>Page : '. write_code1 ' <select name="PAGE_NO" id="PAGE_NO">'.
WHILE fv_total_page > lv_counter. lv_counter = lv_counter + 1. IF lv_counter = fv_active_page_no. CONCATENATE '<option value="' lv_counter '" selected>' lv_counter '</option>' INTO lv_item. ELSE. CONCATENATE '<option value="' lv_counter '" >' lv_counter '</option>' INTO lv_item. ENDIF. write_code1 lv_item.
ENDWHILE.
write_code3 ' </select> / ' fv_total_page ' '. write_code1 ' <input name="Open_Submit" type="submit" id="Open_Submit" value="Open"></td>'. write_code1 ' </tr>'. write_code1 ' </form>'.
ENDFORM. "fm_create_paging_menu
*&--------------------------------------------------------------------* *& Form fm_initialization *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM fm_initialization. IF cc_report_display IS INITIAL.
CREATE OBJECT web_container EXPORTING container_name = 'CC_REPORT_DISPLAY'.
CREATE OBJECT cc_report_display EXPORTING parent = web_container. IF sy-subrc NE 0. * ENDIF. ENDIF. ENDFORM. "fm_initialization
*&--------------------------------------------------------------------* *& Form fm_create_css *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->FV_CSS text *---------------------------------------------------------------------* FORM fm_create_css. write_code1 '<style type="text/css">'. write_code1 '<!--'. write_code1 '.styleHeader {'. write_code1 ' font-family: Arial, Helvetica, sans-serif;'. write_code1 ' font-size: 12px;'. write_code1 ' font-weight: bold;'. write_code1 ' text-align: center;'. write_code1 ' }'. write_code1 '.style1 {'. write_code1 ' font-family: Arial, Helvetica, sans-serif;'. write_code1 ' font-size: 12px;'. write_code1 ' text-align: center;'. write_code1 ' }'. write_code1 '.style2 {'. write_code1 ' font-family: Arial, Helvetica, sans-serif;'. write_code1 ' font-size: 12px;'. write_code1 ' text-align: left;'. write_code1 ' }'. write_code1 '-->'. write_code1 '</style>'.
ENDFORM. "fm_create_css
*&--------------------------------------------------------------------* *& Form fm_create_temp_html *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->FI_FILE text * -->FV_URL text *---------------------------------------------------------------------* FORM fm_create_html_file TABLES fi_file STRUCTURE gi_html_code USING fv_url. CONDENSE fv_url NO-GAPS.
CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = fv_url filetype = 'ASC' TABLES data_tab = fi_file EXCEPTIONS file_open_error = 1 file_write_error = 2 invalid_filesize = 3 invalid_table_width = 4 invalid_type = 5 no_batch = 6 unknown_error = 7 OTHERS = 8.
ENDFORM. "fm_create_temp_html
*&--------------------------------------------------------------------* *& Form fm_load_html *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->URL text *---------------------------------------------------------------------* FORM fm_load_html USING fv_url. TRY. CALL METHOD cc_report_display->show_url EXPORTING url = fv_url. CATCH cx_sy_ref_is_initial. LEAVE TO SCREEN 0. ENDTRY. ENDFORM. "fm_load_html
*&---------------------------------------------------------------------* *& Module STATUS_2000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_2000 OUTPUT. SET PF-STATUS 'ST_2000'. * SET TITLEBAR 'xxx'.
* register event IF NOT cc_report_display IS INITIAL. gv_html_event-eventid = cc_report_display->m_id_sapevent. gv_html_event-appl_event = 'x'. APPEND gv_html_event TO gv_html_event_tab.
CALL METHOD cc_report_display->set_registered_events EXPORTING events = gv_html_event_tab.
CREATE OBJECT gv_evt_receiver.
SET HANDLER gv_evt_receiver->on_sapevent FOR cc_report_display. ELSE. LEAVE TO SCREEN 0. ENDIF. ENDMODULE. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------* *& Module USER_COMMAND_2000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_2000 INPUT. save_ok = ok_code. CLEAR ok_code.
CASE save_ok. WHEN 'BACK'. REFRESH gi_query_table. IF NOT cc_report_display IS INITIAL. CALL METHOD cc_report_display->free. FREE cc_report_display. ENDIF. LEAVE TO SCREEN 0. WHEN OTHERS. CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code. ENDMODULE. " USER_COMMAND_2000 INPUT
|