ABAP Select data from SAP table BAPI2088_COMPONENT 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 BAPI2088_COMPONENT 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 BAPI2088_COMPONENT. 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 BAPI2088_COMPONENT 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_BAPI2088_COMPONENT TYPE STANDARD TABLE OF BAPI2088_COMPONENT,
      WA_BAPI2088_COMPONENT TYPE BAPI2088_COMPONENT,
      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: <BAPI2088_COMPONENT> TYPE BAPI2088_COMPONENT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI2088_COMPONENT
*  INTO TABLE @DATA(IT_BAPI2088_COMPONENT2).
*--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_BAPI2088_COMPONENT INDEX 1 INTO DATA(WA_BAPI2088_COMPONENT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI2088_COMPONENT ASSIGNING <BAPI2088_COMPONENT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI2088_COMPONENT>-RESERV_NO = 1.
<BAPI2088_COMPONENT>-RES_ITEM = 1.
<BAPI2088_COMPONENT>-MOVEMENT = 1.
<BAPI2088_COMPONENT>-WITHDRAWN = 1.
<BAPI2088_COMPONENT>-MATERIAL = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI2088_COMPONENT-PLANT, sy-vline,
WA_BAPI2088_COMPONENT-STGE_LOC, sy-vline,
WA_BAPI2088_COMPONENT-BATCH, sy-vline,
WA_BAPI2088_COMPONENT-SPEC_STOCK, sy-vline,
WA_BAPI2088_COMPONENT-FIXED_QUAN, sy-vline,
WA_BAPI2088_COMPONENT-WITHD_QUAN, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI2088_COMPONENT 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_BAPI2088_COMPONENT 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_BAPI2088_COMPONENT INTO WA_BAPI2088_COMPONENT. *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 MATN1, internal->external for field MATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_BAPI2088_COMPONENT-MATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2088_COMPONENT-MATERIAL.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit NUMCV, internal->external for field ITEM_NUMBER CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_BAPI2088_COMPONENT-ITEM_NUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2088_COMPONENT-ITEM_NUMBER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit NUMCV, internal->external for field ACTIVITY CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_BAPI2088_COMPONENT-ACTIVITY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2088_COMPONENT-ACTIVITY.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field LEAD_TIME_OFFSET_OPR_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI2088_COMPONENT-LEAD_TIME_OFFSET_OPR_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI2088_COMPONENT-LEAD_TIME_OFFSET_OPR_UNIT.
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_BAPI2088_COMPONENT_STR,
RESERV_NO TYPE STRING,
RES_ITEM TYPE STRING,
MOVEMENT TYPE STRING,
WITHDRAWN TYPE STRING,
MATERIAL TYPE STRING,
PLANT TYPE STRING,
STGE_LOC TYPE STRING,
BATCH TYPE STRING,
SPEC_STOCK TYPE STRING,
FIXED_QUAN TYPE STRING,
WITHD_QUAN TYPE STRING,
ENTRY_QNT TYPE STRING,
ENTRY_UOM TYPE STRING,
ENTRY_UOM_ISO TYPE STRING,
PREQ_NO TYPE STRING,
PREQ_ITEM TYPE STRING,
MOVE_TYPE TYPE STRING,
ITEM_CAT TYPE STRING,
ITEM_NUMBER TYPE STRING,
ITEM_TEXT TYPE STRING,
SORT_STRING TYPE STRING,
BULK_MAT TYPE STRING,
ACTIVITY TYPE STRING,
GR_RCPT TYPE STRING,
UNLOAD_PT TYPE STRING,
LEAD_TIME_OFFSET_OPR TYPE STRING,
LEAD_TIME_OFFSET_OPR_UNIT TYPE STRING,
LEAD_TIME_OFFSET_OPR_UNIT_ISO TYPE STRING,
PRE_DELIVERY_INDICATOR TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI2088_COMPONENT_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_BAPI2088_COMPONENT_STR-RESERV_NO sy-vline
WA_BAPI2088_COMPONENT_STR-RES_ITEM sy-vline
WA_BAPI2088_COMPONENT_STR-MOVEMENT sy-vline
WA_BAPI2088_COMPONENT_STR-WITHDRAWN sy-vline
WA_BAPI2088_COMPONENT_STR-MATERIAL sy-vline
WA_BAPI2088_COMPONENT_STR-PLANT sy-vline
WA_BAPI2088_COMPONENT_STR-STGE_LOC sy-vline
WA_BAPI2088_COMPONENT_STR-BATCH sy-vline
WA_BAPI2088_COMPONENT_STR-SPEC_STOCK sy-vline
WA_BAPI2088_COMPONENT_STR-FIXED_QUAN sy-vline
WA_BAPI2088_COMPONENT_STR-WITHD_QUAN sy-vline
WA_BAPI2088_COMPONENT_STR-ENTRY_QNT sy-vline
WA_BAPI2088_COMPONENT_STR-ENTRY_UOM sy-vline
WA_BAPI2088_COMPONENT_STR-ENTRY_UOM_ISO sy-vline
WA_BAPI2088_COMPONENT_STR-PREQ_NO sy-vline
WA_BAPI2088_COMPONENT_STR-PREQ_ITEM sy-vline
WA_BAPI2088_COMPONENT_STR-MOVE_TYPE sy-vline
WA_BAPI2088_COMPONENT_STR-ITEM_CAT sy-vline
WA_BAPI2088_COMPONENT_STR-ITEM_NUMBER sy-vline
WA_BAPI2088_COMPONENT_STR-ITEM_TEXT sy-vline
WA_BAPI2088_COMPONENT_STR-SORT_STRING sy-vline
WA_BAPI2088_COMPONENT_STR-BULK_MAT sy-vline
WA_BAPI2088_COMPONENT_STR-ACTIVITY sy-vline
WA_BAPI2088_COMPONENT_STR-GR_RCPT sy-vline
WA_BAPI2088_COMPONENT_STR-UNLOAD_PT sy-vline
WA_BAPI2088_COMPONENT_STR-LEAD_TIME_OFFSET_OPR sy-vline
WA_BAPI2088_COMPONENT_STR-LEAD_TIME_OFFSET_OPR_UNIT sy-vline
WA_BAPI2088_COMPONENT_STR-LEAD_TIME_OFFSET_OPR_UNIT_ISO sy-vline
WA_BAPI2088_COMPONENT_STR-PRE_DELIVERY_INDICATOR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.