Skip to main content

Chapter 2: Data Ingestion

In the previous chapter, we saw how MassUpload presents your data in a clear, interactive grid. But how does the data get from your local file into that grid in the first place? That's the job of the Data Ingestion process.

The Digital Intake Desk

Think of Data Ingestion as the program's front desk or mailroom. When you send a package (your data file), this desk is responsible for receiving it, opening it, and sorting its contents into organized trays. It doesn't matter if the package is a fancy box (an Excel file) or a simple envelope (a text file); the intake desk knows how to handle both.

The goal is simple: take the raw, unstructured data from your file and transform it into the neat, structured itab1 internal table that the Interactive ALV Workbench can understand and display.

This is a critical first step. Without a reliable way to ingest or "take in" the data, the rest of the program would have nothing to work with.

How It Works: From File to Internal Table

The process is straightforward. When you select a file and run the program, it follows a clear path to read your data.

Let's break down the key parts of this process.

1. Choosing the File and Format

First, the program needs to know what to read and how to read it. The selection screen provides two simple options:

  1. A field to pick your file.
  2. Radio buttons to specify if it's an Excel spreadsheet or a text file.
* This code creates the fields on the initial screen
SELECTION-SCREEN BEGIN OF BLOCK basic_pay.
" Field for the user to select their file
PARAMETERS : header TYPE rlgrap-filename.

" Radio buttons to choose the file format
PARAMETERS : exc_file RADIOBUTTON GROUP rl.
PARAMETERS : txt_file RADIOBUTTON GROUP rl.
SELECTION-SCREEN END OF BLOCK basic_pay.

Based on your choice, the program will call the correct function to handle the file. This is like telling the mailroom, "This is a box, use a box-cutter," or "This is an envelope, use a letter opener."

2. Reading the File: Using Standard SAP Tools

MassUpload doesn't reinvent the wheel. It uses powerful, standard SAP function modules to do the heavy lifting of reading files.

For Excel Files:

If you select the "Excel" radio button, the program calls a routine named excel_to_internal. Inside this routine, it uses the function ALSM_EXCEL_TO_INTERNAL_TABLE.

* This routine handles Excel files
FORM excel_to_internal.

* Call a standard SAP function to read the Excel data
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = header " The file path from the user
i_begin_row = 4 " We tell it to start at row 4 of the sheet
i_begin_col = 2 " And start at column 2
TABLES
intern = i_split " The raw data is put here
EXCEPTIONS ...

* Now, we process the raw data in i_split...
ENDFORM.

This function reads the specified Excel file and dumps all the cell contents into a temporary internal table called i_split. This temporary table is very raw; it's just a long list of (row, column, value). It's not yet in the structured format we need.

For Text Files:

If you select the "Text" radio button, the program uses a different function, GUI_UPLOAD. This function is simpler because it expects the text file to already have a specific, structured format where fields are separated by a special character (in our case, #).

* This routine handles text files
FORM text_to_internal.

* This function uploads a #-separated text file
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = header
has_field_separator = '#'
TABLES
data_tab = itab_text_file.

* The data is already structured, so we just move it
itab1[] = itab_text_file[].
ENDFORM.

3. Parsing and Transformation: Building itab1

This is the most important part of the ingestion process. The program now takes the raw data it read from the file and carefully places it into the columns of our main internal table, itab1.

For Excel, this involves looping through the i_split table (the raw list of cells) and using a CASE statement to figure out which itab1 field to put the value in.

* This is a simplified loop to transform the raw data
LOOP AT i_split INTO w_split.

* Check which column this cell came from
CASE w_split-col.
WHEN 1. " Column 1 from Excel goes into company_code
itab1-company_code = w_split-value.
WHEN 2. " Column 2 from Excel goes into document_type
itab1-document_type = w_split-value.
WHEN 3. " Column 3 goes into document_date
itab1-document_date = w_split-value.
" ... and so on for every column in the file ...
ENDCASE.

ENDLOOP.

This loop runs for every single cell in your spreadsheet. It patiently builds up each row of itab1, transforming your spreadsheet data into a format the program can work with. Each completed row represents a Financial Document Line Item (itab1).

Once this loop is finished, the itab1 internal table is fully populated and ready for the next stage.

Conclusion

Data Ingestion is the invisible but essential first step in the MassUpload workflow. It acts as a reliable gateway, taking data from common file formats like Excel and text files and translating it into a structured internal table. By using standard SAP functions and a clear transformation process, it ensures that your data enters the system cleanly and consistently.

Now that the data has been ingested and loaded onto our workbench, the program's next job is to check it for errors.

Next: Chapter 3: Frontend Data Validation