Handling of SELECT statements on simplified tables during S/4 HANA conversion
This blog is targeted to ABAP technical team working on S4 HANA conversion projects.
This blog is in continuation with my previous blogs on handling of Material Field Length Extension and Amount Field Length Extension issues during S/4 HANA conversion.
Here are links of the blogs
How to handle Amount Field Length Extension scenarios in S/4 HANA conversion
How to handle Material Field Length Extension scenarios in S/4 HANA conversion
In this blog I am going to elaborate how SELECT statements on various simplified tables can be changed at the time of code remediation activity.
Lets discuss some of the most prominent cases of SELECT scenarios in this blog. I will keep on adding new cases in my upcoming blogs.
- SLECT on BSEG.
As per SAP note 2431747 BSEG will not contain the entries of open items . Some postings marked as BKPF-BSTAT will not be posted in BSEG but in ACDOCA table. Hence the SELECT statements on BSEG table need to be reviewed and changed.
SELECT bukrs belnr gjahr buzei INTO TABLE it_bseg FROM bseg FOR ALL ENTRIES IN it_bkpf WHERE bukrs = it_bkpf-bukrs AND belnr = it_bkpf-belnr AND gjahr = it_bkpf-gjahr .
Here SELECT on BSEG table can be replaced by API call as below. But before replacing the BSEG Select statement with API it is recommended to analyze if using of API will impact the functionality since API selects the data only from BSEG table and some entries are not updated in BSEG but in ACDOCA table.
DATA: et_bseg1 TYPE TABLE OF bseg. DATA: et_par1 TYPE fagl_t_field. APPEND 'BUKRS' TO et_par1 . APPEND 'BELNR' TO et_par1 . APPEND 'GJAHR' TO et_par1 . APPEND 'BUZEI' TO et_par1 . CALL FUNCTION 'FAGL_GET_BSEG_FOR_ALL_ENTRIES' EXPORTING it_for_all_entries = it_bkpf i_where_clause = | BUKRS = IT_FOR_ALL_ENTRIES- BUKRS AND BELNR = IT_FOR_ALL_ENTRIES-BELNR AND GJAHR = IT_FOR_ALL_ENTRIES-GJAHR| it_fieldlist = et_par1 IMPORTING et_bseg = et_bseg1 EXCEPTIONS NOT FOUND = 1 OTHERS = 2. IF sy-subrc = 0 . sy-dbcnt = lines( et_cmo_bseg1 ). IF sy-subrc = 0 AND lines( et_bseg1 ) > 0 . MOVE-CORRESPONDING et_bseg1 TO it_bseg . ELSE. sy-subrc = 4. ENDIF. ENDIF.
2. SELECT on VBUK table
SAP note 2198647 provides the details about data model changes in SD area. In below SELECT statement the document status is being fetched from the table VBUK, this query would work in ECC environment but not in S/4 HANA. In S/4 HANA the document status fields have been removed from the vbuk tables and moved to respective header table of the document like LIKP, VBAK.
SELECT SINGLE wbstk FROM vbuk INTO l_delivery_gi_status WHERE vbeln = <lfs_xvttp>-vbeln.
This SELECT statement can be corrected as below
SELECT SINGLE wbstk FROM likp INTO l_delivery_gi_status WHERE vbeln = <lfs_xvttp>-vbeln.
For selecting the multiple column data VBUK or VBUP tables following APIs can be used.
see the example 2 below
SELECT SINGLE wbstk trsta INTO (l_wbstk, l_trsta) FROM vbuk WHERE vbeln = p_v_delivery AND vbtyp = 'J'.
This SELECT statement can be modified as below
DATA: lwa_cmo_VBUK_temp1 TYPE vbuk. CALL FUNCTION 'SD_VBUK_READ_FROM_DOC' EXPORTING i_vbeln = P_V_DELIVERY i_vbtyp = 'J' IMPORTING es_vbuk = lwa_VBUK_temp1 EXCEPTIONS vbeln_not_found = 1 vbtyp_not_supported = 2 OTHERS = 4. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. MOVE lwa_vbuk_temp1-wbstk TO l_wbstk . MOVE lwa_vbuk_temp1-trsta TO l_trsta .
3. SELECT on T881 table
According to note 2431747 , customizing tables T881, T881T and T881G are made obsolete in S/4 HANA. Hence the SELECT statements on these tables have to be replaced by API calls as shown in the example below.
SELECT SINGLE tab FROM t881 INTO v_tabela WHERE rldnr EQ '90'.
This SELECT statement can be corrected by using the class method cl_fins_acdoc_util=>get_t881_emu
cl_fins_acdoc_util=>get_t881_emu( EXPORTING iv_rldnr = '90' " Ledger IMPORTING es_t881 = DATA(EWA_finsdoc2) " Ledger Master EXCEPTIONS not_found = 1 OTHERS = 2 ). IF sy-subrc = 0. v_tabela = ewa_finsdoc2-tab . ENDIF.
4. SELECT on KONV table
According to note 2220005, KONV table has been replaces by PRCD_ELEMENTS table. SELECT on KONV table can be replaced by API cl_prc_result_factory=>get_instance( )->get_prc_result( ). OR CDS view V_KONV can also be used in place of KONV table.See the example below.
SELECT knumv kschl kbetr FROM konv INTO TABLE t_konv FOR ALL ENTRIES IN t_vbak WHERE knumv = t_vbak-knumv.
The SELECT statement can be corrected as below
DATA: BEGIN OF ET_cmo_KONV1 OCCURS 0 , knumv TYPE knumv, kschl TYPE kscha, kbetr TYPE kbetr, END OF ET_KONV1 . SELECT knumv, kschl, kbetr FROM v_konv_cds INTO TABLE @et_konv1 FOR ALL ENTRIES IN @t_vbak WHERE knumv = @t_vbak-knumv. MOVE-CORRESPONDING ET_KONV1 TO t_konv .
5. SELECT on VBRK and VBRP table
As per SAP note 2768887 , the where clause in SELECT statements on VBRK and VBRP tables check should have check for DRAFT field as well to make sure the SELECT will work as before.
SELECT * FROM vbrk INTO TABLE it_vbrk WHERE fkart = 'F2'.
This select statement can be corrected as below
SELECT * FROM vbrk INTO TABLE it_vbrk WHERE fkart = 'F2'. AND draft = space.
If VBRK-DRAFT = space is not added in the where clause , the SELECT statement will return values from FIORI draft table as well , which in not desired. Since draft values are not posted in the table.
|BSEG||Replace SELECT by API|
· If Status fields to be selected up from VBUK, use respective document tables like VBAP and LIKP
· If multiple fields from VBUK to be selected use the API
|VBUP||If multiple fields from VBUK to be selected use the API|
|T881, T881T and T881G||Use API instead of direct SELECT on Tables T881, T881T and T881G|
|KONV||Use the CDS view V_KONV instead of KONV or SAP std API|
|VBRK and VBRP||Use additional condition DRAFT = space in Where clause of SELECT|
This blog doesn’t end here since there are many such scenarios which we come across during code remediation phase. I will keep on adding new blogs for more code remediation scenarios.
Thank you for this comprehensive blog.
Can you please also recommend what should be the fixes for an INSERT / UPDATE on tables like VBUK, VBRK, VBFA etc.? None of the SAP notes or the cookbooks in them say anything about these operations, but ATC does complain about the same.