06-30-2007 7:06 AM
Hi All,
I have generated a flat file with our headers to it , I have a requriement appending headers to that flat file.
My idea is writing a ABAP program calling the flat file into internal table and writing the source file to other new file with headers to it.
EG: SRCfile (with oout headers) -
>ABAP <-----> DESTfile (with Headers)
Please can you give me a clue on the ABAP program
I really appreciate if you can share the code for me.
Thanks a lot !
Phillips
Message was edited by:
phillip muls
06-30-2007 7:25 AM
Hi,
You might have used the loop to copy the internal table into the file.
You can use the code as :
=====
LOOP AT itab
[AT FIRST.
...
ENDAT.]
your logic..
ENDLOOP.
=====
Whenever the first line of internal table is in the header, you can add the header details.
hope this helps.
reward if useful.
regards,
06-30-2007 7:10 AM
HI,
use FM : GUI_DOWNLOAD to get particular file into your internal table... then append your header in that internal table
then use another FM : GUI_UPLOAD .
regards,
shardul shah
06-30-2007 7:28 AM
Hi shardul shah ,
Thanks for your reply !!
I am using CSV file for my purpose. the FMs given by you will also work for CSV.
Please can you suggest me any changes to be made in the FM for my purpose.
I really appreciate if you can share code for me.
Thanks a lot !!
Phillips
06-30-2007 7:25 AM
Hi,
You might have used the loop to copy the internal table into the file.
You can use the code as :
=====
LOOP AT itab
[AT FIRST.
...
ENDAT.]
your logic..
ENDLOOP.
=====
Whenever the first line of internal table is in the header, you can add the header details.
hope this helps.
reward if useful.
regards,
06-30-2007 7:32 AM
Hi Sachin,
Thanks for your reply.
I am entirely new to ABAP coding, please can you share the code for me to achieve it.
Thanks a lot !!
Phillips
06-30-2007 7:52 AM
Hi Phillip,
The code below will be helpful.
Please reward for useful replies.
=====
&----
*& Report ZSCD_TEST7
*&
&----
*&
*&
&----
REPORT ZSCD_TEST7.
DATA: BEGIN OF ITAB occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB.
DATA: BEGIN OF ITAB1 occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB1.
select matnr ernam aenam up to 10 rows from mara into table itab .
loop at itab.
at first.
itab1-matnr = 'Material Number'.
itab1-ernam = 'Created by'.
itab1-aenam = 'Last hanged'.
append itab1.
endat.
itab1-matnr = itab-matnr.
itab1-ernam = itab-ernam.
itab1-aenam = itab-aenam.
append itab1.
endloop.
write : 'Hello'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\Books\demo.txt' " Put your own path here.
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab1
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
======
regards,
sachin
06-30-2007 8:34 AM
Hi Sachin,
Thanks a lot for your code and it is working perfect.
I have a question , Already I have a flat file without headers , how to change the logic if want to read data from file otherthan from tables.
Is there any possibility if to read from data from flatfile to internal tables than write to a flat file, if this is not feasible I will set with your previous code .
The code given by you was really useful to me
Thanks a lot !!
Phillips
06-30-2007 8:50 AM
HI Phillip,
Look at the following code now.
===========
&----
*& Report ZSCD_TEST7
*&
&----
*&
*&
&----
REPORT ZSCD_TEST7.
DATA: BEGIN OF ITAB occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB.
DATA: BEGIN OF ITAB1 occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB1.
****select matnr ernam aenam up to 10 rows from mara into table itab .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Books\demo1.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab.
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
at first.
itab1-matnr = 'Material Number'.
itab1-ernam = 'Created by'.
itab1-aenam = 'Last hanged'.
append itab1.
endat.
itab1-matnr = itab-matnr.
itab1-ernam = itab-ernam.
itab1-aenam = itab-aenam.
append itab1.
endloop.
write : 'Hello'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\Books\demo.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab1
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
============
Reward if useful.
reagrds,
sachin
06-30-2007 9:04 AM
Hi Sachin,
Thanks for your code !!
I have a problem , the output file which got generated does not have any seperator , please help me how to seperate the each column using a spearator in the code.
I will get a CSV file and needs to generate the new CSV file with Headers.
Thanks a lot !!
Phillips
Message was edited by:
phillip muls
06-30-2007 9:27 AM
Hi,
If there is no saperator, check the followingcode.
Important : The input file should contain the exact data.
Eg: If the material number is of length 18 and your file contains the material number as 21121100 - the code will not work.
The file should contain the material number as : 000000000021121100.
&----
*& Report ZSCD_TEST7
*&
&----
*&
*&
&----
REPORT ZSCD_TEST7.
DATA: BEGIN OF ITAB occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB.
DATA: BEGIN OF ITAB1 occurs 0 ,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
AENAM TYPE MARA-AENAM,
END OF ITAB1.
****select matnr ernam aenam up to 10 rows from mara into table itab .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Books\demo1.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab.
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
at first.
itab1-matnr = 'Material Number'.
itab1-ernam = 'Created by'.
itab1-aenam = 'Last hanged'.
append itab1.
clear itab1.
endat.
**itab1-matnr = itab-matnr.
**itab1-ernam = itab-ernam.
**itab1-aenam = itab-aenam.
**append itab1.
*split itab at '#' into itab1-matnr itab1-ernam itab1-aenam.
*append itab1.
itab1-matnr = itab+0(18).
itab1-ernam = itab+19(12).
append itab1.
clear itab1.
endloop.
write : 'Hello'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\Books\demo.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itab1
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
======
reagrds,
sachin