SAP INSERT CLIENT ABEXA Get Example source ABAP code based on a different SAP table
SAP Help
INSERT>, CLIENT> This example demonstrates client handling in the AB-SQL statement
INSERT>>. ABAP_SOURCE_CODE DEMO CL_DEMO_INSERT_USING_CLIENTS ABAP_DESCRIPTION The example demonstrates how the additions USING CLIENT>> and CLIENT SPECIFIED>> are used in INSERT>> statements that use various subqueries> as data sources. The example uses two DDIC database tables, the client-dependent table DEMO_CLNT>> and the client-independent table DEMO_NO_CLNT> >, which are linked in the subqueries using a join. First, DELETE>> statements are used to delete all data in both DDIC database tables without specifying a condition or a source. For the client-dependent table, the addition USING ALL CLIENTS> is used to delete the data of all clients. INSERT>> statements are then used to fill both tables with data from internal tables constructed in a host expression. For the client-dependent table, the addition CLIENT SPECIFIED> is used to respect the client IDs in the client column of the internal table. The output shows the result set of the query used as a subquery in the following INSERT> statement. This query uses the addition USING CLIENT> to ensure that data from the client 100> is read. A LEFT OUTER JOIN> between the client-dependent table and client-independent table produces a null value in the client column. When the result set of the subquery is inserted, INSERT> also uses the addition USING CLIENT>. This ensures that the content of the client column of the subquery is overwritten by the value 100> for each row. This means that the null value itself is ignored. The result is shown in the output. The next output shows the result set of a further query that uses the addition USING CLIENTS IN @rtab> instead of USING CLIENT>. The ranges table also selects only the client 100>, which means that the result is the same as in the preceding query. However, a difference arises when the query is used as a subquery in an INSERT> statement. USING CLIENTS IN @rtab> is interpreted in such a way that the client ID of the subquery is to be inserted, which is why implicit client handling by the INSERT> statement using CLIENT SPECIFIED> has to be switched accordingly. Since the client column of the subquery contains a null value, the corresponding exception is raised. The final INSERT> statement bypasses the exception by using the COALESCE>> function in the SELECT> list to replace the null value with the client ID 100>.