Update Data Tables in batches

Source: Internet
Author: User
This Program You can generate the ABAP source program for table operations based on the input table name. Then, the source program generated by system operation will let you choose to import files. The file must conform to the table structure.
Batch update data tables can be used for batch import. You can use Excel or SQL Server to prepare data and export it as a text file. Development Technology: 1. Text File Upload Technology 2. Dynamic programs Code Generation Technology 3. ABAP dynamic program execution technology 4. Application table field editing technology using TXT text files
Code: Note: During file editing, the date format is 20060201 120000, indicating that the text file at 12:00:00 cannot contain any special symbols other than characters and numbers. If the field data in the table is empty, it should also be empty when editing the data. Program code: The following report z_cbo_abap_01 no standard page heading. Tables: dd03l, dd02t. "table and column 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 (100) 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 (120) type C,
Er_include like sy-repid,
Er_line like sy-index,
Er_off like sy-tabix,
Er_subrc like sy-subrc. * program entry interface parameters: tabname like dd03l-tabname default 'zp023 '. start-of-selection. * select single * From dd02t where tabname = tabname.
Set PF-STATUS 'zstatus'. "customize this GUI stauts
Select * into corresponding fields of table itab from dd03l
Where tabname = tabname
And as4local = 'A'
Order by position.
Itab-chk = 'x'. Modify itab Index 1 transporting chk. * dynamic upload program code generation function
Perform generate_upload_code. * called by the ABAP program code editor
Perform edit_generator_code. "You need to define the GUI status. At user-command.
If sy-ucomm = 'edit '.
Perform edit_generator_code.
Elseif sy-ucomm = 'exec '. Generate subroutine pool uptab name prog message MSG. * program code syntax check
Perform chcek_syntax_error. * dynamic program code execution
Perform dyn1 in program (Prog ).
Endif .*&---------------------------------------------------------------*
* & Form generate_upload_code
* & ----------------------------------------------------------------- * Form generate_upload_code.
Refresh uptab.
Uptab-TEXT = 'report zup19800526 .'.
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 (82) = '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 (80) separated by space.
Append uptab.
Uptab-TEXT = 'data: End of result .'.
Append uptab.
Uptab-TEXT = 'form dyn1 .'.
Append uptab.
Clear uptab.
Uptab-text + 2 (88) = 'call function''' upload '''.
Append uptab.
Clear uptab.
Uptab-text + 4 (86) = 'porting '.
Append uptab.
Clear uptab.
Uptab-text + 6 (84) = 'filename = ''c :\'''.
Append uptab.
Uptab-text + 6 (84) = 'filetype = ''dat '''.
Append uptab.
Uptab-text + 4 (86) = 'tables '.
Append uptab.
Clear uptab.
Uptab-text + 6 (84) = 'data _ tab = uptab .'.
Append uptab.
Uptab-text + 2 (88) = 'loop at uptab .'.
Append uptab.
Clear uptab.
Uptab-text + 4 (86) = 'clear result .'.
Append uptab.
Uptab-text + 4 (86) = 'move-corresponding uptab to result .'.
Append uptab.
Uptab-text + 4 (86) = 'append result .'.
Append uptab.
Uptab-text + 2 (88) = 'endloop .'.
Append uptab.
Clear uptab.
Concatenate 'insert' itab-tabname' from table result .'
Into uptab-text + 2 (88) 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 =''
I _global_program =''
I _program = 'zup19800526'
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_error1. on the initial interface of the program, enter the name of the upload table. 2. the first interface for running the program, showing the upload program code automatically generated by the Program 3. run the program on the second page, check the upload program code automatically generated by the program, and execute 4. on the third page of the program running interface, the program execution prompt is entered in the specific data path 4. OK. the data is uploaded successfully. Supplement 1: the format of the uploaded data file ,*. TXT dat format file, also known as plain text file Supplement 2: SAP table format, be careful not to ignore the mandt client field, other field data corresponds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.