on 2025 May 19 1:33 PM
" Table declaration for delivery header
TABLES: LIKP.
" Selection screen for delivery number range and output file path
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR LIKP-VBELN. " Delivery numbers
PARAMETERS : P_FILE TYPE CHAR120. " Directory path on application server
SELECTION-SCREEN END OF BLOCK B1.
" F4 Help to select file path from the application server (AL11)
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
DIRECTORY = SPACE " Optional: Can be restricted to a specific directory
FILEMASK = SPACE " Optional: Restrict file types if needed
IMPORTING
SERVERFILE = P_FILE " Selected file path
EXCEPTIONS
CANCELED_BY_USER = 1
OTHERS = 2.
" Local variable to store the selected physical path (not used further here)
DATA(G_PHYSICAL_PATH) = P_FILE.
" Start of the main program logic
START-OF-SELECTION.
" Fetch delivery header data for selected VBELNs
SELECT VBELN, ERNAM, ERZET, VKORG, VSTEL
FROM LIKP
INTO TABLE @DATA(LT_LIKP)
WHERE VBELN IN @S_VBELN.
" Convert the internal table to CSV format using standard SAP function
DATA: LT_CSV TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ';' " Use semicolon as delimiter
* I_LINE_HEADER = " Optional: Add header line
* I_FILENAME = " Not needed here
* I_APPL_KEEP = ' ' " Not relevant for this use case
TABLES
I_TAB_SAP_DATA = LT_LIKP " Data to be converted
CHANGING
I_TAB_CONVERTED_DATA = LT_CSV " Output table in CSV format
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
" TODO: Add error message handling
ENDIF.
" Concatenate the final file name with directory path and date
CONCATENATE P_FILE '\Likp_' SY-DATUM INTO DATA(P1_FILE).
" Open file for writing on the application server in text mode
OPEN DATASET P1_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
" Write CSV data line-by-line to the file
LOOP AT LT_CSV INTO DATA(LS_CSV).
TRANSFER LS_CSV TO P1_FILE.
ENDLOOP.
" Close the file after writing
CLOSE DATASET P1_FILE.
Request clarification before answering.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.