Archive for September, 2010
Upload Long Text into Custom Text Object
September 26, 2010
Leave a comment
Uploading long text from uploded file into custom Text Object.
First, create the custom text object and text id in SE75.
Then, apply below code to upload the text. The step is: 1. Upload the file. 2. ‘Reformat’ the uploaded text to match the text object format. 3. Put the text into text object.
TYPES:
BEGIN OF t_gui_upl,
text(1000) TYPE c,
END OF t_gui_upl,
t_gui_upl_tab TYPE STANDARD TABLE OF t_gui_upl.
DATA:
lv_gjahr_c(4) TYPE c VALUE '2010',
lv_perio_c(2) TYPE c VALUE '02',
li_gui_upl TYPE t_gui_upl_tab,
lwa_gui_upl TYPE t_gui_upl,
lwa_tline TYPE tline,
li_wrap TYPE t_gui_upl_tab,
lwa_wrap TYPE t_gui_upl,
li_footer_text TYPE tlinetab,
lv_text_name type tdobname.
concatenate lv_gjahr lv_perio into lv_text_name.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:.xls'
filetype = 'ASC'
replacement = ' '
TABLES
data_tab = li_gui_upl
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.
IF sy-subrc <> 0.
MESSAGE i532(0u) DISPLAY LIKE 'E' WITH 'Failed while uploading file. Upload canceled.'.
CLEAR p_cb_ul.
EXIT.
ENDIF.
LOOP AT li_gui_upl INTO lwa_gui_upl.
IF lwa_gui_upl-text IS INITIAL. "Skip blank line
CONTINUE.
ELSE.
CLEAR: li_wrap.
CALL FUNCTION 'RKD_WORD_WRAP' "Wrap text to be stored in tline table
EXPORTING
textline = lwa_gui_upl-text
delimiter = space
outputlen = 100
TABLES
out_lines = li_wrap
EXCEPTIONS
outputlen_too_large = 1
OTHERS = 2.
IF sy-subrc = 0.
LOOP AT li_wrap INTO lwa_wrap.
CLEAR lwa_tline.
AT FIRST.
lwa_tline-tdformat = '*'.
ENDAT.
lwa_tline-tdline = lwa_wrap-text.
APPEND lwa_tline TO li_footer_text.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid = 'ZID'
flanguage = sy-langu
fname = lv_text_name
fobject = 'ZOBJ'
save_direct = abap_true
fformat = space
TABLES
flines = li_footer_text
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
Dynamic Field Selection
September 19, 2010
Leave a comment
In some structure, for example in COSP, amount of each period is stored in different column, instead of different row. This is an advantage as it will give efficiency when fetching data from the table. However, most of the times we have to add logic to filter the data by period, which mean we have to define which column to be fetched during runtime. For this, we can use one of the dynamic programming method. Below is the code example:
REPORT ztestdynfield.
SELECTION-SCREEN BEGIN OF BLOCK b01.
PARAMETERS:
p_period TYPE perio OBLIGATORY,
p_gjahr TYPE gjahr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.
START-OF-SELECTION.
PERFORM f_dynamic_selection.
*&---------------------------------------------------------------------*
*& Form f_dynamic_selection
*&---------------------------------------------------------------------*
FORM f_dynamic_selection .
DATA:
li_cosp TYPE STANDARD TABLE OF cosp,
lwa_cosp TYPE cosp,
lv_period(3) TYPE c,
lv_field_name TYPE string VALUE 'LWA_COSP-WOG'.
FIELD-SYMBOLS:
<lfs_dynfld> TYPE ANY.
SELECT SINGLE * FROM cosp
INTO lwa_cosp
WHERE gjahr = p_gjahr.
*-- Get value only for column WOGXXX based on selection screen
lv_period = p_period.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_period
IMPORTING
output = lv_period.
CONCATENATE lv_field_name
lv_period
INTO lv_field_name.
ASSIGN (lv_field_name) TO <lfs_dynfld>.
WRITE: / 'Amount in object currency in period', lv_period , '='.
WRITE: / <lfs_dynfld>.
ENDFORM. " f_dynamic_selection
Categories: ABAP, Dynamic Programming, SAP