Development technology:
1. text File Upload Technology
2. Dynamic Program code generation technology
3.ABAP Dynamic Program Execution technology
4.TXT text file to apply table field editing technology
Precautions:
The time-date format of the file file editing process is 20060201 120000 for 2006.02.01 12:00:00
A text file cannot contain special symbols other than characters, numbers. If the corresponding field data in the table is empty, the column should also be empty when editing the data.
Program code: The following
*&------------------------------------------------------------------*
*& Report Z_cbo_abap_txt
*&
*&------------------------------------------------------------------*
* Program Description table Data upload program can only import txt
* Module: Version
* Reference Documents
* Application Consultant
* Program Development
* Development Date
*&------------------------------------------------------------------*
*& Change Record
*& Date Change person module: Version function manual
*&
*&
*&------------------------------------------------------------------*
Report Z_CBO_ABAP.
TABLES:DD03L,DD02T.
*-------------------------------------------------------------------*
* Inner table
*-------------------------------------------------------------------*
Data:begin of tab occurs 10,
FCode (4),
END of tab.
Data:begin of itab occurs 0,
CHK (1) TYPE C, "check box
TabName like Dd03l-tabname, "Table name
FieldName like Dd03l-fieldname, "Feld Name
Position like Dd03l-position, "Table
Keyflag like Dd03l-keyflag, "Primary Key
DataType like Dd03l-datatype, "Data Type
Intlen like Dd03l-leng,
END of Itab.
DATA itab1 like itab occurs 0 with HEADER line.
Data:begin of uptab occurs 0,
* TEXT (*) TYPE C,
Text (+) TYPE C,
END of Uptab.
Data:begin of Error_message,
Line1 (72),
Line2 (72),
Line3 (72),
END of Error_message.
Data:cnt1 (8) TYPE C,
FCode like Sy-ucomm,
Changed like S38e-buf_varied,
Prog (8) TYPE C,
MSG (+) TYPE C,
Er_include like Sy-repid,
Er_line like Sy-index,
Er_off like Sy-tabix,
ER_SUBRC like SY-SUBRC.
*-------------------------------------------------------------------*
* Select screen
*-------------------------------------------------------------------*
Parameters:tabname like Dd03l-tabname.
*------------------------------------------------------------------*
* Start-of-selection *
*-------------------------------------------------------------------*
Start-of-selection.
IF TabName is INITIAL.
MESSAGE ' Please enter a data table name! ' TYPE ' S ' DISPLAY like ' E '.
EXIT.
ENDIF.
* Upload table field analysis
SELECT single * from dd02t WHERE tabname = tabname.
If SY-SUBRC <> 0.
MESSAGE ' Please enter the correct data table name! ' TYPE ' S ' DISPLAY like ' E '.
EXIT.
endif.
SET pf-status ' CBO '.
SELECT * into corresponding fields of TABLE itab from dd03l
& nbsp; WHERE tabname = tabname
as4local = ' A '
ORDER by position.
Itab-chk = ' X '.
MODIFY itab INDEX 1 transporting chk.
* Dynamic Upload program code generation function
PERFORM generate_upload_code.
The *ABAP program code Editor calls
PERFORM Edit_generator_code.
At User-command.
IF Sy-ucomm = ' EDIT '.
PERFORM Edit_generator_code.
ELSEIF Sy-ucomm = ' EXEC '.
GENERATE subroutine POOL uptab NAME prog MESSAGE msg.
IF MSG is not INITIAL.
MESSAGE MSG TYPE ' S ' DISPLAY like ' E '.
EXIT.
ENDIF.
* Program code Syntax detection
PERFORM Chcek_syntax_error.
* Dynamic Program code execution
PERFORM dyn1 in Program (Prog).
ElseIf (Sy-ucomm = ' EXIT ' or Sy-ucomm = ' back ' or Sy-ucomm = ' Canc ').
EXIT.
ENDIF.
*&---------------------------------------------------------------*
*& Form Generate_upload_code
*&---------------------------------------------------------------*
FORM Generate_upload_code.
REFRESH Uptab.
Uptab-text = ' report zupload_table. '
APPEND Uptab.
Concatenate ' TABLES: ' tabname '. ' Into Uptab-text
separated by space.
APPEND Uptab.
Uptab-text = ' Data:begin of uptab occurs 0, '.
APPEND Uptab.
LOOP at itab WHERE chk = '.
CLEAR Uptab.
Concatenate ' itab-fieldname ' (' Itab-intlen ') ' TYPE C, '
into UPTAB-TEXT+10 (80).
APPEND Uptab.
Endloop.
Uptab-text+6 (+) = ' END of Uptab. '.
APPEND Uptab.
Uptab-text = ' Data:begin of RESULT occurs 0. '.
APPEND Uptab.
CLEAR Uptab.
Concatenate ' INCLUDE STRUCTURE ' itab-tabname '. '
Into uptab-text+10, separated by space.
APPEND Uptab.
Uptab-text = ' data:end of RESULT '.
APPEND Uptab.
Uptab-text = ' FORM DYN1. '
APPEND Uptab.
CLEAR Uptab.
uptab-text+2 = ' Call FUNCTION ' UPLOAD '.
APPEND Uptab.
CLEAR Uptab.
Uptab-text+4 = ' exporting '.
APPEND Uptab.
CLEAR Uptab.
uptab-text+6 = ' FILENAME = ' c:/'.
APPEND Uptab.
uptab-text+6 = ' FILETYPE = ' DAT '.
APPEND Uptab.
uptab-text+4 = ' TABLES '.
APPEND Uptab.
CLEAR Uptab.
Uptab-text+6 (+) = ' Data_tab = Uptab. '.
APPEND Uptab.
uptab-text+2 = ' LOOP at Uptab. '
APPEND Uptab.
CLEAR Uptab.
uptab-text+4 = ' CLEAR RESULT. '
APPEND Uptab.
uptab-text+4 = ' move-corresponding uptab to RESULT '.
APPEND Uptab.
uptab-text+4 = ' APPEND RESULT '.
APPEND Uptab.
uptab-text+2 () = ' endloop. '
APPEND Uptab.
CLEAR Uptab.
Concatenate ' MODIFY ' itab-tabname ' from TABLE RESULT. '
into uptab-text+2 (separated) by space.
APPEND Uptab.
Uptab-text = ' EndForm. '
APPEND Uptab.
CLEAR Uptab.
EndForm. "Generate_upload_code
*&---------------------------------------------------------------*
*& Form Edit_generator_code
*&---------------------------------------------------------------*
FORM Edit_generator_code.
Call FUNCTION ' Editor_application '
Exporting
application = ' BF '
display = '
Name = ' Source Code ... '
Importing
FCode = FCode
Changed = Changed
TABLES
Content = Uptab.
LOOP at Uptab.
WRITE:/1 Uptab-text.
Endloop.
EndForm. "Print_generator_code
*&---------------------------------------------------------------*
*& Form Chcek_syntax_error
*&---------------------------------------------------------------*
FORM Chcek_syntax_error.
Call FUNCTION ' Editor_syntax_check '
Exporting
I_global_check = Sy-calld
I_global_program = Sy-repid
I_program = ' zupload_table '
* I_r2_check = "
* I_r2_destination = "
* I_trdir = "
Importing
O_error_include = Er_include
O_error_line = Er_line
O_error_message = Error_message
O_error_offset = Er_off
O_ERROR_SUBRC = ER_SUBRC
TABLES
I_source = Uptab.
IF ER_SUBRC <> 0.
Er_line = er_line-2.
WRITE:/1 ' Error line: ', Er_line.
WRITE:/1 Error_message-line1,error_message-line2,
Error_message-line3.
STOP.
ENDIF.
EndForm. "Chcek_syntax_error
ABAP dynamically generates code to upload TXT data based on the table name entered