Application Development 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: 

another problem with CSV FILE

Former Member
0 Kudos
75

Hi

I have a field called payee1 which has to be 40 In length.

Now I have added blanks/space after i get the field to make it 40 before I call the 'SAP_CONVERT_TO_CSV_FORMAT'. but then my temp table itab1 shows the same filed with no space and I end up with the exact field length in the csv and also I have payee2 which most of the time don't have any records but my csv should show it with 40 character space right. it doesn't.

here is my code

PARAMETERS: OUTFILE LIKE dxfile-filename

DEFAULT 'C:\Apositivepay.txt',

RUNDATE LIKE PAYR-LAUFD,

Bank LIKE T012K-HBKID. "List of Possible Banks

...

type-pools:TRUXS.

DATA: BEGIN OF OUTPUT_REC OCCURS 0, "Output file for USBANK

ACCT(12), "bank account no

...

Payee1(40) type c, "payee 1

Payee2(40) type c, "payee 2

END OF OUTPUT_REC.

data: itab1 type TRUXS_T_TEXT_DATA.

data: v_outputfile type string.

...

SELECT * FROM PAYR WHERE HBKID = BANK

AND RZAWE IN T_TYPE AND LAUFD = RUNDATE.

...

MOVE: PAYR-ZNME1 TO OUTPUT_REC-PAYEE1.

PERFORM PAD_FIELD_ALPHA_40 USING OUTPUT_REC-PAYEE1.

MOVE: PAYR-ZNME2 TO OUTPUT_REC-PAYEE2.

PERFORM PAD_FIELD_ALPHA_40 USING OUTPUT_REC-PAYEE2.

...

v_outputfile = OUTFILE.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = ','

TABLES

I_TAB_SAP_DATA = OUTPUT_REC

CHANGING

I_TAB_CONVERTED_DATA = itab1

EXCEPTIONS

CONVERSION_FAILED = 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.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = v_outputfile

TABLES

DATA_TAB = itab1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

...

*& Form PAD_FIELD_ALPHA_40

FORM PAD_FIELD_ALPHA_40 USING P_NUM.

DATA: L TYPE I, J TYPE I.

L = STRLEN( P_NUM ).

J = 40 - L.

DO J TIMES.

SHIFT P_NUM RIGHT.

ENDDO.

WHILE SY-SUBRC <> 0.

REPLACE ' ' WITH ' ' INTO P_NUM.

ENDWHILE.

ENDFORM. " PAD_FIELD

1 REPLY 1

Former Member
0 Kudos
33

CSV files does not take space into consideration.