ABAP Select data from SAP table FPM_T_TEST_VH 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 FPM_T_TEST_VH 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 FPM_T_TEST_VH. 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 FPM_T_TEST_VH 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_FPM_T_TEST_VH TYPE STANDARD TABLE OF FPM_T_TEST_VH,
      WA_FPM_T_TEST_VH TYPE FPM_T_TEST_VH,
      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: <FPM_T_TEST_VH> TYPE FPM_T_TEST_VH.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FPM_T_TEST_VH
*  INTO TABLE @DATA(IT_FPM_T_TEST_VH2).
*--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_FPM_T_TEST_VH INDEX 1 INTO DATA(WA_FPM_T_TEST_VH2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FPM_T_TEST_VH ASSIGNING <FPM_T_TEST_VH>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FPM_T_TEST_VH>-MANDT = 1.
<FPM_T_TEST_VH>-TABLE_KEY = 1.
<FPM_T_TEST_VH>-CHAR1_WDY_BOOLEAN = 1.
<FPM_T_TEST_VH>-CHAR3_CARRID = 1.
<FPM_T_TEST_VH>-CHAR30_VALUE_SET = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FPM_T_TEST_VH-STRING_FIELD, sy-vline,
WA_FPM_T_TEST_VH-CHBOX_C1, sy-vline,
WA_FPM_T_TEST_VH-CHBOX_FIXED_VALUES, sy-vline,
WA_FPM_T_TEST_VH-CHBOX_WDY_BOOLEAN, sy-vline,
WA_FPM_T_TEST_VH-CONV_EXIT_SDURA_TIME_MIN, sy-vline,
WA_FPM_T_TEST_VH-CONV_EXIT_ALPHA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FPM_T_TEST_VH 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_FPM_T_TEST_VH 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_FPM_T_TEST_VH INTO WA_FPM_T_TEST_VH. *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 SDURA, internal->external for field CONV_EXIT_SDURA_TIME_MIN CALL FUNCTION 'CONVERSION_EXIT_SDURA_OUTPUT' EXPORTING input = WA_FPM_T_TEST_VH-CONV_EXIT_SDURA_TIME_MIN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FPM_T_TEST_VH-CONV_EXIT_SDURA_TIME_MIN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CONV_EXIT_ALPHA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FPM_T_TEST_VH-CONV_EXIT_ALPHA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FPM_T_TEST_VH-CONV_EXIT_ALPHA.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALV2, internal->external for field CONV_EXIT_ALV2_CHAR CALL FUNCTION 'CONVERSION_EXIT_ALV2_OUTPUT' EXPORTING input = WA_FPM_T_TEST_VH-CONV_EXIT_ALV2_CHAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FPM_T_TEST_VH-CONV_EXIT_ALV2_CHAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALV3, internal->external for field CONV_EXIT_ALV3_INT CALL FUNCTION 'CONVERSION_EXIT_ALV3_OUTPUT' EXPORTING input = WA_FPM_T_TEST_VH-CONV_EXIT_ALV3_INT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FPM_T_TEST_VH-CONV_EXIT_ALV3_INT.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit CUNIT, internal->external for field UNIT3_DISTID CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FPM_T_TEST_VH-UNIT3_DISTID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FPM_T_TEST_VH-UNIT3_DISTID.
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_FPM_T_TEST_VH_STR,
MANDT TYPE STRING,
TABLE_KEY TYPE STRING,
CHAR1_WDY_BOOLEAN TYPE STRING,
CHAR3_CARRID TYPE STRING,
CHAR30_VALUE_SET TYPE STRING,
STRING_FIELD TYPE STRING,
CHBOX_C1 TYPE STRING,
CHBOX_FIXED_VALUES TYPE STRING,
CHBOX_WDY_BOOLEAN TYPE STRING,
CONV_EXIT_SDURA_TIME_MIN TYPE STRING,
CONV_EXIT_ALPHA TYPE STRING,
CONV_EXIT_ALV2_CHAR TYPE STRING,
CONV_EXIT_ALV3_INT TYPE STRING,
CONV_EXIT_SPRAS TYPE STRING,
CUKY5_CURRENCY TYPE STRING,
CURR15_PRICE TYPE STRING,
DATE_ TYPE STRING,
DDLB_KEY_FIXED_VALUES_CHAR TYPE STRING,
DDLB_KEY_FIXED_VALUES_INT TYPE STRING,
DDLB_KEY_VALUE_SET_CHAR TYPE STRING,
DDLB_INDEX TYPE STRING,
FIXED_VALUES_CHAR TYPE STRING,
FIXED_VALUES_INT TYPE STRING,
FREESTYLE_CHAR TYPE STRING,
FREESTYLE_INT_PERIOD TYPE STRING,
INT1_PERIOD TYPE STRING,
NUMC4_CONNID TYPE STRING,
HEX_FIELD TYPE STRING,
XSTRING_FIELD TYPE STRING,
OVS_CARRID TYPE STRING,
OVS_CONNID TYPE STRING,
QUAN9_DISTANCE TYPE STRING,
UNIT3_DISTID TYPE STRING,
TIME_ TYPE STRING,
TIME_STAMP_S TYPE STRING,
TIME_STAMP_L TYPE STRING,
ICON_ TYPE STRING,
IMAGE_ TYPE STRING,
TRISTATE TYPE STRING,
INT4_FIELD TYPE STRING,
CHAR3_CARRID_DEACT TYPE STRING,
CHAR3_CARRID_DEFINED_DDIC_VH TYPE STRING,
CHAR3_CARRID_SH TYPE STRING,
CHAR3_CARRID_CHECKTABLE_SH TYPE STRING,
NUMC8_MEAL_CHECKTABLE TYPE STRING,
FREESTYLE_CARRID TYPE STRING,END OF T_EKKO_STR. DATA: WA_FPM_T_TEST_VH_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_FPM_T_TEST_VH_STR-MANDT sy-vline
WA_FPM_T_TEST_VH_STR-TABLE_KEY sy-vline
WA_FPM_T_TEST_VH_STR-CHAR1_WDY_BOOLEAN sy-vline
WA_FPM_T_TEST_VH_STR-CHAR3_CARRID sy-vline
WA_FPM_T_TEST_VH_STR-CHAR30_VALUE_SET sy-vline
WA_FPM_T_TEST_VH_STR-STRING_FIELD sy-vline
WA_FPM_T_TEST_VH_STR-CHBOX_C1 sy-vline
WA_FPM_T_TEST_VH_STR-CHBOX_FIXED_VALUES sy-vline
WA_FPM_T_TEST_VH_STR-CHBOX_WDY_BOOLEAN sy-vline
WA_FPM_T_TEST_VH_STR-CONV_EXIT_SDURA_TIME_MIN sy-vline
WA_FPM_T_TEST_VH_STR-CONV_EXIT_ALPHA sy-vline
WA_FPM_T_TEST_VH_STR-CONV_EXIT_ALV2_CHAR sy-vline
WA_FPM_T_TEST_VH_STR-CONV_EXIT_ALV3_INT sy-vline
WA_FPM_T_TEST_VH_STR-CONV_EXIT_SPRAS sy-vline
WA_FPM_T_TEST_VH_STR-CUKY5_CURRENCY sy-vline
WA_FPM_T_TEST_VH_STR-CURR15_PRICE sy-vline
WA_FPM_T_TEST_VH_STR-DATE_ sy-vline
WA_FPM_T_TEST_VH_STR-DDLB_KEY_FIXED_VALUES_CHAR sy-vline
WA_FPM_T_TEST_VH_STR-DDLB_KEY_FIXED_VALUES_INT sy-vline
WA_FPM_T_TEST_VH_STR-DDLB_KEY_VALUE_SET_CHAR sy-vline
WA_FPM_T_TEST_VH_STR-DDLB_INDEX sy-vline
WA_FPM_T_TEST_VH_STR-FIXED_VALUES_CHAR sy-vline
WA_FPM_T_TEST_VH_STR-FIXED_VALUES_INT sy-vline
WA_FPM_T_TEST_VH_STR-FREESTYLE_CHAR sy-vline
WA_FPM_T_TEST_VH_STR-FREESTYLE_INT_PERIOD sy-vline
WA_FPM_T_TEST_VH_STR-INT1_PERIOD sy-vline
WA_FPM_T_TEST_VH_STR-NUMC4_CONNID sy-vline
WA_FPM_T_TEST_VH_STR-HEX_FIELD sy-vline
WA_FPM_T_TEST_VH_STR-XSTRING_FIELD sy-vline
WA_FPM_T_TEST_VH_STR-OVS_CARRID sy-vline
WA_FPM_T_TEST_VH_STR-OVS_CONNID sy-vline
WA_FPM_T_TEST_VH_STR-QUAN9_DISTANCE sy-vline
WA_FPM_T_TEST_VH_STR-UNIT3_DISTID sy-vline
WA_FPM_T_TEST_VH_STR-TIME_ sy-vline
WA_FPM_T_TEST_VH_STR-TIME_STAMP_S sy-vline
WA_FPM_T_TEST_VH_STR-TIME_STAMP_L sy-vline
WA_FPM_T_TEST_VH_STR-ICON_ sy-vline
WA_FPM_T_TEST_VH_STR-IMAGE_ sy-vline
WA_FPM_T_TEST_VH_STR-TRISTATE sy-vline
WA_FPM_T_TEST_VH_STR-INT4_FIELD sy-vline
WA_FPM_T_TEST_VH_STR-CHAR3_CARRID_DEACT sy-vline
WA_FPM_T_TEST_VH_STR-CHAR3_CARRID_DEFINED_DDIC_VH sy-vline
WA_FPM_T_TEST_VH_STR-CHAR3_CARRID_SH sy-vline
WA_FPM_T_TEST_VH_STR-CHAR3_CARRID_CHECKTABLE_SH sy-vline
WA_FPM_T_TEST_VH_STR-NUMC8_MEAL_CHECKTABLE sy-vline
WA_FPM_T_TEST_VH_STR-FREESTYLE_CARRID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.