2007 Sep 14 5:39 AM
Hi all,
I have a problem in getting the header line from the database table to internal table. This is for generating the report in excel sheet from the internal table with header. I dont want hard code since it to be dynamically pass the table everytime. so that the internal table must get the headerline from the database table passed.
Expecting some input from you guys...
Thanks,
ranjit.
Hi all,
I have a problem in getting the header line from the database table to internal table. This is for generating the report in excel sheet from the internal table with header. I dont want hard code since it to be dynamically pass the table everytime. so that the internal table must get the headerline from the database table passed.
Expecting some input from you guys...
Thanks,
ranjit.
2007 Sep 14 5:49 AM
do it like this
tables : mara
selectsingle * from mara where matnr = your conditons
now----
append mara to internal table
the internal table will get the line from dbase table
declare with tables satement which table you want
and select the data into the same table
and pass the header line to your internal table
2007 Sep 14 5:54 AM
Hi shiva
Thanks for your immediate reply, but my question is like how to get the header of the tables (column head - like Name, Age). As of now i am getting the valuesof the entire table, but the header is not coming. Can you suggest me the possible ways of getting the header.
Regards,
ranjit.
2007 Sep 14 6:02 AM
Hi Ranjit,
Check the code below:
<b>DATA: itab TYPE mara OCCURS 0 WITH HEADER LINE.
SELECT * FROM mara INTO TABLE itab.</b>
Hope it helps.
Regards,
Amit
2007 Sep 14 6:09 AM
2007 Sep 14 6:11 AM
&----
*& Report ZTO_FLAT_DELI
*&
&----
*&
*&
&----
REPORT ZTO_FLAT_DELI.
&----
*& Declaration Section for the Tables *
&----
TABLES: ROOSOURCE.
&----
*& Declaration Section for the Internal Tables
&----
*DATA: intab TYPE TABLE OF ROOSOURCE,
DATA: intab TYPE ROOSOURCE occurs 0 with header line,
wa_intab LIKE LINE OF intab,
no_of_rec TYPE i,
count TYPE i.
DATA: BEGIN OF f_intab,
str(255) TYPE c,
END OF f_intab.
DATA: t_intab LIKE TABLE OF f_intab,
w_intab LIKE LINE OF t_intab,
temp(255) TYPE c.
FIELD-SYMBOLS: <f> TYPE ANY.
&----
*& Selection ScreenSection for the file download
&----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: file TYPE rlgrap-filename MEMORY ID file,
tab RADIOBUTTON GROUP rad1 DEFAULT 'X',
others RADIOBUTTON GROUP rad1,
delimit TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
IF file IS INITIAL. " check to ensure file.
EXIT.
ENDIF.
IF others = 'X'. " check to ensure delimiter.
IF delimit = ' '.
EXIT.
ENDIF.
ENDIF.
SELECT * FROM ROOSOURCE INTO TABLE intab UP TO 5 ROWS.
IF tab = 'X'. " default delimiter tab is used
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'DAT'
mode = 'A'
TABLES
data_tab = intab
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE. " If user defind delimiter is to be used
Counts the number of fields *
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
IF sy-subrc <> 0.
EXIT.
ELSE.
count = count + 1.
ENDIF.
ENDDO.
LOOP AT intab INTO wa_intab.
DO count TIMES. " Adding the delimiter in required places
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
CONCATENATE temp delimit <f> INTO temp.
ENDDO.
SHIFT temp.
APPEND temp TO t_intab.
CLEAR temp.
ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'ASC'
mode = 'A'
TABLES
data_tab = t_intab
EXCEPTIONS
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
WRITE:/ 'The Data has been tranfered to :', file.
2007 Sep 14 6:34 AM
Hi Ranjit,
So you require field names of the table into your internal table.
Use FM <b>DDIF_FIELDINFO_GET</b> to get names of tablefields and you can put them into your internal table.
Hope it solves your problem.
Regards,
Amit
Message was edited by:
Amit Kumar
2007 Sep 14 7:17 AM
hi amit,
Can you suggest me wat the parameters need to give to the FM DDIF_FIELDINFO_GET to ge the column headers of the table.
Regards,
ranjit.
2007 Sep 14 7:39 AM
Hi Ranjit,
You can pass table name into TABNAME and get column names from field FIELDTEXT in table DFIES_TAB.
Get the output of table DFIES_TAB into an internal table of similar structure.
Use this internal table to get header of each field by comparing the field names of table.
Regards,
Amit
Message was edited by:
Amit Kumar
2007 Sep 14 6:05 AM
Can you send your code i can so that i can modify it and send it to you
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |