ABAP Select data from SAP table RMXTS_OTPT_TRSI_HDR 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 RMXTS_OTPT_TRSI_HDR 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 RMXTS_OTPT_TRSI_HDR. 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 RMXTS_OTPT_TRSI_HDR 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_RMXTS_OTPT_TRSI_HDR TYPE STANDARD TABLE OF RMXTS_OTPT_TRSI_HDR,
      WA_RMXTS_OTPT_TRSI_HDR TYPE RMXTS_OTPT_TRSI_HDR,
      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: <RMXTS_OTPT_TRSI_HDR> TYPE RMXTS_OTPT_TRSI_HDR.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RMXTS_OTPT_TRSI_HDR
*  INTO TABLE @DATA(IT_RMXTS_OTPT_TRSI_HDR2).
*--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_RMXTS_OTPT_TRSI_HDR INDEX 1 INTO DATA(WA_RMXTS_OTPT_TRSI_HDR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RMXTS_OTPT_TRSI_HDR ASSIGNING <RMXTS_OTPT_TRSI_HDR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RMXTS_OTPT_TRSI_HDR>-TRIALID = 1.
<RMXTS_OTPT_TRSI_HDR>-TXT_TRIALTYPE = 1.
<RMXTS_OTPT_TRSI_HDR>-TRIALTYPE = 1.
<RMXTS_OTPT_TRSI_HDR>-TRIALNAME = 1.
<RMXTS_OTPT_TRSI_HDR>-TXT_SSTATUS = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RMXTS_OTPT_TRSI_HDR-PRODUCT, sy-vline,
WA_RMXTS_OTPT_TRSI_HDR-TXT_PRODUCT, sy-vline,
WA_RMXTS_OTPT_TRSI_HDR-PRDHA, sy-vline,
WA_RMXTS_OTPT_TRSI_HDR-TXT_PRDHA, sy-vline,
WA_RMXTS_OTPT_TRSI_HDR-PLANT, sy-vline,
WA_RMXTS_OTPT_TRSI_HDR-TXT_PLANT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RMXTS_OTPT_TRSI_HDR 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_RMXTS_OTPT_TRSI_HDR 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_RMXTS_OTPT_TRSI_HDR INTO WA_RMXTS_OTPT_TRSI_HDR. *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 RMXTR, internal->external for field TRIALID CALL FUNCTION 'CONVERSION_EXIT_RMXTR_OUTPUT' EXPORTING input = WA_RMXTS_OTPT_TRSI_HDR-TRIALID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMXTS_OTPT_TRSI_HDR-TRIALID.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ABPSN, internal->external for field PROJECT_DYNP CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_RMXTS_OTPT_TRSI_HDR-PROJECT_DYNP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMXTS_OTPT_TRSI_HDR-PROJECT_DYNP.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field LOGSYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RMXTS_OTPT_TRSI_HDR-LOGSYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMXTS_OTPT_TRSI_HDR-LOGSYS.
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_RMXTS_OTPT_TRSI_HDR_STR,
TRIALID TYPE STRING,
TXT_TRIALTYPE TYPE STRING,
TRIALTYPE TYPE STRING,
TRIALNAME TYPE STRING,
TXT_SSTATUS TYPE STRING,
PRODUCT TYPE STRING,
TXT_PRODUCT TYPE STRING,
PRDHA TYPE STRING,
TXT_PRDHA TYPE STRING,
PLANT TYPE STRING,
TXT_PLANT TYPE STRING,
PROJECT_DYNP TYPE STRING,
TXT_PROJ TYPE STRING,
BATCH TYPE STRING,
LINE TYPE STRING,
RESPONSIBLE TYPE STRING,
TXT_RESPON TYPE STRING,
TXT_USTATUS TYPE STRING,
RECIPE TYPE STRING,
TXT_RCP TYPE STRING,
RCP_AENNR TYPE STRING,
DURA TYPE STRING,
DURA_UNIT TYPE STRING,
TRIALQTY TYPE STRING,
MEINS TYPE STRING,
DAY_REQ_START TYPE STRING,
DAY_REQ_END TYPE STRING,
TIM_REQ_START TYPE STRING,
TIM_REQ_END TYPE STRING,
DAY_SHD_START TYPE STRING,
DAY_SHD_END TYPE STRING,
TIM_SHD_START TYPE STRING,
TIM_SHD_END TYPE STRING,
DAY_EXE_START TYPE STRING,
DAY_EXE_END TYPE STRING,
TIM_EXE_START TYPE STRING,
TIM_EXE_END TYPE STRING,
ADM_CREA_BY TYPE STRING,
TXT_CREABY TYPE STRING,
ADM_CREA_AT TYPE STRING,
ADM_CHG_BY TYPE STRING,
TXT_CHNGBY TYPE STRING,
ADM_CHG_AT TYPE STRING,
AUTHGRP TYPE STRING,
TXT_AUTHGRP TYPE STRING,
LOGSYS TYPE STRING,
TRIALDEL TYPE STRING,END OF T_EKKO_STR. DATA: WA_RMXTS_OTPT_TRSI_HDR_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_RMXTS_OTPT_TRSI_HDR_STR-TRIALID sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_TRIALTYPE sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TRIALTYPE sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TRIALNAME sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_SSTATUS sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-PRODUCT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_PRODUCT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-PRDHA sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_PRDHA sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-PLANT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_PLANT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-PROJECT_DYNP sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_PROJ sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-BATCH sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-LINE sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-RESPONSIBLE sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_RESPON sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_USTATUS sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-RECIPE sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_RCP sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-RCP_AENNR sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DURA sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DURA_UNIT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TRIALQTY sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-MEINS sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_REQ_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_REQ_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_REQ_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_REQ_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_SHD_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_SHD_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_SHD_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_SHD_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_EXE_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-DAY_EXE_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_EXE_START sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TIM_EXE_END sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-ADM_CREA_BY sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_CREABY sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-ADM_CREA_AT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-ADM_CHG_BY sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_CHNGBY sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-ADM_CHG_AT sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-AUTHGRP sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TXT_AUTHGRP sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-LOGSYS sy-vline
WA_RMXTS_OTPT_TRSI_HDR_STR-TRIALDEL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.