2007 Jun 05 7:26 PM
Hi folks,
I have a question, need to format the file that I generate through the logical file path. i.e., The file has the data for various field values, however I need get the field names displayed at the start of the file.
I did something like this
itab -EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
APPEND ITAB.
CLEAR ITAB.
then loop through the internal table that had data for these fields and stored the data
itab -EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.
*****************
DESCRIBE TABLE ITAB LINES COUNTK.
IF COUNTK GT 0.
SORT ITAB BY SSN.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = 'EFGH'
WITH_FILE_EXTENSION = 'X'
IMPORTING
FILE_NAME = FNAME.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc <> 0.
WRITE / msg.
STOP.
ENDIF.
LOOP AT ITAB.
TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.
The file is getting generated with the values first and then the text and I want the other way around. How can i do that?
Thanks in advance,
Sk
2007 Jun 05 7:49 PM
The SORT statement is definitly causing your problem, but if you want to sort by SSN in the file, then you must add the field names after the fact.
* Add detail records
itab-EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.
* Check for line count
DESCRIBE TABLE ITAB LINES COUNTK.
IF COUNTK GT 0.
* SOrt by SSN
SORT ITAB BY SSN.
* Add your Field names now, using the INSERT statement.
itab-EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
INSERT ITAB index 1.
CLEAR ITAB.
* Get the file
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = 'EFGH'
* WITH_FILE_EXTENSION = 'X'
IMPORTING
FILE_NAME = FNAME.
* Open and Write.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc <> 0.
WRITE / msg.
STOP.
ENDIF.
LOOP AT ITAB.
TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.Regards,
RIch Heilman
Hi folks,
I have a question, need to format the file that I generate through the logical file path. i.e., The file has the data for various field values, however I need get the field names displayed at the start of the file.
I did something like this
itab -EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
APPEND ITAB.
CLEAR ITAB.
then loop through the internal table that had data for these fields and stored the data
itab -EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.
*****************
DESCRIBE TABLE ITAB LINES COUNTK.
IF COUNTK GT 0.
SORT ITAB BY SSN.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = 'EFGH'
WITH_FILE_EXTENSION = 'X'
IMPORTING
FILE_NAME = FNAME.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc <> 0.
WRITE / msg.
STOP.
ENDIF.
LOOP AT ITAB.
TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.
The file is getting generated with the values first and then the text and I want the other way around. How can i do that?
Thanks in advance,
Sk
2007 Jun 05 7:35 PM
data v_data(1024) type c.
LOOP AT ITAB.
concatenate itab-fld1 ',' itab-fld2 ',' into v_data.
TRANSFER v_data TO FNAME.
clear v_data.
ENDLOOP.
2007 Jun 05 7:40 PM
2007 Jun 05 7:49 PM
The SORT statement is definitly causing your problem, but if you want to sort by SSN in the file, then you must add the field names after the fact.
* Add detail records
itab-EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.
* Check for line count
DESCRIBE TABLE ITAB LINES COUNTK.
IF COUNTK GT 0.
* SOrt by SSN
SORT ITAB BY SSN.
* Add your Field names now, using the INSERT statement.
itab-EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
INSERT ITAB index 1.
CLEAR ITAB.
* Get the file
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = 'EFGH'
* WITH_FILE_EXTENSION = 'X'
IMPORTING
FILE_NAME = FNAME.
* Open and Write.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc <> 0.
WRITE / msg.
STOP.
ENDIF.
LOOP AT ITAB.
TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.Regards,
RIch Heilman
2007 Jun 05 8:52 PM
Thanks guys. It worked. However, can I format the data further like storing into a table?
SK
2007 Jun 05 8:53 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |