ABAP Select data from SAP table REMM_MN_OBJ_ADOPT 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 REMM_MN_OBJ_ADOPT 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 REMM_MN_OBJ_ADOPT. 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 REMM_MN_OBJ_ADOPT 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_REMM_MN_OBJ_ADOPT TYPE STANDARD TABLE OF REMM_MN_OBJ_ADOPT,
      WA_REMM_MN_OBJ_ADOPT TYPE REMM_MN_OBJ_ADOPT,
      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: <REMM_MN_OBJ_ADOPT> TYPE REMM_MN_OBJ_ADOPT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM REMM_MN_OBJ_ADOPT
*  INTO TABLE @DATA(IT_REMM_MN_OBJ_ADOPT2).
*--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_REMM_MN_OBJ_ADOPT INDEX 1 INTO DATA(WA_REMM_MN_OBJ_ADOPT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_REMM_MN_OBJ_ADOPT ASSIGNING <REMM_MN_OBJ_ADOPT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<REMM_MN_OBJ_ADOPT>-MANDT = 1.
<REMM_MN_OBJ_ADOPT>-INTRENO = 1.
<REMM_MN_OBJ_ADOPT>-BUKRS = 1.
<REMM_MN_OBJ_ADOPT>-SWENR = 1.
<REMM_MN_OBJ_ADOPT>-SGENR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_REMM_MN_OBJ_ADOPT-SGRNR, sy-vline,
WA_REMM_MN_OBJ_ADOPT-SMENR, sy-vline,
WA_REMM_MN_OBJ_ADOPT-OBJNR, sy-vline,
WA_REMM_MN_OBJ_ADOPT-IMKEY, sy-vline,
WA_REMM_MN_OBJ_ADOPT-VALIDFROM, sy-vline,
WA_REMM_MN_OBJ_ADOPT-VALIDTO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_REMM_MN_OBJ_ADOPT 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_REMM_MN_OBJ_ADOPT 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_REMM_MN_OBJ_ADOPT INTO WA_REMM_MN_OBJ_ADOPT. *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 SWENR, internal->external for field SWENR CALL FUNCTION 'CONVERSION_EXIT_SWENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-SWENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-SWENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SGENR, internal->external for field SGENR CALL FUNCTION 'CONVERSION_EXIT_SGENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-SGENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-SGENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SGRNR, internal->external for field SGRNR CALL FUNCTION 'CONVERSION_EXIT_SGRNR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-SGRNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-SGRNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SMENR, internal->external for field SMENR CALL FUNCTION 'CONVERSION_EXIT_SMENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-SMENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-SMENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit IMKEY, internal->external for field IMKEY CALL FUNCTION 'CONVERSION_EXIT_IMKEY_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-IMKEY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-IMKEY.
WRITE:/ 'New Value:', ld_input.

*Conversion exit REDAT, internal->external for field VALIDTO CALL FUNCTION 'CONVERSION_EXIT_REDAT_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-VALIDTO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-VALIDTO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit REDAT, internal->external for field MM_VALIDTO CALL FUNCTION 'CONVERSION_EXIT_REDAT_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-MM_VALIDTO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-MM_VALIDTO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SWENR, internal->external for field MM_SWENR CALL FUNCTION 'CONVERSION_EXIT_SWENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-MM_SWENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-MM_SWENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SGENR, internal->external for field MM_SGENR CALL FUNCTION 'CONVERSION_EXIT_SGENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-MM_SGENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-MM_SGENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SGRNR, internal->external for field MM_SGRNR CALL FUNCTION 'CONVERSION_EXIT_SGRNR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-MM_SGRNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-MM_SGRNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SMENR, internal->external for field MM_SMENR CALL FUNCTION 'CONVERSION_EXIT_SMENR_OUTPUT' EXPORTING input = WA_REMM_MN_OBJ_ADOPT-MM_SMENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REMM_MN_OBJ_ADOPT-MM_SMENR.
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_REMM_MN_OBJ_ADOPT_STR,
MANDT TYPE STRING,
INTRENO TYPE STRING,
BUKRS TYPE STRING,
SWENR TYPE STRING,
SGENR TYPE STRING,
SGRNR TYPE STRING,
SMENR TYPE STRING,
OBJNR TYPE STRING,
IMKEY TYPE STRING,
VALIDFROM TYPE STRING,
VALIDTO TYPE STRING,
MANDATEID TYPE STRING,
MM_VALIDFROM TYPE STRING,
MM_VALIDTO TYPE STRING,
MM_SWENR TYPE STRING,
MM_SGENR TYPE STRING,
MM_SGRNR TYPE STRING,
MM_SMENR TYPE STRING,
MM_OBJNR TYPE STRING,
CHECKBOX_ADOPT TYPE STRING,
CHECKBOX_REMAIN TYPE STRING,END OF T_EKKO_STR. DATA: WA_REMM_MN_OBJ_ADOPT_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_REMM_MN_OBJ_ADOPT_STR-MANDT sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-INTRENO sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-BUKRS sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-SWENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-SGENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-SGRNR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-SMENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-OBJNR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-IMKEY sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-VALIDFROM sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-VALIDTO sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MANDATEID sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_VALIDFROM sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_VALIDTO sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_SWENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_SGENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_SGRNR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_SMENR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-MM_OBJNR sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-CHECKBOX_ADOPT sy-vline
WA_REMM_MN_OBJ_ADOPT_STR-CHECKBOX_REMAIN sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.