ABAP Select data from SAP table RPM_TS_TASK_DETAIL_DATA 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 RPM_TS_TASK_DETAIL_DATA 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 RPM_TS_TASK_DETAIL_DATA. 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 RPM_TS_TASK_DETAIL_DATA 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_RPM_TS_TASK_DETAIL_DATA TYPE STANDARD TABLE OF RPM_TS_TASK_DETAIL_DATA, WA_RPM_TS_TASK_DETAIL_DATA TYPE RPM_TS_TASK_DETAIL_DATA, 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: <RPM_TS_TASK_DETAIL_DATA> TYPE RPM_TS_TASK_DETAIL_DATA. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_RPM_TS_TASK_DETAIL_DATA. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM RPM_TS_TASK_DETAIL_DATA INTO TABLE IT_RPM_TS_TASK_DETAIL_DATA. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM RPM_TS_TASK_DETAIL_DATA * INTO TABLE @DATA(IT_RPM_TS_TASK_DETAIL_DATA2). *--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_RPM_TS_TASK_DETAIL_DATA INDEX 1 INTO DATA(WA_RPM_TS_TASK_DETAIL_DATA2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_RPM_TS_TASK_DETAIL_DATA ASSIGNING <RPM_TS_TASK_DETAIL_DATA>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<RPM_TS_TASK_DETAIL_DATA>-PROJECT_ID = 1.
<RPM_TS_TASK_DETAIL_DATA>-PROJ_DESCRIPTION = 1.
<RPM_TS_TASK_DETAIL_DATA>-PROJECT_STAFF = 1.
<RPM_TS_TASK_DETAIL_DATA>-EXTERNAL_ID = 1.
<RPM_TS_TASK_DETAIL_DATA>-TASK_DESCRIPTION = 1.
ENDLOOP. LOOP AT IT_RPM_TS_TASK_DETAIL_DATA INTO WA_RPM_TS_TASK_DETAIL_DATA. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_RPM_TS_TASK_DETAIL_DATA-ACTUALSTART, sy-vline,
WA_RPM_TS_TASK_DETAIL_DATA-ACTUALFINISH, sy-vline,
WA_RPM_TS_TASK_DETAIL_DATA-PLANSTART, sy-vline,
WA_RPM_TS_TASK_DETAIL_DATA-PLANFINISH, sy-vline,
WA_RPM_TS_TASK_DETAIL_DATA-COMPLETION, sy-vline,
WA_RPM_TS_TASK_DETAIL_DATA-MILESTONE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RPM_TS_TASK_DETAIL_DATA 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_RPM_TS_TASK_DETAIL_DATA 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_RPM_TS_TASK_DETAIL_DATA INTO WA_RPM_TS_TASK_DETAIL_DATA. *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 TSTPS, internal->external for field ACTUALSTART CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-ACTUALSTART IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-ACTUALSTART.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field ACTUALFINISH CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-ACTUALFINISH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-ACTUALFINISH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field PLANSTART CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-PLANSTART IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-PLANSTART.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field PLANFINISH CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-PLANFINISH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-PLANFINISH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field CONSTRAINT_TIME CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-CONSTRAINT_TIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-CONSTRAINT_TIME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field LATEST_START CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-LATEST_START IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-LATEST_START.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field LATEST_FINISH CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-LATEST_FINISH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-LATEST_FINISH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field DURATION_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-DURATION_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-DURATION_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field CONSTR_TIME_FIN CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-CONSTR_TIME_FIN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-CONSTR_TIME_FIN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSTPS, internal->external for field RPM_CHANGED_ON CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-RPM_CHANGED_ON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-RPM_CHANGED_ON.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ASSIGNED_TO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-ASSIGNED_TO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-ASSIGNED_TO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ASSIGNED_BY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-ASSIGNED_BY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-ASSIGNED_BY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field VARIANCE_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_RPM_TS_TASK_DETAIL_DATA-VARIANCE_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RPM_TS_TASK_DETAIL_DATA-VARIANCE_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_RPM_TS_TASK_DETAIL_DATA_STR,
PROJECT_ID TYPE STRING,
PROJ_DESCRIPTION TYPE STRING,
PROJECT_STAFF TYPE STRING,
EXTERNAL_ID TYPE STRING,
TASK_DESCRIPTION TYPE STRING,
ACTUALSTART TYPE STRING,
ACTUALFINISH TYPE STRING,
PLANSTART TYPE STRING,
PLANFINISH TYPE STRING,
COMPLETION TYPE STRING,
MILESTONE TYPE STRING,
CONSTRAINT_TYPE TYPE STRING,
CONSTRAINT_TIME TYPE STRING,
LATEST_START TYPE STRING,
LATEST_FINISH TYPE STRING,
TOTAL_FLOAT TYPE STRING,
DURATION TYPE STRING,
DURATION_UNIT TYPE STRING,
CONSTR_TYPE_FIN TYPE STRING,
CONSTR_TIME_FIN TYPE STRING,
PRIORITY TYPE STRING,
STATUS TYPE STRING,
LOCATION TYPE STRING,
TOP_PROJECT_GUID TYPE STRING,
RPM_CHANGED_ON TYPE STRING,
CRITICAL TYPE STRING,
SUMMARY TYPE STRING,
BASELINE_START TYPE STRING,
BASELINE_FINISH TYPE STRING,
ACTUAL_DURATION TYPE STRING,
PLANNED_DURATION TYPE STRING,
BASELINEDURATION TYPE STRING,
ACTUAL_WORK TYPE STRING,
PLANNED_WORK TYPE STRING,
BASELINE_WORK TYPE STRING,
WORK_UNITS TYPE STRING,
COSTF TYPE STRING,
COSTA TYPE STRING,
BUDGT TYPE STRING,
CURRENCY TYPE STRING,
PHASE TYPE STRING,
DUMMY TYPE STRING,
ASSIGNED_TO TYPE STRING,
ASSIGNED_TO_NAME TYPE STRING,
ASSIGNED_BY TYPE STRING,
ASSIGNED_BY_NAME TYPE STRING,
START_VARIANCE TYPE STRING,
END_VARIANCE TYPE STRING,
VARIANCE_UNIT TYPE STRING,
DATE_PLANSTART TYPE STRING,
DATE_PLANFINISH TYPE STRING,
DATE_ACTUALSTART TYPE STRING,
DATE_ACTUALFINISH TYPE STRING,
NUMBER_OF_CHILDREN TYPE STRING,
DEPENDENCY_COUNT TYPE STRING,
ICON_TASK_STATUS TYPE STRING,
SHADED TYPE STRING,
PARENT_ID TYPE STRING,
LEFT_ID TYPE STRING,
RIGHT_ID TYPE STRING,
TASK_SHORT_TEXT TYPE STRING,
DEPENDENCIES TYPE STRING,
TASK_LONG_TEXT TYPE STRING,
TASK_OBJ_LINKS TYPE STRING,
TASK_ROLE_RESRC TYPE STRING,END OF T_EKKO_STR. DATA: WA_RPM_TS_TASK_DETAIL_DATA_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_RPM_TS_TASK_DETAIL_DATA_STR-PROJECT_ID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PROJ_DESCRIPTION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PROJECT_STAFF sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-EXTERNAL_ID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TASK_DESCRIPTION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ACTUALSTART sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ACTUALFINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PLANSTART sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PLANFINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-COMPLETION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-MILESTONE sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CONSTRAINT_TYPE sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CONSTRAINT_TIME sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-LATEST_START sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-LATEST_FINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TOTAL_FLOAT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DURATION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DURATION_UNIT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CONSTR_TYPE_FIN sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CONSTR_TIME_FIN sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PRIORITY sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-STATUS sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-LOCATION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TOP_PROJECT_GUID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-RPM_CHANGED_ON sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CRITICAL sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-SUMMARY sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-BASELINE_START sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-BASELINE_FINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ACTUAL_DURATION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PLANNED_DURATION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-BASELINEDURATION sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ACTUAL_WORK sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PLANNED_WORK sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-BASELINE_WORK sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-WORK_UNITS sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-COSTF sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-COSTA sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-BUDGT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-CURRENCY sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PHASE sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DUMMY sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ASSIGNED_TO sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ASSIGNED_TO_NAME sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ASSIGNED_BY sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ASSIGNED_BY_NAME sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-START_VARIANCE sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-END_VARIANCE sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-VARIANCE_UNIT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DATE_PLANSTART sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DATE_PLANFINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DATE_ACTUALSTART sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DATE_ACTUALFINISH sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-NUMBER_OF_CHILDREN sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DEPENDENCY_COUNT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-ICON_TASK_STATUS sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-SHADED sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-PARENT_ID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-LEFT_ID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-RIGHT_ID sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TASK_SHORT_TEXT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-DEPENDENCIES sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TASK_LONG_TEXT sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TASK_OBJ_LINKS sy-vline
WA_RPM_TS_TASK_DETAIL_DATA_STR-TASK_ROLE_RESRC sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.