KNKK表SELECT查询迁移至SAP S/4HANA的修改方案咨询
Hey there! Let's break down how to adjust your old KNKK-based SELECT statement to work properly in SAP S/4HANA, especially since you're shifting to the new FSCM credit management tables.
First, Let's Clarify the KUNNR Mapping
The KNKK-KUNNR field (customer number) doesn't have a direct 1:1 replacement in UKMBP_CMS_SGM—here's why: S/4HANA's credit management uses business partners (BP) as the core identifier, whereas the old KNKK table relied on traditional customer numbers.
To link your input p_kunnr (customer number) to the UKMBP_CMS_SGM table, you'll need to use the KNA1 table as a bridge. KNA1-PARTNER stores the business partner ID associated with the customer number, and this is the value that matches UKMBP_CMS_SGM-BP_PARTNER.
Revised SELECT Statement Options
Here are two practical approaches depending on your needs:
Option 1: Single Combined Query
This joins the necessary tables to pull both the customer number and credit limit in one go:
SELECT SINGLE kna1~kunnr, ukmbp_cms_sgm~credit_limit INTO (@DATA(lv_kunnr), @DATA(lv_credit_limit)) FROM kna1 INNER JOIN ukmbp_cms_sgm ON kna1~partner = ukmbp_cms_sgm~bp_partner WHERE kna1~kunnr = @p_kunnr UP TO 1 ROWS.
- Note: If you work with multiple credit segments, add
AND ukmbp_cms_sgm~credit_segment = 'YOUR_SPECIFIC_SEGMENT'to the WHERE clause to avoid ambiguous results (instead of relying onUP TO 1 ROWS).
Option 2: Two Separate Queries (For Clarity)
If you prefer to split the logic into steps (e.g., if you need to validate the business partner first):
DATA: lv_bp_partner TYPE but000-partner, lv_kunnr TYPE knkk-kunnr, lv_credit_limit TYPE ukmbp_cms_sgm-credit_limit. * Step 1: Get the business partner ID linked to your customer number SELECT SINGLE partner INTO lv_bp_partner FROM kna1 WHERE kunnr = @p_kunnr. * Step 2: Fetch the credit limit from the new S/4HANA credit table IF lv_bp_partner IS NOT INITIAL. SELECT SINGLE credit_limit INTO lv_credit_limit FROM ukmbp_cms_sgm WHERE bp_partner = @lv_bp_partner UP TO 1 ROWS. ENDIF. * Use the original customer number directly from your input lv_kunnr = @p_kunnr.
Key Notes
- While the
KNKKtable still exists in S/4HANA, SAP recommends using theUKMBP_*tables for FSCM credit management to align with the new business partner model. - Always add checks for initial values (like the
IF lv_bp_partner IS NOT INITIALin Option 2) to avoid runtime errors if the customer number isn't found.
内容的提问来源于stack exchange,提问作者schmelto




