ABAP Select data from SAP table ROVER_DATASOURCE 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 ROVER_DATASOURCE 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 ROVER_DATASOURCE. 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 ROVER_DATASOURCE 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_ROVER_DATASOURCE TYPE STANDARD TABLE OF ROVER_DATASOURCE,
      WA_ROVER_DATASOURCE TYPE ROVER_DATASOURCE,
      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: <ROVER_DATASOURCE> TYPE ROVER_DATASOURCE.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ROVER_DATASOURCE
*  INTO TABLE @DATA(IT_ROVER_DATASOURCE2).
*--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_ROVER_DATASOURCE INDEX 1 INTO DATA(WA_ROVER_DATASOURCE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ROVER_DATASOURCE ASSIGNING <ROVER_DATASOURCE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ROVER_DATASOURCE>-SEG_0001 = 1.
<ROVER_DATASOURCE>-OLTPSOURCE = 1.
<ROVER_DATASOURCE>-OBJVERS = 1.
<ROVER_DATASOURCE>-TYPE = 1.
<ROVER_DATASOURCE>-APPLNM = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ROVER_DATASOURCE-BASOSOURCE, sy-vline,
WA_ROVER_DATASOURCE-DELTA, sy-vline,
WA_ROVER_DATASOURCE-STOCKUPD, sy-vline,
WA_ROVER_DATASOURCE-UPDFLG1, sy-vline,
WA_ROVER_DATASOURCE-UPDFLG2, sy-vline,
WA_ROVER_DATASOURCE-UPDFLG3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ROVER_DATASOURCE 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_ROVER_DATASOURCE 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_ROVER_DATASOURCE INTO WA_ROVER_DATASOURCE. *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 DELTA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ROVER_DATASOURCE-DELTA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ROVER_DATASOURCE-DELTA.
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_ROVER_DATASOURCE_STR,
SEG_0001 TYPE STRING,
OLTPSOURCE TYPE STRING,
OBJVERS TYPE STRING,
TYPE TYPE STRING,
APPLNM TYPE STRING,
BASOSOURCE TYPE STRING,
DELTA TYPE STRING,
STOCKUPD TYPE STRING,
UPDFLG1 TYPE STRING,
UPDFLG2 TYPE STRING,
UPDFLG3 TYPE STRING,
READONLY TYPE STRING,
INITSIMU TYPE STRING,
INITCOMMIT TYPE STRING,
ZDD_ABLE TYPE STRING,
REALTIME TYPE STRING,
EXMETHOD TYPE STRING,
EXTRACTOR TYPE STRING,
EXSTRUCT TYPE STRING,
GENFLAG TYPE STRING,
VIRTCUBE TYPE STRING,
APPENDFLAG TYPE STRING,
TSTPNM TYPE STRING,
TSTPDAT TYPE STRING,
TSTPTIM TYPE STRING,
INVFIELD TYPE STRING,
GENDELTAFD TYPE STRING,
GENDELTATP TYPE STRING,
DELTASAFE1 TYPE STRING,
DELTASAFE2 TYPE STRING,
DLTAGETMAX TYPE STRING,
SEGMENT TYPE STRING,
AFTERIMP TYPE STRING,
BEFOREXP TYPE STRING,
MAINTAIN TYPE STRING,
CHECKDS TYPE STRING,
SAVEDS TYPE STRING,
TRANSPDS TYPE STRING,
DELETE_DS TYPE STRING,
RESETDELTA TYPE STRING,
APPL_PROP TYPE STRING,
ACTIVATE TYPE STRING,
ZDD_REPLAY TYPE STRING,
TFMETHODS TYPE STRING,
ARCHMETHOD TYPE STRING,
DUPREC TYPE STRING,
SCLIENT TYPE STRING,
PRIMSEGID TYPE STRING,
OBJECTFD TYPE STRING,
CONTSRCVERS TYPE STRING,
RECONCILIATION TYPE STRING,
SEG_0002 TYPE STRING,
SEG_0003 TYPE STRING,
SEG_0004 TYPE STRING,
SEG_0005 TYPE STRING,
SEG_0006 TYPE STRING,END OF T_EKKO_STR. DATA: WA_ROVER_DATASOURCE_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_ROVER_DATASOURCE_STR-SEG_0001 sy-vline
WA_ROVER_DATASOURCE_STR-OLTPSOURCE sy-vline
WA_ROVER_DATASOURCE_STR-OBJVERS sy-vline
WA_ROVER_DATASOURCE_STR-TYPE sy-vline
WA_ROVER_DATASOURCE_STR-APPLNM sy-vline
WA_ROVER_DATASOURCE_STR-BASOSOURCE sy-vline
WA_ROVER_DATASOURCE_STR-DELTA sy-vline
WA_ROVER_DATASOURCE_STR-STOCKUPD sy-vline
WA_ROVER_DATASOURCE_STR-UPDFLG1 sy-vline
WA_ROVER_DATASOURCE_STR-UPDFLG2 sy-vline
WA_ROVER_DATASOURCE_STR-UPDFLG3 sy-vline
WA_ROVER_DATASOURCE_STR-READONLY sy-vline
WA_ROVER_DATASOURCE_STR-INITSIMU sy-vline
WA_ROVER_DATASOURCE_STR-INITCOMMIT sy-vline
WA_ROVER_DATASOURCE_STR-ZDD_ABLE sy-vline
WA_ROVER_DATASOURCE_STR-REALTIME sy-vline
WA_ROVER_DATASOURCE_STR-EXMETHOD sy-vline
WA_ROVER_DATASOURCE_STR-EXTRACTOR sy-vline
WA_ROVER_DATASOURCE_STR-EXSTRUCT sy-vline
WA_ROVER_DATASOURCE_STR-GENFLAG sy-vline
WA_ROVER_DATASOURCE_STR-VIRTCUBE sy-vline
WA_ROVER_DATASOURCE_STR-APPENDFLAG sy-vline
WA_ROVER_DATASOURCE_STR-TSTPNM sy-vline
WA_ROVER_DATASOURCE_STR-TSTPDAT sy-vline
WA_ROVER_DATASOURCE_STR-TSTPTIM sy-vline
WA_ROVER_DATASOURCE_STR-INVFIELD sy-vline
WA_ROVER_DATASOURCE_STR-GENDELTAFD sy-vline
WA_ROVER_DATASOURCE_STR-GENDELTATP sy-vline
WA_ROVER_DATASOURCE_STR-DELTASAFE1 sy-vline
WA_ROVER_DATASOURCE_STR-DELTASAFE2 sy-vline
WA_ROVER_DATASOURCE_STR-DLTAGETMAX sy-vline
WA_ROVER_DATASOURCE_STR-SEGMENT sy-vline
WA_ROVER_DATASOURCE_STR-AFTERIMP sy-vline
WA_ROVER_DATASOURCE_STR-BEFOREXP sy-vline
WA_ROVER_DATASOURCE_STR-MAINTAIN sy-vline
WA_ROVER_DATASOURCE_STR-CHECKDS sy-vline
WA_ROVER_DATASOURCE_STR-SAVEDS sy-vline
WA_ROVER_DATASOURCE_STR-TRANSPDS sy-vline
WA_ROVER_DATASOURCE_STR-DELETE_DS sy-vline
WA_ROVER_DATASOURCE_STR-RESETDELTA sy-vline
WA_ROVER_DATASOURCE_STR-APPL_PROP sy-vline
WA_ROVER_DATASOURCE_STR-ACTIVATE sy-vline
WA_ROVER_DATASOURCE_STR-ZDD_REPLAY sy-vline
WA_ROVER_DATASOURCE_STR-TFMETHODS sy-vline
WA_ROVER_DATASOURCE_STR-ARCHMETHOD sy-vline
WA_ROVER_DATASOURCE_STR-DUPREC sy-vline
WA_ROVER_DATASOURCE_STR-SCLIENT sy-vline
WA_ROVER_DATASOURCE_STR-PRIMSEGID sy-vline
WA_ROVER_DATASOURCE_STR-OBJECTFD sy-vline
WA_ROVER_DATASOURCE_STR-CONTSRCVERS sy-vline
WA_ROVER_DATASOURCE_STR-RECONCILIATION sy-vline
WA_ROVER_DATASOURCE_STR-SEG_0002 sy-vline
WA_ROVER_DATASOURCE_STR-SEG_0003 sy-vline
WA_ROVER_DATASOURCE_STR-SEG_0004 sy-vline
WA_ROVER_DATASOURCE_STR-SEG_0005 sy-vline
WA_ROVER_DATASOURCE_STR-SEG_0006 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.