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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPAPO/PB_ACT_VIEW_STR ASSIGNING </SAPAPO/PB_ACT_VIEW_STR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/PB_ACT_VIEW_STR>-ACTIVE = 1.
</SAPAPO/PB_ACT_VIEW_STR>-PAREAID = 1.
</SAPAPO/PB_ACT_VIEW_STR>-MVW = 1.
</SAPAPO/PB_ACT_VIEW_STR>-MANDT = 1.
</SAPAPO/PB_ACT_VIEW_STR>-MVIEW = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPAPO/PB_ACT_VIEW_STR-PAREANAME, sy-vline,
WA_/SAPAPO/PB_ACT_VIEW_STR-MVIEW_VAL, sy-vline,
WA_/SAPAPO/PB_ACT_VIEW_STR-MVIEW_TXT, sy-vline,
WA_/SAPAPO/PB_ACT_VIEW_STR-MVIEWTYPE, sy-vline,
WA_/SAPAPO/PB_ACT_VIEW_STR-VIEW_STATUS, sy-vline,
WA_/SAPAPO/PB_ACT_VIEW_STR-DEL_VIEW, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/PB_ACT_VIEW_STR 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/PB_ACT_VIEW_STR 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/PB_ACT_VIEW_STR INTO WA_/SAPAPO/PB_ACT_VIEW_STR. *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 PARE2, internal->external for field PAREAID CALL FUNCTION 'CONVERSION_EXIT_PARE2_OUTPUT' EXPORTING input = WA_/SAPAPO/PB_ACT_VIEW_STR-PAREAID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/PB_ACT_VIEW_STR-PAREAID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit VRSIO, internal->external for field VARIABLE_VRSIOID CALL FUNCTION 'CONVERSION_EXIT_VRSIO_OUTPUT' EXPORTING input = WA_/SAPAPO/PB_ACT_VIEW_STR-VARIABLE_VRSIOID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/PB_ACT_VIEW_STR-VARIABLE_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/PB_ACT_VIEW_STR_STR,
ACTIVE TYPE STRING,
PAREAID TYPE STRING,
MVW TYPE STRING,
MANDT TYPE STRING,
MVIEW TYPE STRING,
PAREANAME TYPE STRING,
MVIEW_VAL TYPE STRING,
MVIEW_TXT TYPE STRING,
MVIEWTYPE TYPE STRING,
VIEW_STATUS TYPE STRING,
DEL_VIEW 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,
CDAT TYPE STRING,
CTIME TYPE STRING,
AUTOR TYPE STRING,
UDAT TYPE STRING,
UPNAM TYPE STRING,
UTIME TYPE STRING,
APP_DP TYPE STRING,
DVW TYPE STRING,
MANDT TYPE STRING,
MVIEW TYPE STRING,
DVIEW TYPE STRING,
DVIEW_TXT TYPE STRING,
VIEW_STATUS TYPE STRING,
DEL_VIEW TYPE STRING,
CDAT TYPE STRING,
CTIME TYPE STRING,
AUTOR TYPE STRING,
UDAT TYPE STRING,
UPNAM TYPE STRING,
UTIME TYPE STRING,
DISP_STAT TYPE STRING,
AGC_BASIS TYPE STRING,
CUSTOM_CONTROL TYPE STRING,
SDP_GUI TYPE STRING,
LOG_ENABLED TYPE STRING,
WEB_ENABLED TYPE STRING,
ICONS_ENABLED TYPE STRING,
SECOND_GRID TYPE STRING,
ORIENTATION TYPE STRING,
CONTAINER_SIZE_1 TYPE STRING,
CONTAINER_SIZE_2 TYPE STRING,
DESIGN_MODE TYPE STRING,
SYNCHRONIZE TYPE STRING,
AGC_CHILD1 TYPE STRING,
APOGRID TYPE STRING,
ALVGRID TYPE STRING,
ORIENTATION TYPE STRING,
GRID_VISIBLE TYPE STRING,
CHART_VISIBLE TYPE STRING,
GRID_SIZE TYPE STRING,
CHART_SIZE TYPE STRING,
READONLY TYPE STRING,
HIDE_KF_INDEP_CH TYPE STRING,
AGC_CHILD2 TYPE STRING,
APOGRID TYPE STRING,
ALVGRID TYPE STRING,
ORIENTATION TYPE STRING,
GRID_VISIBLE TYPE STRING,
CHART_VISIBLE TYPE STRING,
GRID_SIZE TYPE STRING,
CHART_SIZE TYPE STRING,
READONLY TYPE STRING,
HIDE_KF_INDEP_CH TYPE STRING,
AGC_GRID1 TYPE STRING,
AGC_CHG_GRID1 TYPE STRING,
AGC_GRID2 TYPE STRING,
AGC_CHG_GRID2 TYPE STRING,
AGC_ATTR1 TYPE STRING,
AGC_ATTR2 TYPE STRING,
AGC_CELL1 TYPE STRING,
AGC_CELL2 TYPE STRING,
AGC_CTRL1 TYPE STRING,
AGC_CTRL2 TYPE STRING,
LINE_COL1 TYPE STRING,
TBID TYPE STRING,
STARTAT TYPE STRING,
COLS_INDEX TYPE STRING,
LINE_INDEX TYPE STRING,
LINE_INDEX_DVW TYPE STRING,
TBID_START TYPE STRING,
TBID_END TYPE STRING,
EXCLUDE_BUCKET TYPE STRING,
SEASYEAR TYPE STRING,
SEASYEAR_AGR TYPE STRING,
FLG_TB_CHANGED TYPE STRING,
LINE_COL2 TYPE STRING,
TBID TYPE STRING,
STARTAT TYPE STRING,
COLS_INDEX TYPE STRING,
LINE_INDEX TYPE STRING,
LINE_INDEX_DVW TYPE STRING,
TBID_START TYPE STRING,
TBID_END TYPE STRING,
EXCLUDE_BUCKET TYPE STRING,
SEASYEAR TYPE STRING,
SEASYEAR_AGR TYPE STRING,
FLG_TB_CHANGED TYPE STRING,
SIMSESSION_OPEN TYPE STRING,
AGC_TB TYPE STRING,
AGC_ADV_TB TYPE STRING,
AGC_CTX TYPE STRING,
CHARS TYPE STRING,
CHAVL TYPE STRING,
ADVM_MVIEW TYPE STRING,
FINAL_MACRO_DRILL_DOWN TYPE STRING,
VARIABLE_VRSIOID TYPE STRING,
VARIABLE_VERSION TYPE STRING,
TIME_ZONE TYPE STRING,
AGC_MACRO_HIDE TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/PB_ACT_VIEW_STR_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/PB_ACT_VIEW_STR_STR-ACTIVE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-PAREAID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MANDT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-PAREANAME sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVIEW_VAL sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVIEW_TXT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVIEWTYPE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-VIEW_STATUS sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DEL_VIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_SNP sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_CAP sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_TLB sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_DEP sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_PROM sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_UNIPR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_MULRE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_KOMPR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CDAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CTIME sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AUTOR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UDAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UPNAM sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UTIME sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APP_DP sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DVW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MANDT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-MVIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DVIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DVIEW_TXT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-VIEW_STATUS sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DEL_VIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CDAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CTIME sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AUTOR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UDAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UPNAM sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-UTIME sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DISP_STAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_BASIS sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CUSTOM_CONTROL sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SDP_GUI sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LOG_ENABLED sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-WEB_ENABLED sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ICONS_ENABLED sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SECOND_GRID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ORIENTATION sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CONTAINER_SIZE_1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CONTAINER_SIZE_2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-DESIGN_MODE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SYNCHRONIZE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CHILD1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APOGRID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ALVGRID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ORIENTATION sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-GRID_VISIBLE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHART_VISIBLE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-GRID_SIZE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHART_SIZE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-READONLY sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-HIDE_KF_INDEP_CH sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CHILD2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-APOGRID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ALVGRID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ORIENTATION sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-GRID_VISIBLE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHART_VISIBLE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-GRID_SIZE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHART_SIZE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-READONLY sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-HIDE_KF_INDEP_CH sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_GRID1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CHG_GRID1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_GRID2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CHG_GRID2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_ATTR1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_ATTR2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CELL1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CELL2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CTRL1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CTRL2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_COL1 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-STARTAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-COLS_INDEX sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_INDEX sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_INDEX_DVW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID_START sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID_END sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-EXCLUDE_BUCKET sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SEASYEAR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SEASYEAR_AGR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-FLG_TB_CHANGED sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_COL2 sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-STARTAT sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-COLS_INDEX sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_INDEX sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-LINE_INDEX_DVW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID_START sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TBID_END sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-EXCLUDE_BUCKET sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SEASYEAR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SEASYEAR_AGR sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-FLG_TB_CHANGED sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-SIMSESSION_OPEN sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_TB sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_ADV_TB sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_CTX sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHARS sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-CHAVL sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-ADVM_MVIEW sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-FINAL_MACRO_DRILL_DOWN sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-VARIABLE_VRSIOID sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-VARIABLE_VERSION sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-TIME_ZONE sy-vline
WA_/SAPAPO/PB_ACT_VIEW_STR_STR-AGC_MACRO_HIDE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.