ABAP Select data from SAP table RMSLS_XML_HEADER 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 RMSLS_XML_HEADER 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 RMSLS_XML_HEADER. 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 RMSLS_XML_HEADER 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_RMSLS_XML_HEADER TYPE STANDARD TABLE OF RMSLS_XML_HEADER,
      WA_RMSLS_XML_HEADER TYPE RMSLS_XML_HEADER,
      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: <RMSLS_XML_HEADER> TYPE RMSLS_XML_HEADER.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RMSLS_XML_HEADER
*  INTO TABLE @DATA(IT_RMSLS_XML_HEADER2).
*--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_RMSLS_XML_HEADER INDEX 1 INTO DATA(WA_RMSLS_XML_HEADER2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RMSLS_XML_HEADER ASSIGNING <RMSLS_XML_HEADER>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RMSLS_XML_HEADER>-LABELID = 1.
<RMSLS_XML_HEADER>-CREADAT = 1.
<RMSLS_XML_HEADER>-CREABY = 1.
<RMSLS_XML_HEADER>-CREABY_TXT = 1.
<RMSLS_XML_HEADER>-CHNGDAT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RMSLS_XML_HEADER-CHNGBY, sy-vline,
WA_RMSLS_XML_HEADER-CHNGBY_TXT, sy-vline,
WA_RMSLS_XML_HEADER-SPECIFICATION_INT, sy-vline,
WA_RMSLS_XML_HEADER-SPECIFICATION_EXT, sy-vline,
WA_RMSLS_XML_HEADER-SPECIFICATION_TXT, sy-vline,
WA_RMSLS_XML_HEADER-LANGU, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RMSLS_XML_HEADER 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_RMSLS_XML_HEADER 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_RMSLS_XML_HEADER INTO WA_RMSLS_XML_HEADER. *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 ALPHA, internal->external for field LABELID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RMSLS_XML_HEADER-LABELID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMSLS_XML_HEADER-LABELID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_RMSLS_XML_HEADER-LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMSLS_XML_HEADER-LANGU.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field AENNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RMSLS_XML_HEADER-AENNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RMSLS_XML_HEADER-AENNR.
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_RMSLS_XML_HEADER_STR,
LABELID TYPE STRING,
CREADAT TYPE STRING,
CREABY TYPE STRING,
CREABY_TXT TYPE STRING,
CHNGDAT TYPE STRING,
CHNGBY TYPE STRING,
CHNGBY_TXT TYPE STRING,
SPECIFICATION_INT TYPE STRING,
SPECIFICATION_EXT TYPE STRING,
SPECIFICATION_TXT TYPE STRING,
LANGU TYPE STRING,
LANGU_TXT TYPE STRING,
DESCRIPTION TYPE STRING,
AENNR TYPE STRING,
AENNR_TXT TYPE STRING,
AENNR_AEGRU TYPE STRING,
VALID_FROM TYPE STRING,
VALID_TO TYPE STRING,
CHNGTIMSTMP TYPE STRING,
STATUS TYPE STRING,
STATUS_STXT TYPE STRING,
STATUS_LTXT TYPE STRING,
STM_OBJNO TYPE STRING,
USAGE_OBJNO TYPE STRING,
CLA_OBJNO TYPE STRING,
DATA_SOURCE_INT TYPE STRING,
DATA_SOURCE_EXT TYPE STRING,
DATA_SOURCE_TXT TYPE STRING,
DATA_SOURCE_TYPE TYPE STRING,
DATA_SOURCE_TYPE_TXT TYPE STRING,
RATING TYPE STRING,
RATING_TXT TYPE STRING,
VALIDITY_AREA TYPE STRING,
VALIDITY_AREA_TXT TYPE STRING,
WUI_ALT_NO TYPE STRING,
WUI_VERS_NO TYPE STRING,
WUI_VALID_FROM TYPE STRING,
WUI_VALID_TO TYPE STRING,
WUI_STATUS TYPE STRING,
LANGUAGES TYPE STRING,
STATEMENTS TYPE STRING,END OF T_EKKO_STR. DATA: WA_RMSLS_XML_HEADER_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_RMSLS_XML_HEADER_STR-LABELID sy-vline
WA_RMSLS_XML_HEADER_STR-CREADAT sy-vline
WA_RMSLS_XML_HEADER_STR-CREABY sy-vline
WA_RMSLS_XML_HEADER_STR-CREABY_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-CHNGDAT sy-vline
WA_RMSLS_XML_HEADER_STR-CHNGBY sy-vline
WA_RMSLS_XML_HEADER_STR-CHNGBY_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-SPECIFICATION_INT sy-vline
WA_RMSLS_XML_HEADER_STR-SPECIFICATION_EXT sy-vline
WA_RMSLS_XML_HEADER_STR-SPECIFICATION_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-LANGU sy-vline
WA_RMSLS_XML_HEADER_STR-LANGU_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-DESCRIPTION sy-vline
WA_RMSLS_XML_HEADER_STR-AENNR sy-vline
WA_RMSLS_XML_HEADER_STR-AENNR_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-AENNR_AEGRU sy-vline
WA_RMSLS_XML_HEADER_STR-VALID_FROM sy-vline
WA_RMSLS_XML_HEADER_STR-VALID_TO sy-vline
WA_RMSLS_XML_HEADER_STR-CHNGTIMSTMP sy-vline
WA_RMSLS_XML_HEADER_STR-STATUS sy-vline
WA_RMSLS_XML_HEADER_STR-STATUS_STXT sy-vline
WA_RMSLS_XML_HEADER_STR-STATUS_LTXT sy-vline
WA_RMSLS_XML_HEADER_STR-STM_OBJNO sy-vline
WA_RMSLS_XML_HEADER_STR-USAGE_OBJNO sy-vline
WA_RMSLS_XML_HEADER_STR-CLA_OBJNO sy-vline
WA_RMSLS_XML_HEADER_STR-DATA_SOURCE_INT sy-vline
WA_RMSLS_XML_HEADER_STR-DATA_SOURCE_EXT sy-vline
WA_RMSLS_XML_HEADER_STR-DATA_SOURCE_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-DATA_SOURCE_TYPE sy-vline
WA_RMSLS_XML_HEADER_STR-DATA_SOURCE_TYPE_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-RATING sy-vline
WA_RMSLS_XML_HEADER_STR-RATING_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-VALIDITY_AREA sy-vline
WA_RMSLS_XML_HEADER_STR-VALIDITY_AREA_TXT sy-vline
WA_RMSLS_XML_HEADER_STR-WUI_ALT_NO sy-vline
WA_RMSLS_XML_HEADER_STR-WUI_VERS_NO sy-vline
WA_RMSLS_XML_HEADER_STR-WUI_VALID_FROM sy-vline
WA_RMSLS_XML_HEADER_STR-WUI_VALID_TO sy-vline
WA_RMSLS_XML_HEADER_STR-WUI_STATUS sy-vline
WA_RMSLS_XML_HEADER_STR-LANGUAGES sy-vline
WA_RMSLS_XML_HEADER_STR-STATEMENTS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.