ABAP Select data from SAP table EHFNDS_MAINT_ORD_OPERATION 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 EHFNDS_MAINT_ORD_OPERATION 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 EHFNDS_MAINT_ORD_OPERATION. 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 EHFNDS_MAINT_ORD_OPERATION 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_EHFNDS_MAINT_ORD_OPERATION TYPE STANDARD TABLE OF EHFNDS_MAINT_ORD_OPERATION, WA_EHFNDS_MAINT_ORD_OPERATION TYPE EHFNDS_MAINT_ORD_OPERATION, 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: <EHFNDS_MAINT_ORD_OPERATION> TYPE EHFNDS_MAINT_ORD_OPERATION. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_EHFNDS_MAINT_ORD_OPERATION. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM EHFNDS_MAINT_ORD_OPERATION INTO TABLE IT_EHFNDS_MAINT_ORD_OPERATION. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM EHFNDS_MAINT_ORD_OPERATION * INTO TABLE @DATA(IT_EHFNDS_MAINT_ORD_OPERATION2). *--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_EHFNDS_MAINT_ORD_OPERATION INDEX 1 INTO DATA(WA_EHFNDS_MAINT_ORD_OPERATION2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_EHFNDS_MAINT_ORD_OPERATION ASSIGNING <EHFNDS_MAINT_ORD_OPERATION>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<EHFNDS_MAINT_ORD_OPERATION>-ACTIVITY = 1.
<EHFNDS_MAINT_ORD_OPERATION>-SUB_ACTIVITY = 1.
<EHFNDS_MAINT_ORD_OPERATION>-CONTROL_KEY = 1.
<EHFNDS_MAINT_ORD_OPERATION>-WORK_CNTR = 1.
<EHFNDS_MAINT_ORD_OPERATION>-STANDARD_TEXT_KEY = 1.
ENDLOOP. LOOP AT IT_EHFNDS_MAINT_ORD_OPERATION INTO WA_EHFNDS_MAINT_ORD_OPERATION. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_EHFNDS_MAINT_ORD_OPERATION-DESCRIPTION, sy-vline,
WA_EHFNDS_MAINT_ORD_OPERATION-LANGU, sy-vline,
WA_EHFNDS_MAINT_ORD_OPERATION-LANGU_ISO, sy-vline,
WA_EHFNDS_MAINT_ORD_OPERATION-NO_OF_TIME_TICKETS, sy-vline,
WA_EHFNDS_MAINT_ORD_OPERATION-WAGETYPE, sy-vline,
WA_EHFNDS_MAINT_ORD_OPERATION-SUITABILITY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_EHFNDS_MAINT_ORD_OPERATION 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_EHFNDS_MAINT_ORD_OPERATION 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_EHFNDS_MAINT_ORD_OPERATION INTO WA_EHFNDS_MAINT_ORD_OPERATION. *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 NUMCV, internal->external for field ACTIVITY CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-ACTIVITY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-ACTIVITY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field SUB_ACTIVITY CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-SUB_ACTIVITY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-SUB_ACTIVITY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-LANGU.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VENDOR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-VENDOR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-VENDOR_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BASE_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-BASE_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-BASE_UOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COST_ELEMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-COST_ELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-COST_ELEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INFO_REC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-INFO_REC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-INFO_REC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AGREEMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-AGREEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-AGREEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FW_ORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-FW_ORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-FW_ORDER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field DURATION_NORMAL_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-DURATION_NORMAL_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-DURATION_NORMAL_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UN_WORK CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-UN_WORK IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-UN_WORK.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNL, internal->external for field ASSEMBLY_EXTERNAL CALL FUNCTION 'CONVERSION_EXIT_MATNL_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-ASSEMBLY_EXTERNAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-ASSEMBLY_EXTERNAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNW, internal->external for field ASSEMBLY_VERSION CALL FUNCTION 'CONVERSION_EXIT_MATNW_OUTPUT' EXPORTING input = WA_EHFNDS_MAINT_ORD_OPERATION-ASSEMBLY_VERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EHFNDS_MAINT_ORD_OPERATION-ASSEMBLY_VERSION.
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_EHFNDS_MAINT_ORD_OPERATION_STR,
ACTIVITY TYPE STRING,
SUB_ACTIVITY TYPE STRING,
CONTROL_KEY TYPE STRING,
WORK_CNTR TYPE STRING,
STANDARD_TEXT_KEY TYPE STRING,
DESCRIPTION TYPE STRING,
LANGU TYPE STRING,
LANGU_ISO TYPE STRING,
NO_OF_TIME_TICKETS TYPE STRING,
WAGETYPE TYPE STRING,
SUITABILITY TYPE STRING,
WAGEGROUP TYPE STRING,
SORT_FLD TYPE STRING,
VENDOR_NO TYPE STRING,
QUANTITY TYPE STRING,
BASE_UOM TYPE STRING,
BASE_UOM_ISO TYPE STRING,
COST_ELEMENT TYPE STRING,
CURRENCY_ISO TYPE STRING,
INFO_REC TYPE STRING,
PURCH_ORG TYPE STRING,
PUR_GROUP TYPE STRING,
MATL_GROUP TYPE STRING,
AGREEMENT TYPE STRING,
AGMT_ITEM TYPE STRING,
PREQ_NAME TYPE STRING,
TRACKINGNO TYPE STRING,
NUMBER_OF_CAPACITIES TYPE STRING,
PERCENT_OF_WORK TYPE STRING,
CALC_KEY TYPE STRING,
ACTTYPE TYPE STRING,
INT_DISTR TYPE STRING,
GR_RCPT TYPE STRING,
UNLOAD_PT TYPE STRING,
PERS_NO TYPE STRING,
FW_ORDER TYPE STRING,
ORDER_ITEM TYPE STRING,
PLND_DELRY TYPE STRING,
DURATION_NORMAL TYPE STRING,
DURATION_NORMAL_UNIT TYPE STRING,
DURATION_NORMAL_UNIT_ISO TYPE STRING,
CONSTRAINT_TYPE_START TYPE STRING,
CONSTRAINT_TYPE_FINISH TYPE STRING,
WORK_ACTIVITY TYPE STRING,
UN_WORK TYPE STRING,
UN_WORK_ISO TYPE STRING,
START_CONS TYPE STRING,
STRTTIMCON TYPE STRING,
FIN_CONSTR TYPE STRING,
FINTIMCONS TYPE STRING,
EXECFACTOR TYPE STRING,
MRP_RELEVANT TYPE STRING,
FIELD_KEY TYPE STRING,
ASSEMBLY_EXTERNAL TYPE STRING,
ASSEMBLY_GUID TYPE STRING,
ASSEMBLY_VERSION TYPE STRING,END OF T_EKKO_STR. DATA: WA_EHFNDS_MAINT_ORD_OPERATION_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_EHFNDS_MAINT_ORD_OPERATION_STR-ACTIVITY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-SUB_ACTIVITY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-CONTROL_KEY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-WORK_CNTR sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-STANDARD_TEXT_KEY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-DESCRIPTION sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-LANGU sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-LANGU_ISO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-NO_OF_TIME_TICKETS sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-WAGETYPE sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-SUITABILITY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-WAGEGROUP sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-SORT_FLD sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-VENDOR_NO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-QUANTITY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-BASE_UOM sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-BASE_UOM_ISO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-COST_ELEMENT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-CURRENCY_ISO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-INFO_REC sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PURCH_ORG sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PUR_GROUP sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-MATL_GROUP sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-AGREEMENT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-AGMT_ITEM sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PREQ_NAME sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-TRACKINGNO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-NUMBER_OF_CAPACITIES sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PERCENT_OF_WORK sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-CALC_KEY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-ACTTYPE sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-INT_DISTR sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-GR_RCPT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-UNLOAD_PT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PERS_NO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-FW_ORDER sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-ORDER_ITEM sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-PLND_DELRY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-DURATION_NORMAL sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-DURATION_NORMAL_UNIT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-DURATION_NORMAL_UNIT_ISO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-CONSTRAINT_TYPE_START sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-CONSTRAINT_TYPE_FINISH sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-WORK_ACTIVITY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-UN_WORK sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-UN_WORK_ISO sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-START_CONS sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-STRTTIMCON sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-FIN_CONSTR sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-FINTIMCONS sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-EXECFACTOR sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-MRP_RELEVANT sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-FIELD_KEY sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-ASSEMBLY_EXTERNAL sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-ASSEMBLY_GUID sy-vline
WA_EHFNDS_MAINT_ORD_OPERATION_STR-ASSEMBLY_VERSION sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.