ABAP Select data from SAP table RECPOIOBJECT02 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 RECPOIOBJECT02 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 RECPOIOBJECT02. 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 RECPOIOBJECT02 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_RECPOIOBJECT02 TYPE STANDARD TABLE OF RECPOIOBJECT02,
      WA_RECPOIOBJECT02 TYPE RECPOIOBJECT02,
      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: <RECPOIOBJECT02> TYPE RECPOIOBJECT02.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RECPOIOBJECT02
*  INTO TABLE @DATA(IT_RECPOIOBJECT022).
*--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_RECPOIOBJECT02 INDEX 1 INTO DATA(WA_RECPOIOBJECT022).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RECPOIOBJECT02 ASSIGNING <RECPOIOBJECT02>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RECPOIOBJECT02>-OBARTOB2 = 1.
<RECPOIOBJECT02>-OBJNROB2 = 1.
<RECPOIOBJECT02>-OBJIDOB2 = 1.
<RECPOIOBJECT02>-OBJTXTOB2 = 1.
<RECPOIOBJECT02>-OBJINFOOB2 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RECPOIOBJECT02-DATGABOB2, sy-vline,
WA_RECPOIOBJECT02-DATBISOB2, sy-vline,
WA_RECPOIOBJECT02-LAND1OBJOB2, sy-vline,
WA_RECPOIOBJECT02-PSTLZOBJOB2, sy-vline,
WA_RECPOIOBJECT02-ORT01OBJOB2, sy-vline,
WA_RECPOIOBJECT02-ORT02OBJOB2, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RECPOIOBJECT02 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_RECPOIOBJECT02 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_RECPOIOBJECT02 INTO WA_RECPOIOBJECT02. *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 CUNIT, internal->external for field FEINS_01OB2 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_RECPOIOBJECT02-FEINS_01OB2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RECPOIOBJECT02-FEINS_01OB2.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field FEINS_10OB2 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_RECPOIOBJECT02-FEINS_10OB2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RECPOIOBJECT02-FEINS_10OB2.
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_RECPOIOBJECT02_STR,
OBARTOB2 TYPE STRING,
OBJNROB2 TYPE STRING,
OBJIDOB2 TYPE STRING,
OBJTXTOB2 TYPE STRING,
OBJINFOOB2 TYPE STRING,
DATGABOB2 TYPE STRING,
DATBISOB2 TYPE STRING,
LAND1OBJOB2 TYPE STRING,
PSTLZOBJOB2 TYPE STRING,
ORT01OBJOB2 TYPE STRING,
ORT02OBJOB2 TYPE STRING,
PSTBZOBJOB2 TYPE STRING,
STRASOBJOB2 TYPE STRING,
STRA1OBJOB2 TYPE STRING,
REGIOOBJOB2 TYPE STRING,
SFLART_01OB2 TYPE STRING,
TFLART_01OB2 TYPE STRING,
DGULTAB_01OB2 TYPE STRING,
FQMFLART_01OB2 TYPE STRING,
FEINS_01OB2 TYPE STRING,
SFLART_02OB2 TYPE STRING,
TFLART_02OB2 TYPE STRING,
DGULTAB_02OB2 TYPE STRING,
FQMFLART_02OB2 TYPE STRING,
FEINS_02OB2 TYPE STRING,
SFLART_03OB2 TYPE STRING,
TFLART_03OB2 TYPE STRING,
DGULTAB_03OB2 TYPE STRING,
FQMFLART_03OB2 TYPE STRING,
FEINS_03OB2 TYPE STRING,
SFLART_04OB2 TYPE STRING,
TFLART_04OB2 TYPE STRING,
DGULTAB_04OB2 TYPE STRING,
FQMFLART_04OB2 TYPE STRING,
FEINS_04OB2 TYPE STRING,
SFLART_05OB2 TYPE STRING,
TFLART_05OB2 TYPE STRING,
DGULTAB_05OB2 TYPE STRING,
FQMFLART_05OB2 TYPE STRING,
FEINS_05OB2 TYPE STRING,
SFLART_06OB2 TYPE STRING,
TFLART_06OB2 TYPE STRING,
DGULTAB_06OB2 TYPE STRING,
FQMFLART_06OB2 TYPE STRING,
FEINS_06OB2 TYPE STRING,
SFLART_07OB2 TYPE STRING,
TFLART_07OB2 TYPE STRING,
DGULTAB_07OB2 TYPE STRING,
FQMFLART_07OB2 TYPE STRING,
FEINS_07OB2 TYPE STRING,
SFLART_08OB2 TYPE STRING,
TFLART_08OB2 TYPE STRING,
DGULTAB_08OB2 TYPE STRING,
FQMFLART_08OB2 TYPE STRING,
FEINS_08OB2 TYPE STRING,
SFLART_09OB2 TYPE STRING,
TFLART_09OB2 TYPE STRING,
DGULTAB_09OB2 TYPE STRING,
FQMFLART_09OB2 TYPE STRING,
FEINS_09OB2 TYPE STRING,
SFLART_10OB2 TYPE STRING,
TFLART_10OB2 TYPE STRING,
DGULTAB_10OB2 TYPE STRING,
FQMFLART_10OB2 TYPE STRING,
FEINS_10OB2 TYPE STRING,END OF T_EKKO_STR. DATA: WA_RECPOIOBJECT02_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_RECPOIOBJECT02_STR-OBARTOB2 sy-vline
WA_RECPOIOBJECT02_STR-OBJNROB2 sy-vline
WA_RECPOIOBJECT02_STR-OBJIDOB2 sy-vline
WA_RECPOIOBJECT02_STR-OBJTXTOB2 sy-vline
WA_RECPOIOBJECT02_STR-OBJINFOOB2 sy-vline
WA_RECPOIOBJECT02_STR-DATGABOB2 sy-vline
WA_RECPOIOBJECT02_STR-DATBISOB2 sy-vline
WA_RECPOIOBJECT02_STR-LAND1OBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-PSTLZOBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-ORT01OBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-ORT02OBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-PSTBZOBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-STRASOBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-STRA1OBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-REGIOOBJOB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_01OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_01OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_01OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_01OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_01OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_02OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_02OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_02OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_02OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_02OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_03OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_03OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_03OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_03OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_03OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_04OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_04OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_04OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_04OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_04OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_05OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_05OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_05OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_05OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_05OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_06OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_06OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_06OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_06OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_06OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_07OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_07OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_07OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_07OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_07OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_08OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_08OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_08OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_08OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_08OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_09OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_09OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_09OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_09OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_09OB2 sy-vline
WA_RECPOIOBJECT02_STR-SFLART_10OB2 sy-vline
WA_RECPOIOBJECT02_STR-TFLART_10OB2 sy-vline
WA_RECPOIOBJECT02_STR-DGULTAB_10OB2 sy-vline
WA_RECPOIOBJECT02_STR-FQMFLART_10OB2 sy-vline
WA_RECPOIOBJECT02_STR-FEINS_10OB2 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.