You are on page 1of 5

Requirement

In Production Order Component Overview screen, user will press F4 in the


Batch field and Search Help will populate only Batches with Available
Stock.

Solution

The below FS is an indication on how to address this requirement; however


significant technical contribution will be required to convert it to a
feasible and applicable solution.

Current SAP F4 search doesn’t have this facility. In the new Search Help,
data will be populated in below format:

Batch Unrestricted Quality Blocked Restricted Available


Stock Stock Stock Stock Stock

1. Create a Help View ZMM_MCHB with reference to Table MCHB and View
Fields:
 MATNR - Material Number
 WERKS - Plant
 LGORT - Storage Location
 CHARG - Batch Number
 CLABS - Valuated Unrestricted-Use Stock
 CINSM - Stock in Quality Inspection
 CEINM - Total Stock of All Restricted Batches
 CSPEM - Blocked Stock

2. Enter a Selection Condition:


MCHB – LABST GT 0 OR
MCHB – INSME GT 0 OR
MCHB - EINME GT 0 OR
MCHB - SPEME GT 0

With this Selection Condition, system will select only those Batches
where any one of the stock is positive.

3. Create an Elementary Search Help ZMM_SHP_MCHB_AVSTOCK with the


following setting
Description – Available Batch Stock
Selection Method - ZMM_MCHB
Search Help Exit – ZBATCH_F4_SHLP_AVSTOCK

Search Help Import Export Default Remarks


Parameter
MATNR X X MAT Setting similar to Search
WERKS X X WRK Help MCH1F
LGORT X X LAG
CHARG X
CLABS X
CINSM X
CEINM X
CSPEM X
CHRULE X 'PP'
AVSTOCK X

4. Append this Elementary Search Help to the Collective Search help MCH1
Function Module ZBATCH_F4_SHLP_AVSTOCK

We use this custom function module to calculate the Available Stock per
Batch. Please note the below points:

1. As per F1 help of this field, the custom function module should have
same interface as of F4IF_SHLP_EXIT_EXAMPLE.
2. For coding, please refer a similar kind of function module
SAPBC_GLOBAL_F4_SFLIGHT
3. The Custom Function Module will have the below parameters:
TABLES
SHLP_TAB TYPE SHLP_DESCT
RECORD_TAB STRUCTURE SEAHLPRES
CHANGING
VALUE(SHLP) TYPE SHLP_DESCR
VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE DDSHF4CTRL

The logic would be something like below:

1. We want to calculate the Available Stock just before displaying the


search result. So, we built our logic when:
CALLCONTROL-STEP = 'DISP'

2. At this point selected data is populated in RECORD_TAB table

3. Call the below function module multiple times and fill the Stockinfo
table. Please refer function module SAPBC_GLOBAL_F4_SFLIGHT DATA
Seatinfo for data declaration

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'MATNR'
FIELDNAME = 'MATNR'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'WERKS'
FIELDNAME = 'WERKS'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'LGORT'
FIELDNAME = 'LGORT'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'CHARG'
FIELDNAME = 'CHARG'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'CLABS'
FIELDNAME = 'CLABS'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'CINSM'
FIELDNAME = 'CINSM'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'CEINM'
FIELDNAME = 'CEINM'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'


EXPORTING
PARAMETER = 'CSPEM'
FIELDNAME = 'CSPEM'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
RESULTS_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

4. After the above step we expect Stockinfo table will have the following form
Matl Plant Sloc Batch Unres Quality Blocked Restricted Available
Stock Stock Stock Stock Stock
MAT1 1000 0001 BATCH1 100 20
MAT1 1000 0001 BATCH2 50 15 5 10

5. We now want to calculate the Available Stock of each batch. For this
we would use Function Module BAPI_MATERIAL_AVAILABILITY. To calculate
the Available Stock, we need to know the Checking Rule which would be
used to calculate ATP quantity. Checking Rule PP is defaulted in the
search parameter, however it should be modifiable.

Find the checking rule from SHLP_TAB-SELOPT structure corresponding


to SHLPFIELD = CHRULE

CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'


EXPORTING
PLANT = Stockinfo-Plant
MATERIAL = Stockinfo-Material
UNIT = BUn of Stockinfo-Material from MARA
CHECK_RULE = CHRULE from SHLP_TAB-SELOPT
STGE_LOC = Stockinfo-Sloc
BATCH = Stockinfo-Batch
READ_ATP_LOCK = 'X'
READ_ATP_LOCK_X = 'X'
TABLES
WMDVSX = wmdvsx
WMDVEX = wmdvex

6. WMDVEX-COM_QTY stores the committed quantity. Store this in the


respective Available Stock field of the Stockinfo table. However we
would require a upgraded logic to calculate the Availability Stock
because in our case because:
 It is possible that multiple users are trying to create
commitment on the same material (by creating several production
orders or stock transfer orders etc.), so everyone should feel
the impact of the others activity.
 READ_ATP_LOCK, READ_ATP_LOCK_X can take care of it but here
there is a special requirement that in production order
component will be used in full batch quantity. To clarify,
suppose a sheet roll has total stock of 1000 kg. Two users are
creating 2 production orders simultaneously where the sheet
requirement is 400 kg each. Only one of them should be able to
choose the batch, because only one person will occupy the full
quantity.

We can take care of it later if the other deliverables of this FS are


performing correctly.

7. Transfer the computed data to RECORD_TAB

CALL FUNCTION 'F4UT_PARAMETER_RESULTS_PUT'


EXPORTING
PARAMETER = 'AVSTOCK'
FIELDNAME = 'AVSTOCK'
TABLES
SHLP_TAB = shlp_tab
RECORD_TAB = record_tab
SOURCE_TAB = Stockinfo
CHANGING
SHLP = shlp
CALLCONTROL = callcontrol

You might also like