The blog is inspired from a real life challenge I faced while trying to upload a excel to the custom Z Table.
At the start, considering the vast amount of ABAP content, this seemed like a straight forward job. I wanted to finish it in 30 minutes. It took me 3 days.
Caveat: I am not a Pro-ABAPer. I m one who knows ABAP but works on UI/UX.
As a developer, my first step towards writing code:
I Googled It.
The results were many, which immediately boosted by confidence of accomplishing the task. However, I found that most of solutions which were proposed, were not relevant to S4HANA(1709) system, which was the one I was working on.
The function module : ALSM_EXCEL_TO_INTERNAL_TABLE does not exist
The function module : TEXT_CONVERT_XLS_TO_SAP does not exist
So, final resort, GUI_UPLOAD .
The code approach is very simple.
- Convert the .XLSX to TXT(Tab delimited file).
HOW ? – Open the .XLSX file and choose option File-Save As and choose the file type as Text(Tab-Delimited) (*.txt)
2. Ensure that there is no header line ex: Column names are removed and only data is retained in the TXT file.
3. Create a executable program in SE38.
4. Call the function module – GUI_UPLOAD using Pattern option.
5. To the function module, pass the following parameters:
a. Path to the file in your local disk – FILENAME
b. field separator “#” – HAS_FIELD_SEPARATOR
c. An internal table of the type of the actual ZTable. ex: DATA: ZINTERNAL TYPE TABLE OF ZCUSTOMTABLE.
6. (Optional) Sit back and watch the data load into the internal table in debug mode. 🙂
7. Finally, look through internal table, and insert into the actual ZTable using the temporary work area.
DATA: ZINTERNALTABLE TYPE TABLE OF ZCUSTOMTABLE. DATA: WA_ZINTERNALTABLE TYPE ZCUSTOMTABLE. PARAMETERS: P_FILE TYPE STRING DEFAULT '<Path to your actual text file>' OBLIGATORY. " File Name CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = P_FILE HAS_FIELD_SEPARATOR = '#' TABLES DATA_TAB = ZINTERNALTABLE. IF SY-SUBRC EQ 0. LOOP AT ZINTERNALTABLE INTO WA_ZINTERNALTABLE. INSERT ZCUSTOMTABLE FROM WA_ZINTERNALTABLE. ENDLOOP. ENDIF.
Hopefully, its not TLDR.
Hope it helps.
Disclaimer: The opinions expressed in this blog are purely personal and has to relevance to anything/anyone else.