BAPI
ABAP DevelopmentAdvanced

BAPI in Upload Programs and Interfaces

Design robust BAPI-based uploads and integrations with row-wise logging.

Explanation

BAPIs are widely used in Excel uploads, file interfaces, middleware integrations and background jobs. The design should include input validation, conversion, BAPI call, RETURN handling, commit or rollback, row-wise log and restart strategy. In mass uploads, one bad row should not always stop the full file unless the business requirement says so. Each row or transaction group should have a clear success/error status.

Code example

ABAP Code
* Purpose:* Process upload rows using BAPI with row-wise logging.* Each row gets success/error status for user correction. LOOP AT lt_upload ASSIGNING FIELD-SYMBOL(<ls_upload>).   CLEAR: lt_return, lv_document.   * Step 1: Convert and validate input before BAPI call  PERFORM validate_upload_row USING <ls_upload> CHANGING lt_return.   IF line_exists( lt_return[ type = 'E' ] ).    <ls_upload>-status  = 'E'.    <ls_upload>-message = 'Validation failed before BAPI call'.    CONTINUE.  ENDIF.   * Step 2: Call BAPI for this row/business object  CALL FUNCTION 'BAPI_EXAMPLE_CREATE'    EXPORTING      is_input = <ls_upload>-bapi_input    IMPORTING      ev_doc   = lv_document    TABLES      return   = lt_return.   * Step 3: Check BAPI messages  IF line_exists( lt_return[ type = 'E' ] ) OR     line_exists( lt_return[ type = 'A' ] ).    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.    <ls_upload>-status  = 'E'.    <ls_upload>-message = 'BAPI failed'.  ELSE.    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'      EXPORTING        wait = abap_true.    <ls_upload>-status  = 'S'.    <ls_upload>-message = |Created document { lv_document }|.  ENDIF. ENDLOOP.

Real project scenario

A material master upload processes each material as one unit. For each material, the program validates input, calls the BAPI, commits only if no errors are returned and writes a row-wise ALV log.

Common mistakes

- No row-wise error log. - Stopping entire file for one bad row without requirement. - Committing even after error. - Not converting input values before BAPI call.

Best practices

- Validate before BAPI call. - Log every row result. - Commit only successful units. - Design restart/reprocess capability. - Handle conversion exits.

Interview angle

Senior interviews often ask how to design upload programs. A good answer includes validation, BAPI, RETURN, commit, rollback and log.