ABAP Select data from SAP table BAPI_ACT_ELEMENT 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 BAPI_ACT_ELEMENT 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 BAPI_ACT_ELEMENT. 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 BAPI_ACT_ELEMENT 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_BAPI_ACT_ELEMENT TYPE STANDARD TABLE OF BAPI_ACT_ELEMENT, WA_BAPI_ACT_ELEMENT TYPE BAPI_ACT_ELEMENT, 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: <BAPI_ACT_ELEMENT> TYPE BAPI_ACT_ELEMENT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI_ACT_ELEMENT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI_ACT_ELEMENT INTO TABLE IT_BAPI_ACT_ELEMENT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI_ACT_ELEMENT * INTO TABLE @DATA(IT_BAPI_ACT_ELEMENT2). *--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_BAPI_ACT_ELEMENT INDEX 1 INTO DATA(WA_BAPI_ACT_ELEMENT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI_ACT_ELEMENT ASSIGNING <BAPI_ACT_ELEMENT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_ACT_ELEMENT>-NETWORK = 1.
<BAPI_ACT_ELEMENT>-ACTIVITY = 1.
<BAPI_ACT_ELEMENT>-ELEMENT = 1.
<BAPI_ACT_ELEMENT>-CONTROL_KEY = 1.
<BAPI_ACT_ELEMENT>-WORK_CNTR = 1.
ENDLOOP. LOOP AT IT_BAPI_ACT_ELEMENT INTO WA_BAPI_ACT_ELEMENT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI_ACT_ELEMENT-PLANT, sy-vline,
WA_BAPI_ACT_ELEMENT-DESCRIPTION, sy-vline,
WA_BAPI_ACT_ELEMENT-VENDOR_NO, sy-vline,
WA_BAPI_ACT_ELEMENT-PRICE, sy-vline,
WA_BAPI_ACT_ELEMENT-PRICE_UNIT, sy-vline,
WA_BAPI_ACT_ELEMENT-COST_ELEM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_ACT_ELEMENT 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_BAPI_ACT_ELEMENT 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_BAPI_ACT_ELEMENT INTO WA_BAPI_ACT_ELEMENT. *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 NETWORK CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-NETWORK IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-NETWORK.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field ACTIVITY CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-ACTIVITY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-ACTIVITY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field ELEMENT CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-ELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-ELEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VENDOR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-VENDOR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-VENDOR_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COST_ELEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-COST_ELEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-COST_ELEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INFO_REC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-INFO_REC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-INFO_REC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field PROJECT_DEFINITION CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-PROJECT_DEFINITION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-PROJECT_DEFINITION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSN, internal->external for field WBS_ELEMENT CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-WBS_ELEMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-WBS_ELEMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PROFIT_CTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-PROFIT_CTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-PROFIT_CTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field OPERATION_MEASURE_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-OPERATION_MEASURE_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-OPERATION_MEASURE_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UN_WORK CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-UN_WORK IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-UN_WORK.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field USER_FIELD_UNIT1 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-USER_FIELD_UNIT1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-USER_FIELD_UNIT1.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field USER_FIELD_UNIT2 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-USER_FIELD_UNIT2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-USER_FIELD_UNIT2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field OFFSET_START_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-OFFSET_START_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-OFFSET_START_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field OFFSET_END_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPI_ACT_ELEMENT-OFFSET_END_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_ACT_ELEMENT-OFFSET_END_UNIT.
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_BAPI_ACT_ELEMENT_STR,
NETWORK TYPE STRING,
ACTIVITY TYPE STRING,
ELEMENT TYPE STRING,
CONTROL_KEY TYPE STRING,
WORK_CNTR TYPE STRING,
PLANT TYPE STRING,
DESCRIPTION TYPE STRING,
VENDOR_NO TYPE STRING,
PRICE TYPE STRING,
PRICE_UNIT TYPE STRING,
COST_ELEM TYPE STRING,
CURRENCY TYPE STRING,
CURRENCY_ISO TYPE STRING,
INFO_REC TYPE STRING,
PURCH_ORG TYPE STRING,
PUR_GROUP TYPE STRING,
MATL_GROUP TYPE STRING,
NUMBER_OF_CAPACITIES TYPE STRING,
PERCENT_OF_WORK TYPE STRING,
ACTTYPE TYPE STRING,
ACTIVITY_COSTS TYPE STRING,
PROJECT_DEFINITION TYPE STRING,
WBS_ELEMENT TYPE STRING,
DISTRIBUTING_KEY TYPE STRING,
TAXJURCODE TYPE STRING,
PROFIT_CTR TYPE STRING,
NOT_MRP_APPLICABLE TYPE STRING,
PROJECT_SUMMARIZATION TYPE STRING,
OPERATION_MEASURE_UNIT TYPE STRING,
OPERATION_MEASURE_UNIT_ISO TYPE STRING,
PLND_DELRY TYPE STRING,
WORK_ACTIVITY TYPE STRING,
UN_WORK TYPE STRING,
UN_WORK_ISO TYPE STRING,
EARLY_START_DATE TYPE STRING,
EARLY_START_TIME TYPE STRING,
EARLY_FINISH_DATE TYPE STRING,
EARLY_FINISH_TIME TYPE STRING,
LATEST_START_DATE TYPE STRING,
LATEST_START_TIME TYPE STRING,
LATEST_FINISH_DATE TYPE STRING,
LATEST_FINISH_TIME TYPE STRING,
USER_FIELD_KEY TYPE STRING,
USER_FIELD_CHAR20_1 TYPE STRING,
USER_FIELD_CHAR20_2 TYPE STRING,
USER_FIELD_CHAR10_1 TYPE STRING,
USER_FIELD_CHAR10_2 TYPE STRING,
USER_FIELD_QUAN1 TYPE STRING,
USER_FIELD_UNIT1 TYPE STRING,
USER_FIELD_UNIT1_ISO TYPE STRING,
USER_FIELD_QUAN2 TYPE STRING,
USER_FIELD_UNIT2 TYPE STRING,
USER_FIELD_UNIT2_ISO TYPE STRING,
USER_FIELD_CURR1 TYPE STRING,
USER_FIELD_CUKY1 TYPE STRING,
USER_FIELD_CUKY1_ISO TYPE STRING,
USER_FIELD_CURR2 TYPE STRING,
USER_FIELD_CUKY2 TYPE STRING,
USER_FIELD_CUKY2_ISO TYPE STRING,
USER_FIELD_DATE1 TYPE STRING,
USER_FIELD_DATE2 TYPE STRING,
USER_FIELD_FLAG1 TYPE STRING,
USER_FIELD_FLAG2 TYPE STRING,
EARLY_START_DATE_FC TYPE STRING,
EARLY_START_TIME_FC TYPE STRING,
EARLY_FINISH_DATE_FC TYPE STRING,
EARLY_FINISH_TIME_FC TYPE STRING,
LATEST_START_DATE_FC TYPE STRING,
LATEST_START_TIME_FC TYPE STRING,
LATEST_FINISH_DATE_FC TYPE STRING,
LATEST_FINISH_TIME_FC TYPE STRING,
OBJECTCLASS_EXT TYPE STRING,
OFFSET_START TYPE STRING,
OFFSET_START_UNIT TYPE STRING,
OFFSET_START_UNIT_ISO TYPE STRING,
OFFSET_END TYPE STRING,
OFFSET_END_UNIT TYPE STRING,
OFFSET_END_UNIT_ISO TYPE STRING,
FUNC_AREA TYPE STRING,
FUNC_AREA_LONG TYPE STRING,
PERS_NO TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_ACT_ELEMENT_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_BAPI_ACT_ELEMENT_STR-NETWORK sy-vline
WA_BAPI_ACT_ELEMENT_STR-ACTIVITY sy-vline
WA_BAPI_ACT_ELEMENT_STR-ELEMENT sy-vline
WA_BAPI_ACT_ELEMENT_STR-CONTROL_KEY sy-vline
WA_BAPI_ACT_ELEMENT_STR-WORK_CNTR sy-vline
WA_BAPI_ACT_ELEMENT_STR-PLANT sy-vline
WA_BAPI_ACT_ELEMENT_STR-DESCRIPTION sy-vline
WA_BAPI_ACT_ELEMENT_STR-VENDOR_NO sy-vline
WA_BAPI_ACT_ELEMENT_STR-PRICE sy-vline
WA_BAPI_ACT_ELEMENT_STR-PRICE_UNIT sy-vline
WA_BAPI_ACT_ELEMENT_STR-COST_ELEM sy-vline
WA_BAPI_ACT_ELEMENT_STR-CURRENCY sy-vline
WA_BAPI_ACT_ELEMENT_STR-CURRENCY_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-INFO_REC sy-vline
WA_BAPI_ACT_ELEMENT_STR-PURCH_ORG sy-vline
WA_BAPI_ACT_ELEMENT_STR-PUR_GROUP sy-vline
WA_BAPI_ACT_ELEMENT_STR-MATL_GROUP sy-vline
WA_BAPI_ACT_ELEMENT_STR-NUMBER_OF_CAPACITIES sy-vline
WA_BAPI_ACT_ELEMENT_STR-PERCENT_OF_WORK sy-vline
WA_BAPI_ACT_ELEMENT_STR-ACTTYPE sy-vline
WA_BAPI_ACT_ELEMENT_STR-ACTIVITY_COSTS sy-vline
WA_BAPI_ACT_ELEMENT_STR-PROJECT_DEFINITION sy-vline
WA_BAPI_ACT_ELEMENT_STR-WBS_ELEMENT sy-vline
WA_BAPI_ACT_ELEMENT_STR-DISTRIBUTING_KEY sy-vline
WA_BAPI_ACT_ELEMENT_STR-TAXJURCODE sy-vline
WA_BAPI_ACT_ELEMENT_STR-PROFIT_CTR sy-vline
WA_BAPI_ACT_ELEMENT_STR-NOT_MRP_APPLICABLE sy-vline
WA_BAPI_ACT_ELEMENT_STR-PROJECT_SUMMARIZATION sy-vline
WA_BAPI_ACT_ELEMENT_STR-OPERATION_MEASURE_UNIT sy-vline
WA_BAPI_ACT_ELEMENT_STR-OPERATION_MEASURE_UNIT_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-PLND_DELRY sy-vline
WA_BAPI_ACT_ELEMENT_STR-WORK_ACTIVITY sy-vline
WA_BAPI_ACT_ELEMENT_STR-UN_WORK sy-vline
WA_BAPI_ACT_ELEMENT_STR-UN_WORK_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_START_DATE sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_START_TIME sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_FINISH_DATE sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_FINISH_TIME sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_START_DATE sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_START_TIME sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_FINISH_DATE sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_FINISH_TIME sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_KEY sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CHAR20_1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CHAR20_2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CHAR10_1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CHAR10_2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_QUAN1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_UNIT1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_UNIT1_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_QUAN2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_UNIT2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_UNIT2_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CURR1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CUKY1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CUKY1_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CURR2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CUKY2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_CUKY2_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_DATE1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_DATE2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_FLAG1 sy-vline
WA_BAPI_ACT_ELEMENT_STR-USER_FIELD_FLAG2 sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_START_DATE_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_START_TIME_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_FINISH_DATE_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-EARLY_FINISH_TIME_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_START_DATE_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_START_TIME_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_FINISH_DATE_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-LATEST_FINISH_TIME_FC sy-vline
WA_BAPI_ACT_ELEMENT_STR-OBJECTCLASS_EXT sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_START sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_START_UNIT sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_START_UNIT_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_END sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_END_UNIT sy-vline
WA_BAPI_ACT_ELEMENT_STR-OFFSET_END_UNIT_ISO sy-vline
WA_BAPI_ACT_ELEMENT_STR-FUNC_AREA sy-vline
WA_BAPI_ACT_ELEMENT_STR-FUNC_AREA_LONG sy-vline
WA_BAPI_ACT_ELEMENT_STR-PERS_NO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.