0% found this document useful (0 votes)
2 views7 pages

BAPI SAP Script Exercise

The document outlines four beginner-friendly exercises for S/4HANA, including two BAPI exercises for creating a Sales Order and fetching Material details, and two SAPscript exercises for printing Material and Vendor reports. Each exercise includes clear objectives, steps, working code, and expected outputs. Important notes highlight the continued use of BAPI, the legacy status of SAPscript, and the preference for CDS and OData in new developments.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

BAPI SAP Script Exercise

The document outlines four beginner-friendly exercises for S/4HANA, including two BAPI exercises for creating a Sales Order and fetching Material details, and two SAPscript exercises for printing Material and Vendor reports. Each exercise includes clear objectives, steps, working code, and expected outputs. Important notes highlight the continued use of BAPI, the legacy status of SAPscript, and the preference for CDS and OData in new developments.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Below are 4 simple, end-to-end exercises (2 BAPI + 2 SAPscript) for S/4HANA, each based

on standard SAP tables, with clear steps + working code + expected output. These are
beginner-friendly but still realistic.

🔷 🔹 BAPI EXERCISE 1: Create Sales Order

🎯 Objective

Create a Sales Order using BAPI with data stored in

 VBAK

 VBAP

🔹 Steps

1. Create Report

SE38 → ZBAPI_SO_CREATE

2. ABAP Code

REPORT zbapi_so_create.

DATA: ls_header TYPE bapisdhd1,

lt_items TYPE TABLE OF bapisditm,

ls_item TYPE bapisditm,

lt_return TYPE TABLE OF bapiret2.

DATA: lv_vbeln TYPE vbak-vbeln.

* Header Data

ls_header-doc_type = 'OR'.

ls_header-sales_org = '1000'.

ls_header-distr_chan = '10'.

ls_header-division = '00'.
* Item Data

ls_item-material = 'MAT1'.

ls_item-target_qty = '10'.

APPEND ls_item TO lt_items.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

order_header_in = ls_header

IMPORTING

salesdocument = lv_vbeln

TABLES

order_items_in = lt_items

return = lt_return.

* Commit

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING wait = 'X'.

WRITE: / 'Sales Order Created:', lv_vbeln.

✅ Output

Sales Order Number created → check in VA03

🔷 🔹 BAPI EXERCISE 2: Get Material Details

🎯 Objective

Fetch Material data from

 MARA
🔹 Steps

1. Create Report

ZBAPI_MATERIAL_GET

2. Code

REPORT zbapi_material_get.

DATA: ls_mat TYPE bapimatdoa.

CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'

EXPORTING

material = 'MAT1'

IMPORTING

material_general_data = ls_mat.

WRITE: / 'Material:', ls_mat-material,

/ 'Type:', ls_mat-matl_type.

✅ Output

Material details displayed

🔷 🔹 SAPSCRIPT EXERCISE 1: Material Report Print

🎯 Objective

Print Material list using SAPscript

 Table: MARA

🔹 Steps
Step 1: Create SAPscript Form

Go to: SE71
Form Name: ZMAT_FORM

Step 2: Define Windows

 MAIN (for data)

 HEADER (title)

Step 3: Write Text Elements

HEADER Window

Material Report

MAIN Window

/ &MARA-MATNR& &MARA-MTART& &MARA-MATKL&

Step 4: Driver Program

REPORT zscript_material.

DATA: it_mara TYPE TABLE OF mara,

wa_mara TYPE mara.

SELECT * INTO TABLE it_mara FROM mara UP TO 10 ROWS.

LOOP AT it_mara INTO wa_mara.

CALL FUNCTION 'OPEN_FORM'

EXPORTING form = 'ZMAT_FORM'.

CALL FUNCTION 'WRITE_FORM'


EXPORTING element = 'MAIN'.

CALL FUNCTION 'CLOSE_FORM'.

ENDLOOP.

✅ Output

Printed material list (Spool request)

🔷 🔹 SAPSCRIPT EXERCISE 2: Vendor Print Form

🎯 Objective

Print Vendor details using

 LFA1

🔹 Steps

Step 1: Create Form

SE71 → ZVENDOR_FORM

Step 2: Layout

HEADER

Vendor Report

MAIN

/ &LFA1-LIFNR& &LFA1-NAME1& &LFA1-LAND1&

Step 3: Driver Program

REPORT zscript_vendor.

DATA: it_lfa1 TYPE TABLE OF lfa1,


wa_lfa1 TYPE lfa1.

SELECT * INTO TABLE it_lfa1 FROM lfa1 UP TO 10 ROWS.

CALL FUNCTION 'OPEN_FORM'

EXPORTING form = 'ZVENDOR_FORM'.

LOOP AT it_lfa1 INTO wa_lfa1.

CALL FUNCTION 'WRITE_FORM'

EXPORTING element = 'MAIN'.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'.

✅ Output

Vendor report printed

🔥 Important Notes (S/4HANA)

✔ BAPI still widely used


✔ SAPscript is legacy → replaced by Smart Forms / Adobe Forms
✔ In S/4:

 Prefer CDS + OData for new developments

🔷 🎯 What You Learn

BAPI

 Standard API usage

 Commit handling
 Business object interaction

SAPscript

 Form layout

 Windows

 Driver program

 Spool output

🚀 If You Want Next Level

I can provide:

✅ Real-time Invoice Smart Form (very important)


✅ Advanced BAPI (PO creation ME21N equivalent)
✅ Debugging BAPI + SAPscript
✅ S/4HANA CDS + Fiori alternative scenarios

Just tell me 👍

You might also like