ABAP Select data from SAP table RN2DWSWL_TASK_C 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 RN2DWSWL_TASK_C 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 RN2DWSWL_TASK_C. 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 RN2DWSWL_TASK_C 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_RN2DWSWL_TASK_C TYPE STANDARD TABLE OF RN2DWSWL_TASK_C,
      WA_RN2DWSWL_TASK_C TYPE RN2DWSWL_TASK_C,
      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: <RN2DWSWL_TASK_C> TYPE RN2DWSWL_TASK_C.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RN2DWSWL_TASK_C
*  INTO TABLE @DATA(IT_RN2DWSWL_TASK_C2).
*--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_RN2DWSWL_TASK_C INDEX 1 INTO DATA(WA_RN2DWSWL_TASK_C2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RN2DWSWL_TASK_C ASSIGNING <RN2DWSWL_TASK_C>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RN2DWSWL_TASK_C>-MANDT = 1.
<RN2DWSWL_TASK_C>-TASK_ID = 1.
<RN2DWSWL_TASK_C>-EINRI = 1.
<RN2DWSWL_TASK_C>-PATNR = 1.
<RN2DWSWL_TASK_C>-AREA = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RN2DWSWL_TASK_C-WS_ID, sy-vline,
WA_RN2DWSWL_TASK_C-PATTERN_ID, sy-vline,
WA_RN2DWSWL_TASK_C-WORK_ID, sy-vline,
WA_RN2DWSWL_TASK_C-OBJ_ORDER, sy-vline,
WA_RN2DWSWL_TASK_C-SHORT_CODE, sy-vline,
WA_RN2DWSWL_TASK_C-NAME, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RN2DWSWL_TASK_C 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_RN2DWSWL_TASK_C 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_RN2DWSWL_TASK_C INTO WA_RN2DWSWL_TASK_C. *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 EINRI CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RN2DWSWL_TASK_C-EINRI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RN2DWSWL_TASK_C-EINRI.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ALPHA, internal->external for field ORGPF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RN2DWSWL_TASK_C-ORGPF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RN2DWSWL_TASK_C-ORGPF.
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_RN2DWSWL_TASK_C_STR,
MANDT TYPE STRING,
TASK_ID TYPE STRING,
EINRI TYPE STRING,
PATNR TYPE STRING,
AREA TYPE STRING,
WS_ID TYPE STRING,
PATTERN_ID TYPE STRING,
WORK_ID TYPE STRING,
OBJ_ORDER TYPE STRING,
SHORT_CODE TYPE STRING,
NAME TYPE STRING,
TASK_STATE TYPE STRING,
STATE_SET_BY TYPE STRING,
RESPONSIBLE TYPE STRING,
IS_MANDATORY TYPE STRING,
BASEITEM_TYPE TYPE STRING,
BASEITEM_ID TYPE STRING,
ACTION_EXECUTED TYPE STRING,
INFO_MODE TYPE STRING,
INFO_ID TYPE STRING,
HAS_NOTE TYPE STRING,
CONTACT_PERSON TYPE STRING,
CONTACT_PHONE TYPE STRING,
CONTACT_EMAIL TYPE STRING,
USER_FIELD TYPE STRING,
INSDATE TYPE STRING,
INSUSER TYPE STRING,
UPDDATE TYPE STRING,
UPDUSER TYPE STRING,
TPACK_ID TYPE STRING,
PLDAT TYPE STRING,
PRIORITY TYPE STRING,
ORGFA TYPE STRING,
ORGPF TYPE STRING,
CHART_CONFIG_ID TYPE STRING,
PRODUCED_BY TYPE STRING,
HAS_TASK_TEXT TYPE STRING,
CHART_MODE TYPE STRING,
INSTIME TYPE STRING,
UPDTIME TYPE STRING,
EINRI_X TYPE STRING,
PATNR_X TYPE STRING,
WORK_ID_X TYPE STRING,
AREA_X TYPE STRING,
SHORT_CODE_X TYPE STRING,
NAME_X TYPE STRING,
TASK_STATE_X TYPE STRING,
ACTION_EXECUTED_X TYPE STRING,
CONTACT_PERSON_X TYPE STRING,
CONTACT_PHONE_X TYPE STRING,
CONTACT_EMAIL_X TYPE STRING,
INSDATE_X TYPE STRING,
INSUSER_X TYPE STRING,
UPDDATE_X TYPE STRING,
UPDUSER_X TYPE STRING,
PLDAT_X TYPE STRING,
PRIORITY_X TYPE STRING,
RESPONSIBLE_X TYPE STRING,
ORGFA_X TYPE STRING,
ORGPF_X TYPE STRING,
CHART_CONFIG_ID_X TYPE STRING,
PRODUCED_BY_X TYPE STRING,
IS_MANDATORY_X TYPE STRING,END OF T_EKKO_STR. DATA: WA_RN2DWSWL_TASK_C_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_RN2DWSWL_TASK_C_STR-MANDT sy-vline
WA_RN2DWSWL_TASK_C_STR-TASK_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-EINRI sy-vline
WA_RN2DWSWL_TASK_C_STR-PATNR sy-vline
WA_RN2DWSWL_TASK_C_STR-AREA sy-vline
WA_RN2DWSWL_TASK_C_STR-WS_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-PATTERN_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-WORK_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-OBJ_ORDER sy-vline
WA_RN2DWSWL_TASK_C_STR-SHORT_CODE sy-vline
WA_RN2DWSWL_TASK_C_STR-NAME sy-vline
WA_RN2DWSWL_TASK_C_STR-TASK_STATE sy-vline
WA_RN2DWSWL_TASK_C_STR-STATE_SET_BY sy-vline
WA_RN2DWSWL_TASK_C_STR-RESPONSIBLE sy-vline
WA_RN2DWSWL_TASK_C_STR-IS_MANDATORY sy-vline
WA_RN2DWSWL_TASK_C_STR-BASEITEM_TYPE sy-vline
WA_RN2DWSWL_TASK_C_STR-BASEITEM_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-ACTION_EXECUTED sy-vline
WA_RN2DWSWL_TASK_C_STR-INFO_MODE sy-vline
WA_RN2DWSWL_TASK_C_STR-INFO_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-HAS_NOTE sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_PERSON sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_PHONE sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_EMAIL sy-vline
WA_RN2DWSWL_TASK_C_STR-USER_FIELD sy-vline
WA_RN2DWSWL_TASK_C_STR-INSDATE sy-vline
WA_RN2DWSWL_TASK_C_STR-INSUSER sy-vline
WA_RN2DWSWL_TASK_C_STR-UPDDATE sy-vline
WA_RN2DWSWL_TASK_C_STR-UPDUSER sy-vline
WA_RN2DWSWL_TASK_C_STR-TPACK_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-PLDAT sy-vline
WA_RN2DWSWL_TASK_C_STR-PRIORITY sy-vline
WA_RN2DWSWL_TASK_C_STR-ORGFA sy-vline
WA_RN2DWSWL_TASK_C_STR-ORGPF sy-vline
WA_RN2DWSWL_TASK_C_STR-CHART_CONFIG_ID sy-vline
WA_RN2DWSWL_TASK_C_STR-PRODUCED_BY sy-vline
WA_RN2DWSWL_TASK_C_STR-HAS_TASK_TEXT sy-vline
WA_RN2DWSWL_TASK_C_STR-CHART_MODE sy-vline
WA_RN2DWSWL_TASK_C_STR-INSTIME sy-vline
WA_RN2DWSWL_TASK_C_STR-UPDTIME sy-vline
WA_RN2DWSWL_TASK_C_STR-EINRI_X sy-vline
WA_RN2DWSWL_TASK_C_STR-PATNR_X sy-vline
WA_RN2DWSWL_TASK_C_STR-WORK_ID_X sy-vline
WA_RN2DWSWL_TASK_C_STR-AREA_X sy-vline
WA_RN2DWSWL_TASK_C_STR-SHORT_CODE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-NAME_X sy-vline
WA_RN2DWSWL_TASK_C_STR-TASK_STATE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-ACTION_EXECUTED_X sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_PERSON_X sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_PHONE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-CONTACT_EMAIL_X sy-vline
WA_RN2DWSWL_TASK_C_STR-INSDATE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-INSUSER_X sy-vline
WA_RN2DWSWL_TASK_C_STR-UPDDATE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-UPDUSER_X sy-vline
WA_RN2DWSWL_TASK_C_STR-PLDAT_X sy-vline
WA_RN2DWSWL_TASK_C_STR-PRIORITY_X sy-vline
WA_RN2DWSWL_TASK_C_STR-RESPONSIBLE_X sy-vline
WA_RN2DWSWL_TASK_C_STR-ORGFA_X sy-vline
WA_RN2DWSWL_TASK_C_STR-ORGPF_X sy-vline
WA_RN2DWSWL_TASK_C_STR-CHART_CONFIG_ID_X sy-vline
WA_RN2DWSWL_TASK_C_STR-PRODUCED_BY_X sy-vline
WA_RN2DWSWL_TASK_C_STR-IS_MANDATORY_X sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.