< Page d'accueil du blog

SAPCooking recipe: update purchase requisitions data from an editable ALV

Publié le 29 janvier 2024

SAP cooking

Here is an example of a technical specification for the kind of ABAP programs that can be obtained with Chronos within a few minutes. It involves ALV and BAPI features in a SAP MM context (purchase requisitions).

Presentation

Side salad: purchase requisitions (MM module)

Kitchen tool: BAPI_REQUISITION_CHANGE

The Chef's secret: the BAPI must be provided with the old PR data, fetched with BAPI_REQUISITION_GETDETAIL.

Ingredients list

Selection-screen

Authority-checks

Data selections

Mapping

Editable ALV report

BAPI processing

Method

Selection-screen

Element Type Element Label Properties
Block "Purchase requisitions selection"
Select-option (EBAN-WERKS) Plant Mandatory
Select-option (EBAN-MATNR) Material
Select-option (EBAN-BSART) Document Type
Select-option (EBAN-EKGRP) Purchasing Group
Select-option (EBAN-FLIEF) Fixed Vendor

Selection-screen checks

Authorizations checks on Plant

Check each Plant matching the select-option and existing in table T001W.

Use authorization object M_BANF_WRK and activity 03.

If authorization is missing on a Plant, remove it from the selection and display information message: "Authorizations missing on plant: selections will be restricted".

If authorizations are missing on all Plants, display error message: "No authorization for plant".

Authorizations checks on Document Type

Check each Document Type matching the select-option and existing in table T161.

Use authorization object M_BANF_BSA and activity 03.

If authorization is missing on a Document Type, remove it from the selection and display information message: "Authorizations missing on document type: selections will be restricted".

If authorizations are missing on all Document Types, display error message: "No authorization for document type".

Authorizations checks on Purchasing Group

Check each Purchasing Group matching the select-option and existing in table T024.

Use authorization object M_BANF_EKG and activity 03.

If authorization is missing on a Purchasing Group, remove it from the selection and display information message: "Authorizations missing on purchasing group: selections will be restricted".

If authorizations are missing on all Purchasing Groups, display error message: "No authorization for purchasing group.

Data selection

Fetch data from table EBAN with Plant, Material, Document Type, Purchasing Group and Fixed Vendor matching selection-screen values.

Fetch data from table MARA with Material belonging to EBAN selection.

Mapping

Reading sequence

Loop at records from EBAN.

Read data from KNA1.

Endloop.

Mapped Fields

Field label Origin Rule
Purchase Requisition Number EBAN-BANFN Direct mapping
Purchase Requisition Item Number EBAN-BNFPO Direct mapping
Material Number EBAN-MATNR Direct mapping
Material Type MARA-MTART Direct mapping
Net weight MARA-NTGEW Direct mapping
Weight unit MARA-GEWEI Direct mapping
Plant EBAN-WERKS Direct mapping
Document type EBAN-BSART Direct mapping
Purchasing group EBAN-EKGRP Direct mapping
Release date EBAN-FRGDT Direct mapping
Vendor EBAN-FLIEF Direct mapping
Short text EBAN-TXZ01 Direct mapping
Requisition processing state EBAN-BANPR Direct mapping
Processing status EBAN-STATU Direct mapping
Purchase Requisition closed EBAN-EBAKZ Direct mapping
Purchase Requisition Quantity EBAN-MENGE Direct mapping
Purchase Requisition Unit of measure EBAN-MEINS Direct mapping
New quantity Calculated value Initially same value than EBAN-MENGE

ALV Report

Grid options

Option Rule
Window title bar "Purchase requisitions : update quantities"
General display Stripped pattern
Status

Use a custom status.

Add a toolbar button "Update quantities" with function code "&QTY".

Fields options

Field Rules
PR Number Display as key field
PR Item Number Display as key field
Material Number
Material Type
Net weight Unit field = MARA-GEWEI
Weight unit
Plant
Document type
Purchasing group
Release date
Vendor
Short text
Processing state
Processing status
PR closed
PR Quantity

Unit field = EBAN-MEINS

Display total

PR Unit of measure
New quantity

Editable field

Unit field = EBAN-MEINS

Display total

User-commands

Triggering event Action
Function code &QTY Call BAPI_REQUISITION_CHANGE to update selected PR items with column "New quantity". See details below.

BAPI processing

Loop at ALV selected rows.

At each new PR number, call BAPI_REQUISITION_GETDETAIL with this PR number. Initialize tables REQUISITION_ITEMS_OLD and REQUISITION_ITEMS_NEW from BAPI_REQUISITION_CREATE with content of table REQUISITION_ITEMS.

Update table REQUISITION_ITEMS_NEW with item new quantity for the same item number.

At end of a PR number, call BAPI_REQUISITION_CREATE.

In case of failure, call BAPI_TRANSACTION_ROLLBACK and collect BAPI error messages in a global messages table.

In case of success, call BAPI_TRANSACTION_COMMIT and add a success message for the PR update in the global messages table.

Endloop.

Show collected messages in a popup, using function modules MESSAGES_INITIALIZE, MESSAGE_STORE and MESSAGE_SHOW.

The recipe in video