Sitemap
Deepika Ravichandran

Deepika Ravichandran

SAP ABAP Developer | Learning and sharing my journey in SAP, ABAP and software development.

Day 6: GRN Upload Automation Using Excel and BAPI

2 min readSep 9, 2026

--

As part of my SAP ABAP learning journey, I worked on a GRN Upload Automation requirement in SAP MM.

The main objective was to allow users to upload GRN details through an Excel file instead of entering the data manually in SAP.

Requirement

The program was developed to:

  • Upload GRN data from Excel.
  • Read and validate the uploaded records.
  • Retrieve required Purchase Order details.
  • Create GRNs using BAPI_GOODSMVT_CREATE.
  • Prevent duplicate invoice processing.
  • Display success and error messages.
  • Improve performance for multiple records.

Excel Data

The Excel file contains details such as:

  • Document Date
  • Posting Date
  • Invoice Number
  • Header Text
  • PO Number
  • PO Item
  • Plant
  • Storage Location
  • Quantity
  • Batch

The uploaded data is converted into an internal table and processed by the ABAP program.

Processing Flow

Excel Upload → Validation → PO Data → BAPI → GRN Creation → Result Log

The program first validates the uploaded data, including PO, item, plant, storage location, quantity, batch, and invoice number.

Get Deepika Ravichandran’s stories in your inbox

Join Medium for free to get updates from this writer.

The required PO information is then retrieved from SAP. One enhancement was to retrieve the PO Item Text and pass it to the BAPI item structure instead of maintaining it separately in Excel.

Press enter or click to view image in full size

GRN Creation Using BAPI

The main BAPI used in this program is:

BAPI_GOODSMVT_CREATE

The required header and item details are mapped to the BAPI structures, and the Goods Receipt is created.

After successful processing, the material document number and document year returned by the BAPI are captured and displayed in the output.

Duplicate Invoice Validation

A duplicate invoice validation was also implemented.

Before creating the GRN, the program checks whether the invoice has already been processed. If it is a duplicate, the record is rejected to avoid creating the GRN again.

Error Handling

BAPI return messages are captured and displayed in the processing log.

This helps users identify which records were successfully processed and which records failed due to validation or BAPI errors.

Performance Optimization

During testing, the upload became slow when processing multiple records.

I learned that unnecessary database queries inside loops can affect ABAP performance.

The program was optimized by:

  • Reducing database calls.
  • Fetching required data efficiently.
  • Reusing already retrieved data.
  • Avoiding unnecessary loops.
  • Processing only required records.

Key Learning

This task helped me understand how Excel upload, internal tables, database validation, BAPI mapping, Goods Movement, error handling, and performance optimization work together in an SAP ABAP program.

The important learning was that implementing a BAPI is not only about calling the function. Proper validation, data mapping, duplicate checking, error handling, and performance are equally important.

Conclusion

The GRN Upload Automation task provided practical experience in automating an SAP MM process using ABAP.

Users can upload GRN details through Excel, and the program validates the data and creates Goods Receipts automatically using BAPI_GOODSMVT_CREATE.

--

--

Deepika Ravichandran
Deepika Ravichandran

Written by Deepika Ravichandran

SAP ABAP Developer | Learning and sharing my journey in SAP, ABAP and software development.