[SAP ABAP] - Read TABLE v02

*&---------------------------------------------------------------------*
*& Report YABApa_TOOLS_READ_TABLE_02
*&
*&---------------------------------------------------------------------*
*& Created By : Albertus Reinandang
*& Date : 12.05.2010 *
*&---------------------------------------------------------------------*

REPORT yabapa_tools_read_table_02.

TABLES : dd02l, dd03l,soid.

DATA : gi_dd02l LIKE STANDARD TABLE OF dd02l WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK zblk01 WITH FRAME TITLE text_101.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) text_102 FOR FIELD so_tbma.
SELECT-OPTIONS : so_tbma FOR dd02l-tabname." DEFAULT 'ZTA*'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) text_103 FOR FIELD pa_spara.
PARAMETERS pa_spara TYPE c LENGTH 3 DEFAULT ',' OBLIGATORY.
SELECTION-SCREEN END OF LINE.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) text_104 FOR FIELD pa_data.
PARAMETERS : pa_data LIKE sonv-flag.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(19) text_105 FOR FIELD pa_dir.
PARAMETERS : pa_dir TYPE string DEFAULT 'c:\backup\dictionary\'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK zblk01.

*SELECTION-SCREEN BEGIN OF BLOCK zblk02 WITH FRAME TITLE text_201.
*
*SELECTION-SCREEN BEGIN OF LINE.
*SELECT-OPTIONS so_row FOR soid-accnt NO-EXTENSION
* DEFAULT 1 TO 1000.
*SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN END OF BLOCK zblk02.


INITIALIZATION.

text_101 = 'Transport to txt File'.
text_102 = 'Table Name '.
text_103 = 'Sparator'.
text_104 = 'With Data'.
text_105 = 'Directory'.
* text_201 = 'Row Selection'.


START-OF-SELECTION.
PERFORM fm_collect_data.
PERFORM fm_process_data.

*&---------------------------------------------------------------------*
*& Form fm_collect_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_collect_data.
SELECT *
INTO TABLE gi_dd02l
FROM dd02l
WHERE tabname IN so_tbma.

ENDFORM. "fm_collect_data


*&---------------------------------------------------------------------*
*& Form fm_process_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_process_data.
DATA : lv_filename1 TYPE string,
lv_filename2 TYPE string,
lv_no_data.

DATA : li_options LIKE STANDARD TABLE OF rfc_db_opt WITH HEADER LINE,
li_fields LIKE STANDARD TABLE OF rfc_db_fld WITH HEADER LINE,
li_data LIKE STANDARD TABLE OF ytab WITH HEADER LINE,
"YTAB -> Lihat pada ABAP Tutorial "Cara Meningkatkan Buffer pada Function RFC_READ_TABLE"
li_table_structure LIKE STANDARD TABLE OF dfies WITH HEADER LINE.

IF pa_data = ' '.
lv_no_data = 'X'.
ENDIF.

CONDENSE pa_dir.
LOOP AT gi_dd02l.
REFRESH : li_options, li_fields, li_data, li_table_structure.
CONCATENATE pa_dir gi_dd02l-tabname '_STRUCTURE.txt' INTO lv_filename1.
CONCATENATE pa_dir gi_dd02l-tabname '_CONTENT.txt' INTO lv_filename2.
CONDENSE : lv_filename1, lv_filename2.

"YRFC_READ_TABLE -> Lihat pada ABAP Tutorial "Cara Meningkatkan Buffer pada Function RFC_READ_TABLE"
CALL FUNCTION 'YRFC_READ_TABLE'
EXPORTING
query_table = gi_dd02l-tabname
delimiter = pa_spara
no_data = lv_no_data
TABLES
OPTIONS = li_options
fields = li_fields
data = li_data
table_structure = li_table_structure.

"Download Stucture
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_filename1
show_transfer_status = ' '
TABLES
data_tab = li_table_structure.

"Download Data
IF pa_data = 'X'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_filename2
show_transfer_status = ' '
TABLES
data_tab = li_data.
ENDIF.

ENDLOOP.

ENDFORM. "fm_process_data

Comments

成功多屬於那些很快做出決定,卻又不輕易變更的人。而失敗也經常屬於那些很難做出決定,卻又經常變更的人.............................................
韋于倫成 said…
我對自己的信心已超越別人對我的評價..............................
juliancu said…
一個人的價值,應該看他貢獻了什麼,而不是他取得了什麼..................................................
很棒的分享~留言支持!.................................................................                           
孫俊翔 said…
心中醒,口中說,紙上作,不從身上習過,皆無用也。..................................................
凱許倫 said…
唯有用熱情、用智慧去觀察事物,這事物才會把他的秘密,洩漏給我們......................................................................
怡楊雯 said…
開懷幸福的生活,是每個人的夢想~~希望大家都能夠實現!..................................................................
瑰潼 said…
人類的聰明,並非以經驗為依歸,而是以接受經驗的行程為依歸。..................................................
孫邦柔 said…
在莫非定律中有項笨蛋定律:「一個組織中的笨蛋,恆大於等於三分之二。」..................................................