ABAP Select data from SAP table IDAMAGEANALYCUBE 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 IDAMAGEANALYCUBE 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 IDAMAGEANALYCUBE. 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 IDAMAGEANALYCUBE 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_IDAMAGEANALYCUBE TYPE STANDARD TABLE OF IDAMAGEANALYCUBE,
      WA_IDAMAGEANALYCUBE TYPE IDAMAGEANALYCUBE,
      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: <IDAMAGEANALYCUBE> TYPE IDAMAGEANALYCUBE.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IDAMAGEANALYCUBE
*  INTO TABLE @DATA(IT_IDAMAGEANALYCUBE2).
*--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_IDAMAGEANALYCUBE INDEX 1 INTO DATA(WA_IDAMAGEANALYCUBE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IDAMAGEANALYCUBE ASSIGNING <IDAMAGEANALYCUBE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IDAMAGEANALYCUBE>-MANDT = 1.
<IDAMAGEANALYCUBE>-MAINTENANCENOTIFICATION = 1.
<IDAMAGEANALYCUBE>-MAINTENANCENOTIFICATIONITEM = 1.
<IDAMAGEANALYCUBE>-MAINTENANCENOTIFICATIONCAUSE = 1.
<IDAMAGEANALYCUBE>-MAINTNOTIFICATIONACTIVITY = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IDAMAGEANALYCUBE-NOTIFICATIONTYPE, sy-vline,
WA_IDAMAGEANALYCUBE-MAINTENANCEPLANNINGPLANT, sy-vline,
WA_IDAMAGEANALYCUBE-MAINWORKCENTER, sy-vline,
WA_IDAMAGEANALYCUBE-MAINTENANCEPLANT, sy-vline,
WA_IDAMAGEANALYCUBE-WORKCENTER, sy-vline,
WA_IDAMAGEANALYCUBE-MAINWORKCENTERPLANT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IDAMAGEANALYCUBE 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_IDAMAGEANALYCUBE 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_IDAMAGEANALYCUBE INTO WA_IDAMAGEANALYCUBE. *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 MAINTENANCENOTIFICATION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IDAMAGEANALYCUBE-MAINTENANCENOTIFICATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDAMAGEANALYCUBE-MAINTENANCENOTIFICATION.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ABPSP, internal->external for field WBSELEMENTINTERNALID CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_IDAMAGEANALYCUBE-WBSELEMENTINTERNALID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDAMAGEANALYCUBE-WBSELEMENTINTERNALID.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit TECHO, internal->external for field TECHNICALOBJECTLABEL CALL FUNCTION 'CONVERSION_EXIT_TECHO_OUTPUT' EXPORTING input = WA_IDAMAGEANALYCUBE-TECHNICALOBJECTLABEL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDAMAGEANALYCUBE-TECHNICALOBJECTLABEL.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit TPLNR, internal->external for field FUNCTIONALLOCATION CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_IDAMAGEANALYCUBE-FUNCTIONALLOCATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDAMAGEANALYCUBE-FUNCTIONALLOCATION.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit GJAHR, internal->external for field CONSTRUCTIONYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_IDAMAGEANALYCUBE-CONSTRUCTIONYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IDAMAGEANALYCUBE-CONSTRUCTIONYEAR.
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_IDAMAGEANALYCUBE_STR,
MANDT TYPE STRING,
MAINTENANCENOTIFICATION TYPE STRING,
MAINTENANCENOTIFICATIONITEM TYPE STRING,
MAINTENANCENOTIFICATIONCAUSE TYPE STRING,
MAINTNOTIFICATIONACTIVITY TYPE STRING,
NOTIFICATIONTYPE TYPE STRING,
MAINTENANCEPLANNINGPLANT TYPE STRING,
MAINWORKCENTER TYPE STRING,
MAINTENANCEPLANT TYPE STRING,
WORKCENTER TYPE STRING,
MAINWORKCENTERPLANT TYPE STRING,
NOTIFPROCESSINGPHASE TYPE STRING,
CREATEDBYUSER TYPE STRING,
LASTCHANGEDBYUSER TYPE STRING,
REPORTEDBYUSER TYPE STRING,
CREATIONDATE TYPE STRING,
LASTCHANGEDATE TYPE STRING,
LASTCHANGEDATETIME TYPE STRING,
NOTIFICATIONCREATIONDATE TYPE STRING,
REQUIREDSTARTDATE TYPE STRING,
REQUIREDENDDATE TYPE STRING,
NOTIFICATIONREFERENCEDATE TYPE STRING,
MALFUNCTIONSTARTDATE TYPE STRING,
MALFUNCTIONENDDATE TYPE STRING,
NOTIFICATIONCREATIONYEAR TYPE STRING,
MAINTNOTIFICATIONCATALOG TYPE STRING,
MAINTNOTIFICATIONCODE TYPE STRING,
MAINTNOTIFICATIONCODEGROUP TYPE STRING,
MALFUNCTIONEFFECT TYPE STRING,
PLANTSECTION TYPE STRING,
ASSETLOCATION TYPE STRING,
ASSETROOM TYPE STRING,
BUSINESSAREA TYPE STRING,
ASSEMBLY TYPE STRING,
MAINTENANCEPLANNERGROUP TYPE STRING,
ABCINDICATOR TYPE STRING,
MAINTOBJECTFREEDEFINEDATTRIB TYPE STRING,
WBSELEMENTINTERNALID TYPE STRING,
COMPANYCODE TYPE STRING,
COSTCENTER TYPE STRING,
CONTROLLINGAREA TYPE STRING,
MAINTPRIORITY TYPE STRING,
MAINTPRIORITYTYPE TYPE STRING,
TECHNICALOBJECT TYPE STRING,
TECHNICALOBJECTLABEL TYPE STRING,
TECHOBJISEQUIPORFUNCNLLOC TYPE STRING,
EQUIPMENT TYPE STRING,
FUNCTIONALLOCATION TYPE STRING,
TECHNICALOBJECTCATEGORY TYPE STRING,
CATALOGPROFILE TYPE STRING,
TECHNICALOBJECTTYPE TYPE STRING,
ASSETMANUFACTURERNAME TYPE STRING,
MANUFACTURERPARTTYPENAME TYPE STRING,
MANUFACTURERCOUNTRY TYPE STRING,
CONSTRUCTIONMATERIAL TYPE STRING,
CONSTRUCTIONYEAR TYPE STRING,
CONSTRUCTIONMONTH TYPE STRING,
AUTHORIZATIONGROUP TYPE STRING,
MAINTNOTIFDAMAGECODECATALOG TYPE STRING,
MAINTNOTIFICATIONDAMAGECODE TYPE STRING,
MAINTNOTIFDAMAGECODEGROUP TYPE STRING,
NUMBEROFMAINTNOTIFDAMAGES TYPE STRING,
MAINTNOTIFOBJPRTCODECATALOG TYPE STRING,
MAINTNOTIFOBJPRTCODE TYPE STRING,
MAINTNOTIFOBJPRTCODEGROUP TYPE STRING,
NUMBEROFMAINTNOTIFOBJECTPARTS TYPE STRING,
MAINTNOTIFCAUSECODECATALOG TYPE STRING,
MAINTNOTIFICATIONCAUSECODE TYPE STRING,
MAINTNOTIFCAUSECODEGROUP TYPE STRING,
MAINTNOTIFICATIONROOTCAUSE TYPE STRING,
NUMBEROFMAINTNOTIFCAUSES TYPE STRING,
MAINTNOTIFACTIVITYCODECATALOG TYPE STRING,
MAINTNOTIFICATIONACTIVITYCODE TYPE STRING,
MAINTNOTIFACTIVITYCODEGROUP TYPE STRING,
NUMBEROFMAINTNOTIFACTIVITIES TYPE STRING,END OF T_EKKO_STR. DATA: WA_IDAMAGEANALYCUBE_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_IDAMAGEANALYCUBE_STR-MANDT sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCENOTIFICATION sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCENOTIFICATIONITEM sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCENOTIFICATIONCAUSE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONACTIVITY sy-vline
WA_IDAMAGEANALYCUBE_STR-NOTIFICATIONTYPE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCEPLANNINGPLANT sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINWORKCENTER sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCEPLANT sy-vline
WA_IDAMAGEANALYCUBE_STR-WORKCENTER sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINWORKCENTERPLANT sy-vline
WA_IDAMAGEANALYCUBE_STR-NOTIFPROCESSINGPHASE sy-vline
WA_IDAMAGEANALYCUBE_STR-CREATEDBYUSER sy-vline
WA_IDAMAGEANALYCUBE_STR-LASTCHANGEDBYUSER sy-vline
WA_IDAMAGEANALYCUBE_STR-REPORTEDBYUSER sy-vline
WA_IDAMAGEANALYCUBE_STR-CREATIONDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-LASTCHANGEDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-LASTCHANGEDATETIME sy-vline
WA_IDAMAGEANALYCUBE_STR-NOTIFICATIONCREATIONDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-REQUIREDSTARTDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-REQUIREDENDDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-NOTIFICATIONREFERENCEDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-MALFUNCTIONSTARTDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-MALFUNCTIONENDDATE sy-vline
WA_IDAMAGEANALYCUBE_STR-NOTIFICATIONCREATIONYEAR sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONCATALOG sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONCODE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONCODEGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-MALFUNCTIONEFFECT sy-vline
WA_IDAMAGEANALYCUBE_STR-PLANTSECTION sy-vline
WA_IDAMAGEANALYCUBE_STR-ASSETLOCATION sy-vline
WA_IDAMAGEANALYCUBE_STR-ASSETROOM sy-vline
WA_IDAMAGEANALYCUBE_STR-BUSINESSAREA sy-vline
WA_IDAMAGEANALYCUBE_STR-ASSEMBLY sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTENANCEPLANNERGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-ABCINDICATOR sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTOBJECTFREEDEFINEDATTRIB sy-vline
WA_IDAMAGEANALYCUBE_STR-WBSELEMENTINTERNALID sy-vline
WA_IDAMAGEANALYCUBE_STR-COMPANYCODE sy-vline
WA_IDAMAGEANALYCUBE_STR-COSTCENTER sy-vline
WA_IDAMAGEANALYCUBE_STR-CONTROLLINGAREA sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTPRIORITY sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTPRIORITYTYPE sy-vline
WA_IDAMAGEANALYCUBE_STR-TECHNICALOBJECT sy-vline
WA_IDAMAGEANALYCUBE_STR-TECHNICALOBJECTLABEL sy-vline
WA_IDAMAGEANALYCUBE_STR-TECHOBJISEQUIPORFUNCNLLOC sy-vline
WA_IDAMAGEANALYCUBE_STR-EQUIPMENT sy-vline
WA_IDAMAGEANALYCUBE_STR-FUNCTIONALLOCATION sy-vline
WA_IDAMAGEANALYCUBE_STR-TECHNICALOBJECTCATEGORY sy-vline
WA_IDAMAGEANALYCUBE_STR-CATALOGPROFILE sy-vline
WA_IDAMAGEANALYCUBE_STR-TECHNICALOBJECTTYPE sy-vline
WA_IDAMAGEANALYCUBE_STR-ASSETMANUFACTURERNAME sy-vline
WA_IDAMAGEANALYCUBE_STR-MANUFACTURERPARTTYPENAME sy-vline
WA_IDAMAGEANALYCUBE_STR-MANUFACTURERCOUNTRY sy-vline
WA_IDAMAGEANALYCUBE_STR-CONSTRUCTIONMATERIAL sy-vline
WA_IDAMAGEANALYCUBE_STR-CONSTRUCTIONYEAR sy-vline
WA_IDAMAGEANALYCUBE_STR-CONSTRUCTIONMONTH sy-vline
WA_IDAMAGEANALYCUBE_STR-AUTHORIZATIONGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFDAMAGECODECATALOG sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONDAMAGECODE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFDAMAGECODEGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-NUMBEROFMAINTNOTIFDAMAGES sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFOBJPRTCODECATALOG sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFOBJPRTCODE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFOBJPRTCODEGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-NUMBEROFMAINTNOTIFOBJECTPARTS sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFCAUSECODECATALOG sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONCAUSECODE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFCAUSECODEGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONROOTCAUSE sy-vline
WA_IDAMAGEANALYCUBE_STR-NUMBEROFMAINTNOTIFCAUSES sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFACTIVITYCODECATALOG sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFICATIONACTIVITYCODE sy-vline
WA_IDAMAGEANALYCUBE_STR-MAINTNOTIFACTIVITYCODEGROUP sy-vline
WA_IDAMAGEANALYCUBE_STR-NUMBEROFMAINTNOTIFACTIVITIES sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.