Overview
Text spool can be viewing using transaction SP01.
Spool can be seen on following display modes:
- Graphical
- Raw
- Hex
If spool has lines longer than 255 characters and contains accented characters like chèque, none of above modes allow user to download spool to local text file without loss of information. A program was written to overcome this.
Technical Details
Graphical display mode shows accented characters, but it truncates lines longer than 255 characters.
Raw display mode shows long lines without truncation, but it shows # instead of accented characters.
Hex display mode shows 3 times the lines in Raw mode. In every 3 line set, 1st line is similar to Raw mode text and 2nd and 3rd lines show hex equivalent code.
Program essentially reads the Hex mode spool stored in local text file, converts hex codes and generates local spool file.
Input file: C:\input.txt should have Hex mode spool contents downloaded using Download button or Menu System > List > Save > Local file.
Output file: C:\output.txt file would have desired spool content once program is run.
Logic
Assuming spool has only one word CHEÈQUE, spool content in Hex mode would be something like this:
|CHE#QUE
2|444C554
0|3858155
Hex code for È is C8. In the above example, the hex code is placed in same column as original character, but in lines 2nd and 3rd. This is the reason why characters below È are C and 8.
Program will read the data and store lines starting with 2| (first half of hex code) and 0| (second half of hex code) in separate internal tables.
The internal tables would then be merged to form hex code written left to right. For above data, merged hex code would be 434845C8515545.
The merged internal table would be converted from hex to string using function module.
Converted text would be download to C:\output.txt.
Code Snippet
TYPES:
tty_string TYPE TABLE OF string,
BEGIN OF ty_pair,
first TYPE string,
second TYPE string,
END OF ty_pair,
tty_pair TYPE TABLE OF ty_pair.
DATA: gv_path TYPE string,
gt_input TYPE TABLE OF string.
gv_path = 'c:\input.txt'.
PERFORM read_local_file USING gv_path CHANGING gt_input[].
DATA: gv_identifier1 TYPE string,
gv_identifier2 TYPE string,
gt_pair TYPE TABLE OF ty_pair.
gv_identifier1 = '2|'.
gv_identifier2 = '0|'.
PERFORM extract_hex_pairs USING gt_input[] gv_identifier1 gv_identifier2 CHANGING gt_pair[].
DATA gt_merged TYPE TABLE OF string.
PERFORM hex_merge USING gt_pair CHANGING gt_merged.
DATA gt_output TYPE TABLE OF string.
PERFORM hex_to_string USING gt_merged CHANGING gt_output.
gv_path = 'c:\output.txt'.
PERFORM write_local_file USING gv_path gt_output.
*&---------------------------------------------------------------------*
*& Form READ_LOCAL_FILE
*&---------------------------------------------------------------------*
FORM read_local_file USING pv_path TYPE string
CHANGING ct_data TYPE tty_string.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = pv_path
TABLES
data_tab = ct_data
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
ENDFORM. " READ_LOCAL_FILE
*&---------------------------------------------------------------------*
*& Form EXTRACT_HEX_PAIRS
*&---------------------------------------------------------------------*
FORM extract_hex_pairs USING pt_input TYPE tty_string
pv_identifier1 TYPE string
pv_identifier2 TYPE string
CHANGING ct_pair TYPE tty_pair.
DATA: lv_input TYPE string,
lv_offset TYPE i,
ls_pair TYPE ty_pair,
lv_length TYPE i,
lv_dummy TYPE c LENGTH 9999.
lv_length = STRLEN( pv_identifier1 ).
LOOP AT pt_input INTO lv_input.
FIND FIRST OCCURRENCE OF pv_identifier1 IN lv_input MATCH OFFSET lv_offset.
IF sy-subrc EQ 0.
lv_dummy = lv_input.
ls_pair-first = lv_input+lv_length.
ENDIF.
FIND FIRST OCCURRENCE OF pv_identifier2 IN lv_input MATCH OFFSET lv_offset.
IF sy-subrc EQ 0.
lv_dummy = lv_input.
ls_pair-second = lv_dummy+lv_length.
APPEND ls_pair TO ct_pair.
CLEAR: ls_pair.
ENDIF.
ENDLOOP.
ENDFORM. " EXTRACT_HEX_PAIRS
*&---------------------------------------------------------------------*
*& Form HEX_MERGE
*&---------------------------------------------------------------------*
FORM hex_merge USING pt_pair TYPE tty_pair
CHANGING ct_merged TYPE tty_string.
DATA: ls_pair TYPE ty_pair,
lv_merged TYPE string,
lv_offset TYPE i,
lv_length TYPE i.
LOOP AT pt_pair INTO ls_pair.
lv_length = STRLEN( ls_pair-first ).
lv_offset = 0.
DO lv_length TIMES.
CONCATENATE lv_merged
ls_pair-first+lv_offset(1)
ls_pair-second+lv_offset(1)
INTO lv_merged.
lv_offset = lv_offset + 1.
ENDDO.
APPEND lv_merged TO ct_merged.
CLEAR lv_merged.
ENDLOOP.
ENDFORM. " HEX_MERGE
*&---------------------------------------------------------------------*
*& Form HEX_TO_STRING
*&---------------------------------------------------------------------*
FORM hex_to_string USING pt_input TYPE tty_string
CHANGING ct_output TYPE tty_string.
DATA: lv_input TYPE xstring,
lv_output TYPE string.
LOOP AT pt_input INTO lv_input.
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_STRING'
EXPORTING
in_xstring = lv_input
in_codepage = '1100'
IMPORTING
ex_string = lv_output
EXCEPTIONS
error = 1
OTHERS = 2.
APPEND lv_output TO ct_output.
CLEAR lv_output.
ENDLOOP.
ENDFORM. " HEX_TO_STRING
*&---------------------------------------------------------------------*
*& Form WRITE_LOCAL_FILE
*&---------------------------------------------------------------------*
FORM write_local_file USING pv_path
pt_input TYPE tty_string.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = pv_path
TABLES
data_tab = pt_input
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.
ENDFORM. " WRITE_LOCAL_FILE