Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

copying structure to flat file

Former Member
0 Likes
1,592

Hi Frens,

I need to copy the entire structure of some master tables in to a flat file. I am using se16 and highlighting all the fields and then copying it to a file. But can anyone of you suggest me a small code or any best method to make it fast.

appreciate for your time and effort.

thanks

Sony

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,490

DATA: T_FIELD TYPE STANDARD TABLE OF DFIES WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,

FIELDNAME(25),

TYPE(4),

LENG type numc2,

DECS type numc2,

TEXT(35),

END OF T_OUTPUT.

CALL FUNCTION 'DDIF_NAMETAB_GET'

EXPORTING

tabname = 'KNVV'

TABLES

DFIES_TAB = T_FIELD

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

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 T_FIELD.

T_OUTPUT-FIELDNAME = T_FIELD-FIELDNAME.

T_OUTPUT-TYPE = T_FIELD-DATATYPE.

T_OUTPUT-LENG = T_FIELD-LENG.

T_OUTPUT-DECS = T_FIELD-DECIMALS.

SELECT SINGLE DDTEXT FROM DD04T

INTO T_OUTPUT-TEXT

WHERE DDLANGUAGE = SY-LANGU

AND ROLLNAME = T_FIELD-ROLLNAME.

APPEND T_OUTPUT.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEST.TXT'

FILETYPE = 'ASC'

tables

data_tab = T_OUTPUT

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Please let me know if it works.

Thanks,

Naren

12 REPLIES 12
Read only

Former Member
0 Likes
1,490

You can use the function module GET_COMPONENT_LIST to get all the fields in a strucure or a table.

Then you can use GUI_DOWNLOAD function module to download the internal table to a flat file.

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'MARA'

TABLES

components = components.

loop at components.

*move data from components to datatab.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:/ test.txt'

FILETYPE = 'ASC'

TABLES

DATA_TAB = datatab

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6.

Regards,

Ravi

Read only

0 Likes
1,490

Hi Ravi,

Thank you for your quick reply. It says field data is unknown ( move data from components....) and also shud i declare datatab as wht??

Thanks

sony

Read only

0 Likes
1,490

The other easy way is in SE16 data screen follow path

SYSTEM --> LIST --> SAVE --> LOCAL FILE.

Here give file name and desired format. It will downlaod data in respective format.

Read only

0 Likes
1,490

Hi Ashwin...im doin the same but i need it as a automated program...thanks for your answer.

Thanks

Sony

Read only

0 Likes
1,490

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

DATA : begin of datatab occurs 0,

COMPNAME(30),

LEVEL(10),

LENG(5),

TYPE(1),

OLEN(3),

DECS(3),

end of datatab.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'MARA'

TABLES

components = components.

loop at components.

*move data from components to datatab.

move-corresponding components to datatab.

append datatab.

clear datatab.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:/ test.txt'

FILETYPE = 'ASC'

TABLES

DATA_TAB = datatab

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6.

This code is to download the structure related information only...not the actual data stored in a table.

Regards,

Ravi

Read only

0 Likes
1,490

Hi Ravi,

syntactically its correct but 0 bytes r copying in to the file...

Thanks

Sony

Read only

Former Member
0 Likes
1,490

Hi,

Try to use the FM DDIF_NAMETAB_GET to get the DDIC information and use the GUI_DOWNLOAD FM to download.

Thanks,

Naren

Read only

0 Likes
1,490

Hi Narendran..can u make me more clear...im bit new to this

thanks

Sony

Read only

Former Member
0 Likes
1,490

DATA: T_FIELD TYPE STANDARD TABLE OF DFIES WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,

FIELDNAME TYPE CHAR30,

  • ADD THE REQUIRED FIELDS.....

END OF T_OUTPUT.

CALL FUNCTION 'DDIF_NAMETAB_GET'

EXPORTING

tabname = 'MARA'

TABLES

DFIES_TAB = T_FIELD

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

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 T_FIELD.

  • Move the require the fields

MOVE-CORRESPONDING T_FIELD to T_OUTPUT.

APPEND T_OUTPUT.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEST.TXT'

FILETYPE = 'ASC'

tables

data_tab = T_OUTPUT

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

I tested this with the list of field names. It is working fine. You have to add the fields required for you.

Thanks,

Naren

Message was edited by: Narendran Muthukumaran

Read only

0 Likes
1,490

Hi Narendran,

I have placed these fields and im not getting the decimal values and also description...im only getting the field names and values not even the data types...

FIELDNAME(25),

TYPE(4),

LENG type numc2,

DECS type numc2,

TEXT(35),

here for type im not getting any nad also for text...and for decs im getting all 0's

im doin it for KNVV table..

help me

Thanks

Sony

Read only

Former Member
0 Likes
1,491

DATA: T_FIELD TYPE STANDARD TABLE OF DFIES WITH HEADER LINE.

DATA: BEGIN OF T_OUTPUT OCCURS 0,

FIELDNAME(25),

TYPE(4),

LENG type numc2,

DECS type numc2,

TEXT(35),

END OF T_OUTPUT.

CALL FUNCTION 'DDIF_NAMETAB_GET'

EXPORTING

tabname = 'KNVV'

TABLES

DFIES_TAB = T_FIELD

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

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 T_FIELD.

T_OUTPUT-FIELDNAME = T_FIELD-FIELDNAME.

T_OUTPUT-TYPE = T_FIELD-DATATYPE.

T_OUTPUT-LENG = T_FIELD-LENG.

T_OUTPUT-DECS = T_FIELD-DECIMALS.

SELECT SINGLE DDTEXT FROM DD04T

INTO T_OUTPUT-TEXT

WHERE DDLANGUAGE = SY-LANGU

AND ROLLNAME = T_FIELD-ROLLNAME.

APPEND T_OUTPUT.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEST.TXT'

FILETYPE = 'ASC'

tables

data_tab = T_OUTPUT

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Please let me know if it works.

Thanks,

Naren

Read only

0 Likes
1,490

wow thanks naren..its solved

Thanks

Sony