ABAP Select data from SAP table TDS_DOCFLOW 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 TDS_DOCFLOW 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 TDS_DOCFLOW. 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 TDS_DOCFLOW 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_TDS_DOCFLOW TYPE STANDARD TABLE OF TDS_DOCFLOW,
      WA_TDS_DOCFLOW TYPE TDS_DOCFLOW,
      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: <TDS_DOCFLOW> TYPE TDS_DOCFLOW.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TDS_DOCFLOW
*  INTO TABLE @DATA(IT_TDS_DOCFLOW2).
*--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_TDS_DOCFLOW INDEX 1 INTO DATA(WA_TDS_DOCFLOW2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TDS_DOCFLOW ASSIGNING <TDS_DOCFLOW>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TDS_DOCFLOW>-DOCNUM = 1.
<TDS_DOCFLOW>-ITEMNUM = 1.
<TDS_DOCFLOW>-DOCNUV = 1.
<TDS_DOCFLOW>-ITEMNUV = 1.
<TDS_DOCFLOW>-DESCRIPTION = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TDS_DOCFLOW-HLEVEL, sy-vline,
WA_TDS_DOCFLOW-FOCUS, sy-vline,
WA_TDS_DOCFLOW-VBELV, sy-vline,
WA_TDS_DOCFLOW-POSNV, sy-vline,
WA_TDS_DOCFLOW-VBELN, sy-vline,
WA_TDS_DOCFLOW-POSNN, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TDS_DOCFLOW 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_TDS_DOCFLOW 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_TDS_DOCFLOW INTO WA_TDS_DOCFLOW. *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 DOCNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-DOCNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-DOCNUM.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-MEINS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-MATNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field GEWEI CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-GEWEI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-GEWEI.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field VOLEH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-VOLEH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-VOLEH.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field VRKME CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-VRKME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-VRKME.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-GJAHR.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit ALPHA, internal->external for field LOGSYS_N CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TDS_DOCFLOW-LOGSYS_N IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_DOCFLOW-LOGSYS_N.
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_TDS_DOCFLOW_STR,
DOCNUM TYPE STRING,
ITEMNUM TYPE STRING,
DOCNUV TYPE STRING,
ITEMNUV TYPE STRING,
DESCRIPTION TYPE STRING,
HLEVEL TYPE STRING,
FOCUS TYPE STRING,
VBELV TYPE STRING,
POSNV TYPE STRING,
VBELN TYPE STRING,
POSNN TYPE STRING,
KZVOR TYPE STRING,
KZDET TYPE STRING,
APPLI TYPE STRING,
MANDT TYPE STRING,
VBTYP_N TYPE STRING,
RFMNG TYPE STRING,
MEINS TYPE STRING,
RFWRT TYPE STRING,
WAERS TYPE STRING,
VBTYP_V TYPE STRING,
PLMIN TYPE STRING,
TAQUI TYPE STRING,
ERDAT TYPE STRING,
ERZET TYPE STRING,
MATNR TYPE STRING,
BWART TYPE STRING,
BDART TYPE STRING,
PLART TYPE STRING,
STUFE TYPE STRING,
LGNUM TYPE STRING,
AEDAT TYPE STRING,
FKTYP TYPE STRING,
BRGEW TYPE STRING,
GEWEI TYPE STRING,
VOLUM TYPE STRING,
VOLEH TYPE STRING,
FPLNR TYPE STRING,
FPLTR TYPE STRING,
RFMNG_FLO TYPE STRING,
RFMNG_FLT TYPE STRING,
VRKME TYPE STRING,
ABGES TYPE STRING,
SOBKZ TYPE STRING,
SONUM TYPE STRING,
KZBEF TYPE STRING,
LOGSYS TYPE STRING,
WBSTA TYPE STRING,
BUKRS TYPE STRING,
GJAHR TYPE STRING,
OBJ_BEZEI TYPE STRING,
POS_VTEXT TYPE STRING,
MAKTX TYPE STRING,
STATUS TYPE STRING,
OBJKEY TYPE STRING,
OBJTYPE TYPE STRING,
LOGSYS_AIP TYPE STRING,
AUFNR TYPE STRING,
VBTYP TYPE STRING,
BEZKO TYPE STRING,
BEZPO TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
LOGSYS_A TYPE STRING,
LOGSYS_B TYPE STRING,
LOGSYS_V TYPE STRING,
LOGSYS_N TYPE STRING,
RELTYPE TYPE STRING,END OF T_EKKO_STR. DATA: WA_TDS_DOCFLOW_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_TDS_DOCFLOW_STR-DOCNUM sy-vline
WA_TDS_DOCFLOW_STR-ITEMNUM sy-vline
WA_TDS_DOCFLOW_STR-DOCNUV sy-vline
WA_TDS_DOCFLOW_STR-ITEMNUV sy-vline
WA_TDS_DOCFLOW_STR-DESCRIPTION sy-vline
WA_TDS_DOCFLOW_STR-HLEVEL sy-vline
WA_TDS_DOCFLOW_STR-FOCUS sy-vline
WA_TDS_DOCFLOW_STR-VBELV sy-vline
WA_TDS_DOCFLOW_STR-POSNV sy-vline
WA_TDS_DOCFLOW_STR-VBELN sy-vline
WA_TDS_DOCFLOW_STR-POSNN sy-vline
WA_TDS_DOCFLOW_STR-KZVOR sy-vline
WA_TDS_DOCFLOW_STR-KZDET sy-vline
WA_TDS_DOCFLOW_STR-APPLI sy-vline
WA_TDS_DOCFLOW_STR-MANDT sy-vline
WA_TDS_DOCFLOW_STR-VBTYP_N sy-vline
WA_TDS_DOCFLOW_STR-RFMNG sy-vline
WA_TDS_DOCFLOW_STR-MEINS sy-vline
WA_TDS_DOCFLOW_STR-RFWRT sy-vline
WA_TDS_DOCFLOW_STR-WAERS sy-vline
WA_TDS_DOCFLOW_STR-VBTYP_V sy-vline
WA_TDS_DOCFLOW_STR-PLMIN sy-vline
WA_TDS_DOCFLOW_STR-TAQUI sy-vline
WA_TDS_DOCFLOW_STR-ERDAT sy-vline
WA_TDS_DOCFLOW_STR-ERZET sy-vline
WA_TDS_DOCFLOW_STR-MATNR sy-vline
WA_TDS_DOCFLOW_STR-BWART sy-vline
WA_TDS_DOCFLOW_STR-BDART sy-vline
WA_TDS_DOCFLOW_STR-PLART sy-vline
WA_TDS_DOCFLOW_STR-STUFE sy-vline
WA_TDS_DOCFLOW_STR-LGNUM sy-vline
WA_TDS_DOCFLOW_STR-AEDAT sy-vline
WA_TDS_DOCFLOW_STR-FKTYP sy-vline
WA_TDS_DOCFLOW_STR-BRGEW sy-vline
WA_TDS_DOCFLOW_STR-GEWEI sy-vline
WA_TDS_DOCFLOW_STR-VOLUM sy-vline
WA_TDS_DOCFLOW_STR-VOLEH sy-vline
WA_TDS_DOCFLOW_STR-FPLNR sy-vline
WA_TDS_DOCFLOW_STR-FPLTR sy-vline
WA_TDS_DOCFLOW_STR-RFMNG_FLO sy-vline
WA_TDS_DOCFLOW_STR-RFMNG_FLT sy-vline
WA_TDS_DOCFLOW_STR-VRKME sy-vline
WA_TDS_DOCFLOW_STR-ABGES sy-vline
WA_TDS_DOCFLOW_STR-SOBKZ sy-vline
WA_TDS_DOCFLOW_STR-SONUM sy-vline
WA_TDS_DOCFLOW_STR-KZBEF sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS sy-vline
WA_TDS_DOCFLOW_STR-WBSTA sy-vline
WA_TDS_DOCFLOW_STR-BUKRS sy-vline
WA_TDS_DOCFLOW_STR-GJAHR sy-vline
WA_TDS_DOCFLOW_STR-OBJ_BEZEI sy-vline
WA_TDS_DOCFLOW_STR-POS_VTEXT sy-vline
WA_TDS_DOCFLOW_STR-MAKTX sy-vline
WA_TDS_DOCFLOW_STR-STATUS sy-vline
WA_TDS_DOCFLOW_STR-OBJKEY sy-vline
WA_TDS_DOCFLOW_STR-OBJTYPE sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS_AIP sy-vline
WA_TDS_DOCFLOW_STR-AUFNR sy-vline
WA_TDS_DOCFLOW_STR-VBTYP sy-vline
WA_TDS_DOCFLOW_STR-BEZKO sy-vline
WA_TDS_DOCFLOW_STR-BEZPO sy-vline
WA_TDS_DOCFLOW_STR-VKORG sy-vline
WA_TDS_DOCFLOW_STR-VTWEG sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS_A sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS_B sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS_V sy-vline
WA_TDS_DOCFLOW_STR-LOGSYS_N sy-vline
WA_TDS_DOCFLOW_STR-RELTYPE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.