ABAP Select data from SAP table BICS_DT_S_CHARACTERISTIC 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 BICS_DT_S_CHARACTERISTIC 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 BICS_DT_S_CHARACTERISTIC. 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 BICS_DT_S_CHARACTERISTIC 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_BICS_DT_S_CHARACTERISTIC TYPE STANDARD TABLE OF BICS_DT_S_CHARACTERISTIC,
      WA_BICS_DT_S_CHARACTERISTIC TYPE BICS_DT_S_CHARACTERISTIC,
      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: <BICS_DT_S_CHARACTERISTIC> TYPE BICS_DT_S_CHARACTERISTIC.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM BICS_DT_S_CHARACTERISTIC
  INTO TABLE IT_BICS_DT_S_CHARACTERISTIC.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BICS_DT_S_CHARACTERISTIC
*  INTO TABLE @DATA(IT_BICS_DT_S_CHARACTERISTIC2).
*--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_BICS_DT_S_CHARACTERISTIC INDEX 1 INTO DATA(WA_BICS_DT_S_CHARACTERISTIC2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BICS_DT_S_CHARACTERISTIC ASSIGNING <BICS_DT_S_CHARACTERISTIC>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BICS_DT_S_CHARACTERISTIC>-NAME = 1.
<BICS_DT_S_CHARACTERISTIC>-ALTERNATIVE_NAME = 1.
<BICS_DT_S_CHARACTERISTIC>-ID = 1.
<BICS_DT_S_CHARACTERISTIC>-TEXT = 1.
<BICS_DT_S_CHARACTERISTIC>-HAS_SHORT_TEXT = 1.
ENDLOOP.

LOOP AT IT_BICS_DT_S_CHARACTERISTIC INTO WA_BICS_DT_S_CHARACTERISTIC.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BICS_DT_S_CHARACTERISTIC-HAS_MEDIUM_TEXT, sy-vline,
WA_BICS_DT_S_CHARACTERISTIC-HAS_LONG_TEXT, sy-vline,
WA_BICS_DT_S_CHARACTERISTIC-HAS_TEXT, sy-vline,
WA_BICS_DT_S_CHARACTERISTIC-SUPPORTS_LOWERCASE_KEYS, sy-vline,
WA_BICS_DT_S_CHARACTERISTIC-HAS_COMPOUNDMENT, sy-vline,
WA_BICS_DT_S_CHARACTERISTIC-COMPOUNDMENT_KEY_OFFSET, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BICS_DT_S_CHARACTERISTIC 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_BICS_DT_S_CHARACTERISTIC 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_BICS_DT_S_CHARACTERISTIC INTO WA_BICS_DT_S_CHARACTERISTIC. *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 ALPHA, internal->external for field OBN_SYSTEM_ALIAS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BICS_DT_S_CHARACTERISTIC-OBN_SYSTEM_ALIAS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BICS_DT_S_CHARACTERISTIC-OBN_SYSTEM_ALIAS.
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_BICS_DT_S_CHARACTERISTIC_STR,
NAME TYPE STRING,
ALTERNATIVE_NAME TYPE STRING,
ID TYPE STRING,
TEXT TYPE STRING,
HAS_SHORT_TEXT TYPE STRING,
HAS_MEDIUM_TEXT TYPE STRING,
HAS_LONG_TEXT TYPE STRING,
HAS_TEXT TYPE STRING,
SUPPORTS_LOWERCASE_KEYS TYPE STRING,
HAS_COMPOUNDMENT TYPE STRING,
COMPOUNDMENT_KEY_OFFSET TYPE STRING,
HAS_CONV_EXIT TYPE STRING,
INTTP TYPE STRING,
DEFAULT_MEMBER_ACCESS_MODE TYPE STRING,
IS_DOCUMENT_RELEVANT TYPE STRING,
BASE_CHARACTERISTIC TYPE STRING,
BASE_CHARACTERISTIC_ID TYPE STRING,
DEFAULT_SELECTOR_PRSNT TYPE STRING,
SELECTION_MODE TYPE STRING,
BON_NAME TYPE STRING,
BON_NAMESPACE TYPE STRING,
BON_CCTS_NAME TYPE STRING,
BON_CCTS_NAMESPACE TYPE STRING,
OBN_SYSTEM_ALIAS TYPE STRING,
DEFAULT_VISUALIZATION_LEVEL TYPE STRING,
USED_FOR_NAVIGATION TYPE STRING,
USED_FOR_SELECTION_SPACE TYPE STRING,
USED_FOR_DATA_CELL_DEFINITION TYPE STRING,
CONTAINS_KEYFIGURES TYPE STRING,
SUPPORTS_AGGREGATION TYPE STRING,
SUPPORTS_SELECTION TYPE STRING,
GIS_TYPE TYPE STRING,
GIS_ATTRIBUTE_NAME TYPE STRING,
BOR_OBJTYP TYPE STRING,
SUPPORTS_HIERARCHIES TYPE STRING,
SUPPORTS_SORT_BY_SELECT_SPACE TYPE STRING,
IS_STRUCTURE TYPE STRING,
STRUCTURE_MEMBERS TYPE STRING,
MEMBER_ACCESS_MODE TYPE STRING,
SUPPORTED_MEMBER_ACCESS_MODES TYPE STRING,
SUPPORTED_RS_ACCESS_MODES TYPE STRING,
DEFAULT_RS_ACCESS_MODE TYPE STRING,
IS_SUMMABLE TYPE STRING,
DIMENSION TYPE STRING,
HIENM TYPE STRING,
VERSION TYPE STRING,
DATETO TYPE STRING,
STRT_LVL TYPE STRING,
HRY_ACTIVE TYPE STRING,
HIENMFLAG TYPE STRING,
VERSIONFLAG TYPE STRING,
DATETOFLAG TYPE STRING,
HIERARCHY_SORTING TYPE STRING,
TYPE TYPE STRING,
DIRECTION TYPE STRING,
ATTRIBUTE_ID TYPE STRING,
DATA_CELL_ID TYPE STRING,
PREDEFINED_MEMBERS_ORDER TYPE STRING,
PREDEFINED_MEMBERS_BOTTOM TYPE STRING,
MEMBER_ACCESS_PRESENTATION TYPE STRING,
RESULT_SET_PRESENTATION TYPE STRING,
RESULT_SET_ATTRIBUTES TYPE STRING,
RESULT_SET_SORTING TYPE STRING,
TYPE TYPE STRING,
DIRECTION TYPE STRING,
ATTRIBUTE_ID TYPE STRING,
DATA_CELL_ID TYPE STRING,
PREDEFINED_MEMBERS_ORDER TYPE STRING,
PREDEFINED_MEMBERS_BOTTOM TYPE STRING,
RESULT_VISIBILITY TYPE STRING,
MEMBER_ACCESS_ATTRIBUTES TYPE STRING,
MEMBER_ACCESS_SORTING TYPE STRING,
TYPE TYPE STRING,
DIRECTION TYPE STRING,
ATTRIBUTE_ID TYPE STRING,
DATA_CELL_ID TYPE STRING,
PREDEFINED_MEMBERS_ORDER TYPE STRING,
PREDEFINED_MEMBERS_BOTTOM TYPE STRING,
STRUCTURE_HRY_DRILL_LEVEL TYPE STRING,
STRUCTURE_HRY_NODE_ALIGNMENT TYPE STRING,
STRUCTURE_GROUPS_TUPLES TYPE STRING,END OF T_EKKO_STR. DATA: WA_BICS_DT_S_CHARACTERISTIC_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_BICS_DT_S_CHARACTERISTIC_STR-NAME sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-ALTERNATIVE_NAME sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-TEXT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_SHORT_TEXT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_MEDIUM_TEXT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_LONG_TEXT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_TEXT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTS_LOWERCASE_KEYS sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_COMPOUNDMENT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-COMPOUNDMENT_KEY_OFFSET sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HAS_CONV_EXIT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-INTTP sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DEFAULT_MEMBER_ACCESS_MODE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-IS_DOCUMENT_RELEVANT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BASE_CHARACTERISTIC sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BASE_CHARACTERISTIC_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DEFAULT_SELECTOR_PRSNT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SELECTION_MODE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BON_NAME sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BON_NAMESPACE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BON_CCTS_NAME sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BON_CCTS_NAMESPACE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-OBN_SYSTEM_ALIAS sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DEFAULT_VISUALIZATION_LEVEL sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-USED_FOR_NAVIGATION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-USED_FOR_SELECTION_SPACE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-USED_FOR_DATA_CELL_DEFINITION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-CONTAINS_KEYFIGURES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTS_AGGREGATION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTS_SELECTION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-GIS_TYPE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-GIS_ATTRIBUTE_NAME sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-BOR_OBJTYP sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTS_HIERARCHIES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTS_SORT_BY_SELECT_SPACE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-IS_STRUCTURE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-STRUCTURE_MEMBERS sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-MEMBER_ACCESS_MODE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTED_MEMBER_ACCESS_MODES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-SUPPORTED_RS_ACCESS_MODES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DEFAULT_RS_ACCESS_MODE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-IS_SUMMABLE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DIMENSION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HIENM sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-VERSION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DATETO sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-STRT_LVL sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HRY_ACTIVE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HIENMFLAG sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-VERSIONFLAG sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DATETOFLAG sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-HIERARCHY_SORTING sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-TYPE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DIRECTION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-ATTRIBUTE_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DATA_CELL_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_ORDER sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_BOTTOM sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-MEMBER_ACCESS_PRESENTATION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-RESULT_SET_PRESENTATION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-RESULT_SET_ATTRIBUTES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-RESULT_SET_SORTING sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-TYPE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DIRECTION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-ATTRIBUTE_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DATA_CELL_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_ORDER sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_BOTTOM sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-RESULT_VISIBILITY sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-MEMBER_ACCESS_ATTRIBUTES sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-MEMBER_ACCESS_SORTING sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-TYPE sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DIRECTION sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-ATTRIBUTE_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-DATA_CELL_ID sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_ORDER sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-PREDEFINED_MEMBERS_BOTTOM sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-STRUCTURE_HRY_DRILL_LEVEL sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-STRUCTURE_HRY_NODE_ALIGNMENT sy-vline
WA_BICS_DT_S_CHARACTERISTIC_STR-STRUCTURE_GROUPS_TUPLES sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.