2008 Jul 18 2:36 PM
Hello Friends,
I have to create the table data Backup and Store the entire table data in the application server and also be able to restore the data back if needed.
this should be dynamic program for any table based on the table name given on the application server.. I have developed a program for this but its having problems with the Quantity, amount. Its not writing it correctly at the application level.
ANy Suggestions on this.
Below is the program for this.
Thanks,
Ster.
*---------------------------------------------------------------------*
* Report YWMM_TABLE_DUMP *
*---------------------------------------------------------------------*
REPORT ywmm_table_dump .
TABLES :
dd03l.
* Type spool declaration
TYPE-POOLS:
abap, slis.
DATA: i_table_data1 TYPE REF TO data.
DATA : it_dd03l LIKE dd03l OCCURS 0 WITH HEADER LINE.
*DATA : gt_fieldcat TYPE lvc_s_fcat.
DATA : i_fcat TYPE STANDARD TABLE OF lvc_s_fcat,
l_dr_line TYPE REF TO data,
l_v_as4vers TYPE as4vers.
FIELD-SYMBOLS: <f_table_data1> TYPE STANDARD TABLE,
<f_wa_table_data1> TYPE ANY.
SELECTION-SCREEN: BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
PARAMETERS: rb_copy RADIOBUTTON GROUP map DEFAULT 'X',
rb_rest RADIOBUTTON GROUP map.
SELECTION-SCREEN: END OF BLOCK bl1.
SELECTION-SCREEN: BEGIN OF BLOCK bl2 WITH FRAME TITLE text-002.
PARAMETERS: p_table TYPE tabname OBLIGATORY,
p_plfld TYPE dd03l-fieldname.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_bkfile TYPE localfile OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK bl2.
PERFORM get_data.
IF rb_copy = 'X'.
PERFORM backup.
ELSEIF rb_rest = 'X'.
PERFORM database_update.
ENDIF.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data.
CLEAR i_fcat.
REFRESH i_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_table " Table Name
CHANGING
ct_fieldcat = i_fcat
EXCEPTIONS
OTHERS = 1.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fcat
IMPORTING
ep_table = i_table_data1.
IF sy-subrc = 0.
ASSIGN i_table_data1->* TO <f_table_data1>.
ELSE.
WRITE: 'Error creating internal table'.
ENDIF.
IF rb_copy = 'X'.
SELECT * FROM (p_table) INTO CORRESPONDING FIELDS OF
TABLE <f_table_data1> UP TO 20 ROWS.
ELSEIF rb_rest = 'X'.
CREATE DATA l_dr_line LIKE LINE OF <f_table_data1>.
ASSIGN l_dr_line->* TO <f_wa_table_data1>.
*Get Data from Application Server
* Opening the dataset P_BKFILE given in the selection screen
TRANSLATE p_bkfile TO LOWER CASE.
OPEN DATASET p_bkfile FOR INPUT IN TEXT MODE." ENCODING DEFAULT.
IF sy-subrc NE 0.
* MESSAGE:
ELSE.
DO.
* Reading the file from application server
READ DATASET p_bkfile INTO <f_wa_table_data1>.
IF sy-subrc = 0.
APPEND <f_wa_table_data1> TO <f_table_data1>.
ELSE.
EXIT.
ENDIF.
ENDDO.
* Closing the dataset
CLOSE DATASET p_bkfile.
ENDIF.
ENDIF.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form backup
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM backup.
TRANSLATE p_bkfile TO LOWER CASE.
OPEN DATASET p_bkfile FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0.
WRITE: text-017.
STOP.
ELSE.
LOOP AT <f_table_data1> ASSIGNING <f_wa_table_data1>.
TRANSFER <f_wa_table_data1> TO p_bkfile.
ENDLOOP.
ENDIF.
CLOSE DATASET p_bkfile.
ENDFORM. " backup
*&---------------------------------------------------------------------*
*& Form database_update
*&---------------------------------------------------------------------*
FORM database_update.
DATA : i_mara_u TYPE STANDARD TABLE OF mara WITH HEADER LINE,
i_ekpo_u TYPE STANDARD TABLE OF ekpo WITH HEADER LINE,
i_eban_u TYPE STANDARD TABLE OF eban WITH HEADER LINE,
i_resb_u TYPE STANDARD TABLE OF resb WITH HEADER LINE,
i_plpo_u TYPE STANDARD TABLE OF plpo WITH HEADER LINE,
i_stpo_u TYPE STANDARD TABLE OF stpo WITH HEADER LINE,
i_vbap_u TYPE STANDARD TABLE OF vbap WITH HEADER LINE,
i_vbrp_u TYPE STANDARD TABLE OF vbrp WITH HEADER LINE,
i_lips_u TYPE STANDARD TABLE OF lips WITH HEADER LINE,
i_afvc_u TYPE STANDARD TABLE OF afvc WITH HEADER LINE,
i_asmd_u TYPE STANDARD TABLE OF asmd WITH HEADER LINE,
* i_cooi_u TYPE STANDARD TABLE OF cooi WITH HEADER LINE,
i_qmel_u TYPE STANDARD TABLE OF qmel WITH HEADER LINE,
i_cooi_u TYPE STANDARD TABLE OF cooi WITH HEADER LINE,
i_esll_u TYPE STANDARD TABLE OF esll WITH HEADER LINE,
i_t165_u TYPE STANDARD TABLE OF t165 WITH HEADER LINE,
i_t165e_u TYPE STANDARD TABLE OF t165e WITH HEADER LINE,
i_twpko_u TYPE STANDARD TABLE OF twpko WITH HEADER LINE,
i_tpext_u TYPE STANDARD TABLE OF tpext WITH HEADER LINE,
i_ce4mxpa_u TYPE STANDARD TABLE OF ce4mxpa WITH HEADER LINE,
i_ce4mxpa_acct_u TYPE STANDARD TABLE OF ce4mxpa_acct WITH
HEADER LINE,
i_zaim_u TYPE STANDARD TABLE OF zaim WITH HEADER LINE,
i_s012_d TYPE STANDARD TABLE OF s012 WITH HEADER LINE,
i_s012_i TYPE STANDARD TABLE OF s012 WITH HEADER LINE,
i_dummy TYPE STANDARD TABLE OF mara.
CASE p_table.
WHEN 'MARA'.
* Non-Key
PERFORM move_to_table USING <f_table_data1>
CHANGING i_mara_u[]
i_mara_u.
PERFORM update_table USING i_mara_u[].
ENDCASE.
ENDFORM. " database_update
*&---------------------------------------------------------------------*
*& Form move_to_mara
*&---------------------------------------------------------------------*
FORM move_to_table USING p_tab_from TYPE STANDARD TABLE
CHANGING p_tab_to TYPE STANDARD TABLE
p_w_table.
DATA: l_wa_fcat TYPE lvc_s_fcat.
FIELD-SYMBOLS: <f_field_from> TYPE ANY,
<f_field_to> TYPE ANY.
LOOP AT p_tab_from ASSIGNING <f_wa_table_data1>.
LOOP AT i_fcat INTO l_wa_fcat.
ASSIGN COMPONENT l_wa_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field_from>.
ASSIGN COMPONENT l_wa_fcat-fieldname
OF STRUCTURE p_w_table TO <f_field_to>.
<f_field_to> = <f_field_from>.
ENDLOOP.
APPEND p_w_table TO p_tab_to.
ENDLOOP.
ENDFORM. " move_to_mara
*&---------------------------------------------------------------------*
*& Form update_table
*&---------------------------------------------------------------------*
FORM update_table USING p_table_update TYPE STANDARD TABLE.
SELECT SINGLE *
FROM dd03l
WHERE fieldname = p_plfld
AND tabname = p_table
AND keyflag <> 'X'
AND as4local = 'A'
AND as4vers = l_v_as4vers
AND ( comptype = 'E' OR comptype = space ).
IF sy-subrc = 0.
* Do update
IF NOT p_table_update IS INITIAL.
UPDATE (p_table) FROM TABLE p_table_update.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: text-003.
STOP.
ENDIF.
ENDIF.
ELSE.
*delete and insert.
IF NOT p_table_update IS INITIAL.
* DELETE (p_table).
IF sy-subrc = 0.
INSERT (p_table) FROM TABLE p_table_update.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: text-018.
STOP.
ENDIF.
ELSE.
ROLLBACK WORK.
WRITE: text-018.
STOP.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " update_table
Edited by: Julius Bussche on Jul 18, 2008 1:43 PM
Please use a meaningfull subject title!
2008 Jul 18 2:40 PM
Hello Ster,
I think u r passing the quantity fields directly to application server. U should convert those into character then only it will take them and print them properly.
Regards,
Subbu
Hello Ster,
I think u r passing the quantity fields directly to application server. U should convert those into character then only it will take them and print them properly.
Regards,
Subbu
2008 Jul 18 2:39 PM
2008 Jul 18 2:40 PM
Hello Ster,
I think u r passing the quantity fields directly to application server. U should convert those into character then only it will take them and print them properly.
Regards,
Subbu
2008 Jul 18 2:53 PM
THanks All for all ur suggestions.
I was wondering how would I change them to the CHAR format as everything here is dynamic. Please suggest.
Ster
2008 Jul 18 2:57 PM
Ster,
You need to convert the quantity field content into character format.
in your form BACKUP you need to convert like the following
LOOP AT <f_table_data1> ASSIGNING <f_wa_table_data1>.
LOOP AT i_fcat INTO l_wa_fcat.
if l_wa_fcat-inttype eq 'P'.
assign component l_wa_fcat-fieldname
of structure <f_wa_table_data1> to <comp>
type fields_int-type
decimals fields_int-decimals.
else.
assign component l_wa_fcat-fieldname
of structure <f_wa_table_data1> to <comp>
type fields_int-type.
endif.
" Move <com> to a new table and use this table for download
endloop.
endloop.
a®
2008 Jul 18 3:24 PM
Thanks ARS.
However I am facing a bit difficulties in getting this.
Anyways I will try more and get back to you.
Thanks,
Ster.
2008 Jul 18 3:42 PM
ARS,
I am struggling a bit to get this.
there is a syntax error,
Field "FIELDS_INT-TYPE" is unknown. It is neither in one of thespecified tables nor defined by a "DATA" statement.
Again you have asked to move to a diffrent table. What is that table and how to build it.
LOOP AT <f_table_data1> ASSIGNING <f_wa_table_data1>.
LOOP AT i_fcat INTO l_fcat.
IF l_fcat-inttype EQ 'P'.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE fields_int-type
DECIMALS fields_int-decimals.
ELSE.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE fields_int-type.
ENDIF.
" Move <f_field> to a new table and use this table for download
ENDLOOP.
TRANSFER <f_wa_table_data1> TO p_bkfile.
ENDLOOP.
Ster
2008 Jul 18 3:54 PM
Please change the lines
fields_int-type
with
fields l_wa_fcat-inttype
a®
2008 Jul 18 4:39 PM
Thanks ARS for all your suggestions.
However I am stuck with one more thing and I am wondering would that work.
How would you move this to another table and download.
LOOP AT <f_table_data1> ASSIGNING <f_wa_table_data1>.
LOOP AT i_fcat INTO l_fcat.
IF l_fcat-inttype EQ 'P'.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE l_fcat-inttype
decimals l_fcat-decimals.
ELSE.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE l_fcat-inttype.
ENDIF.
* Move <f_field> to a new table and use this table for download
ENDLOOP.
Ster
2008 Jul 18 5:11 PM
Check this
data : begin of i_output occurs 0.
data : sdata(10000) type c.
data : end of i_output.
LOOP AT <f_table_data1> ASSIGNING <f_wa_table_data1>.
clear : line_cursor.
LOOP AT i_fcat INTO l_fcat.
IF l_fcat-inttype EQ 'P'.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE l_fcat-inttype
decimals l_fcat-decimals.
ELSE.
ASSIGN COMPONENT l_fcat-fieldname
OF STRUCTURE <f_wa_table_data1> TO <f_field>
TYPE l_fcat-inttype.
ENDIF.
line_cursor = line_cursor + l_fcat-intlen.
write <f_field> to i_output-sdata + line_cursor(l_fcat-intlen).
ENDLOOP.
append i_output.
ENDLOOP.
a®s
Edited by: a®s on Jul 18, 2008 12:12 PM
2008 Jul 18 6:48 PM
Thanks ARS.
It writes now.
But there is one more concern.
The file on the app server does not have all the data. I mean it has all the rows but for each row some of the fields have disappeared.
Any Suggestions.
Ster
2008 Jul 18 7:06 PM
Please check the I_OUTPUT table and closely check the lines
line_cursor = line_cursor + l_fcat-intlen.
write <f_field> to i_output-sdata + line_cursor(l_fcat-intlen).
a®
2008 Jul 18 7:12 PM
Thanks Buddy.
However I have made samlll changes to the code.
I have writted the addition datatement after the write statement and also have included the decimals in addition.
WRITE <f_field> TO i_output-sdata+line_cursor(l_fcat-intlen).
line_cursor = line_cursor + l_fcat-intlen + l_fcat-decimals.But Now another challenge, the restore program.
Ster.
2008 Jul 18 7:15 PM
2008 Jul 18 7:17 PM
is I_FCAT-INTLEN ( i think this contains the total lenth of the field including decials also )
then why are you adding DECIMALS along with INTLEN to line_cursor
line_cursor = line_cursor + l_fcat-intlen + l_fcat-decimals.
a®
2008 Jul 18 7:25 PM
yes the download is working fine Now. WIll have to look more in details each and every Value.
I have removed the decimals Addition.
Can you help me in getting the restore done.
LOOP AT i_output.
CLEAR : line_cursor.
LOOP AT i_fcat INTO l_fcat.
<f_wa_table_data1>-l_fcat-fieldname =
i_output-sdata+line_cursor(l_fcat-intlen). "Syntax Error
line_cursor = line_cursor + l_fcat-intlen + l_fcat-decimals.
ENDLOOP.
APPEND <f_wa_table_data1> to <f_table_data1>.
ENDLOOP.
Thanks,
Ster
2008 Jul 18 7:42 PM
Try with simple way
loop at i_output.
write i_output to <f_table_data1>. " dyn table using p_table
append <f_table_data1>.
endloop.
a®
2008 Jul 18 7:55 PM
ARS,
It dosent work this simple way.
The values get Jumbled up from the 'P' field type.
I also see some 20202020 passed which is not on the app.
Ster.
2008 Jul 18 8:05 PM
I am leaving for the day. I will look into your query on monday
a®
2008 Jul 18 8:07 PM
Thanks Buddy for all the help you have done so far.
It was of lot of help.
Thanks again.
Ster.
2008 Jul 18 2:41 PM
I'd suggest you look at the options on OPEN DATASET. I think you want to open the datasets in BINARY mode. Numeric data is stored (most often) as Binary Coded Decimal.
I really hope this is just an exercise, and that you'd NEVER run this on a real system!
matt
2008 Jul 18 2:43 PM
I have developed a program for this but its having problems with the Quantity, amount. Its not writing it correctly at the application level.
Quantities, Currencies are not trnasferred to Application server. Before Transfering the Quantities and Amounts you have to convert them to Character format and then Transfer the data.
2008 Jul 18 5:08 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |