ABAP Select data from SAP table CTABSTAT_64 into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP CTABSTAT_64 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to CTABSTAT_64. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the CTABSTAT_64 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_CTABSTAT_64 TYPE STANDARD TABLE OF CTABSTAT_64, WA_CTABSTAT_64 TYPE CTABSTAT_64, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <CTABSTAT_64> TYPE CTABSTAT_64. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CTABSTAT_64. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CTABSTAT_64 INTO TABLE IT_CTABSTAT_64. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CTABSTAT_64 * INTO TABLE @DATA(IT_CTABSTAT_642). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_CTABSTAT_64 INDEX 1 INTO DATA(WA_CTABSTAT_642). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CTABSTAT_64 ASSIGNING <CTABSTAT_64>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CTABSTAT_64>-UPDCNT = 1.
<CTABSTAT_64>-UPDFAIL = 1.
<CTABSTAT_64>-DELCNT = 1.
<CTABSTAT_64>-DELFAIL = 1.
<CTABSTAT_64>-INSCNT = 1.
ENDLOOP. LOOP AT IT_CTABSTAT_64 INTO WA_CTABSTAT_64. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CTABSTAT_64-INSFAIL, sy-vline,
WA_CTABSTAT_64-MODCNT, sy-vline,
WA_CTABSTAT_64-DIRCNT, sy-vline,
WA_CTABSTAT_64-DIRFAIL, sy-vline,
WA_CTABSTAT_64-SEQCNT, sy-vline,
WA_CTABSTAT_64-SEQFAIL, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CTABSTAT_64 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_CTABSTAT_64 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_CTABSTAT_64 INTO WA_CTABSTAT_64. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_CTABSTAT_64_STR,
UPDCNT TYPE STRING,
UPDFAIL TYPE STRING,
DELCNT TYPE STRING,
DELFAIL TYPE STRING,
INSCNT TYPE STRING,
INSFAIL TYPE STRING,
MODCNT TYPE STRING,
DIRCNT TYPE STRING,
DIRFAIL TYPE STRING,
SEQCNT TYPE STRING,
SEQFAIL TYPE STRING,
UPD_PREP TYPE STRING,
UPD_EXEC TYPE STRING,
UPD_ROW TYPE STRING,
UPD_DUR TYPE STRING,
DEL_PREP TYPE STRING,
DEL_EXEC TYPE STRING,
DEL_ROW TYPE STRING,
DEL_DUR TYPE STRING,
INS_PREP TYPE STRING,
INS_EXEC TYPE STRING,
INS_ROW TYPE STRING,
INS_DUR TYPE STRING,
MOD_PREP TYPE STRING,
MOD_EXEC TYPE STRING,
MOD_ROW TYPE STRING,
MOD_DUR TYPE STRING,
DIR_PREP TYPE STRING,
DIR_OPEN TYPE STRING,
DIR_FETCH TYPE STRING,
DIR_DUR TYPE STRING,
SEQ_PREP TYPE STRING,
SEQ_OPEN TYPE STRING,
SEQ_FETCH TYPE STRING,
SEQ_ROW TYPE STRING,
SEQ_DUR TYPE STRING,
LOAD_PREP TYPE STRING,
LOAD_OPEN TYPE STRING,
LOAD_FETCH TYPE STRING,
LOAD_ROW TYPE STRING,
LOAD_DUR TYPE STRING,
BUF_RESET TYPE STRING,
BUF_SIZE TYPE STRING,
BUF_SIZEMX TYPE STRING,
BUF_RECS TYPE STRING,
BUF_RECSMX TYPE STRING,
BUF_DIR TYPE STRING,
BUF_SEQ TYPE STRING,
REGIONS_N TYPE STRING,
SEQ_SCAN TYPE STRING,
BUF_STATE TYPE STRING,
TNAME TYPE STRING,
REF TYPE STRING,
RNAME TYPE STRING,
BYPASSBUF TYPE STRING,
SQL TYPE STRING,END OF T_EKKO_STR. DATA: WA_CTABSTAT_64_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_CTABSTAT_64_STR-UPDCNT sy-vline
WA_CTABSTAT_64_STR-UPDFAIL sy-vline
WA_CTABSTAT_64_STR-DELCNT sy-vline
WA_CTABSTAT_64_STR-DELFAIL sy-vline
WA_CTABSTAT_64_STR-INSCNT sy-vline
WA_CTABSTAT_64_STR-INSFAIL sy-vline
WA_CTABSTAT_64_STR-MODCNT sy-vline
WA_CTABSTAT_64_STR-DIRCNT sy-vline
WA_CTABSTAT_64_STR-DIRFAIL sy-vline
WA_CTABSTAT_64_STR-SEQCNT sy-vline
WA_CTABSTAT_64_STR-SEQFAIL sy-vline
WA_CTABSTAT_64_STR-UPD_PREP sy-vline
WA_CTABSTAT_64_STR-UPD_EXEC sy-vline
WA_CTABSTAT_64_STR-UPD_ROW sy-vline
WA_CTABSTAT_64_STR-UPD_DUR sy-vline
WA_CTABSTAT_64_STR-DEL_PREP sy-vline
WA_CTABSTAT_64_STR-DEL_EXEC sy-vline
WA_CTABSTAT_64_STR-DEL_ROW sy-vline
WA_CTABSTAT_64_STR-DEL_DUR sy-vline
WA_CTABSTAT_64_STR-INS_PREP sy-vline
WA_CTABSTAT_64_STR-INS_EXEC sy-vline
WA_CTABSTAT_64_STR-INS_ROW sy-vline
WA_CTABSTAT_64_STR-INS_DUR sy-vline
WA_CTABSTAT_64_STR-MOD_PREP sy-vline
WA_CTABSTAT_64_STR-MOD_EXEC sy-vline
WA_CTABSTAT_64_STR-MOD_ROW sy-vline
WA_CTABSTAT_64_STR-MOD_DUR sy-vline
WA_CTABSTAT_64_STR-DIR_PREP sy-vline
WA_CTABSTAT_64_STR-DIR_OPEN sy-vline
WA_CTABSTAT_64_STR-DIR_FETCH sy-vline
WA_CTABSTAT_64_STR-DIR_DUR sy-vline
WA_CTABSTAT_64_STR-SEQ_PREP sy-vline
WA_CTABSTAT_64_STR-SEQ_OPEN sy-vline
WA_CTABSTAT_64_STR-SEQ_FETCH sy-vline
WA_CTABSTAT_64_STR-SEQ_ROW sy-vline
WA_CTABSTAT_64_STR-SEQ_DUR sy-vline
WA_CTABSTAT_64_STR-LOAD_PREP sy-vline
WA_CTABSTAT_64_STR-LOAD_OPEN sy-vline
WA_CTABSTAT_64_STR-LOAD_FETCH sy-vline
WA_CTABSTAT_64_STR-LOAD_ROW sy-vline
WA_CTABSTAT_64_STR-LOAD_DUR sy-vline
WA_CTABSTAT_64_STR-BUF_RESET sy-vline
WA_CTABSTAT_64_STR-BUF_SIZE sy-vline
WA_CTABSTAT_64_STR-BUF_SIZEMX sy-vline
WA_CTABSTAT_64_STR-BUF_RECS sy-vline
WA_CTABSTAT_64_STR-BUF_RECSMX sy-vline
WA_CTABSTAT_64_STR-BUF_DIR sy-vline
WA_CTABSTAT_64_STR-BUF_SEQ sy-vline
WA_CTABSTAT_64_STR-REGIONS_N sy-vline
WA_CTABSTAT_64_STR-SEQ_SCAN sy-vline
WA_CTABSTAT_64_STR-BUF_STATE sy-vline
WA_CTABSTAT_64_STR-TNAME sy-vline
WA_CTABSTAT_64_STR-REF sy-vline
WA_CTABSTAT_64_STR-RNAME sy-vline
WA_CTABSTAT_64_STR-BYPASSBUF sy-vline
WA_CTABSTAT_64_STR-SQL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.