ABAP Select data from SAP table ALMONITOR 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 ALMONITOR 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 ALMONITOR. 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 ALMONITOR 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_ALMONITOR TYPE STANDARD TABLE OF ALMONITOR,
      WA_ALMONITOR TYPE ALMONITOR,
      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: <ALMONITOR> TYPE ALMONITOR.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ALMONITOR
*  INTO TABLE @DATA(IT_ALMONITOR2).
*--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_ALMONITOR INDEX 1 INTO DATA(WA_ALMONITOR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ALMONITOR ASSIGNING <ALMONITOR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ALMONITOR>-MONINAME = 1.
<ALMONITOR>-MONINR = 1.
<ALMONITOR>-TYPE = 1.
<ALMONITOR>-MSETATTR = 1.
<ALMONITOR>-MSETGUID = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ALMONITOR-MONISET, sy-vline,
WA_ALMONITOR-OWNER, sy-vline,
WA_ALMONITOR-FORMATVERS, sy-vline,
WA_ALMONITOR-MANDT, sy-vline,
WA_ALMONITOR-PUBLICSET, sy-vline,
WA_ALMONITOR-MBUSRONLY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ALMONITOR 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_ALMONITOR 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_ALMONITOR INTO WA_ALMONITOR. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_ALMONITOR_STR,
MONINAME TYPE STRING,
MONINR TYPE STRING,
TYPE TYPE STRING,
MSETATTR TYPE STRING,
MSETGUID TYPE STRING,
MONISET TYPE STRING,
OWNER TYPE STRING,
FORMATVERS TYPE STRING,
MANDT TYPE STRING,
PUBLICSET TYPE STRING,
MBUSRONLY TYPE STRING,
MBYUSRAADM TYPE STRING,
MBYOTHERS TYPE STRING,
CREABYADM TYPE STRING,
CHUSER TYPE STRING,
CHTIMESTMP TYPE STRING,
V2CONFINFO TYPE STRING,
MONDEFGUID TYPE STRING,
MONIDEF TYPE STRING,
MONIDEFDRF TYPE STRING,
GLOBALPARM TYPE STRING,
MDEDITFLGS TYPE STRING,
OPMODE TYPE STRING,
GENMONITOR TYPE STRING,
CANCBYUSER TYPE STRING,
MDMODIFIED TYPE STRING,
POPUPMODE TYPE STRING,
MONITEMPL TYPE STRING,
TEMPLISNEW TYPE STRING,
TEMPLGTSMP TYPE STRING,
MONISTREES TYPE STRING,
MONIPRES TYPE STRING,
PRESGNDATA TYPE STRING,
PRESALDATA TYPE STRING,
PRESCVDATA TYPE STRING,
PRESTLDATA TYPE STRING,
PRESGTSTMP TYPE STRING,
DISPLATTR TYPE STRING,
SHGENDTL TYPE STRING,
SHSNGMDTL TYPE STRING,
SHCURPFDTL TYPE STRING,
SH30MINDTL TYPE STRING,
SH24HDTL TYPE STRING,
SHPROTCDTL TYPE STRING,
PCTDFLINTV TYPE STRING,
SHERRNODES TYPE STRING,
SHALSOURCE TYPE STRING,
SHALALWAYS TYPE STRING,
SHALATATTR TYPE STRING,
SHLASTVAL TYPE STRING,
REFRESHTIM TYPE STRING,
TIMDIFFWRN TYPE STRING,
SHMESCOUNT TYPE STRING,
DISPLTZONE TYPE STRING,
VISUSLVL TYPE STRING,
RFEXTRONLY TYPE STRING,
PRESVIEW TYPE STRING,
CHUSER TYPE STRING,
CHTIMESTMP TYPE STRING,
MSETGUID TYPE STRING,
MONIGUID TYPE STRING,END OF T_EKKO_STR. DATA: WA_ALMONITOR_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_ALMONITOR_STR-MONINAME sy-vline
WA_ALMONITOR_STR-MONINR sy-vline
WA_ALMONITOR_STR-TYPE sy-vline
WA_ALMONITOR_STR-MSETATTR sy-vline
WA_ALMONITOR_STR-MSETGUID sy-vline
WA_ALMONITOR_STR-MONISET sy-vline
WA_ALMONITOR_STR-OWNER sy-vline
WA_ALMONITOR_STR-FORMATVERS sy-vline
WA_ALMONITOR_STR-MANDT sy-vline
WA_ALMONITOR_STR-PUBLICSET sy-vline
WA_ALMONITOR_STR-MBUSRONLY sy-vline
WA_ALMONITOR_STR-MBYUSRAADM sy-vline
WA_ALMONITOR_STR-MBYOTHERS sy-vline
WA_ALMONITOR_STR-CREABYADM sy-vline
WA_ALMONITOR_STR-CHUSER sy-vline
WA_ALMONITOR_STR-CHTIMESTMP sy-vline
WA_ALMONITOR_STR-V2CONFINFO sy-vline
WA_ALMONITOR_STR-MONDEFGUID sy-vline
WA_ALMONITOR_STR-MONIDEF sy-vline
WA_ALMONITOR_STR-MONIDEFDRF sy-vline
WA_ALMONITOR_STR-GLOBALPARM sy-vline
WA_ALMONITOR_STR-MDEDITFLGS sy-vline
WA_ALMONITOR_STR-OPMODE sy-vline
WA_ALMONITOR_STR-GENMONITOR sy-vline
WA_ALMONITOR_STR-CANCBYUSER sy-vline
WA_ALMONITOR_STR-MDMODIFIED sy-vline
WA_ALMONITOR_STR-POPUPMODE sy-vline
WA_ALMONITOR_STR-MONITEMPL sy-vline
WA_ALMONITOR_STR-TEMPLISNEW sy-vline
WA_ALMONITOR_STR-TEMPLGTSMP sy-vline
WA_ALMONITOR_STR-MONISTREES sy-vline
WA_ALMONITOR_STR-MONIPRES sy-vline
WA_ALMONITOR_STR-PRESGNDATA sy-vline
WA_ALMONITOR_STR-PRESALDATA sy-vline
WA_ALMONITOR_STR-PRESCVDATA sy-vline
WA_ALMONITOR_STR-PRESTLDATA sy-vline
WA_ALMONITOR_STR-PRESGTSTMP sy-vline
WA_ALMONITOR_STR-DISPLATTR sy-vline
WA_ALMONITOR_STR-SHGENDTL sy-vline
WA_ALMONITOR_STR-SHSNGMDTL sy-vline
WA_ALMONITOR_STR-SHCURPFDTL sy-vline
WA_ALMONITOR_STR-SH30MINDTL sy-vline
WA_ALMONITOR_STR-SH24HDTL sy-vline
WA_ALMONITOR_STR-SHPROTCDTL sy-vline
WA_ALMONITOR_STR-PCTDFLINTV sy-vline
WA_ALMONITOR_STR-SHERRNODES sy-vline
WA_ALMONITOR_STR-SHALSOURCE sy-vline
WA_ALMONITOR_STR-SHALALWAYS sy-vline
WA_ALMONITOR_STR-SHALATATTR sy-vline
WA_ALMONITOR_STR-SHLASTVAL sy-vline
WA_ALMONITOR_STR-REFRESHTIM sy-vline
WA_ALMONITOR_STR-TIMDIFFWRN sy-vline
WA_ALMONITOR_STR-SHMESCOUNT sy-vline
WA_ALMONITOR_STR-DISPLTZONE sy-vline
WA_ALMONITOR_STR-VISUSLVL sy-vline
WA_ALMONITOR_STR-RFEXTRONLY sy-vline
WA_ALMONITOR_STR-PRESVIEW sy-vline
WA_ALMONITOR_STR-CHUSER sy-vline
WA_ALMONITOR_STR-CHTIMESTMP sy-vline
WA_ALMONITOR_STR-MSETGUID sy-vline
WA_ALMONITOR_STR-MONIGUID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.