SAP DB_CREATE_TABLE_AS_SELECT Function Module for
DB_CREATE_TABLE_AS_SELECT is a standard db create table as select SAP function module available within SAP R/3 or S/4 Hana systems, depending on your version and release level. It is used to perform a specific ABAP function and below is the pattern details, showing its interface including any import and export parameters, exceptions etc. there is also a full "cut and paste" ABAP pattern code example, along with implementation ABAP coding, documentation and contribution comments specific to this or related objects.
See here to view full function module documentation and code listing for db create table as select FM, simply by entering the name DB_CREATE_TABLE_AS_SELECT into the relevant SAP transaction such as SE37 or SE38.
Function Group: SDB2
Program Name: SAPLSDB2
Main Program: SAPLSDB2
Appliation area: S
Release date: N/A
Mode(Normal, Remote etc): Normal Function Module
Update:

Function DB_CREATE_TABLE_AS_SELECT pattern details
In-order to call this FM within your sap programs, simply using the below ABAP pattern details to trigger the function call...or see the full ABAP code listing at the end of this article. You can simply cut and paste this code into your ABAP progrom as it is, including variable declarations.CALL FUNCTION 'DB_CREATE_TABLE_AS_SELECT'".
EXPORTING
* DBSYS = SY-DBSYS "DBS for which program is generated
* STORPAR_SRC = ' ' "
* NO_LOGGING = ' ' "
* NO_EXEC = ' ' "X: Do not execute generated program
* NO_PROG = ' ' "
* PRID = 0 "
* PROGNAME = ' ' "
* CHECK_CREATE_AS = 'X' "
* WITH_KEYCHECK = 'X' "
TABNAME_SRC = "Name of Source Table
TABNAME_DST = "Name of Target Table
IMPORTING
GENPROG = "Actual name of the generated program
TABLES
SELECT_FIELDS = "
EXCEPTIONS
CREATE_TABLE_AS_NOT_POSSIBLE = 1 CREATE_TABLE_AS_NOT_SUPPORTED = 2 CREATE_TABLE_AS_FAILED = 3 PROGRAM_NOT_GENERATED = 4 PROGRAM_NOT_WRITTEN = 5 SRC_TABLE_DOES_NOT_EXIST = 6 DST_TABLE_DOES_EXIST = 7 TPARAM_SOURCE_NOT_DETERMINATED = 8 KEYFIELDS_DELETED = 9
IMPORTING Parameters details for DB_CREATE_TABLE_AS_SELECT
DBSYS - DBS for which program is generated
Data type: SY-DBSYSDefault: SY-DBSYS
Optional: Yes
Call by Reference: No ( called with pass by value option)
STORPAR_SRC -
Data type: DDREFSTRUC-BOOLDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
NO_LOGGING -
Data type: DDREFSTRUC-BOOLDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
NO_EXEC - X: Do not execute generated program
Data type:Default: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
NO_PROG -
Data type:Default: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
PRID -
Data type: SY-TABIXOptional: Yes
Call by Reference: No ( called with pass by value option)
PROGNAME -
Data type: TRDIR-NAMEDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
CHECK_CREATE_AS -
Data type:Default: 'X'
Optional: Yes
Call by Reference: No ( called with pass by value option)
WITH_KEYCHECK -
Data type:Default: 'X'
Optional: Yes
Call by Reference: No ( called with pass by value option)
TABNAME_SRC - Name of Source Table
Data type: DD02L-TABNAMEOptional: No
Call by Reference: No ( called with pass by value option)
TABNAME_DST - Name of Target Table
Data type: DD02L-TABNAMEOptional: No
Call by Reference: No ( called with pass by value option)
EXPORTING Parameters details for DB_CREATE_TABLE_AS_SELECT
GENPROG - Actual name of the generated program
Data type: TRDIR-NAMEOptional: No
Call by Reference: No ( called with pass by value option)
TABLES Parameters details for DB_CREATE_TABLE_AS_SELECT
SELECT_FIELDS -
Data type: IDD03NOptional: No
Call by Reference: No ( called with pass by value option)
EXCEPTIONS details
CREATE_TABLE_AS_NOT_POSSIBLE -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
CREATE_TABLE_AS_NOT_SUPPORTED -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
CREATE_TABLE_AS_FAILED -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
PROGRAM_NOT_GENERATED - Program could not be generated
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
PROGRAM_NOT_WRITTEN - Program could not be written
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
SRC_TABLE_DOES_NOT_EXIST -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
DST_TABLE_DOES_EXIST -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
TPARAM_SOURCE_NOT_DETERMINATED -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
KEYFIELDS_DELETED -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
Copy and paste ABAP code example for DB_CREATE_TABLE_AS_SELECT Function Module
The ABAP code below is a full code listing to execute function module POPUP_TO_CONFIRM including all data declarations. The code uses the original data declarations rather than the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the newer method of declaring data variables on the fly. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8), which i why i have stuck to the origianl for this example.| DATA: | ||||
| lv_dbsys | TYPE SY-DBSYS, " SY-DBSYS | |||
| lv_genprog | TYPE TRDIR-NAME, " | |||
| lt_select_fields | TYPE STANDARD TABLE OF IDD03N, " | |||
| lv_create_table_as_not_possible | TYPE IDD03N, " | |||
| lv_storpar_src | TYPE DDREFSTRUC-BOOL, " SPACE | |||
| lv_no_logging | TYPE DDREFSTRUC-BOOL, " SPACE | |||
| lv_no_exec | TYPE DDREFSTRUC, " SPACE | |||
| lv_create_table_as_not_supported | TYPE DDREFSTRUC, " | |||
| lv_no_prog | TYPE DDREFSTRUC, " SPACE | |||
| lv_create_table_as_failed | TYPE DDREFSTRUC, " | |||
| lv_prid | TYPE SY-TABIX, " 0 | |||
| lv_program_not_generated | TYPE SY, " | |||
| lv_progname | TYPE TRDIR-NAME, " SPACE | |||
| lv_program_not_written | TYPE TRDIR, " | |||
| lv_check_create_as | TYPE TRDIR, " 'X' | |||
| lv_src_table_does_not_exist | TYPE TRDIR, " | |||
| lv_with_keycheck | TYPE TRDIR, " 'X' | |||
| lv_dst_table_does_exist | TYPE TRDIR, " | |||
| lv_tabname_src | TYPE DD02L-TABNAME, " | |||
| lv_tparam_source_not_determinated | TYPE DD02L, " | |||
| lv_tabname_dst | TYPE DD02L-TABNAME, " | |||
| lv_keyfields_deleted | TYPE DD02L. " |
|   CALL FUNCTION 'DB_CREATE_TABLE_AS_SELECT' " |
| EXPORTING | ||
| DBSYS | = lv_dbsys | |
| STORPAR_SRC | = lv_storpar_src | |
| NO_LOGGING | = lv_no_logging | |
| NO_EXEC | = lv_no_exec | |
| NO_PROG | = lv_no_prog | |
| PRID | = lv_prid | |
| PROGNAME | = lv_progname | |
| CHECK_CREATE_AS | = lv_check_create_as | |
| WITH_KEYCHECK | = lv_with_keycheck | |
| TABNAME_SRC | = lv_tabname_src | |
| TABNAME_DST | = lv_tabname_dst | |
| IMPORTING | ||
| GENPROG | = lv_genprog | |
| TABLES | ||
| SELECT_FIELDS | = lt_select_fields | |
| EXCEPTIONS | ||
| CREATE_TABLE_AS_NOT_POSSIBLE = 1 | ||
| CREATE_TABLE_AS_NOT_SUPPORTED = 2 | ||
| CREATE_TABLE_AS_FAILED = 3 | ||
| PROGRAM_NOT_GENERATED = 4 | ||
| PROGRAM_NOT_WRITTEN = 5 | ||
| SRC_TABLE_DOES_NOT_EXIST = 6 | ||
| DST_TABLE_DOES_EXIST = 7 | ||
| TPARAM_SOURCE_NOT_DETERMINATED = 8 | ||
| KEYFIELDS_DELETED = 9 | ||
| . " DB_CREATE_TABLE_AS_SELECT | ||
ABAP code using 7.40 inline data declarations to call FM DB_CREATE_TABLE_AS_SELECT
The below ABAP code uses the newer in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. Please note some of the newer syntax below, such as the @DATA is not available until 4.70 EHP 8.| "SELECT single DBSYS FROM SY INTO @DATA(ld_dbsys). | ||||
| DATA(ld_dbsys) | = SY-DBSYS. | |||
| "SELECT single NAME FROM TRDIR INTO @DATA(ld_genprog). | ||||
| "SELECT single BOOL FROM DDREFSTRUC INTO @DATA(ld_storpar_src). | ||||
| DATA(ld_storpar_src) | = ' '. | |||
| "SELECT single BOOL FROM DDREFSTRUC INTO @DATA(ld_no_logging). | ||||
| DATA(ld_no_logging) | = ' '. | |||
| DATA(ld_no_exec) | = ' '. | |||
| DATA(ld_no_prog) | = ' '. | |||
| "SELECT single TABIX FROM SY INTO @DATA(ld_prid). | ||||
| "SELECT single NAME FROM TRDIR INTO @DATA(ld_progname). | ||||
| DATA(ld_progname) | = ' '. | |||
| DATA(ld_check_create_as) | = 'X'. | |||
| DATA(ld_with_keycheck) | = 'X'. | |||
| "SELECT single TABNAME FROM DD02L INTO @DATA(ld_tabname_src). | ||||
| "SELECT single TABNAME FROM DD02L INTO @DATA(ld_tabname_dst). | ||||
Search for further information about these or an SAP related objects