ABAP Select data from SAP table INM_TS_INITIATIVE_DIS 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 INM_TS_INITIATIVE_DIS 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 INM_TS_INITIATIVE_DIS. 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 INM_TS_INITIATIVE_DIS 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_INM_TS_INITIATIVE_DIS TYPE STANDARD TABLE OF INM_TS_INITIATIVE_DIS, WA_INM_TS_INITIATIVE_DIS TYPE INM_TS_INITIATIVE_DIS, 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: <INM_TS_INITIATIVE_DIS> TYPE INM_TS_INITIATIVE_DIS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_INM_TS_INITIATIVE_DIS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM INM_TS_INITIATIVE_DIS INTO TABLE IT_INM_TS_INITIATIVE_DIS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM INM_TS_INITIATIVE_DIS * INTO TABLE @DATA(IT_INM_TS_INITIATIVE_DIS2). *--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_INM_TS_INITIATIVE_DIS INDEX 1 INTO DATA(WA_INM_TS_INITIATIVE_DIS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_INM_TS_INITIATIVE_DIS ASSIGNING <INM_TS_INITIATIVE_DIS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<INM_TS_INITIATIVE_DIS>-GUID = 1.
<INM_TS_INITIATIVE_DIS>-CREATED_ON = 1.
<INM_TS_INITIATIVE_DIS>-CREATED_BY = 1.
<INM_TS_INITIATIVE_DIS>-CHANGED_ON = 1.
<INM_TS_INITIATIVE_DIS>-CHANGED_BY = 1.
ENDLOOP. LOOP AT IT_INM_TS_INITIATIVE_DIS INTO WA_INM_TS_INITIATIVE_DIS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_INM_TS_INITIATIVE_DIS-LAST_CHANGED_ON, sy-vline,
WA_INM_TS_INITIATIVE_DIS-LAST_CHANGED_BY, sy-vline,
WA_INM_TS_INITIATIVE_DIS-NO_OF_ITEMS, sy-vline,
WA_INM_TS_INITIATIVE_DIS-ITEM_GUID, sy-vline,
WA_INM_TS_INITIATIVE_DIS-BUCKET_NAME, sy-vline,
WA_INM_TS_INITIATIVE_DIS-BUCKET_ID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_INM_TS_INITIATIVE_DIS 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_INM_TS_INITIATIVE_DIS 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_INM_TS_INITIATIVE_DIS INTO WA_INM_TS_INITIATIVE_DIS. *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 LAST_CHANGED_ON CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_INM_TS_INITIATIVE_DIS-LAST_CHANGED_ON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_INM_TS_INITIATIVE_DIS-LAST_CHANGED_ON.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field DURATION_UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_INM_TS_INITIATIVE_DIS-DURATION_UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_INM_TS_INITIATIVE_DIS-DURATION_UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PAYBACK_PLAN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_INM_TS_INITIATIVE_DIS-PAYBACK_PLAN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_INM_TS_INITIATIVE_DIS-PAYBACK_PLAN.
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_INM_TS_INITIATIVE_DIS_STR,
GUID TYPE STRING,
CREATED_ON TYPE STRING,
CREATED_BY TYPE STRING,
CHANGED_ON TYPE STRING,
CHANGED_BY TYPE STRING,
LAST_CHANGED_ON TYPE STRING,
LAST_CHANGED_BY TYPE STRING,
NO_OF_ITEMS TYPE STRING,
ITEM_GUID TYPE STRING,
BUCKET_NAME TYPE STRING,
BUCKET_ID TYPE STRING,
PRIORITY_ICON TYPE STRING,
RISK_ICON TYPE STRING,
RISK_D_ICON TYPE STRING,
PROPOSAL TYPE STRING,
BUDGET_TOTAL TYPE STRING,
BUDGET_ANNUAL TYPE STRING,
PLANNED_COST TYPE STRING,
PLANNED_COST_YTD TYPE STRING,
ACTUAL_COST TYPE STRING,
ACTUAL_COST_YTD TYPE STRING,
SCHEDULE_ICON TYPE STRING,
STAFFING_ICON TYPE STRING,
BUDGET_ICON TYPE STRING,
ACT_DECPT_STAT_ICON TYPE STRING,
DAYS_UNTIL_PLAN_FINISH TYPE STRING,
DAYS_UNTIL_NEXT_DECISION TYPE STRING,
FORCTED_DURATION TYPE STRING,
PLANNED_DURATION TYPE STRING,
ACTUAL_DURATION TYPE STRING,
DURATION_UNIT TYPE STRING,
ACT_PHASE_NAME TYPE STRING,
ACT_PHASE_GUID TYPE STRING,
ACT_PHASE_STAT_TEXT TYPE STRING,
WORKEFFORT_TOTAL TYPE STRING,
WORKEFFORT_YTD TYPE STRING,
PLANNED_EFFORT TYPE STRING,
PLANNED_EFFORT_YTD TYPE STRING,
ACT_DPCPT_GUID TYPE STRING,
ACT_DECPT_NAME TYPE STRING,
ACT_DECPT_STAT_TEXT TYPE STRING,
DECPT_INFO TYPE STRING,
D_PLANSTART TYPE STRING,
D_PLANFINISH TYPE STRING,
D_ACTUALSTART TYPE STRING,
D_ACTUALFINISH TYPE STRING,
D_FORECASTED_START TYPE STRING,
D_FORECASTED_FINISH TYPE STRING,
ACTUAL_DECISION_DATE TYPE STRING,
FORCASTED_DECISION_DATE TYPE STRING,
PLANNED_DECISION_DATE TYPE STRING,
BUDGET_GROUP TYPE STRING,
STAFFING_GROUP TYPE STRING,
SCHEDULE_GROUP TYPE STRING,
PORTFOLIO_NAME TYPE STRING,
PORTFOLIO_ID TYPE STRING,
PLANNED_REVENUE TYPE STRING,
PLANNED_REV_YTD TYPE STRING,
ACTUAL_REVENUE TYPE STRING,
ACTUAL_REV_YTD TYPE STRING,
NPV_PLAN TYPE STRING,
IRR_PLAN TYPE STRING,
ROI_PLAN TYPE STRING,
PAYBACK_PLAN TYPE STRING,
ECV_PLAN TYPE STRING,
EA_DUMMY_KPI TYPE STRING,
DPR_GUID TYPE STRING,
SYSTEM_STATUS TYPE STRING,
USER_STATUS TYPE STRING,
STATUS_TEXT_SHORT TYPE STRING,
STATUS_TEXT_LONG TYPE STRING,
RESP_ORG_U_SHORT TYPE STRING,
RESP_ORG_U_STEXT TYPE STRING,END OF T_EKKO_STR. DATA: WA_INM_TS_INITIATIVE_DIS_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_INM_TS_INITIATIVE_DIS_STR-GUID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-CREATED_ON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-CREATED_BY sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-CHANGED_ON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-CHANGED_BY sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-LAST_CHANGED_ON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-LAST_CHANGED_BY sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-NO_OF_ITEMS sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ITEM_GUID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUCKET_NAME sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUCKET_ID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PRIORITY_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-RISK_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-RISK_D_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PROPOSAL sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUDGET_TOTAL sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUDGET_ANNUAL sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_COST sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_COST_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_COST sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_COST_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-SCHEDULE_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-STAFFING_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUDGET_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_DECPT_STAT_ICON sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-DAYS_UNTIL_PLAN_FINISH sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-DAYS_UNTIL_NEXT_DECISION sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-FORCTED_DURATION sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_DURATION sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_DURATION sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-DURATION_UNIT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_PHASE_NAME sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_PHASE_GUID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_PHASE_STAT_TEXT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-WORKEFFORT_TOTAL sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-WORKEFFORT_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_EFFORT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_EFFORT_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_DPCPT_GUID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_DECPT_NAME sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACT_DECPT_STAT_TEXT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-DECPT_INFO sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_PLANSTART sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_PLANFINISH sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_ACTUALSTART sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_ACTUALFINISH sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_FORECASTED_START sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-D_FORECASTED_FINISH sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_DECISION_DATE sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-FORCASTED_DECISION_DATE sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_DECISION_DATE sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-BUDGET_GROUP sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-STAFFING_GROUP sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-SCHEDULE_GROUP sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PORTFOLIO_NAME sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PORTFOLIO_ID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_REVENUE sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PLANNED_REV_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_REVENUE sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ACTUAL_REV_YTD sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-NPV_PLAN sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-IRR_PLAN sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ROI_PLAN sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-PAYBACK_PLAN sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-ECV_PLAN sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-EA_DUMMY_KPI sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-DPR_GUID sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-SYSTEM_STATUS sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-USER_STATUS sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-STATUS_TEXT_SHORT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-STATUS_TEXT_LONG sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-RESP_ORG_U_SHORT sy-vline
WA_INM_TS_INITIATIVE_DIS_STR-RESP_ORG_U_STEXT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.