ABAP Select data from SAP table BAPI_TANKDIPS_D 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_TANKDIPS_D 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_TANKDIPS_D. 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_TANKDIPS_D 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_TANKDIPS_D TYPE STANDARD TABLE OF BAPI_TANKDIPS_D, WA_BAPI_TANKDIPS_D TYPE BAPI_TANKDIPS_D, 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_TANKDIPS_D> TYPE BAPI_TANKDIPS_D. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI_TANKDIPS_D. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI_TANKDIPS_D INTO TABLE IT_BAPI_TANKDIPS_D. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI_TANKDIPS_D * INTO TABLE @DATA(IT_BAPI_TANKDIPS_D2). *--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_TANKDIPS_D INDEX 1 INTO DATA(WA_BAPI_TANKDIPS_D2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI_TANKDIPS_D ASSIGNING <BAPI_TANKDIPS_D>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_TANKDIPS_D>-COUNTER = 1.
<BAPI_TANKDIPS_D>-WERKS = 1.
<BAPI_TANKDIPS_D>-LGORT = 1.
<BAPI_TANKDIPS_D>-SEQNR = 1.
<BAPI_TANKDIPS_D>-DIPDATE = 1.
ENDLOOP. LOOP AT IT_BAPI_TANKDIPS_D INTO WA_BAPI_TANKDIPS_D. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI_TANKDIPS_D-DIPTIME, sy-vline,
WA_BAPI_TANKDIPS_D-TZONE, sy-vline,
WA_BAPI_TANKDIPS_D-SOCEV, sy-vline,
WA_BAPI_TANKDIPS_D-TOTALHEIGHT_FLTP, sy-vline,
WA_BAPI_TANKDIPS_D-TOTHUOM, sy-vline,
WA_BAPI_TANKDIPS_D-WATERHEIGHT_FLTP, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_TANKDIPS_D 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_TANKDIPS_D 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_TANKDIPS_D INTO WA_BAPI_TANKDIPS_D. *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 SEQNR, internal->external for field SEQNR CALL FUNCTION 'CONVERSION_EXIT_SEQNR_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-SEQNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-SEQNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TOTHUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-TOTHUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-TOTHUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field WATHUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-WATHUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-WATHUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TVOLUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-TVOLUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-TVOLUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field WVOLUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-WVOLUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-WVOLUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field SHTEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-SHTEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-SHTEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TSTEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-TSTEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-TSTEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MTTEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-MTTEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-MTTEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BDNEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-BDNEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-BDNEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TDNEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-TDNEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-TDNEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field FDNEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-FDNEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-FDNEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MTPRESEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-MTPRESEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-MTPRESEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field TPREDEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-TPREDEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-TPREDEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field ATPRESEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-ATPRESEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-ATPRESEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field VAPRESEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-VAPRESEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-VAPRESEH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BSWCNEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_TANKDIPS_D-BSWCNEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_TANKDIPS_D-BSWCNEH.
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_TANKDIPS_D_STR,
COUNTER TYPE STRING,
WERKS TYPE STRING,
LGORT TYPE STRING,
SEQNR TYPE STRING,
DIPDATE TYPE STRING,
DIPTIME TYPE STRING,
TZONE TYPE STRING,
SOCEV TYPE STRING,
TOTALHEIGHT_FLTP TYPE STRING,
TOTHUOM TYPE STRING,
WATERHEIGHT_FLTP TYPE STRING,
WATHUOM TYPE STRING,
QUAN_LVC TYPE STRING,
TVOLUOM TYPE STRING,
WATR_LVC TYPE STRING,
WVOLUOM TYPE STRING,
DNTYP TYPE STRING,
SHTMP TYPE STRING,
SHTEH TYPE STRING,
UL_IN_IND TYPE STRING,
TSTMP TYPE STRING,
TSTEH TYPE STRING,
MTTMP TYPE STRING,
MTTEH TYPE STRING,
BDICH TYPE STRING,
BDNEH TYPE STRING,
TDICH TYPE STRING,
TDNEH TYPE STRING,
FDICH TYPE STRING,
FDNEH TYPE STRING,
MTPRES TYPE STRING,
MTPRESEH TYPE STRING,
TPRED TYPE STRING,
TPREDEH TYPE STRING,
ATPRES TYPE STRING,
ATPRESEH TYPE STRING,
VAPRES TYPE STRING,
VAPRESEH TYPE STRING,
HYDRO TYPE STRING,
ABIND TYPE STRING,
ABFAC TYPE STRING,
MCF TYPE STRING,
BSWCN TYPE STRING,
BSWCNEH TYPE STRING,
UMRSL TYPE STRING,
COEFF TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_TANKDIPS_D_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_TANKDIPS_D_STR-COUNTER sy-vline
WA_BAPI_TANKDIPS_D_STR-WERKS sy-vline
WA_BAPI_TANKDIPS_D_STR-LGORT sy-vline
WA_BAPI_TANKDIPS_D_STR-SEQNR sy-vline
WA_BAPI_TANKDIPS_D_STR-DIPDATE sy-vline
WA_BAPI_TANKDIPS_D_STR-DIPTIME sy-vline
WA_BAPI_TANKDIPS_D_STR-TZONE sy-vline
WA_BAPI_TANKDIPS_D_STR-SOCEV sy-vline
WA_BAPI_TANKDIPS_D_STR-TOTALHEIGHT_FLTP sy-vline
WA_BAPI_TANKDIPS_D_STR-TOTHUOM sy-vline
WA_BAPI_TANKDIPS_D_STR-WATERHEIGHT_FLTP sy-vline
WA_BAPI_TANKDIPS_D_STR-WATHUOM sy-vline
WA_BAPI_TANKDIPS_D_STR-QUAN_LVC sy-vline
WA_BAPI_TANKDIPS_D_STR-TVOLUOM sy-vline
WA_BAPI_TANKDIPS_D_STR-WATR_LVC sy-vline
WA_BAPI_TANKDIPS_D_STR-WVOLUOM sy-vline
WA_BAPI_TANKDIPS_D_STR-DNTYP sy-vline
WA_BAPI_TANKDIPS_D_STR-SHTMP sy-vline
WA_BAPI_TANKDIPS_D_STR-SHTEH sy-vline
WA_BAPI_TANKDIPS_D_STR-UL_IN_IND sy-vline
WA_BAPI_TANKDIPS_D_STR-TSTMP sy-vline
WA_BAPI_TANKDIPS_D_STR-TSTEH sy-vline
WA_BAPI_TANKDIPS_D_STR-MTTMP sy-vline
WA_BAPI_TANKDIPS_D_STR-MTTEH sy-vline
WA_BAPI_TANKDIPS_D_STR-BDICH sy-vline
WA_BAPI_TANKDIPS_D_STR-BDNEH sy-vline
WA_BAPI_TANKDIPS_D_STR-TDICH sy-vline
WA_BAPI_TANKDIPS_D_STR-TDNEH sy-vline
WA_BAPI_TANKDIPS_D_STR-FDICH sy-vline
WA_BAPI_TANKDIPS_D_STR-FDNEH sy-vline
WA_BAPI_TANKDIPS_D_STR-MTPRES sy-vline
WA_BAPI_TANKDIPS_D_STR-MTPRESEH sy-vline
WA_BAPI_TANKDIPS_D_STR-TPRED sy-vline
WA_BAPI_TANKDIPS_D_STR-TPREDEH sy-vline
WA_BAPI_TANKDIPS_D_STR-ATPRES sy-vline
WA_BAPI_TANKDIPS_D_STR-ATPRESEH sy-vline
WA_BAPI_TANKDIPS_D_STR-VAPRES sy-vline
WA_BAPI_TANKDIPS_D_STR-VAPRESEH sy-vline
WA_BAPI_TANKDIPS_D_STR-HYDRO sy-vline
WA_BAPI_TANKDIPS_D_STR-ABIND sy-vline
WA_BAPI_TANKDIPS_D_STR-ABFAC sy-vline
WA_BAPI_TANKDIPS_D_STR-MCF sy-vline
WA_BAPI_TANKDIPS_D_STR-BSWCN sy-vline
WA_BAPI_TANKDIPS_D_STR-BSWCNEH sy-vline
WA_BAPI_TANKDIPS_D_STR-UMRSL sy-vline
WA_BAPI_TANKDIPS_D_STR-COEFF sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.