Posted: Fri Nov 09, 2007 5:06 pm Post subject: Dynamic table export / import facility
Code:
*----------------------------------------------------------------------
* N Overton : Created ( T/Code ZTUD)
*
* Dynamic table export / import facility.
*
* Restrictions - Table definition MUST exist on target
* system for import.
* - Entire table is exported / imported
* - Must be WIN95/98 WIN-NT long filenames
*----------------------------------------------------------------------
* TEXTS
*
* List Header...: For SAP Table: &1............................
*
* Column Heading: | Function Status(48 spaces)# Records |
*
* Selection Texts: PATH Folder Path for file
* P_CLEAR Delete Existing Records
* P_EXP Export to PC File
* P_IMP Import from PC File
* TABNAME SAP table name
*
* Text Symbols: B00 Dynamic Import/Export of SAP data
* B01 SAP Table Name
* B02 Program Function
* B03 Folder For Data File
* B04 Existing Records Deletion Selection
* ER2 File not found. Please check.
* PGE Page
*----------------------------------------------------------------------
* This program once created will allow you to download or upload table
* data from any SAP table. It has the functionality to allow you to
* select whether data should be appended or original data cleaed before
* inserting new data.
* This is very useful when attempting to transfer data from one client
* to another
*----------------------------------------------------------------------
report sy-repid line-size 80
line-count 65
no standard page heading.
tables: dd02l, dd03l.
* selection screen
selection-screen begin of block b00 with frame title text-b00.
*
selection-screen begin of block b01 with frame title text-b01.
parameters: tabname like dd02l-tabname obligatory.
selection-screen end of block b01.
*
selection-screen begin of block b03 with frame title text-b03.
parameters: path(30) type c default 'C:\SAPWorkdir'.
selection-screen end of block b03.
*
selection-screen begin of block b04 with frame title text-b04.
parameters: p_exp radiobutton group radi,
p_imp radiobutton group radi,
p_clear as checkbox.
selection-screen end of block b04.
selection-screen end of block b00.
* data
data: q_return like syst-subrc,
err_flag(1) type c,
answer(1) type c,
w_text1(62) type c,
w_text2(40) type c,
winfile(128) type c,
w_system(40) type c,
winsys(7) type c,
zname(8) type c,
w_line(80) type c.
* internal tables
data : begin of textpool_tab occurs 0.
include structure textpool.
data : end of textpool_tab.
* table for subroutine pool
data : itab(80) occurs 0.
* events
initialization.
perform check_system.
*
at selection-screen on tabname.
perform check_table_exists.
at selection-screen on radiobutton group radi.
if sy-sysid eq 'PEP' and p_exp is initial.
message e427(mo) with tabname.
endif.
*
start-of-selection.
perform init_report_texts.
perform request_confirmation.
*
end-of-selection.
if answer = 'J'.
perform execute_program_function.
endif.
*
top-of-page.
perform process_top_of_page.
* forms
*---------------------------------------------------------------------*
* FORM CHECK_TABLE_EXISTS *
*---------------------------------------------------------------------*
form check_table_exists.
select single * from dd02l
into corresponding fields of dd02l
where tabname = tabname.
check syst-subrc ne 0.
message e402(mo) with tabname.
endform.
*---------------------------------------------------------------------*
* FORM INIT_REPORT_TEXTS *
*---------------------------------------------------------------------*
form init_report_texts.
read textpool syst-repid
into textpool_tab language syst-langu.
loop at textpool_tab
where id eq 'R' or id eq 'T'.
replace '&1............................'
with tabname into textpool_tab-entry.
modify textpool_tab.
endloop.
endform.
*---------------------------------------------------------------------*
* FORM REQUEST_CONFIRMATION *
*---------------------------------------------------------------------*
form request_confirmation.
* import selected, confirm action
if p_imp = 'X'.
* build message text for popup
concatenate 'Data for table'
tabname
'will be imported' into w_text1 separated by space.
* check if delete existing selected, and change message text
if p_clear = ' '.
w_text2 = 'and appended to the end of existing data'.
else.
w_text2 = 'Existing Data will be deleted'.
endif.
call function 'POPUP_TO_CONFIRM_STEP'
exporting
defaultoption = 'N'
textline1 = w_text1
textline2 = w_text2
titel = 'Confirm Import of Data'
cancel_display = ' '
importing
answer = answer
exceptions
others = 1.
else.
* export selected, set answer to yes so export can continue
answer = 'J'.
endif.
endform.
*---------------------------------------------------------------------*
* FORM EXECUTE_PROGRAM_FUNCTION *
*---------------------------------------------------------------------*
form execute_program_function.
perform build_file_name.
clear: q_return,err_flag.
if p_imp = 'X'.
perform check_file_exists.
check err_flag = ' '.
perform func_import.
else.
perform func_export.
endif.
endform.
*---------------------------------------------------------------------*
* FORM BUILD_FILE_NAME *
*---------------------------------------------------------------------*
form build_file_name.
move path to winfile.
write '\' to winfile+30.
write tabname to winfile+31.
write '.TAB' to winfile+61(4).
condense winfile no-gaps.
endform.
*---------------------------------------------------------------------*
* FORM CHECK_FILE_EXISTS *
*---------------------------------------------------------------------*
form check_file_exists.
if syst-subrc ne 0 or q_return ne 1.
err_flag = 'X'.
endif.
endform.
*---------------------------------------------------------------------*
* FORM func_export *
*---------------------------------------------------------------------*
form func_export.
clear itab. refresh itab.
append 'PROGRAM SUBPOOL.' to itab.
append 'FORM DOWNLOAD.' to itab.
append 'DATA: BEGIN OF IT_TAB OCCURS 0.' to itab.
concatenate 'INCLUDE STRUCTURE'
tabname
'.' into w_line separated by space.
append w_line to itab.
append 'DATA: END OF IT_TAB.' to itab.
concatenate 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB.' into w_line separated by space.
append w_line to itab.
append 'CALL FUNCTION ''WS_DOWNLOAD''' to itab.
append 'EXPORTING' to itab.
concatenate 'filename = ' ''''
winfile '''' into w_line separated by space.
append w_line to itab.
append 'filetype = ''DAT''' to itab.
append 'TABLES' to itab.
append 'DATA_TAB = IT_TAB.' to itab.
append 'DESCRIBE TABLE IT_TAB LINES sy-index.' to itab.
append 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' to itab.
append 'WRITE: /1 syst-vline,' to itab.
append '''EXPORT'',' to itab.
append '15 ''data line(s) have been exported'',' to itab.
append '68 syst-index,' to itab.
append '80 syst-vline.' to itab.
append 'ULINE.' to itab.
append 'ENDFORM.' to itab.
generate subroutine pool itab name zname.
perform download in program (zname).
endform.
*---------------------------------------------------------------------*
* FORM func_import *
*---------------------------------------------------------------------*
form func_import.
clear itab. refresh itab.
append 'PROGRAM SUBPOOL.' to itab.
append 'FORM UPLOAD.' to itab.
append 'DATA: BEGIN OF IT_TAB OCCURS 0.' to itab.
concatenate 'INCLUDE STRUCTURE'
tabname
'.' into w_line separated by space.
append w_line to itab.
append 'DATA: END OF IT_TAB.' to itab.
append 'DATA: BEGIN OF IT_TAB2 OCCURS 0.' to itab.
concatenate 'INCLUDE STRUCTURE'
tabname
'.' into w_line separated by space.
append w_line to itab.
append 'DATA: END OF IT_TAB2.' to itab.
append 'CALL FUNCTION ''WS_UPLOAD''' to itab.
append 'EXPORTING' to itab.
concatenate 'filename = ' ''''
winfile '''' into w_line separated by space.
append w_line to itab.
append 'filetype = ''DAT''' to itab.
append 'TABLES' to itab.
append 'DATA_TAB = IT_TAB.' to itab.
if p_clear = 'X'.
concatenate 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB2.' into w_line separated by space.
append w_line to itab.
append 'LOOP AT IT_TAB2.' to itab.
concatenate 'DELETE'
tabname
'FROM IT_TAB2.' into w_line separated by space.
append w_line to itab.
append 'ENDLOOP.' to itab.
append 'COMMIT WORK.' to itab.
endif.
append 'LOOP AT IT_TAB.' to itab.
concatenate 'MODIFY'
tabname
'FROM IT_TAB.' into w_line separated by space.
append w_line to itab.
append 'ENDLOOP.' to itab.
append 'DESCRIBE TABLE IT_TAB LINES sy-index.' to itab.
append 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' to itab.
append 'WRITE: /1 syst-vline,' to itab.
append '''IMPORT'',' to itab.
append '15 ''data line(s) have been imported'',' to itab.
append '68 syst-index,' to itab.
append '80 syst-vline.' to itab.
append 'ULINE.' to itab.
append 'ENDFORM.' to itab.
generate subroutine pool itab name zname.
perform upload in program (zname).
endform.
*---------------------------------------------------------------------*
* Form CHECK_SYSTEM
* Check users workstation is running
* WINDOWS 95, or WINDOWS NT.
* OS/2 uses 8.3 file names which are no good for
* this application as filenames created are 30 char
* same as table name.
* You could change the logic to only use the first 8 chars
* of the table name for the filename, but you could possibly
* get problems if users had exported already with a table
* with the same first 8 chars.
* As an alternate method you could request the user to input
* the full path including filename and remove the logic to
* build the path using the table name.
*---------------------------------------------------------------------*
form check_system.
call function 'WS_QUERY'
exporting
query = 'WS'
importing
return = winsys.
if winsys ne 'WN32_95'.
write: 'Windows NT or Windows 95/98 is required'.
exit.
endif.
endform. " CHECK_SYSTEM
*---------------------------------------------------------------------*
* FORM PROCESS_TOP_OF_PAGE *
*---------------------------------------------------------------------*
form process_top_of_page.
format color col_heading intensified on.
uline.
concatenate syst-sysid
syst-saprl
syst-host into w_system separated by space.
write : at /1(syst-linsz) w_system centered.
write : at 1 syst-vline, syst-uname.
syst-linsz = syst-linsz - 11.
write : at syst-linsz syst-repid(008).
syst-linsz = syst-linsz + 11.
write : at syst-linsz syst-vline.
loop at textpool_tab where id eq 'R'.
write : at /1(syst-linsz) textpool_tab-entry centered.
endloop.
write : at 1 syst-vline, syst-datum.
syst-linsz = syst-linsz - 11.
write : at syst-linsz syst-tcode(004).
syst-linsz = syst-linsz + 11.
write : at syst-linsz syst-vline.
loop at textpool_tab where id eq 'T'.
write : at /1(syst-linsz) textpool_tab-entry centered.
endloop.
write : at 1 syst-vline, syst-uzeit.
syst-linsz = syst-linsz - 11.
write : at syst-linsz 'Page', syst-pagno.
syst-linsz = syst-linsz + 11.
write : at syst-linsz syst-vline.
uline.
format color col_heading intensified off.
loop at textpool_tab where id eq 'H'.
write : at /1(syst-linsz) textpool_tab-entry.
endloop.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.