Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Internal Table to Text, Excel, PDF & Html File

$
0
0

 

 

 

 

Internal Table to Text


TYPES: BEGINOF ty_text,
fld1(
20) TYPEc,
fld2(
20) TYPEc,
fld3(
20) TYPEc,
ENDOF ty_text.

DATA: it_t001 TYPETABLEOF t001.
DATA: wa_t001 TYPE t001.
DATA: it_text TYPETABLEOF ty_text.
DATA: wa_text TYPE ty_text.

SELECT * INTOTABLE it_t001 FROM t001.

wa_text-fld1 =
'Field 1'.
wa_text-fld2 =
'Field 2'.
wa_text-fld3 =
'Field 3'.
APPEND wa_text TO it_text.

LOOPAT it_t001 INTO wa_t001.
wa_text-fld1 = wa_t001-bukrs.
wa_text-fld2 = wa_t001-butxt.
wa_text-fld3 = wa_t001-ort01.
APPEND wa_text TO it_text.
ENDLOOP.


CALLMETHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename =
'C:\test.txt'
filetype =
'ASC'
CHANGING
data_tab = it_text.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 

 

Internal Table to Excel

TYPES: BEGINOF ty_excel,
fld1(
20) TYPEc,
fld2(
20) TYPEc,
fld3(
20) TYPEc,
ENDOF ty_excel.

DATA: it_t001 TYPETABLEOF t001.
DATA: wa_t001 TYPE t001.
DATA: it_excel TYPETABLEOF ty_excel.
DATA: wa_excel TYPE ty_excel.

SELECT * INTOTABLE it_t001 FROM t001.

wa_excel-fld1 =
'Field 1'.
wa_excel-fld2 =
'Field 2'.
wa_excel-fld3 =
'Field 3'.
APPEND wa_excel TO it_excel.

LOOPAT it_t001 INTO wa_t001.
wa_excel-fld1 = wa_t001-bukrs.
wa_excel-fld2 = wa_t001-butxt.
wa_excel-fld3 = wa_t001-ort01.
APPEND wa_excel TO it_excel.
ENDLOOP.


CALLMETHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename              =
'C:/test.xls'
write_field_separator =
'X'
CHANGING
data_tab              = it_excel.

 


Internal Table to PDF

 



TYPES: BEGINOF ty_pdf,
fld1(
20) TYPEc,
fld2(
20) TYPEc,
fld3(
20) TYPEc,
ENDOF ty_pdf.

DATA  : g_val      TYPEc,
w_pripar 
TYPE pri_params,
w_arcpar 
TYPE arc_params,
spool_no 
LIKE tsp01-rqident,
it_pdf   
TYPETABLEOF tline WITHHEADERLINE,
file_tab 
TYPESTANDARDTABLEOF solisti1,
bytecount
TYPEi.

DATA: it_t001 TYPETABLEOF t001.
DATA: wa_t001 TYPE t001.
DATA: it_FINAL TYPETABLEOF ty_pdf.
DATA: wa_FINAL TYPE ty_pdf.



START-
OF-SELECTION.
PERFORM get_data.
PERFORM print_data CHANGING spool_no.
PERFORM convert_spool_2_pdf.
PERFORM download_pdf_file.



*&---------------------------------------------------------------------*
*&    Form  get_data

*&---------------------------------------------------------------------*

FORM get_data .

SELECT * INTOTABLE it_t001 FROM t001 upto10rows.

wa_final-fld1 =
'Field 1'.
wa_final-fld2 =
'Field 2'.
wa_final-fld3 =
'Field 3'.
APPEND wa_final TO it_final.

LOOPAT it_t001 INTO wa_t001.
wa_final-fld1 = wa_t001-bukrs.
wa_final-fld2 = wa_t001-butxt.
wa_final-fld3 = wa_t001-ort01.
APPEND wa_final TO it_final.
ENDLOOP.

ENDFORM.                  " get_data

*&---------------------------------------------------------------------*
*&    Form  print_data

*&---------------------------------------------------------------------*

FORM print_data  CHANGING spool_no.

CALLFUNCTION'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters  = w_arcpar
in_parameters          = w_pripar
layout                 =
'X_65_132'
line_count             =
65
line_size              =
132
no_dialog              =
'X'
IMPORTING
out_archive_parameters = w_arcpar
out_parameters         = w_pripar
valid                  = g_val.

IF g_val  NE space AND sy-subrc = 0.
w_pripar-prrel = space.
w_pripar-primm = space.
NEW-PAGEPRINTONNEW-SECTIONPARAMETERS w_pripar ARCHIVE PARAMETERS w_arcpar NODIALOG.

LOOPAT it_final into wa_final.
WRITE:/ wa_final.
ENDLOOP.
NEW-PAGEPRINT OFF.
CALLFUNCTION'ABAP4_COMMIT_WORK'.

ENDIF.

IFNOT sy-spono ISINITIAL.
spool_no = sy-spono.

ENDIF.
ENDFORM.                  " print_data

*&---------------------------------------------------------------------*
*&    Form  convert_spool_2_pdf
*&---------------------------------------------------------------------*

FORM convert_spool_2_pdf .

CALLFUNCTION'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid   = spool_no
no_dialog     = space
IMPORTING
pdf_bytecount = bytecount
TABLES
pdf           = it_pdf.

CALLFUNCTION'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src =
134
line_width_dst =
255
TABLES
content_in     = it_pdf
content_out    = file_tab.


ENDFORM.                  " convert_spool_2_pdf

*&---------------------------------------------------------------------*
*&    Form  download_PDF_file

*&---------------------------------------------------------------------*

FORM download_pdf_file .

CALLMETHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize          = bytecount
filename              =
'D:/test.pdf'
filetype              =
'BIN'
CHANGING
data_tab              = file_tab.

ENDFORM.                  " download_PDF_file

 

 
 

 

Internal Table to HTML

 


 

TYPES: BEGINOF ty_t001,
bukrs
TYPE t001-bukrs,
BUTXT
TYPE t001-BUTXT,
ORT01
TYPE t001-ORT01,
ENDOF ty_t001.

DATA:  it_header TYPESTANDARDTABLEOF w3head WITHHEADERLINE,
it_fields
TYPESTANDARDTABLEOF w3fields WITHHEADERLINE,
it_html
TYPESTANDARDTABLEOF w3html,
wa_header
TYPE w3head,
wa_head
TYPE w3head.

DATA : it_fcat TYPE lvc_t_fcat WITHHEADERLINE.

DATA: it_t001 TYPETABLEOF ty_t001.
DATA: wa_t001 TYPE ty_t001.


SELECT bukrs
BUTXT
ORT01
INTOTABLE it_t001 FROM t001 upto10ROWS.

it_fcat-coltext =
'Field 1'.
APPEND it_fcat.
it_fcat-coltext =
'Field 2'.
APPEND it_fcat.
it_fcat-coltext =
'Field 3'.
APPEND it_fcat.

LOOPAT it_fcat.
wa_head-
text = it_fcat-coltext.

CALLFUNCTION'WWW_ITAB_TO_HTML_HEADERS'
EXPORTING
field_nr = sy-tabix
text     = wa_head-text
fgcolor  =
'black'
bgcolor  =
'green'
TABLES
header   = it_header.

CALLFUNCTION'WWW_ITAB_TO_HTML_LAYOUT'
EXPORTING
field_nr = sy-tabix
fgcolor  =
'black'
size     = '3'
TABLES
fields   = it_fields.

ENDLOOP.

REFRESH it_html.

CALLFUNCTION'WWW_ITAB_TO_HTML'
EXPORTING
table_header = wa_header
TABLES
html         = it_html
fields       = it_fields
row_header   = it_header
itable       = it_t001.


CALLMETHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename              =
'C:/test.htm'
CHANGING
data_tab              = it_html.

 



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>