ABAP Select data from SAP table CTECHOBJFLATVH1 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 CTECHOBJFLATVH1 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 CTECHOBJFLATVH1. 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 CTECHOBJFLATVH1 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_CTECHOBJFLATVH1 TYPE STANDARD TABLE OF CTECHOBJFLATVH1,
      WA_CTECHOBJFLATVH1 TYPE CTECHOBJFLATVH1,
      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: <CTECHOBJFLATVH1> TYPE CTECHOBJFLATVH1.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CTECHOBJFLATVH1
*  INTO TABLE @DATA(IT_CTECHOBJFLATVH12).
*--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_CTECHOBJFLATVH1 INDEX 1 INTO DATA(WA_CTECHOBJFLATVH12).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CTECHOBJFLATVH1 ASSIGNING <CTECHOBJFLATVH1>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CTECHOBJFLATVH1>-MANDT = 1.
<CTECHOBJFLATVH1>-TECHNICALOBJECT = 1.
<CTECHOBJFLATVH1>-TECHOBJISEQUIPORFUNCNLLOC = 1.
<CTECHOBJFLATVH1>-TECHNICALOBJECTLABEL = 1.
<CTECHOBJFLATVH1>-FUNCTIONALLOCATIONLABELNAME = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CTECHOBJFLATVH1-TECHNICALOBJECTDESCRIPTION, sy-vline,
WA_CTECHOBJFLATVH1-SUPERIORTECHNICALOBJECT, sy-vline,
WA_CTECHOBJFLATVH1-SUPERIOROBJISEQUIPORFUNCNLLOC, sy-vline,
WA_CTECHOBJFLATVH1-EQUIPMENT, sy-vline,
WA_CTECHOBJFLATVH1-PLANT, sy-vline,
WA_CTECHOBJFLATVH1-EQUIPMENTWITHLEADINGZEROS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CTECHOBJFLATVH1 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_CTECHOBJFLATVH1 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_CTECHOBJFLATVH1 INTO WA_CTECHOBJFLATVH1. *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 TECHNICALOBJECTLABEL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CTECHOBJFLATVH1-TECHNICALOBJECTLABEL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CTECHOBJFLATVH1-TECHNICALOBJECTLABEL.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit TECHO, internal->external for field SUPERIORTECHNICALOBJECTLABEL CALL FUNCTION 'CONVERSION_EXIT_TECHO_OUTPUT' EXPORTING input = WA_CTECHOBJFLATVH1-SUPERIORTECHNICALOBJECTLABEL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CTECHOBJFLATVH1-SUPERIORTECHNICALOBJECTLABEL.
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_CTECHOBJFLATVH1_STR,
MANDT TYPE STRING,
TECHNICALOBJECT TYPE STRING,
TECHOBJISEQUIPORFUNCNLLOC TYPE STRING,
TECHNICALOBJECTLABEL TYPE STRING,
FUNCTIONALLOCATIONLABELNAME TYPE STRING,
TECHNICALOBJECTDESCRIPTION TYPE STRING,
SUPERIORTECHNICALOBJECT TYPE STRING,
SUPERIOROBJISEQUIPORFUNCNLLOC TYPE STRING,
EQUIPMENT TYPE STRING,
PLANT TYPE STRING,
EQUIPMENTWITHLEADINGZEROS TYPE STRING,
FUNCTIONALLOCATION TYPE STRING,
ABCINDICATOR TYPE STRING,
ABCINDICATORDESC TYPE STRING,
AUTHORIZATIONGROUP TYPE STRING,
BUSINESSAREA TYPE STRING,
BUSINESSAREANAME TYPE STRING,
CATALOGPROFILE TYPE STRING,
COMPANYCODE TYPE STRING,
COMPANYCODENAME TYPE STRING,
CONTROLLINGAREA TYPE STRING,
CONTROLLINGAREANAME TYPE STRING,
COSTCENTER TYPE STRING,
COSTCENTERDESCRIPTION TYPE STRING,
WORKCENTER TYPE STRING,
WORKCENTERINTERNALID TYPE STRING,
WORKCENTERTYPECODE TYPE STRING,
MAINWORKCENTERPLANT TYPE STRING,
WORKCENTERTEXT TYPE STRING,
MAINWORKCENTER TYPE STRING,
MAINWORKCENTERINTERNALID TYPE STRING,
MAINWORKCENTERTYPECODE TYPE STRING,
MAINWORKCENTERTEXT TYPE STRING,
MAINTENANCEPLANT TYPE STRING,
MAINTENANCEPLANTNAME TYPE STRING,
ASSETMANUFACTURERNAME TYPE STRING,
MANUFACTURERPARTTYPENAME TYPE STRING,
MAINTENANCEPLANNINGPLANT TYPE STRING,
MAINTENANCEPLANNINGPLANTNAME TYPE STRING,
MAINTENANCEPLANNERGROUP TYPE STRING,
MAINTENANCEPLANNERGROUPNAME TYPE STRING,
PLANTSECTION TYPE STRING,
PLANTSECTIONPERSONRESPNAME TYPE STRING,
ASSETROOM TYPE STRING,
MAINTOBJECTFREEDEFINEDATTRIB TYPE STRING,
TECHNICALOBJECTCATEGORY TYPE STRING,
TECHNICALOBJECTCATEGORYDESC TYPE STRING,
TECHNICALOBJECTTYPE TYPE STRING,
ACQUISITIONVALUE TYPE STRING,
CURRENCY TYPE STRING,
CREATEDBYUSER TYPE STRING,
CREATIONDATE TYPE STRING,
LASTCHANGEDBYUSER TYPE STRING,
LASTCHANGEDATE TYPE STRING,
DIVISION TYPE STRING,
DIVISIONNAME TYPE STRING,
ASSETLOCATION TYPE STRING,
LOCATIONNAME TYPE STRING,
TECHOBJISEQUIPORFUNCNLLOCDESC TYPE STRING,
TECHOBJINSTALLATIONLOCATION TYPE STRING,
HIERARCHYNODELEVEL TYPE STRING,
NUMBEROFORDERS TYPE STRING,
NMBROFOPENMAINTNOTIFICATIONS TYPE STRING,
CONCATENATEDACTIVESYSTSTSNAME TYPE STRING,
MAINWORKCENTERPLANTNAME TYPE STRING,
SUPERIORTECHNICALOBJECTLABEL TYPE STRING,
MAINTOBJECTINTERNALID TYPE STRING,END OF T_EKKO_STR. DATA: WA_CTECHOBJFLATVH1_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_CTECHOBJFLATVH1_STR-MANDT sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECT sy-vline
WA_CTECHOBJFLATVH1_STR-TECHOBJISEQUIPORFUNCNLLOC sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECTLABEL sy-vline
WA_CTECHOBJFLATVH1_STR-FUNCTIONALLOCATIONLABELNAME sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECTDESCRIPTION sy-vline
WA_CTECHOBJFLATVH1_STR-SUPERIORTECHNICALOBJECT sy-vline
WA_CTECHOBJFLATVH1_STR-SUPERIOROBJISEQUIPORFUNCNLLOC sy-vline
WA_CTECHOBJFLATVH1_STR-EQUIPMENT sy-vline
WA_CTECHOBJFLATVH1_STR-PLANT sy-vline
WA_CTECHOBJFLATVH1_STR-EQUIPMENTWITHLEADINGZEROS sy-vline
WA_CTECHOBJFLATVH1_STR-FUNCTIONALLOCATION sy-vline
WA_CTECHOBJFLATVH1_STR-ABCINDICATOR sy-vline
WA_CTECHOBJFLATVH1_STR-ABCINDICATORDESC sy-vline
WA_CTECHOBJFLATVH1_STR-AUTHORIZATIONGROUP sy-vline
WA_CTECHOBJFLATVH1_STR-BUSINESSAREA sy-vline
WA_CTECHOBJFLATVH1_STR-BUSINESSAREANAME sy-vline
WA_CTECHOBJFLATVH1_STR-CATALOGPROFILE sy-vline
WA_CTECHOBJFLATVH1_STR-COMPANYCODE sy-vline
WA_CTECHOBJFLATVH1_STR-COMPANYCODENAME sy-vline
WA_CTECHOBJFLATVH1_STR-CONTROLLINGAREA sy-vline
WA_CTECHOBJFLATVH1_STR-CONTROLLINGAREANAME sy-vline
WA_CTECHOBJFLATVH1_STR-COSTCENTER sy-vline
WA_CTECHOBJFLATVH1_STR-COSTCENTERDESCRIPTION sy-vline
WA_CTECHOBJFLATVH1_STR-WORKCENTER sy-vline
WA_CTECHOBJFLATVH1_STR-WORKCENTERINTERNALID sy-vline
WA_CTECHOBJFLATVH1_STR-WORKCENTERTYPECODE sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTERPLANT sy-vline
WA_CTECHOBJFLATVH1_STR-WORKCENTERTEXT sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTER sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTERINTERNALID sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTERTYPECODE sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTERTEXT sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANT sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANTNAME sy-vline
WA_CTECHOBJFLATVH1_STR-ASSETMANUFACTURERNAME sy-vline
WA_CTECHOBJFLATVH1_STR-MANUFACTURERPARTTYPENAME sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANNINGPLANT sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANNINGPLANTNAME sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANNERGROUP sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTENANCEPLANNERGROUPNAME sy-vline
WA_CTECHOBJFLATVH1_STR-PLANTSECTION sy-vline
WA_CTECHOBJFLATVH1_STR-PLANTSECTIONPERSONRESPNAME sy-vline
WA_CTECHOBJFLATVH1_STR-ASSETROOM sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTOBJECTFREEDEFINEDATTRIB sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECTCATEGORY sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECTCATEGORYDESC sy-vline
WA_CTECHOBJFLATVH1_STR-TECHNICALOBJECTTYPE sy-vline
WA_CTECHOBJFLATVH1_STR-ACQUISITIONVALUE sy-vline
WA_CTECHOBJFLATVH1_STR-CURRENCY sy-vline
WA_CTECHOBJFLATVH1_STR-CREATEDBYUSER sy-vline
WA_CTECHOBJFLATVH1_STR-CREATIONDATE sy-vline
WA_CTECHOBJFLATVH1_STR-LASTCHANGEDBYUSER sy-vline
WA_CTECHOBJFLATVH1_STR-LASTCHANGEDATE sy-vline
WA_CTECHOBJFLATVH1_STR-DIVISION sy-vline
WA_CTECHOBJFLATVH1_STR-DIVISIONNAME sy-vline
WA_CTECHOBJFLATVH1_STR-ASSETLOCATION sy-vline
WA_CTECHOBJFLATVH1_STR-LOCATIONNAME sy-vline
WA_CTECHOBJFLATVH1_STR-TECHOBJISEQUIPORFUNCNLLOCDESC sy-vline
WA_CTECHOBJFLATVH1_STR-TECHOBJINSTALLATIONLOCATION sy-vline
WA_CTECHOBJFLATVH1_STR-HIERARCHYNODELEVEL sy-vline
WA_CTECHOBJFLATVH1_STR-NUMBEROFORDERS sy-vline
WA_CTECHOBJFLATVH1_STR-NMBROFOPENMAINTNOTIFICATIONS sy-vline
WA_CTECHOBJFLATVH1_STR-CONCATENATEDACTIVESYSTSTSNAME sy-vline
WA_CTECHOBJFLATVH1_STR-MAINWORKCENTERPLANTNAME sy-vline
WA_CTECHOBJFLATVH1_STR-SUPERIORTECHNICALOBJECTLABEL sy-vline
WA_CTECHOBJFLATVH1_STR-MAINTOBJECTINTERNALID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.