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