ABAP Select data from SAP table BAPI_CPE_TERMINPUT_TMP 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 BAPI_CPE_TERMINPUT_TMP 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 BAPI_CPE_TERMINPUT_TMP. 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 BAPI_CPE_TERMINPUT_TMP 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_BAPI_CPE_TERMINPUT_TMP TYPE STANDARD TABLE OF BAPI_CPE_TERMINPUT_TMP, WA_BAPI_CPE_TERMINPUT_TMP TYPE BAPI_CPE_TERMINPUT_TMP, 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: <BAPI_CPE_TERMINPUT_TMP> TYPE BAPI_CPE_TERMINPUT_TMP. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI_CPE_TERMINPUT_TMP. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI_CPE_TERMINPUT_TMP INTO TABLE IT_BAPI_CPE_TERMINPUT_TMP. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI_CPE_TERMINPUT_TMP * INTO TABLE @DATA(IT_BAPI_CPE_TERMINPUT_TMP2). *--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_BAPI_CPE_TERMINPUT_TMP INDEX 1 INTO DATA(WA_BAPI_CPE_TERMINPUT_TMP2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI_CPE_TERMINPUT_TMP ASSIGNING <BAPI_CPE_TERMINPUT_TMP>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_CPE_TERMINPUT_TMP>-OPERATION = 1.
<BAPI_CPE_TERMINPUT_TMP>-TERMINPUT_GUID = 1.
<BAPI_CPE_TERMINPUT_TMP>-TERMTYPE = 1.
<BAPI_CPE_TERMINPUT_TMP>-TERMRULE = 1.
<BAPI_CPE_TERMINPUT_TMP>-REFDOCCAT = 1.
ENDLOOP. LOOP AT IT_BAPI_CPE_TERMINPUT_TMP INTO WA_BAPI_CPE_TERMINPUT_TMP. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI_CPE_TERMINPUT_TMP-REFDOC, sy-vline,
WA_BAPI_CPE_TERMINPUT_TMP-REFITEM, sy-vline,
WA_BAPI_CPE_TERMINPUT_TMP-REFGUID, sy-vline,
WA_BAPI_CPE_TERMINPUT_TMP-REFCOND, sy-vline,
WA_BAPI_CPE_TERMINPUT_TMP-FIXTERMRATE, sy-vline,
WA_BAPI_CPE_TERMINPUT_TMP-FIXTERMCURR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_CPE_TERMINPUT_TMP 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_BAPI_CPE_TERMINPUT_TMP 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_BAPI_CPE_TERMINPUT_TMP INTO WA_BAPI_CPE_TERMINPUT_TMP. *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 CUNIT, internal->external for field FIXTERMUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_CPE_TERMINPUT_TMP-FIXTERMUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CPE_TERMINPUT_TMP-FIXTERMUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field USERUOM1 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_CPE_TERMINPUT_TMP-USERUOM1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CPE_TERMINPUT_TMP-USERUOM1.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CALCMMUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_CPE_TERMINPUT_TMP-CALCMMUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CPE_TERMINPUT_TMP-CALCMMUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field SURCHARGEUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_CPE_TERMINPUT_TMP-SURCHARGEUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CPE_TERMINPUT_TMP-SURCHARGEUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field QUOTGROUP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CPE_TERMINPUT_TMP-QUOTGROUP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CPE_TERMINPUT_TMP-QUOTGROUP.
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_BAPI_CPE_TERMINPUT_TMP_STR,
OPERATION TYPE STRING,
TERMINPUT_GUID TYPE STRING,
TERMTYPE TYPE STRING,
TERMRULE TYPE STRING,
REFDOCCAT TYPE STRING,
REFDOC TYPE STRING,
REFITEM TYPE STRING,
REFGUID TYPE STRING,
REFCOND TYPE STRING,
FIXTERMRATE TYPE STRING,
FIXTERMCURR TYPE STRING,
FIXTERMPRUN TYPE STRING,
FIXTERMUOM TYPE STRING,
USERVAL1 TYPE STRING,
USERUOM1 TYPE STRING,
CALCRULE TYPE STRING,
SURCHARGERULE TYPE STRING,
PERDETRULE_Q TYPE STRING,
PERDETRULE_C TYPE STRING,
PRICEFIXRULE TYPE STRING,
PERDTIN_GUID_Q TYPE STRING,
PERDTIN_GUID_C TYPE STRING,
CALCROUT TYPE STRING,
CALCMIN TYPE STRING,
CALCMAX TYPE STRING,
CALCMMCURR TYPE STRING,
CALCMMPRUN TYPE STRING,
CALCMMUOM TYPE STRING,
SURCHARGEROUT TYPE STRING,
SURCHARGEABS TYPE STRING,
SURCHARGEABS_DF34 TYPE STRING,
SURCHARGECURR TYPE STRING,
SURCHARGEPRUN TYPE STRING,
SURCHARGEUOM TYPE STRING,
SURCHARGEFACTOR1 TYPE STRING,
SURCHARGEFACTOR2 TYPE STRING,
FIXTERMRATE_ISO TYPE STRING,
FIXTERMCURR_ISO TYPE STRING,
FIXTERMUOM_ISO TYPE STRING,
USERUOM1_ISO TYPE STRING,
CALCMIN_ISO TYPE STRING,
CALCMAX_ISO TYPE STRING,
CALCMMCURR_ISO TYPE STRING,
CALCMMUOM_ISO TYPE STRING,
SURCHARGEABS_ISO TYPE STRING,
SURCHARGECUR_ISO TYPE STRING,
SURCHARGEUOM_ISO TYPE STRING,
QUOTKEY TYPE STRING,
DCSID TYPE STRING,
MIC TYPE STRING,
TENOR TYPE STRING,
PRICETYPE TYPE STRING,
FORECAST_ROUTINE TYPE STRING,
CURVE_TYPE TYPE STRING,
CURVE_DCSID TYPE STRING,
CURVE_MIC TYPE STRING,
DCS_SELECTION_TYPE TYPE STRING,
TIMING TYPE STRING,
KEYDATE_REFDATE_ROUT TYPE STRING,
KEYDATE_SELECTION_ROUT TYPE STRING,
KEYDATE_OFFSET_ROUT TYPE STRING,
KEYDATE_OFFSET_UNITS TYPE STRING,
DCS_PERIOD_TYPE TYPE STRING,
BASIS_TYPE TYPE STRING,
QUOTGROUP TYPE STRING,
CALCMIN_DF34 TYPE STRING,
CALCMAX_DF34 TYPE STRING,
FIXTERMRATE_DF34 TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_CPE_TERMINPUT_TMP_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_BAPI_CPE_TERMINPUT_TMP_STR-OPERATION sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-TERMINPUT_GUID sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-TERMTYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-TERMRULE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-REFDOCCAT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-REFDOC sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-REFITEM sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-REFGUID sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-REFCOND sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMRATE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMCURR sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMPRUN sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMUOM sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-USERVAL1 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-USERUOM1 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCRULE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGERULE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PERDETRULE_Q sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PERDETRULE_C sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PRICEFIXRULE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PERDTIN_GUID_Q sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PERDTIN_GUID_C sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCROUT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMIN sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMAX sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMMCURR sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMMPRUN sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMMUOM sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEROUT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEABS sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEABS_DF34 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGECURR sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEPRUN sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEUOM sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEFACTOR1 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEFACTOR2 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMRATE_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMCURR_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMUOM_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-USERUOM1_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMIN_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMAX_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMMCURR_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMMUOM_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEABS_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGECUR_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-SURCHARGEUOM_ISO sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-QUOTKEY sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-DCSID sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-MIC sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-TENOR sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-PRICETYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FORECAST_ROUTINE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CURVE_TYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CURVE_DCSID sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CURVE_MIC sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-DCS_SELECTION_TYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-TIMING sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-KEYDATE_REFDATE_ROUT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-KEYDATE_SELECTION_ROUT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-KEYDATE_OFFSET_ROUT sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-KEYDATE_OFFSET_UNITS sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-DCS_PERIOD_TYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-BASIS_TYPE sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-QUOTGROUP sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMIN_DF34 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-CALCMAX_DF34 sy-vline
WA_BAPI_CPE_TERMINPUT_TMP_STR-FIXTERMRATE_DF34 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.