The Problem
: I need to develop a tutorial to be published on my personal website. Unfortunately, my personal website being free-hosted, can't afford heavy images generated using print-screen for Z transactions. It should work on MiniSAP - SAP Release 6.10 (Basis/ABA) [ Who caresabout the rest of the world
Other Benefits : Unlike print-screen
- HTML pages are scrollable and light.
- Also there will not be any resolution related problems as in case of images.
- Users can cut & paste the data from HTML Screen , if required.
- The downloaded SCREEN-HTML can be used for documentation
purpose and for sharing it over the web. - At times SAP Users demand for exact Print of Screens
rather than a List. This utility, being generic, can be
used to enable PRINT facility for simple transactions.
Requirement
Processing :
- The function module Z_RMTIWARI_PRINTSCREEN_TO_HTML is called, in the PAI of the screen to be printed,
at command for 'Print'.
lv_program = sy-repid. lv_dynnr = sy-dynnr.
CALL FUNCTION 'Z_RMTIWARI_PRINTSCREEN_TO_HTML' EXPORTING PROGRAM = lv_program DYNPRO = lv_dynnr.
- .......
- ENDCASE.
- This FM 'Z_RMTIWARI_PRINTSCREEN_TO_HTML'
first generates HTML code for a blank
screen-display of current screen. This is achieved by
submitting a program Z_RMTIWARI_PRINTSCREEN_TO_HTML
which in turn calls FM 'RS_SCRP_PRINT_IN_LIST'
for the transaction screen. The program generates a
spool for a simple list of the blank Screen [ Only the field name
and blank input/output fields ]. - This list will be read using FM LIST_FROM_MEMORY. Further, it will be converted into HTML.
Also the field-values needs to
be supplemented in the subsequent processing.
FM 'WWW_HTML_FROM_LISTOBJECT' is used to convert List to
HTML and further actual field values, retrieved using
'DYNP_VALUES_READ', are imposed on the generated
HTML and downloaded to the local folder. The final HTML file displays a screen similar to
SAPGui Xn screen including the field values.
Result :
It seems IFRAMEs can't be used here. Also, I tried pasting the html code directly but SDN's weblog is not able to show it properly. So no other go...
Check this link to see the result page:
Result Screen
Function Module :
FUNCTION Z_RMTIWARI_PRINTSCREEN_TO_HTML. *"----
""Local interface: *" IMPORTING *" REFERENCE(PROGRAM) TYPE SY-REPID *" REFERENCE(DYNPRO) TYPE SY-DYNNR *" EXCEPTIONS *" DOWNLOAD_ERROR *"----
- Written By : Ram Manohar Tiwari
- Problem : I need to develop a tutorial to be published on my
- personal website. Unfortunately my personal website
- being free-hosted, can't afford heavy images created
- using print-screen for Z transactions.
- Function : The attempt is to provide
- "Print-Screen to HTML" functionality for simple SAP
- Transaction Screens .
- This function module can be called
- at 'Print' command for the current screen.
- It will generate a HTML file to display simple SAP
- Transaction screens ( Fields with Contents ) as HTML.
- The functionality should be generic in nature and
- re-usable for other transactions.
- Other Benifits : Unlike print-screen the HTML pages are scrollable and
- light. Also there will not be any resolution related
- problems as in case of images. Further, users can
- cut & paste the data from HTML Screen , if required.
- The downloaded SCREEN-HTML can be used for documentation
- purpose and for sharing it over the web.
- At times SAP Users demand for exact Print of Screens
- rather than a List. This utility, being generic, can be
- used to enable PRINT facility for simple transactions.
- Processing : This FM first generates HTML code for a blank
- screen-display of current screen. This is achieved by
- submitting a program Z_RMTIWARI_PRINTSCREEN_TO_HTML
- which in turn calls FM 'RS_SCRP_PRINT_IN_LIST'
- for the transaction screen. This program generates a
- simple list for the blank Screen [ Only the field name
- and blank input/output fields ]. Further this list
- requires to be converted into HTML and values needs to
- be supplemented in the subsequent processing.
- FM 'WWW_HTML_FROM_LISTOBJECT' is used to convert List to
- HTML and further actual field values, retrived using
- 'DYNP_VALUES_READ', are imposed on the generated
- HTML. The final HTML file displays a screen similar to
- SAPGui Xn screen including the field values.
DATA: lv_dynpname TYPE TSTC-PGMNA, lv_dynpnumb TYPE TSTC-DYPNO.
DATA: BEGIN OF lt_dynpvaluetab OCCURS 1. INCLUDE STRUCTURE dynpread. DATA: END OF lt_dynpvaluetab.
DATA: lt_dyn_fields TYPE standard table of RSDCF with header line, lt_lines TYPE standard table of TLINE with header line.
DATA: lt_abap_list LIKE abaplist OCCURS 1. DATA: BEGIN OF lt_html_tab OCCURS 0. INCLUDE STRUCTURE w3html. DATA: END OF lt_html_tab. DATA: lv_html_tab_wide(50000) type c.
DATA: BEGIN OF lt_html_tab_str OCCURS 0, line type string. DATA: END OF lt_html_tab_str. DATA: lt_icontab(32) OCCURS 10 WITH HEADER LINE. ----
TYPE-POOLS: sbdst.
DATA: lineno TYPE i, length TYPE i, size TYPE i. DATA: icon_wa TYPE icon, internal TYPE icon-internal, existing TYPE c. DATA: my_bds TYPE REF TO cl_bds_document_set, key TYPE sbdst_object_key, files TYPE sbdst_files, wa TYPE bapifiles. data: filename type string, filefilter type string, path type string, fullpath type string. data: user_action type i. data: cur_guicopdepage(4) type n.
----
- Get Data Fields of current Screen.
CALL FUNCTION 'DYNPRO_FIELD_GET' EXPORTING DYNPRO = lv_dynpnumb PROGRAM = lv_dynpname TABLES DYNP_FIELDS = lt_dyn_fields LINES = lt_lines EXCEPTIONS DYNPRO_NOT_FOUND = 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.
REFRESH lt_dynpvaluetab. LOOP AT lt_dyn_fields. check not lt_dyn_fields-fldname is initial. lt_dynpvaluetab-fieldname = lt_dyn_fields-DYNPRO_FLD. APPEND lt_dynpvaluetab. ENDLOOP.
DATA: lv_dynpname1 TYPE D020S-PROG, lv_dynpnumb1 TYPE D020S-DNUM. . lv_dynpname1 = program. lv_dynpnumb1 = dynpro. .
- Read values of data-fields on the current screen.
ENDIF.
- Call program and then get the list from memory.
- This program generates a simple list for the blank Screen
- .
- Further values needs to be supplemented in the subsequent
- processing.
CALL FUNCTION 'LIST_FROM_MEMORY' TABLES LISTOBJECT = lt_abap_list
- EXCEPTIONS
- NOT_FOUND = 1
- OTHERS = 2
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT' EXPORTING
- REPORT_NAME =
- for UNICODE Systems we need a new type of DOWNLOAD: table-lines of
- html_table must be downloaded without end-marks or blanks between the
- lines (still to be developed!, the same problem as with EBCDIC)
data : lv_row type sy-tabix, lv_text_pos type sy-fdpos. field-symbols : type any. data : lv_count type i, lv_char type c, lv_replace_str(200) type C, lv_field_length type i, lv_value_length type i.
LOOP AT lt_html_tab. TRANSLATE lt_html_tab using ' *'. CONCATENATE lv_html_tab_wide lt_html_tab into lv_html_tab_wide.
ENDLOOP.
- lt_html_tab_wide[] = lt_html_tab[].
TRANSLATE lv_html_tab_wide using '* '.
- Step below is to overwrite the blank input / outputs fields
- retrived in the last step with actual runtime values of those
- fields.
SEARCH lv_html_tab_wide FOR lt_dyn_fields-stxt1 . check sy-subrc eq 0. lv_row = 1. "sy-tabix. lv_text_pos = sy-fdpos.
- READ TABLE lt_html_tab_wide index lv_row.
- check sy-subrc eq 0.
- assign (lt_dynpvaluetab-FIELDNAME) to <fs>.
- <fs> = lt_dynpvaluetab-FIELDVALUE.
IF lt_dynpvaluetab-FIELDVALUE CO ' 0123456789'. lv_field_length = strlen( lv_replace_str ). lv_value_length = strlen( lt_dynpvaluetab-FIELDVALUE ).
if lv_field_length ne lv_value_length. lv_field_length = ( lv_field_length - lv_value_length ). DO lv_field_length times. CONCATENATE '0' lt_dynpvaluetab-FIELDVALUE into lt_dynpvaluetab-FIELDVALUE. ENDDO. endif. endif.
REPLACE lv_replace_str IN lv_html_tab_wide with lt_dynpvaluetab-FIELDVALUE.
- REPLACE ALL occurrences OF '_' in lt_html_tab
- with ' '.
- REPLACE SECTION OFFSET sy-fdpos length 1 OF lt_html_tab
- WITH lt_dynpvaluetab-FIELDVALUE.
- check sy-subrc eq 0.
- MODIFY lt_html_tab_wide index lv_row.
REFRESH lt_html_tab[].
- DESCRIBE TABLE lt_html_tab_wide LINES lineno .
- DESCRIBE FIELD lt_html_tab_wide LENGTH length in byte mode.
- size = length * lineno.
- For the time-being limit of downloaded file size is set to 20000.
- DELIMITER = ' '
- IMPORTING
- OUT_LINE1 =
- OUT_LINE2 =
- OUT_LINE3 =
- EXCEPTIONS
- OUTPUTLEN_TOO_LARGE = 1
- OTHERS = 2
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
- size = 20000.
- data : lv_pos1 type i.
- DO 80 times.
- lt_html_tab = lv_html_tab_wide+lv_pos1(255).
- lv_pos1 = lv_pos1 + 255.
- APPEND lt_html_tab.
- SEARCH lt_html_tab for '</html>'.
- if sy-subrc eq 0.
- exit.
- endif.
- ENDDO.
- Save HTML File
if user_action = CL_GUI_FRONTEND_SERVICES=>ACTION_OK. call 'CUR_LCL' id 'GUICP' field cur_guicopdepage. loop at lt_html_tab. call function 'SCP_TRANSLATE_CHARS' EXPORTING inbuff = lt_html_tab outcode = cur_guicopdepage csubst = 'X' substc_space = 'X' IMPORTING outbuff = lt_html_tab EXCEPTIONS invalid_codepage = 1 internal_error = 2 cannot_convert = 3 fields_bad_type = 4 others = 5. if sy-subrc <> 0. message i020(02) raising download_error. endif. modify lt_html_tab. endloop.
CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = fullpath FILETYPE = 'ASC'
- bin_filesize = size
- download of SAP icons appearing in the list
- no icon download if icon already exists in directory
IF existing is initial.
- icon not there -> download from BDS
ENDFUNCTION.
Program :
&----
*& Report Z_RMTIWARI_PRINTSCREEN_TO_HTML * *& * &----
*& Written By : Ram Manohar Tiwari * *& Function : It can print a spool-list for the specified Screen * &----
REPORT Z_RMTIWARI_PRINTSCREEN_TO_HTML . PARAMETERS : P_PROG LIKE d020s-prog OBLIGATORY. PARAMETERS : P_DYNNR(4) TYPE C OBLIGATORY. SET LANGUAGE 'EN'..
CALL FUNCTION 'RS_SCRP_PRINT_IN_LIST' EXPORTING ATTRIBS = ' ' DYNNR = P_DYNNR FIELDS = ' ' FULLSCR = 'X' LOGIC = ' ' PROGNAME = P_PROG
- TRANS = ' '
- EXCEPTIONS
- CANCELLED = 1
- NOT_FOUND = 2
- OTHERS = 3
- MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
- WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Conclusion:
As you must have figured it out by now ...it's useless...well almost