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
RUNDATE LIKE PAYR-LAUFD,
Bank LIKE T012K-HBKID. "List of Possible Banks
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'
I_FIELD_SEPERATOR = ','
I_TAB_SAP_DATA = OUTPUT_REC
I_TAB_CONVERTED_DATA = itab1
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.
CALL FUNCTION 'GUI_DOWNLOAD'
filename = v_outputfile
DATA_TAB = itab1
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.
WHILE SY-SUBRC <> 0.
REPLACE ' ' WITH ' ' INTO P_NUM.
ENDFORM. " PAD_FIELD