ABAP Select data from SAP table P21_EB11_FH 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 P21_EB11_FH 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 P21_EB11_FH. 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 P21_EB11_FH 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_P21_EB11_FH TYPE STANDARD TABLE OF P21_EB11_FH,
      WA_P21_EB11_FH TYPE P21_EB11_FH,
      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: <P21_EB11_FH> TYPE P21_EB11_FH.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM P21_EB11_FH
*  INTO TABLE @DATA(IT_P21_EB11_FH2).
*--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_P21_EB11_FH INDEX 1 INTO DATA(WA_P21_EB11_FH2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_P21_EB11_FH ASSIGNING <P21_EB11_FH>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<P21_EB11_FH>-INPER = 1.
<P21_EB11_FH>-ADOSZAM = 1.
<P21_EB11_FH>-KSH = 1.
<P21_EB11_FH>-VALL = 1.
<P21_EB11_FH>-SZEKH = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_P21_EB11_FH-CIM, sy-vline,
WA_P21_EB11_FH-UGYINT, sy-vline,
WA_P21_EB11_FH-BANKL, sy-vline,
WA_P21_EB11_FH-BANKN, sy-vline,
WA_P21_EB11_FH-S01, sy-vline,
WA_P21_EB11_FH-S02, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P21_EB11_FH 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_P21_EB11_FH 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_P21_EB11_FH INTO WA_P21_EB11_FH. *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_P21_EB11_FH_STR,
INPER TYPE STRING,
ADOSZAM TYPE STRING,
KSH TYPE STRING,
VALL TYPE STRING,
SZEKH TYPE STRING,
CIM TYPE STRING,
UGYINT TYPE STRING,
BANKL TYPE STRING,
BANKN TYPE STRING,
S01 TYPE STRING,
S02 TYPE STRING,
S03 TYPE STRING,
S04 TYPE STRING,
S05 TYPE STRING,
S06 TYPE STRING,
S07 TYPE STRING,
S08 TYPE STRING,
S09 TYPE STRING,
S10 TYPE STRING,
S11 TYPE STRING,
S12 TYPE STRING,
S13 TYPE STRING,
S14 TYPE STRING,
S15 TYPE STRING,
S16 TYPE STRING,
S17 TYPE STRING,
S18 TYPE STRING,
S19 TYPE STRING,
S20 TYPE STRING,
S21 TYPE STRING,
S22 TYPE STRING,
S23 TYPE STRING,
S24 TYPE STRING,
S25 TYPE STRING,
S26 TYPE STRING,
S27 TYPE STRING,
S28 TYPE STRING,
S29 TYPE STRING,
S30 TYPE STRING,
S31 TYPE STRING,
S32 TYPE STRING,
S33 TYPE STRING,
S34 TYPE STRING,
S35 TYPE STRING,
S36 TYPE STRING,
S37 TYPE STRING,
S38 TYPE STRING,
S39 TYPE STRING,
S40 TYPE STRING,
S41 TYPE STRING,
S42 TYPE STRING,
S43 TYPE STRING,
S44 TYPE STRING,
S45 TYPE STRING,
S46 TYPE STRING,
S47 TYPE STRING,
S48 TYPE STRING,
S49 TYPE STRING,
S50 TYPE STRING,
S51 TYPE STRING,
S60 TYPE STRING,
S61 TYPE STRING,
S81 TYPE STRING,
S82 TYPE STRING,
S83 TYPE STRING,
S84 TYPE STRING,
S85 TYPE STRING,
S86 TYPE STRING,
S87 TYPE STRING,
S88 TYPE STRING,
S89 TYPE STRING,
S80 TYPE STRING,
WAERS TYPE STRING,END OF T_EKKO_STR. DATA: WA_P21_EB11_FH_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_P21_EB11_FH_STR-INPER sy-vline
WA_P21_EB11_FH_STR-ADOSZAM sy-vline
WA_P21_EB11_FH_STR-KSH sy-vline
WA_P21_EB11_FH_STR-VALL sy-vline
WA_P21_EB11_FH_STR-SZEKH sy-vline
WA_P21_EB11_FH_STR-CIM sy-vline
WA_P21_EB11_FH_STR-UGYINT sy-vline
WA_P21_EB11_FH_STR-BANKL sy-vline
WA_P21_EB11_FH_STR-BANKN sy-vline
WA_P21_EB11_FH_STR-S01 sy-vline
WA_P21_EB11_FH_STR-S02 sy-vline
WA_P21_EB11_FH_STR-S03 sy-vline
WA_P21_EB11_FH_STR-S04 sy-vline
WA_P21_EB11_FH_STR-S05 sy-vline
WA_P21_EB11_FH_STR-S06 sy-vline
WA_P21_EB11_FH_STR-S07 sy-vline
WA_P21_EB11_FH_STR-S08 sy-vline
WA_P21_EB11_FH_STR-S09 sy-vline
WA_P21_EB11_FH_STR-S10 sy-vline
WA_P21_EB11_FH_STR-S11 sy-vline
WA_P21_EB11_FH_STR-S12 sy-vline
WA_P21_EB11_FH_STR-S13 sy-vline
WA_P21_EB11_FH_STR-S14 sy-vline
WA_P21_EB11_FH_STR-S15 sy-vline
WA_P21_EB11_FH_STR-S16 sy-vline
WA_P21_EB11_FH_STR-S17 sy-vline
WA_P21_EB11_FH_STR-S18 sy-vline
WA_P21_EB11_FH_STR-S19 sy-vline
WA_P21_EB11_FH_STR-S20 sy-vline
WA_P21_EB11_FH_STR-S21 sy-vline
WA_P21_EB11_FH_STR-S22 sy-vline
WA_P21_EB11_FH_STR-S23 sy-vline
WA_P21_EB11_FH_STR-S24 sy-vline
WA_P21_EB11_FH_STR-S25 sy-vline
WA_P21_EB11_FH_STR-S26 sy-vline
WA_P21_EB11_FH_STR-S27 sy-vline
WA_P21_EB11_FH_STR-S28 sy-vline
WA_P21_EB11_FH_STR-S29 sy-vline
WA_P21_EB11_FH_STR-S30 sy-vline
WA_P21_EB11_FH_STR-S31 sy-vline
WA_P21_EB11_FH_STR-S32 sy-vline
WA_P21_EB11_FH_STR-S33 sy-vline
WA_P21_EB11_FH_STR-S34 sy-vline
WA_P21_EB11_FH_STR-S35 sy-vline
WA_P21_EB11_FH_STR-S36 sy-vline
WA_P21_EB11_FH_STR-S37 sy-vline
WA_P21_EB11_FH_STR-S38 sy-vline
WA_P21_EB11_FH_STR-S39 sy-vline
WA_P21_EB11_FH_STR-S40 sy-vline
WA_P21_EB11_FH_STR-S41 sy-vline
WA_P21_EB11_FH_STR-S42 sy-vline
WA_P21_EB11_FH_STR-S43 sy-vline
WA_P21_EB11_FH_STR-S44 sy-vline
WA_P21_EB11_FH_STR-S45 sy-vline
WA_P21_EB11_FH_STR-S46 sy-vline
WA_P21_EB11_FH_STR-S47 sy-vline
WA_P21_EB11_FH_STR-S48 sy-vline
WA_P21_EB11_FH_STR-S49 sy-vline
WA_P21_EB11_FH_STR-S50 sy-vline
WA_P21_EB11_FH_STR-S51 sy-vline
WA_P21_EB11_FH_STR-S60 sy-vline
WA_P21_EB11_FH_STR-S61 sy-vline
WA_P21_EB11_FH_STR-S81 sy-vline
WA_P21_EB11_FH_STR-S82 sy-vline
WA_P21_EB11_FH_STR-S83 sy-vline
WA_P21_EB11_FH_STR-S84 sy-vline
WA_P21_EB11_FH_STR-S85 sy-vline
WA_P21_EB11_FH_STR-S86 sy-vline
WA_P21_EB11_FH_STR-S87 sy-vline
WA_P21_EB11_FH_STR-S88 sy-vline
WA_P21_EB11_FH_STR-S89 sy-vline
WA_P21_EB11_FH_STR-S80 sy-vline
WA_P21_EB11_FH_STR-WAERS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.