ABAP Select data from SAP table P08_P11D_COMPLETE_2001 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_P11D_COMPLETE_2001 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_P11D_COMPLETE_2001. 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_P11D_COMPLETE_2001 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_P11D_COMPLETE_2001 TYPE STANDARD TABLE OF P08_P11D_COMPLETE_2001,
      WA_P08_P11D_COMPLETE_2001 TYPE P08_P11D_COMPLETE_2001,
      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_P11D_COMPLETE_2001> TYPE P08_P11D_COMPLETE_2001.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM P08_P11D_COMPLETE_2001
*  INTO TABLE @DATA(IT_P08_P11D_COMPLETE_20012).
*--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_P11D_COMPLETE_2001 INDEX 1 INTO DATA(WA_P08_P11D_COMPLETE_20012).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_P08_P11D_COMPLETE_2001 ASSIGNING <P08_P11D_COMPLETE_2001>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<P08_P11D_COMPLETE_2001>-BUKRS = 1.
<P08_P11D_COMPLETE_2001>-BUTXT = 1.
<P08_P11D_COMPLETE_2001>-WERKS = 1.
<P08_P11D_COMPLETE_2001>-NAME1 = 1.
<P08_P11D_COMPLETE_2001>-BTRTL = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_P08_P11D_COMPLETE_2001-BTEXT, sy-vline,
WA_P08_P11D_COMPLETE_2001-PERSG, sy-vline,
WA_P08_P11D_COMPLETE_2001-PGTXT, sy-vline,
WA_P08_P11D_COMPLETE_2001-PERSK, sy-vline,
WA_P08_P11D_COMPLETE_2001-PKTXT, sy-vline,
WA_P08_P11D_COMPLETE_2001-ORGEH, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P08_P11D_COMPLETE_2001 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_P11D_COMPLETE_2001 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_P11D_COMPLETE_2001 INTO WA_P08_P11D_COMPLETE_2001. *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 KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_P08_P11D_COMPLETE_2001-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_P08_P11D_COMPLETE_2001-KOSTL.
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_P08_P11D_COMPLETE_2001_STR,
BUKRS TYPE STRING,
BUTXT TYPE STRING,
WERKS TYPE STRING,
NAME1 TYPE STRING,
BTRTL TYPE STRING,
BTEXT TYPE STRING,
PERSG TYPE STRING,
PGTXT TYPE STRING,
PERSK TYPE STRING,
PKTXT TYPE STRING,
ORGEH TYPE STRING,
ORGTX TYPE STRING,
KOSTL TYPE STRING,
KOSTT TYPE STRING,
ABKRS TYPE STRING,
ABKTX TYPE STRING,
PERNR TYPE STRING,
ER_NAME TYPE STRING,
TDREF TYPE STRING,
TDNUM TYPE STRING,
EE_NAME TYPE STRING,
WTEXT TYPE STRING,
DIRECTR TYPE STRING,
NINUM TYPE STRING,
A_GROSS TYPE STRING,
A_TAXED TYPE STRING,
A_BENF TYPE STRING,
A_DESCRI TYPE STRING,
B1_BENF TYPE STRING,
B1_DESCRI TYPE STRING,
B2_BENF TYPE STRING,
C_GROSS TYPE STRING,
C_TAXED TYPE STRING,
C_BENF TYPE STRING,
D_BENF TYPE STRING,
E_GROSS TYPE STRING,
E_TAXED TYPE STRING,
E_BENF TYPE STRING,
F1_MAKE_MODEL TYPE STRING,
F1_RGNDA TYPE STRING,
F1_BEGDA TYPE STRING,
F1_ENDDA TYPE STRING,
F1_BAND1 TYPE STRING,
F1_BAND2 TYPE STRING,
F1_BAND3 TYPE STRING,
F1_ECAPC TYPE STRING,
F1_EPETR TYPE STRING,
F1_EDIES TYPE STRING,
F1_LISTP TYPE STRING,
F1_ACCSS TYPE STRING,
F1_ACSS2 TYPE STRING,
F1_CAPCN TYPE STRING,
F1_PPUCR TYPE STRING,
F1_TXBEN TYPE STRING,
F1_FSCHG TYPE STRING,
F2_MAKE_MODEL TYPE STRING,
F2_RGNDA TYPE STRING,
F2_BEGDA TYPE STRING,
F2_ENDDA TYPE STRING,
F2_BAND1 TYPE STRING,
F2_BAND2 TYPE STRING,
F2_BAND3 TYPE STRING,
F2_ECAPC TYPE STRING,
F2_EPETR TYPE STRING,
F2_EDIES TYPE STRING,
F2_LISTP TYPE STRING,
F2_ACCSS TYPE STRING,
F2_ACSS2 TYPE STRING,
F2_CAPCN TYPE STRING,
F2_PPUCR TYPE STRING,
F2_TXBEN TYPE STRING,
F2_FSCHG TYPE STRING,
F_TXBEN TYPE STRING,
F_FSCHG TYPE STRING,
G_BENF TYPE STRING,
H1_BRWRS TYPE STRING,
H1_LAB TYPE STRING,
H1_LAE TYPE STRING,
H1_LMA TYPE STRING,
H1_LID TYPE STRING,
H1_DATE TYPE STRING,
H1_DATE2 TYPE STRING,
H1_LCE TYPE STRING,
H2_BRWRS TYPE STRING,
H2_LAB TYPE STRING,
H2_LAE TYPE STRING,
H2_LMA TYPE STRING,
H2_LID TYPE STRING,
H2_DATE TYPE STRING,
H2_DATE2 TYPE STRING,
H2_LCE TYPE STRING,
I_GROSS TYPE STRING,
I_TAXED TYPE STRING,
I_BENF TYPE STRING,
J_BENF TYPE STRING,
K_GROSS TYPE STRING,
K_TAXED TYPE STRING,
K_BENF TYPE STRING,
L_GROSS TYPE STRING,
L_TAXED TYPE STRING,
L_BENF TYPE STRING,
L_DESCRI TYPE STRING,
M_CHECK TYPE STRING,
N1_GROSS TYPE STRING,
N1_TAXED TYPE STRING,
N1_BENF TYPE STRING,
N1_DESCRI TYPE STRING,
N2_GROSS TYPE STRING,
N2_TAXED TYPE STRING,
N2_BENF TYPE STRING,
N2_DESCRI TYPE STRING,
N3_BENF TYPE STRING,
O1_GROSS TYPE STRING,
O1_TAXED TYPE STRING,
O1_BENF TYPE STRING,
O2_GROSS TYPE STRING,
O2_TAXED TYPE STRING,
O2_BENF TYPE STRING,
O3_GROSS TYPE STRING,
O3_TAXED TYPE STRING,
O3_BENF TYPE STRING,
O4_GROSS TYPE STRING,
O4_TAXED TYPE STRING,
O4_BENF TYPE STRING,
O5_GROSS TYPE STRING,
O5_TAXED TYPE STRING,
O5_BENF TYPE STRING,
O6_GROSS TYPE STRING,
O6_TAXED TYPE STRING,
O6_BENF TYPE STRING,
O6_DESCRI TYPE STRING,
SUM1A TYPE STRING,
TEST TYPE STRING,END OF T_EKKO_STR. DATA: WA_P08_P11D_COMPLETE_2001_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_P11D_COMPLETE_2001_STR-BUKRS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-BUTXT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-WERKS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-NAME1 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-BTRTL sy-vline
WA_P08_P11D_COMPLETE_2001_STR-BTEXT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-PERSG sy-vline
WA_P08_P11D_COMPLETE_2001_STR-PGTXT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-PERSK sy-vline
WA_P08_P11D_COMPLETE_2001_STR-PKTXT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-ORGEH sy-vline
WA_P08_P11D_COMPLETE_2001_STR-ORGTX sy-vline
WA_P08_P11D_COMPLETE_2001_STR-KOSTL sy-vline
WA_P08_P11D_COMPLETE_2001_STR-KOSTT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-ABKRS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-ABKTX sy-vline
WA_P08_P11D_COMPLETE_2001_STR-PERNR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-ER_NAME sy-vline
WA_P08_P11D_COMPLETE_2001_STR-TDREF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-TDNUM sy-vline
WA_P08_P11D_COMPLETE_2001_STR-EE_NAME sy-vline
WA_P08_P11D_COMPLETE_2001_STR-WTEXT sy-vline
WA_P08_P11D_COMPLETE_2001_STR-DIRECTR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-NINUM sy-vline
WA_P08_P11D_COMPLETE_2001_STR-A_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-A_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-A_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-A_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-B1_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-B1_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-B2_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-C_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-C_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-C_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-D_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-E_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-E_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-E_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_MAKE_MODEL sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_RGNDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_BEGDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_ENDDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_BAND1 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_BAND2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_BAND3 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_ECAPC sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_EPETR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_EDIES sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_LISTP sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_ACCSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_ACSS2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_CAPCN sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_PPUCR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_TXBEN sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F1_FSCHG sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_MAKE_MODEL sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_RGNDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_BEGDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_ENDDA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_BAND1 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_BAND2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_BAND3 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_ECAPC sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_EPETR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_EDIES sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_LISTP sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_ACCSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_ACSS2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_CAPCN sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_PPUCR sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_TXBEN sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F2_FSCHG sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F_TXBEN sy-vline
WA_P08_P11D_COMPLETE_2001_STR-F_FSCHG sy-vline
WA_P08_P11D_COMPLETE_2001_STR-G_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_BRWRS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_LAB sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_LAE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_LMA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_LID sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_DATE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_DATE2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H1_LCE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_BRWRS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_LAB sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_LAE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_LMA sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_LID sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_DATE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_DATE2 sy-vline
WA_P08_P11D_COMPLETE_2001_STR-H2_LCE sy-vline
WA_P08_P11D_COMPLETE_2001_STR-I_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-I_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-I_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-J_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-K_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-K_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-K_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-L_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-L_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-L_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-L_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-M_CHECK sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N1_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N1_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N1_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N1_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N2_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N2_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N2_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N2_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-N3_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O1_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O1_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O1_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O2_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O2_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O2_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O3_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O3_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O3_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O4_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O4_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O4_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O5_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O5_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O5_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O6_GROSS sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O6_TAXED sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O6_BENF sy-vline
WA_P08_P11D_COMPLETE_2001_STR-O6_DESCRI sy-vline
WA_P08_P11D_COMPLETE_2001_STR-SUM1A sy-vline
WA_P08_P11D_COMPLETE_2001_STR-TEST sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.