ABAP Select data from SAP table /AIF/BDC_SAVE 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 /AIF/BDC_SAVE 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 /AIF/BDC_SAVE. 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 /AIF/BDC_SAVE 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_/AIF/BDC_SAVE TYPE STANDARD TABLE OF /AIF/BDC_SAVE,
      WA_/AIF/BDC_SAVE TYPE /AIF/BDC_SAVE,
      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: </AIF/BDC_SAVE> TYPE /AIF/BDC_SAVE.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/AIF/BDC_SAVE.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /AIF/BDC_SAVE
  INTO TABLE IT_/AIF/BDC_SAVE.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /AIF/BDC_SAVE
*  INTO TABLE @DATA(IT_/AIF/BDC_SAVE2).
*--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_/AIF/BDC_SAVE INDEX 1 INTO DATA(WA_/AIF/BDC_SAVE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/AIF/BDC_SAVE ASSIGNING </AIF/BDC_SAVE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</AIF/BDC_SAVE>-HEADER = 1.
</AIF/BDC_SAVE>-TABNAME = 1.
</AIF/BDC_SAVE>-DDLANGUAGE = 1.
</AIF/BDC_SAVE>-TABCLASS = 1.
</AIF/BDC_SAVE>-SQLTAB = 1.
ENDLOOP.

LOOP AT IT_/AIF/BDC_SAVE INTO WA_/AIF/BDC_SAVE.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/AIF/BDC_SAVE-DATMIN, sy-vline,
WA_/AIF/BDC_SAVE-DATMAX, sy-vline,
WA_/AIF/BDC_SAVE-DATAVG, sy-vline,
WA_/AIF/BDC_SAVE-CLIDEP, sy-vline,
WA_/AIF/BDC_SAVE-BUFFERED, sy-vline,
WA_/AIF/BDC_SAVE-COMPRFLAG, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/AIF/BDC_SAVE 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_/AIF/BDC_SAVE 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_/AIF/BDC_SAVE INTO WA_/AIF/BDC_SAVE. *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.

*Conversion exit ISOLA, internal->external for field DDLANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/AIF/BDC_SAVE-DDLANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/AIF/BDC_SAVE-DDLANGUAGE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field MASTERLANG CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/AIF/BDC_SAVE-MASTERLANG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/AIF/BDC_SAVE-MASTERLANG.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/AIF/BDC_SAVE_STR,
HEADER TYPE STRING,
TABNAME TYPE STRING,
DDLANGUAGE TYPE STRING,
TABCLASS TYPE STRING,
SQLTAB TYPE STRING,
DATMIN TYPE STRING,
DATMAX TYPE STRING,
DATAVG TYPE STRING,
CLIDEP TYPE STRING,
BUFFERED TYPE STRING,
COMPRFLAG TYPE STRING,
LANGDEP TYPE STRING,
DDTEXT TYPE STRING,
ACTFLAG TYPE STRING,
APPLCLASS TYPE STRING,
AUTHCLASS TYPE STRING,
AS4USER TYPE STRING,
AS4DATE TYPE STRING,
AS4TIME TYPE STRING,
MASTERLANG TYPE STRING,
MAINFLAG TYPE STRING,
CONTFLAG TYPE STRING,
RESERVETAB TYPE STRING,
GLOBALFLAG TYPE STRING,
PROZPUFF TYPE STRING,
VIEWCLASS TYPE STRING,
VIEWGRANT TYPE STRING,
MULTIPLEX TYPE STRING,
SHLPEXI TYPE STRING,
PROXYTYPE TYPE STRING,
EXCLASS TYPE STRING,
WRONGCL TYPE STRING,
ALWAYSTRP TYPE STRING,
ALLDATAINCL TYPE STRING,
WITH_PARAMETERS TYPE STRING,
EXVIEW_INCLUDED TYPE STRING,
KEYMAX_FEATURE TYPE STRING,
KEYLEN_FEATURE TYPE STRING,
TABLEN_FEATURE TYPE STRING,
NONTRP_INCLUDED TYPE STRING,
VIEWREF TYPE STRING,
VIEWREF_ERR TYPE STRING,
VIEWREF_POS_CHG TYPE STRING,
TBFUNC_INCLUDED TYPE STRING,
IS_GTT TYPE STRING,
SESSION_VAR_EX TYPE STRING,
FROM_ENTITY TYPE STRING,
PK_IS_INVHASH TYPE STRING,
USED_SESSION_VARS TYPE STRING,
HDB_ONLY_ENTITY_INCLUDED TYPE STRING,
FIELD_SUFFIX TYPE STRING,
QUOTA_MAX_FIELDS TYPE STRING,
QUOTA_MAX_BYTES TYPE STRING,
QUOTA_SHARE_PARTNER TYPE STRING,
QUOTA_SHARE_CUSTOMER TYPE STRING,
COMPONENTS TYPE STRING,END OF T_EKKO_STR. DATA: WA_/AIF/BDC_SAVE_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_/AIF/BDC_SAVE_STR-HEADER sy-vline
WA_/AIF/BDC_SAVE_STR-TABNAME sy-vline
WA_/AIF/BDC_SAVE_STR-DDLANGUAGE sy-vline
WA_/AIF/BDC_SAVE_STR-TABCLASS sy-vline
WA_/AIF/BDC_SAVE_STR-SQLTAB sy-vline
WA_/AIF/BDC_SAVE_STR-DATMIN sy-vline
WA_/AIF/BDC_SAVE_STR-DATMAX sy-vline
WA_/AIF/BDC_SAVE_STR-DATAVG sy-vline
WA_/AIF/BDC_SAVE_STR-CLIDEP sy-vline
WA_/AIF/BDC_SAVE_STR-BUFFERED sy-vline
WA_/AIF/BDC_SAVE_STR-COMPRFLAG sy-vline
WA_/AIF/BDC_SAVE_STR-LANGDEP sy-vline
WA_/AIF/BDC_SAVE_STR-DDTEXT sy-vline
WA_/AIF/BDC_SAVE_STR-ACTFLAG sy-vline
WA_/AIF/BDC_SAVE_STR-APPLCLASS sy-vline
WA_/AIF/BDC_SAVE_STR-AUTHCLASS sy-vline
WA_/AIF/BDC_SAVE_STR-AS4USER sy-vline
WA_/AIF/BDC_SAVE_STR-AS4DATE sy-vline
WA_/AIF/BDC_SAVE_STR-AS4TIME sy-vline
WA_/AIF/BDC_SAVE_STR-MASTERLANG sy-vline
WA_/AIF/BDC_SAVE_STR-MAINFLAG sy-vline
WA_/AIF/BDC_SAVE_STR-CONTFLAG sy-vline
WA_/AIF/BDC_SAVE_STR-RESERVETAB sy-vline
WA_/AIF/BDC_SAVE_STR-GLOBALFLAG sy-vline
WA_/AIF/BDC_SAVE_STR-PROZPUFF sy-vline
WA_/AIF/BDC_SAVE_STR-VIEWCLASS sy-vline
WA_/AIF/BDC_SAVE_STR-VIEWGRANT sy-vline
WA_/AIF/BDC_SAVE_STR-MULTIPLEX sy-vline
WA_/AIF/BDC_SAVE_STR-SHLPEXI sy-vline
WA_/AIF/BDC_SAVE_STR-PROXYTYPE sy-vline
WA_/AIF/BDC_SAVE_STR-EXCLASS sy-vline
WA_/AIF/BDC_SAVE_STR-WRONGCL sy-vline
WA_/AIF/BDC_SAVE_STR-ALWAYSTRP sy-vline
WA_/AIF/BDC_SAVE_STR-ALLDATAINCL sy-vline
WA_/AIF/BDC_SAVE_STR-WITH_PARAMETERS sy-vline
WA_/AIF/BDC_SAVE_STR-EXVIEW_INCLUDED sy-vline
WA_/AIF/BDC_SAVE_STR-KEYMAX_FEATURE sy-vline
WA_/AIF/BDC_SAVE_STR-KEYLEN_FEATURE sy-vline
WA_/AIF/BDC_SAVE_STR-TABLEN_FEATURE sy-vline
WA_/AIF/BDC_SAVE_STR-NONTRP_INCLUDED sy-vline
WA_/AIF/BDC_SAVE_STR-VIEWREF sy-vline
WA_/AIF/BDC_SAVE_STR-VIEWREF_ERR sy-vline
WA_/AIF/BDC_SAVE_STR-VIEWREF_POS_CHG sy-vline
WA_/AIF/BDC_SAVE_STR-TBFUNC_INCLUDED sy-vline
WA_/AIF/BDC_SAVE_STR-IS_GTT sy-vline
WA_/AIF/BDC_SAVE_STR-SESSION_VAR_EX sy-vline
WA_/AIF/BDC_SAVE_STR-FROM_ENTITY sy-vline
WA_/AIF/BDC_SAVE_STR-PK_IS_INVHASH sy-vline
WA_/AIF/BDC_SAVE_STR-USED_SESSION_VARS sy-vline
WA_/AIF/BDC_SAVE_STR-HDB_ONLY_ENTITY_INCLUDED sy-vline
WA_/AIF/BDC_SAVE_STR-FIELD_SUFFIX sy-vline
WA_/AIF/BDC_SAVE_STR-QUOTA_MAX_FIELDS sy-vline
WA_/AIF/BDC_SAVE_STR-QUOTA_MAX_BYTES sy-vline
WA_/AIF/BDC_SAVE_STR-QUOTA_SHARE_PARTNER sy-vline
WA_/AIF/BDC_SAVE_STR-QUOTA_SHARE_CUSTOMER sy-vline
WA_/AIF/BDC_SAVE_STR-COMPONENTS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.