ABAP Select data from SAP table E1BP1036_COST 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 E1BP1036_COST 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 E1BP1036_COST. 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 E1BP1036_COST 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_E1BP1036_COST TYPE STANDARD TABLE OF E1BP1036_COST,
      WA_E1BP1036_COST TYPE E1BP1036_COST,
      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: <E1BP1036_COST> TYPE E1BP1036_COST.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM E1BP1036_COST
*  INTO TABLE @DATA(IT_E1BP1036_COST2).
*--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_E1BP1036_COST INDEX 1 INTO DATA(WA_E1BP1036_COST2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_E1BP1036_COST ASSIGNING <E1BP1036_COST>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1BP1036_COST>-MANDT = 1.
<E1BP1036_COST>-LEDNR = 1.
<E1BP1036_COST>-OBJNR = 1.
<E1BP1036_COST>-GJAHR = 1.
<E1BP1036_COST>-WRTTP = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_E1BP1036_COST-VERSN, sy-vline,
WA_E1BP1036_COST-TARKZ, sy-vline,
WA_E1BP1036_COST-PERBL, sy-vline,
WA_E1BP1036_COST-VRGNG, sy-vline,
WA_E1BP1036_COST-TKG001, sy-vline,
WA_E1BP1036_COST-TKG002, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1BP1036_COST 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_E1BP1036_COST 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_E1BP1036_COST INTO WA_E1BP1036_COST. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_E1BP1036_COST_STR,
MANDT TYPE STRING,
LEDNR TYPE STRING,
OBJNR TYPE STRING,
GJAHR TYPE STRING,
WRTTP TYPE STRING,
VERSN TYPE STRING,
TARKZ TYPE STRING,
PERBL TYPE STRING,
VRGNG TYPE STRING,
TKG001 TYPE STRING,
TKG002 TYPE STRING,
TKG003 TYPE STRING,
TKG004 TYPE STRING,
TKG005 TYPE STRING,
TKG006 TYPE STRING,
TKG007 TYPE STRING,
TKG008 TYPE STRING,
TKG009 TYPE STRING,
TKG010 TYPE STRING,
TKG011 TYPE STRING,
TKG012 TYPE STRING,
TKG013 TYPE STRING,
TKG014 TYPE STRING,
TKG015 TYPE STRING,
TKG016 TYPE STRING,
TKF001 TYPE STRING,
TKF002 TYPE STRING,
TKF003 TYPE STRING,
TKF004 TYPE STRING,
TKF005 TYPE STRING,
TKF006 TYPE STRING,
TKF007 TYPE STRING,
TKF008 TYPE STRING,
TKF009 TYPE STRING,
TKF010 TYPE STRING,
TKF011 TYPE STRING,
TKF012 TYPE STRING,
TKF013 TYPE STRING,
TKF014 TYPE STRING,
TKF015 TYPE STRING,
TKF016 TYPE STRING,
TKE001 TYPE STRING,
TKE002 TYPE STRING,
TKE003 TYPE STRING,
TKE004 TYPE STRING,
TKE005 TYPE STRING,
TKE006 TYPE STRING,
TKE007 TYPE STRING,
TKE008 TYPE STRING,
TKE009 TYPE STRING,
TKE010 TYPE STRING,
TKE011 TYPE STRING,
TKE012 TYPE STRING,
TKE013 TYPE STRING,
TKE014 TYPE STRING,
TKE015 TYPE STRING,
TKE016 TYPE STRING,
TOG001 TYPE STRING,
TOG002 TYPE STRING,
TOG003 TYPE STRING,
TOG004 TYPE STRING,
TOG005 TYPE STRING,
TOG006 TYPE STRING,
TOG007 TYPE STRING,
TOG008 TYPE STRING,
TOG009 TYPE STRING,
TOG010 TYPE STRING,
TOG011 TYPE STRING,
TOG012 TYPE STRING,
TOG013 TYPE STRING,
TOG014 TYPE STRING,
TOG015 TYPE STRING,
TOG016 TYPE STRING,
TOF001 TYPE STRING,
TOF002 TYPE STRING,
TOF003 TYPE STRING,
TOF004 TYPE STRING,
TOF005 TYPE STRING,
TOF006 TYPE STRING,
TOF007 TYPE STRING,
TOF008 TYPE STRING,
TOF009 TYPE STRING,
TOF010 TYPE STRING,
TOF011 TYPE STRING,
TOF012 TYPE STRING,
TOF013 TYPE STRING,
TOF014 TYPE STRING,
TOF015 TYPE STRING,
TOF016 TYPE STRING,
TOE001 TYPE STRING,
TOE002 TYPE STRING,
TOE003 TYPE STRING,
TOE004 TYPE STRING,
TOE005 TYPE STRING,
TOE006 TYPE STRING,
TOE007 TYPE STRING,
TOE008 TYPE STRING,END OF T_EKKO_STR. DATA: WA_E1BP1036_COST_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_E1BP1036_COST_STR-MANDT sy-vline
WA_E1BP1036_COST_STR-LEDNR sy-vline
WA_E1BP1036_COST_STR-OBJNR sy-vline
WA_E1BP1036_COST_STR-GJAHR sy-vline
WA_E1BP1036_COST_STR-WRTTP sy-vline
WA_E1BP1036_COST_STR-VERSN sy-vline
WA_E1BP1036_COST_STR-TARKZ sy-vline
WA_E1BP1036_COST_STR-PERBL sy-vline
WA_E1BP1036_COST_STR-VRGNG sy-vline
WA_E1BP1036_COST_STR-TKG001 sy-vline
WA_E1BP1036_COST_STR-TKG002 sy-vline
WA_E1BP1036_COST_STR-TKG003 sy-vline
WA_E1BP1036_COST_STR-TKG004 sy-vline
WA_E1BP1036_COST_STR-TKG005 sy-vline
WA_E1BP1036_COST_STR-TKG006 sy-vline
WA_E1BP1036_COST_STR-TKG007 sy-vline
WA_E1BP1036_COST_STR-TKG008 sy-vline
WA_E1BP1036_COST_STR-TKG009 sy-vline
WA_E1BP1036_COST_STR-TKG010 sy-vline
WA_E1BP1036_COST_STR-TKG011 sy-vline
WA_E1BP1036_COST_STR-TKG012 sy-vline
WA_E1BP1036_COST_STR-TKG013 sy-vline
WA_E1BP1036_COST_STR-TKG014 sy-vline
WA_E1BP1036_COST_STR-TKG015 sy-vline
WA_E1BP1036_COST_STR-TKG016 sy-vline
WA_E1BP1036_COST_STR-TKF001 sy-vline
WA_E1BP1036_COST_STR-TKF002 sy-vline
WA_E1BP1036_COST_STR-TKF003 sy-vline
WA_E1BP1036_COST_STR-TKF004 sy-vline
WA_E1BP1036_COST_STR-TKF005 sy-vline
WA_E1BP1036_COST_STR-TKF006 sy-vline
WA_E1BP1036_COST_STR-TKF007 sy-vline
WA_E1BP1036_COST_STR-TKF008 sy-vline
WA_E1BP1036_COST_STR-TKF009 sy-vline
WA_E1BP1036_COST_STR-TKF010 sy-vline
WA_E1BP1036_COST_STR-TKF011 sy-vline
WA_E1BP1036_COST_STR-TKF012 sy-vline
WA_E1BP1036_COST_STR-TKF013 sy-vline
WA_E1BP1036_COST_STR-TKF014 sy-vline
WA_E1BP1036_COST_STR-TKF015 sy-vline
WA_E1BP1036_COST_STR-TKF016 sy-vline
WA_E1BP1036_COST_STR-TKE001 sy-vline
WA_E1BP1036_COST_STR-TKE002 sy-vline
WA_E1BP1036_COST_STR-TKE003 sy-vline
WA_E1BP1036_COST_STR-TKE004 sy-vline
WA_E1BP1036_COST_STR-TKE005 sy-vline
WA_E1BP1036_COST_STR-TKE006 sy-vline
WA_E1BP1036_COST_STR-TKE007 sy-vline
WA_E1BP1036_COST_STR-TKE008 sy-vline
WA_E1BP1036_COST_STR-TKE009 sy-vline
WA_E1BP1036_COST_STR-TKE010 sy-vline
WA_E1BP1036_COST_STR-TKE011 sy-vline
WA_E1BP1036_COST_STR-TKE012 sy-vline
WA_E1BP1036_COST_STR-TKE013 sy-vline
WA_E1BP1036_COST_STR-TKE014 sy-vline
WA_E1BP1036_COST_STR-TKE015 sy-vline
WA_E1BP1036_COST_STR-TKE016 sy-vline
WA_E1BP1036_COST_STR-TOG001 sy-vline
WA_E1BP1036_COST_STR-TOG002 sy-vline
WA_E1BP1036_COST_STR-TOG003 sy-vline
WA_E1BP1036_COST_STR-TOG004 sy-vline
WA_E1BP1036_COST_STR-TOG005 sy-vline
WA_E1BP1036_COST_STR-TOG006 sy-vline
WA_E1BP1036_COST_STR-TOG007 sy-vline
WA_E1BP1036_COST_STR-TOG008 sy-vline
WA_E1BP1036_COST_STR-TOG009 sy-vline
WA_E1BP1036_COST_STR-TOG010 sy-vline
WA_E1BP1036_COST_STR-TOG011 sy-vline
WA_E1BP1036_COST_STR-TOG012 sy-vline
WA_E1BP1036_COST_STR-TOG013 sy-vline
WA_E1BP1036_COST_STR-TOG014 sy-vline
WA_E1BP1036_COST_STR-TOG015 sy-vline
WA_E1BP1036_COST_STR-TOG016 sy-vline
WA_E1BP1036_COST_STR-TOF001 sy-vline
WA_E1BP1036_COST_STR-TOF002 sy-vline
WA_E1BP1036_COST_STR-TOF003 sy-vline
WA_E1BP1036_COST_STR-TOF004 sy-vline
WA_E1BP1036_COST_STR-TOF005 sy-vline
WA_E1BP1036_COST_STR-TOF006 sy-vline
WA_E1BP1036_COST_STR-TOF007 sy-vline
WA_E1BP1036_COST_STR-TOF008 sy-vline
WA_E1BP1036_COST_STR-TOF009 sy-vline
WA_E1BP1036_COST_STR-TOF010 sy-vline
WA_E1BP1036_COST_STR-TOF011 sy-vline
WA_E1BP1036_COST_STR-TOF012 sy-vline
WA_E1BP1036_COST_STR-TOF013 sy-vline
WA_E1BP1036_COST_STR-TOF014 sy-vline
WA_E1BP1036_COST_STR-TOF015 sy-vline
WA_E1BP1036_COST_STR-TOF016 sy-vline
WA_E1BP1036_COST_STR-TOE001 sy-vline
WA_E1BP1036_COST_STR-TOE002 sy-vline
WA_E1BP1036_COST_STR-TOE003 sy-vline
WA_E1BP1036_COST_STR-TOE004 sy-vline
WA_E1BP1036_COST_STR-TOE005 sy-vline
WA_E1BP1036_COST_STR-TOE006 sy-vline
WA_E1BP1036_COST_STR-TOE007 sy-vline
WA_E1BP1036_COST_STR-TOE008 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.