ABAP Select data from SAP table P08_ALV_RECON 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 P08_ALV_RECON 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 P08_ALV_RECON. 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 P08_ALV_RECON 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_P08_ALV_RECON TYPE STANDARD TABLE OF P08_ALV_RECON,
      WA_P08_ALV_RECON TYPE P08_ALV_RECON,
      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: <P08_ALV_RECON> TYPE P08_ALV_RECON.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM P08_ALV_RECON
*  INTO TABLE @DATA(IT_P08_ALV_RECON2).
*--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_P08_ALV_RECON INDEX 1 INTO DATA(WA_P08_ALV_RECON2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_P08_ALV_RECON ASSIGNING <P08_ALV_RECON>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<P08_ALV_RECON>-PERNR = 1.
<P08_ALV_RECON>-TPYEM1 = 1.
<P08_ALV_RECON>-TPYEM2 = 1.
<P08_ALV_RECON>-TPYEM3 = 1.
<P08_ALV_RECON>-TXPEM1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_P08_ALV_RECON-TXPEM2, sy-vline,
WA_P08_ALV_RECON-TXPEM3, sy-vline,
WA_P08_ALV_RECON-SSPYD1, sy-vline,
WA_P08_ALV_RECON-SSPYD2, sy-vline,
WA_P08_ALV_RECON-SSPYD3, sy-vline,
WA_P08_ALV_RECON-SMPYD1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P08_ALV_RECON 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_P08_ALV_RECON 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_P08_ALV_RECON INTO WA_P08_ALV_RECON. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_P08_ALV_RECON_STR,
PERNR TYPE STRING,
TPYEM1 TYPE STRING,
TPYEM2 TYPE STRING,
TPYEM3 TYPE STRING,
TXPEM1 TYPE STRING,
TXPEM2 TYPE STRING,
TXPEM3 TYPE STRING,
SSPYD1 TYPE STRING,
SSPYD2 TYPE STRING,
SSPYD3 TYPE STRING,
SMPYD1 TYPE STRING,
SMPYD2 TYPE STRING,
SMPYD3 TYPE STRING,
OSSPY1 TYPE STRING,
OSSPY2 TYPE STRING,
OSSPY3 TYPE STRING,
SAPYD1 TYPE STRING,
SAPYD2 TYPE STRING,
SAPYD3 TYPE STRING,
ASPPY1 TYPE STRING,
ASPPY2 TYPE STRING,
ASPPY3 TYPE STRING,
NICAT1 TYPE STRING,
AMTTOLELW1 TYPE STRING,
AMTTOLELW2 TYPE STRING,
AMTTOLELW3 TYPE STRING,
AMTLELERTW1 TYPE STRING,
AMTLELERTW2 TYPE STRING,
AMTLELERTW3 TYPE STRING,
AMTERTUAPW1 TYPE STRING,
AMTERTUAPW2 TYPE STRING,
AMTERTUAPW3 TYPE STRING,
AMTFROMUELW1 TYPE STRING,
AMTFROMUELW2 TYPE STRING,
AMTFROMUELW3 TYPE STRING,
ERNIC_YTDW1 TYPE STRING,
ERNIC_YTDW2 TYPE STRING,
ERNIC_YTDW3 TYPE STRING,
EENIC_YTDW1 TYPE STRING,
EENIC_YTDW2 TYPE STRING,
EENIC_YTDW3 TYPE STRING,
NICAT2 TYPE STRING,
AMTTOLELX1 TYPE STRING,
AMTTOLELX2 TYPE STRING,
AMTTOLELX3 TYPE STRING,
AMTLELERTX1 TYPE STRING,
AMTLELERTX2 TYPE STRING,
AMTLELERTX3 TYPE STRING,
AMTERTUAPX1 TYPE STRING,
AMTERTUAPX2 TYPE STRING,
AMTERTUAPX3 TYPE STRING,
AMTFROMUELX1 TYPE STRING,
AMTFROMUELX2 TYPE STRING,
AMTFROMUELX3 TYPE STRING,
ERNIC_YTDX1 TYPE STRING,
ERNIC_YTDX2 TYPE STRING,
ERNIC_YTDX3 TYPE STRING,
EENIC_YTDX1 TYPE STRING,
EENIC_YTDX2 TYPE STRING,
EENIC_YTDX3 TYPE STRING,
NICAT3 TYPE STRING,
AMTTOLELY1 TYPE STRING,
AMTTOLELY2 TYPE STRING,
AMTTOLELY3 TYPE STRING,
AMTLELERTY1 TYPE STRING,
AMTLELERTY2 TYPE STRING,
AMTLELERTY3 TYPE STRING,
AMTERTUAPY1 TYPE STRING,
AMTERTUAPY2 TYPE STRING,
AMTERTUAPY3 TYPE STRING,
AMTFROMUELY1 TYPE STRING,
AMTFROMUELY2 TYPE STRING,
AMTFROMUELY3 TYPE STRING,
ERNIC_YTDY1 TYPE STRING,
ERNIC_YTDY2 TYPE STRING,
ERNIC_YTDY3 TYPE STRING,
EENIC_YTDY1 TYPE STRING,
EENIC_YTDY2 TYPE STRING,
EENIC_YTDY3 TYPE STRING,
NICAT4 TYPE STRING,
AMTTOLELZ1 TYPE STRING,
AMTTOLELZ2 TYPE STRING,
AMTTOLELZ3 TYPE STRING,
AMTLELERTZ1 TYPE STRING,
AMTLELERTZ2 TYPE STRING,
AMTLELERTZ3 TYPE STRING,
AMTERTUAPZ1 TYPE STRING,
AMTERTUAPZ2 TYPE STRING,
AMTERTUAPZ3 TYPE STRING,
AMTFROMUELZ1 TYPE STRING,
AMTFROMUELZ2 TYPE STRING,
AMTFROMUELZ3 TYPE STRING,
ERNIC_YTDZ1 TYPE STRING,
ERNIC_YTDZ2 TYPE STRING,
ERNIC_YTDZ3 TYPE STRING,
EENIC_YTDZ1 TYPE STRING,
EENIC_YTDZ2 TYPE STRING,
EENIC_YTDZ3 TYPE STRING,END OF T_EKKO_STR. DATA: WA_P08_ALV_RECON_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_P08_ALV_RECON_STR-PERNR sy-vline
WA_P08_ALV_RECON_STR-TPYEM1 sy-vline
WA_P08_ALV_RECON_STR-TPYEM2 sy-vline
WA_P08_ALV_RECON_STR-TPYEM3 sy-vline
WA_P08_ALV_RECON_STR-TXPEM1 sy-vline
WA_P08_ALV_RECON_STR-TXPEM2 sy-vline
WA_P08_ALV_RECON_STR-TXPEM3 sy-vline
WA_P08_ALV_RECON_STR-SSPYD1 sy-vline
WA_P08_ALV_RECON_STR-SSPYD2 sy-vline
WA_P08_ALV_RECON_STR-SSPYD3 sy-vline
WA_P08_ALV_RECON_STR-SMPYD1 sy-vline
WA_P08_ALV_RECON_STR-SMPYD2 sy-vline
WA_P08_ALV_RECON_STR-SMPYD3 sy-vline
WA_P08_ALV_RECON_STR-OSSPY1 sy-vline
WA_P08_ALV_RECON_STR-OSSPY2 sy-vline
WA_P08_ALV_RECON_STR-OSSPY3 sy-vline
WA_P08_ALV_RECON_STR-SAPYD1 sy-vline
WA_P08_ALV_RECON_STR-SAPYD2 sy-vline
WA_P08_ALV_RECON_STR-SAPYD3 sy-vline
WA_P08_ALV_RECON_STR-ASPPY1 sy-vline
WA_P08_ALV_RECON_STR-ASPPY2 sy-vline
WA_P08_ALV_RECON_STR-ASPPY3 sy-vline
WA_P08_ALV_RECON_STR-NICAT1 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELW1 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELW2 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELW3 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTW1 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTW2 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTW3 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPW1 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPW2 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPW3 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELW1 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELW2 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELW3 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDW1 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDW2 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDW3 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDW1 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDW2 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDW3 sy-vline
WA_P08_ALV_RECON_STR-NICAT2 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELX1 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELX2 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELX3 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTX1 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTX2 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTX3 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPX1 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPX2 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPX3 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELX1 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELX2 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELX3 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDX1 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDX2 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDX3 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDX1 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDX2 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDX3 sy-vline
WA_P08_ALV_RECON_STR-NICAT3 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELY1 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELY2 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELY3 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTY1 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTY2 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTY3 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPY1 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPY2 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPY3 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELY1 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELY2 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELY3 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDY1 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDY2 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDY3 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDY1 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDY2 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDY3 sy-vline
WA_P08_ALV_RECON_STR-NICAT4 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELZ1 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELZ2 sy-vline
WA_P08_ALV_RECON_STR-AMTTOLELZ3 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTZ1 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTZ2 sy-vline
WA_P08_ALV_RECON_STR-AMTLELERTZ3 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPZ1 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPZ2 sy-vline
WA_P08_ALV_RECON_STR-AMTERTUAPZ3 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELZ1 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELZ2 sy-vline
WA_P08_ALV_RECON_STR-AMTFROMUELZ3 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDZ1 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDZ2 sy-vline
WA_P08_ALV_RECON_STR-ERNIC_YTDZ3 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDZ1 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDZ2 sy-vline
WA_P08_ALV_RECON_STR-EENIC_YTDZ3 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.