ABAP Select data from SAP table /SAPAPO/SDP_IO 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 /SAPAPO/SDP_IO 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 /SAPAPO/SDP_IO. 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 /SAPAPO/SDP_IO 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_/SAPAPO/SDP_IO TYPE STANDARD TABLE OF /SAPAPO/SDP_IO,
      WA_/SAPAPO/SDP_IO TYPE /SAPAPO/SDP_IO,
      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: </SAPAPO/SDP_IO> TYPE /SAPAPO/SDP_IO.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SAPAPO/SDP_IO
  INTO TABLE IT_/SAPAPO/SDP_IO.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SAPAPO/SDP_IO
*  INTO TABLE @DATA(IT_/SAPAPO/SDP_IO2).
*--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_/SAPAPO/SDP_IO INDEX 1 INTO DATA(WA_/SAPAPO/SDP_IO2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPAPO/SDP_IO ASSIGNING </SAPAPO/SDP_IO>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/SDP_IO>-MVIEW = 1.
</SAPAPO/SDP_IO>-COPY_MVIEW = 1.
</SAPAPO/SDP_IO>-PAREANAME = 1.
</SAPAPO/SDP_IO>-MVIEW_TXT = 1.
</SAPAPO/SDP_IO>-MVIEW_STATUS = 1.
ENDLOOP.

LOOP AT IT_/SAPAPO/SDP_IO INTO WA_/SAPAPO/SDP_IO.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPAPO/SDP_IO-MVIEW_STATUS_TXT, sy-vline,
WA_/SAPAPO/SDP_IO-MVW_CDAT, sy-vline,
WA_/SAPAPO/SDP_IO-MVW_CTIME, sy-vline,
WA_/SAPAPO/SDP_IO-MVW_AUTOR, sy-vline,
WA_/SAPAPO/SDP_IO-MVW_UDAT, sy-vline,
WA_/SAPAPO/SDP_IO-MVW_UPNAM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/SDP_IO 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_/SAPAPO/SDP_IO 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_/SAPAPO/SDP_IO INTO WA_/SAPAPO/SDP_IO. *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 VRSIO, internal->external for field VRSIOID CALL FUNCTION 'CONVERSION_EXIT_VRSIO_OUTPUT' EXPORTING input = WA_/SAPAPO/SDP_IO-VRSIOID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/SDP_IO-VRSIOID.
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_/SAPAPO/SDP_IO_STR,
MVIEW TYPE STRING,
COPY_MVIEW TYPE STRING,
PAREANAME TYPE STRING,
MVIEW_TXT TYPE STRING,
MVIEW_STATUS TYPE STRING,
MVIEW_STATUS_TXT TYPE STRING,
MVW_CDAT TYPE STRING,
MVW_CTIME TYPE STRING,
MVW_AUTOR TYPE STRING,
MVW_UDAT TYPE STRING,
MVW_UPNAM TYPE STRING,
MVW_UTIME TYPE STRING,
DVIEW TYPE STRING,
COPY_DVIEW TYPE STRING,
FLG_COPY_DVIEW TYPE STRING,
DVIEW_TXT TYPE STRING,
DVIEW_STATUS TYPE STRING,
DVIEW_STATUS_TXT TYPE STRING,
DVW_CDAT TYPE STRING,
DVW_CTIME TYPE STRING,
DVW_AUTOR TYPE STRING,
DVW_UDAT TYPE STRING,
DVW_UPNAM TYPE STRING,
DVW_UTIME TYPE STRING,
LIVE_MODE TYPE STRING,
ALL_BOOKS TYPE STRING,
ONE_BOOK TYPE STRING,
SAVE_MDVIEW TYPE STRING,
SAVE_CHART TYPE STRING,
SAVE_ADVM TYPE STRING,
TCODE TYPE STRING,
TBID_PAST TYPE STRING,
TBID_PAST_VIS TYPE STRING,
TBID_START_VIS TYPE STRING,
TBID_START_VIS_DATE TYPE STRING,
TBID_PAST_INP TYPE STRING,
TBID_START_INP TYPE STRING,
TBID_START_INP_DATE TYPE STRING,
TBID_FUTURE TYPE STRING,
INIT_COL TYPE STRING,
INIT_COL_TXT TYPE STRING,
TBID_START TYPE STRING,
TBID_OFFSET TYPE STRING,
TBID_END TYPE STRING,
SINGLE_BUCKET TYPE STRING,
TITLE_GRID1 TYPE STRING,
FLG_FIRST_GRID TYPE STRING,
TITLE_GRID2 TYPE STRING,
FLG_SECOND_GRID TYPE STRING,
APP_SNP TYPE STRING,
APP_CAP TYPE STRING,
APP_TLB TYPE STRING,
APP_DEP TYPE STRING,
APP_PROM TYPE STRING,
APP_UNIPR TYPE STRING,
APP_MULRE TYPE STRING,
APP_KOMPR TYPE STRING,
FLG_DVW TYPE STRING,
FLG_MVW TYPE STRING,
FLG_TXTLG TYPE STRING,
FLG_TXTSH TYPE STRING,
FLG_FREET TYPE STRING,
FLG_VRSIOID TYPE STRING,
VRSIOID TYPE STRING,
VERSION TYPE STRING,
PERIO_CHANGED TYPE STRING,
PERIO_STANDARD TYPE STRING,
UOM_COLUMN TYPE STRING,
UOM_HIDDEN TYPE STRING,
UOM_READONLY TYPE STRING,
UOM_WIDTH TYPE STRING,
PERIO_FORMAT TYPE STRING,
APP_DP TYPE STRING,
PERKZ_T TYPE STRING,
PERKZ_W TYPE STRING,
PERKZ_M TYPE STRING,
PERKZ_Y TYPE STRING,
PERKZ_P TYPE STRING,
PERKZ_Q TYPE STRING,
PERIV TYPE STRING,
SEASYEAR TYPE STRING,
SYEARTEXT TYPE STRING,
SYR_FUTURE_CNT TYPE STRING,
SYR_PAST_CNT TYPE STRING,
SEASYEAR_AGR TYPE STRING,
SYR_FUTURE_BASIS TYPE STRING,
SYR_PAST_BASIS TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/SDP_IO_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_/SAPAPO/SDP_IO_STR-MVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-COPY_MVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-PAREANAME sy-vline
WA_/SAPAPO/SDP_IO_STR-MVIEW_TXT sy-vline
WA_/SAPAPO/SDP_IO_STR-MVIEW_STATUS sy-vline
WA_/SAPAPO/SDP_IO_STR-MVIEW_STATUS_TXT sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_CDAT sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_CTIME sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_AUTOR sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_UDAT sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_UPNAM sy-vline
WA_/SAPAPO/SDP_IO_STR-MVW_UTIME sy-vline
WA_/SAPAPO/SDP_IO_STR-DVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-COPY_DVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_COPY_DVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-DVIEW_TXT sy-vline
WA_/SAPAPO/SDP_IO_STR-DVIEW_STATUS sy-vline
WA_/SAPAPO/SDP_IO_STR-DVIEW_STATUS_TXT sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_CDAT sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_CTIME sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_AUTOR sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_UDAT sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_UPNAM sy-vline
WA_/SAPAPO/SDP_IO_STR-DVW_UTIME sy-vline
WA_/SAPAPO/SDP_IO_STR-LIVE_MODE sy-vline
WA_/SAPAPO/SDP_IO_STR-ALL_BOOKS sy-vline
WA_/SAPAPO/SDP_IO_STR-ONE_BOOK sy-vline
WA_/SAPAPO/SDP_IO_STR-SAVE_MDVIEW sy-vline
WA_/SAPAPO/SDP_IO_STR-SAVE_CHART sy-vline
WA_/SAPAPO/SDP_IO_STR-SAVE_ADVM sy-vline
WA_/SAPAPO/SDP_IO_STR-TCODE sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_PAST sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_PAST_VIS sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_START_VIS sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_START_VIS_DATE sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_PAST_INP sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_START_INP sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_START_INP_DATE sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_FUTURE sy-vline
WA_/SAPAPO/SDP_IO_STR-INIT_COL sy-vline
WA_/SAPAPO/SDP_IO_STR-INIT_COL_TXT sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_START sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_OFFSET sy-vline
WA_/SAPAPO/SDP_IO_STR-TBID_END sy-vline
WA_/SAPAPO/SDP_IO_STR-SINGLE_BUCKET sy-vline
WA_/SAPAPO/SDP_IO_STR-TITLE_GRID1 sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_FIRST_GRID sy-vline
WA_/SAPAPO/SDP_IO_STR-TITLE_GRID2 sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_SECOND_GRID sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_SNP sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_CAP sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_TLB sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_DEP sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_PROM sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_UNIPR sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_MULRE sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_KOMPR sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_DVW sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_MVW sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_TXTLG sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_TXTSH sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_FREET sy-vline
WA_/SAPAPO/SDP_IO_STR-FLG_VRSIOID sy-vline
WA_/SAPAPO/SDP_IO_STR-VRSIOID sy-vline
WA_/SAPAPO/SDP_IO_STR-VERSION sy-vline
WA_/SAPAPO/SDP_IO_STR-PERIO_CHANGED sy-vline
WA_/SAPAPO/SDP_IO_STR-PERIO_STANDARD sy-vline
WA_/SAPAPO/SDP_IO_STR-UOM_COLUMN sy-vline
WA_/SAPAPO/SDP_IO_STR-UOM_HIDDEN sy-vline
WA_/SAPAPO/SDP_IO_STR-UOM_READONLY sy-vline
WA_/SAPAPO/SDP_IO_STR-UOM_WIDTH sy-vline
WA_/SAPAPO/SDP_IO_STR-PERIO_FORMAT sy-vline
WA_/SAPAPO/SDP_IO_STR-APP_DP sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_T sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_W sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_M sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_Y sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_P sy-vline
WA_/SAPAPO/SDP_IO_STR-PERKZ_Q sy-vline
WA_/SAPAPO/SDP_IO_STR-PERIV sy-vline
WA_/SAPAPO/SDP_IO_STR-SEASYEAR sy-vline
WA_/SAPAPO/SDP_IO_STR-SYEARTEXT sy-vline
WA_/SAPAPO/SDP_IO_STR-SYR_FUTURE_CNT sy-vline
WA_/SAPAPO/SDP_IO_STR-SYR_PAST_CNT sy-vline
WA_/SAPAPO/SDP_IO_STR-SEASYEAR_AGR sy-vline
WA_/SAPAPO/SDP_IO_STR-SYR_FUTURE_BASIS sy-vline
WA_/SAPAPO/SDP_IO_STR-SYR_PAST_BASIS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.