ABAP Select data from SAP table IPVWCDVL 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 IPVWCDVL 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 IPVWCDVL. 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 IPVWCDVL 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_IPVWCDVL TYPE STANDARD TABLE OF IPVWCDVL,
      WA_IPVWCDVL TYPE IPVWCDVL,
      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: <IPVWCDVL> TYPE IPVWCDVL.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IPVWCDVL
*  INTO TABLE @DATA(IT_IPVWCDVL2).
*--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_IPVWCDVL INDEX 1 INTO DATA(WA_IPVWCDVL2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IPVWCDVL ASSIGNING <IPVWCDVL>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IPVWCDVL>-MANDT = 1.
<IPVWCDVL>-WELLCOMPLTNVOLDOCYR = 1.
<IPVWCDVL>-WELLCOMPLTNVOLDOC = 1.
<IPVWCDVL>-WELL = 1.
<IPVWCDVL>-WELLCOMPLETION = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IPVWCDVL-DELIVERYNETWORK, sy-vline,
WA_IPVWCDVL-EFFECTIVEVALIDITYSTARTDATE, sy-vline,
WA_IPVWCDVL-EFFECTIVEVALIDITYENDDATE, sy-vline,
WA_IPVWCDVL-PRODUCTIONDATE, sy-vline,
WA_IPVWCDVL-RECLASSIFIEDMATERIAL, sy-vline,
WA_IPVWCDVL-MATERIAL, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IPVWCDVL 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_IPVWCDVL 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_IPVWCDVL INTO WA_IPVWCDVL. *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 GJAHR, internal->external for field WELLCOMPLTNVOLDOCYR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_IPVWCDVL-WELLCOMPLTNVOLDOCYR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-WELLCOMPLTNVOLDOCYR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit MATN1, internal->external for field RECLASSIFIEDMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPVWCDVL-RECLASSIFIEDMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-RECLASSIFIEDMATERIAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field MATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPVWCDVL-MATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-MATERIAL.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field STANDARDVOLUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPVWCDVL-STANDARDVOLUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-STANDARDVOLUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field ENERGYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPVWCDVL-ENERGYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-ENERGYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field THRTCLVOLUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPVWCDVL-THRTCLVOLUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-THRTCLVOLUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field HEATINGVALUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPVWCDVL-HEATINGVALUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-HEATINGVALUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field STANDARDDENSITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPVWCDVL-STANDARDDENSITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPVWCDVL-STANDARDDENSITYUNIT.
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_IPVWCDVL_STR,
MANDT TYPE STRING,
WELLCOMPLTNVOLDOCYR TYPE STRING,
WELLCOMPLTNVOLDOC TYPE STRING,
WELL TYPE STRING,
WELLCOMPLETION TYPE STRING,
DELIVERYNETWORK TYPE STRING,
EFFECTIVEVALIDITYSTARTDATE TYPE STRING,
EFFECTIVEVALIDITYENDDATE TYPE STRING,
PRODUCTIONDATE TYPE STRING,
RECLASSIFIEDMATERIAL TYPE STRING,
MATERIAL TYPE STRING,
ALLOCATIONFREQUENCY TYPE STRING,
TANKBATTERYMEASUREMENTPT TYPE STRING,
VOLUMETYPE TYPE STRING,
VOLUMECLASS TYPE STRING,
VOLUMESOURCE TYPE STRING,
TRANSPORTER TYPE STRING,
TRANSPORTERREFERENCE TYPE STRING,
TICKETNUMBER TYPE STRING,
TICKETDATETIME TYPE STRING,
ORIGINATINGMEASUREMENTPT TYPE STRING,
CONVERSIONGROUP TYPE STRING,
DENSITYTYPE TYPE STRING,
INVENTORYDATE TYPE STRING,
CROSSREFWELL TYPE STRING,
CROSSREFWELLCOMPLETION TYPE STRING,
CREATEDBYUSER TYPE STRING,
CREATIONDATETIME TYPE STRING,
ORIGINTRANSACTION TYPE STRING,
STANDARDVOLUNIT TYPE STRING,
ENERGYUNIT TYPE STRING,
THRTCLVOLUNIT TYPE STRING,
HEATINGVALUNIT TYPE STRING,
STANDARDDENSITYUNIT TYPE STRING,
HEATINGVALUE TYPE STRING,
STANDARDDENSITY TYPE STRING,
NMBROFDAYSPRODUCED TYPE STRING,
NMBROFHOURSPRODUCED TYPE STRING,
NUMBEROFITEMS TYPE STRING,
THEORETICALVOLUME TYPE STRING,
STANDARDVOLUME TYPE STRING,
ENERGY TYPE STRING,
GASMOLARVOLUME TYPE STRING,END OF T_EKKO_STR. DATA: WA_IPVWCDVL_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_IPVWCDVL_STR-MANDT sy-vline
WA_IPVWCDVL_STR-WELLCOMPLTNVOLDOCYR sy-vline
WA_IPVWCDVL_STR-WELLCOMPLTNVOLDOC sy-vline
WA_IPVWCDVL_STR-WELL sy-vline
WA_IPVWCDVL_STR-WELLCOMPLETION sy-vline
WA_IPVWCDVL_STR-DELIVERYNETWORK sy-vline
WA_IPVWCDVL_STR-EFFECTIVEVALIDITYSTARTDATE sy-vline
WA_IPVWCDVL_STR-EFFECTIVEVALIDITYENDDATE sy-vline
WA_IPVWCDVL_STR-PRODUCTIONDATE sy-vline
WA_IPVWCDVL_STR-RECLASSIFIEDMATERIAL sy-vline
WA_IPVWCDVL_STR-MATERIAL sy-vline
WA_IPVWCDVL_STR-ALLOCATIONFREQUENCY sy-vline
WA_IPVWCDVL_STR-TANKBATTERYMEASUREMENTPT sy-vline
WA_IPVWCDVL_STR-VOLUMETYPE sy-vline
WA_IPVWCDVL_STR-VOLUMECLASS sy-vline
WA_IPVWCDVL_STR-VOLUMESOURCE sy-vline
WA_IPVWCDVL_STR-TRANSPORTER sy-vline
WA_IPVWCDVL_STR-TRANSPORTERREFERENCE sy-vline
WA_IPVWCDVL_STR-TICKETNUMBER sy-vline
WA_IPVWCDVL_STR-TICKETDATETIME sy-vline
WA_IPVWCDVL_STR-ORIGINATINGMEASUREMENTPT sy-vline
WA_IPVWCDVL_STR-CONVERSIONGROUP sy-vline
WA_IPVWCDVL_STR-DENSITYTYPE sy-vline
WA_IPVWCDVL_STR-INVENTORYDATE sy-vline
WA_IPVWCDVL_STR-CROSSREFWELL sy-vline
WA_IPVWCDVL_STR-CROSSREFWELLCOMPLETION sy-vline
WA_IPVWCDVL_STR-CREATEDBYUSER sy-vline
WA_IPVWCDVL_STR-CREATIONDATETIME sy-vline
WA_IPVWCDVL_STR-ORIGINTRANSACTION sy-vline
WA_IPVWCDVL_STR-STANDARDVOLUNIT sy-vline
WA_IPVWCDVL_STR-ENERGYUNIT sy-vline
WA_IPVWCDVL_STR-THRTCLVOLUNIT sy-vline
WA_IPVWCDVL_STR-HEATINGVALUNIT sy-vline
WA_IPVWCDVL_STR-STANDARDDENSITYUNIT sy-vline
WA_IPVWCDVL_STR-HEATINGVALUE sy-vline
WA_IPVWCDVL_STR-STANDARDDENSITY sy-vline
WA_IPVWCDVL_STR-NMBROFDAYSPRODUCED sy-vline
WA_IPVWCDVL_STR-NMBROFHOURSPRODUCED sy-vline
WA_IPVWCDVL_STR-NUMBEROFITEMS sy-vline
WA_IPVWCDVL_STR-THEORETICALVOLUME sy-vline
WA_IPVWCDVL_STR-STANDARDVOLUME sy-vline
WA_IPVWCDVL_STR-ENERGY sy-vline
WA_IPVWCDVL_STR-GASMOLARVOLUME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.