ABAP Select data from SAP table REXCESIBI_S 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 REXCESIBI_S 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 REXCESIBI_S. 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 REXCESIBI_S 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_REXCESIBI_S TYPE STANDARD TABLE OF REXCESIBI_S,
      WA_REXCESIBI_S TYPE REXCESIBI_S,
      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: <REXCESIBI_S> TYPE REXCESIBI_S.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM REXCESIBI_S
*  INTO TABLE @DATA(IT_REXCESIBI_S2).
*--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_REXCESIBI_S INDEX 1 INTO DATA(WA_REXCESIBI_S2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_REXCESIBI_S ASSIGNING <REXCESIBI_S>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<REXCESIBI_S>-MANDT = 1.
<REXCESIBI_S>-INTRENO = 1.
<REXCESIBI_S>-DATEFROM = 1.
<REXCESIBI_S>-BUKRS = 1.
<REXCESIBI_S>-CURRENCY = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_REXCESIBI_S-DATETO, sy-vline,
WA_REXCESIBI_S-IBIAMOUNT, sy-vline,
WA_REXCESIBI_S-IBICALCAMOUNT, sy-vline,
WA_REXCESIBI_S-CITY, sy-vline,
WA_REXCESIBI_S-IBIRATE, sy-vline,
WA_REXCESIBI_S-ISMANUALAMOUNT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_REXCESIBI_S 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_REXCESIBI_S 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_REXCESIBI_S INTO WA_REXCESIBI_S. *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 REDAT, internal->external for field DATETO CALL FUNCTION 'CONVERSION_EXIT_REDAT_OUTPUT' EXPORTING input = WA_REXCESIBI_S-DATETO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REXCESIBI_S-DATETO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_REXCESIBI_S-PARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_REXCESIBI_S-PARTNER.
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_REXCESIBI_S_STR,
MANDT TYPE STRING,
INTRENO TYPE STRING,
DATEFROM TYPE STRING,
BUKRS TYPE STRING,
CURRENCY TYPE STRING,
DATETO TYPE STRING,
IBIAMOUNT TYPE STRING,
IBICALCAMOUNT TYPE STRING,
CITY TYPE STRING,
IBIRATE TYPE STRING,
ISMANUALAMOUNT TYPE STRING,
VPT TYPE STRING,
TAXCATID TYPE STRING,
DISCHRGID TYPE STRING,
DISCHRGAMNT TYPE STRING,
DSCNTAPPL TYPE STRING,
SURCHRGID TYPE STRING,
SURCHRGFROM TYPE STRING,
SURCHRGAMNT TYPE STRING,
INSTDATE1 TYPE STRING,
INSTAMOUNT1 TYPE STRING,
INSTDATE2 TYPE STRING,
INSTAMOUNT2 TYPE STRING,
INSTDATE3 TYPE STRING,
INSTAMOUNT3 TYPE STRING,
INSTDATE4 TYPE STRING,
INSTAMOUNT4 TYPE STRING,
INSTDATE5 TYPE STRING,
INSTAMOUNT5 TYPE STRING,
INSTDATE6 TYPE STRING,
INSTAMOUNT6 TYPE STRING,
INSTDATE7 TYPE STRING,
INSTAMOUNT7 TYPE STRING,
INSTDATE8 TYPE STRING,
INSTAMOUNT8 TYPE STRING,
INSTDATE9 TYPE STRING,
INSTAMOUNT9 TYPE STRING,
INSTDATE10 TYPE STRING,
INSTAMOUNT10 TYPE STRING,
INSTDATE11 TYPE STRING,
INSTAMOUNT11 TYPE STRING,
INSTDATE12 TYPE STRING,
INSTAMOUNT12 TYPE STRING,
ISRECORDLOCKED TYPE STRING,
ACCTASSIGOBJNR TYPE STRING,
LIABLE_TAX TYPE STRING,
AWKEY1 TYPE STRING,
AWTYP1 TYPE STRING,
AWKEY2 TYPE STRING,
AWTYP2 TYPE STRING,
AWKEY3 TYPE STRING,
AWTYP3 TYPE STRING,
AWKEY4 TYPE STRING,
AWTYP4 TYPE STRING,
AWKEY5 TYPE STRING,
AWTYP5 TYPE STRING,
AWKEY6 TYPE STRING,
AWTYP6 TYPE STRING,
AWKEY7 TYPE STRING,
AWTYP7 TYPE STRING,
AWKEY8 TYPE STRING,
AWTYP8 TYPE STRING,
AWKEY9 TYPE STRING,
AWTYP9 TYPE STRING,
AWKEY10 TYPE STRING,
AWTYP10 TYPE STRING,
AWKEY11 TYPE STRING,
AWTYP11 TYPE STRING,
AWKEY12 TYPE STRING,
AWTYP12 TYPE STRING,
PARTNER TYPE STRING,
RERF TYPE STRING,
DERF TYPE STRING,
TERF TYPE STRING,
REHER TYPE STRING,
RBEAR TYPE STRING,
DBEAR TYPE STRING,
TBEAR TYPE STRING,
RBHER TYPE STRING,
XTAXCATID TYPE STRING,
XMUNICIPALITY TYPE STRING,
ASSIGXIDENT TYPE STRING,
DSCNTMIN TYPE STRING,
DSCNTMAX TYPE STRING,
SELINDEX TYPE STRING,END OF T_EKKO_STR. DATA: WA_REXCESIBI_S_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_REXCESIBI_S_STR-MANDT sy-vline
WA_REXCESIBI_S_STR-INTRENO sy-vline
WA_REXCESIBI_S_STR-DATEFROM sy-vline
WA_REXCESIBI_S_STR-BUKRS sy-vline
WA_REXCESIBI_S_STR-CURRENCY sy-vline
WA_REXCESIBI_S_STR-DATETO sy-vline
WA_REXCESIBI_S_STR-IBIAMOUNT sy-vline
WA_REXCESIBI_S_STR-IBICALCAMOUNT sy-vline
WA_REXCESIBI_S_STR-CITY sy-vline
WA_REXCESIBI_S_STR-IBIRATE sy-vline
WA_REXCESIBI_S_STR-ISMANUALAMOUNT sy-vline
WA_REXCESIBI_S_STR-VPT sy-vline
WA_REXCESIBI_S_STR-TAXCATID sy-vline
WA_REXCESIBI_S_STR-DISCHRGID sy-vline
WA_REXCESIBI_S_STR-DISCHRGAMNT sy-vline
WA_REXCESIBI_S_STR-DSCNTAPPL sy-vline
WA_REXCESIBI_S_STR-SURCHRGID sy-vline
WA_REXCESIBI_S_STR-SURCHRGFROM sy-vline
WA_REXCESIBI_S_STR-SURCHRGAMNT sy-vline
WA_REXCESIBI_S_STR-INSTDATE1 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT1 sy-vline
WA_REXCESIBI_S_STR-INSTDATE2 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT2 sy-vline
WA_REXCESIBI_S_STR-INSTDATE3 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT3 sy-vline
WA_REXCESIBI_S_STR-INSTDATE4 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT4 sy-vline
WA_REXCESIBI_S_STR-INSTDATE5 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT5 sy-vline
WA_REXCESIBI_S_STR-INSTDATE6 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT6 sy-vline
WA_REXCESIBI_S_STR-INSTDATE7 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT7 sy-vline
WA_REXCESIBI_S_STR-INSTDATE8 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT8 sy-vline
WA_REXCESIBI_S_STR-INSTDATE9 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT9 sy-vline
WA_REXCESIBI_S_STR-INSTDATE10 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT10 sy-vline
WA_REXCESIBI_S_STR-INSTDATE11 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT11 sy-vline
WA_REXCESIBI_S_STR-INSTDATE12 sy-vline
WA_REXCESIBI_S_STR-INSTAMOUNT12 sy-vline
WA_REXCESIBI_S_STR-ISRECORDLOCKED sy-vline
WA_REXCESIBI_S_STR-ACCTASSIGOBJNR sy-vline
WA_REXCESIBI_S_STR-LIABLE_TAX sy-vline
WA_REXCESIBI_S_STR-AWKEY1 sy-vline
WA_REXCESIBI_S_STR-AWTYP1 sy-vline
WA_REXCESIBI_S_STR-AWKEY2 sy-vline
WA_REXCESIBI_S_STR-AWTYP2 sy-vline
WA_REXCESIBI_S_STR-AWKEY3 sy-vline
WA_REXCESIBI_S_STR-AWTYP3 sy-vline
WA_REXCESIBI_S_STR-AWKEY4 sy-vline
WA_REXCESIBI_S_STR-AWTYP4 sy-vline
WA_REXCESIBI_S_STR-AWKEY5 sy-vline
WA_REXCESIBI_S_STR-AWTYP5 sy-vline
WA_REXCESIBI_S_STR-AWKEY6 sy-vline
WA_REXCESIBI_S_STR-AWTYP6 sy-vline
WA_REXCESIBI_S_STR-AWKEY7 sy-vline
WA_REXCESIBI_S_STR-AWTYP7 sy-vline
WA_REXCESIBI_S_STR-AWKEY8 sy-vline
WA_REXCESIBI_S_STR-AWTYP8 sy-vline
WA_REXCESIBI_S_STR-AWKEY9 sy-vline
WA_REXCESIBI_S_STR-AWTYP9 sy-vline
WA_REXCESIBI_S_STR-AWKEY10 sy-vline
WA_REXCESIBI_S_STR-AWTYP10 sy-vline
WA_REXCESIBI_S_STR-AWKEY11 sy-vline
WA_REXCESIBI_S_STR-AWTYP11 sy-vline
WA_REXCESIBI_S_STR-AWKEY12 sy-vline
WA_REXCESIBI_S_STR-AWTYP12 sy-vline
WA_REXCESIBI_S_STR-PARTNER sy-vline
WA_REXCESIBI_S_STR-RERF sy-vline
WA_REXCESIBI_S_STR-DERF sy-vline
WA_REXCESIBI_S_STR-TERF sy-vline
WA_REXCESIBI_S_STR-REHER sy-vline
WA_REXCESIBI_S_STR-RBEAR sy-vline
WA_REXCESIBI_S_STR-DBEAR sy-vline
WA_REXCESIBI_S_STR-TBEAR sy-vline
WA_REXCESIBI_S_STR-RBHER sy-vline
WA_REXCESIBI_S_STR-XTAXCATID sy-vline
WA_REXCESIBI_S_STR-XMUNICIPALITY sy-vline
WA_REXCESIBI_S_STR-ASSIGXIDENT sy-vline
WA_REXCESIBI_S_STR-DSCNTMIN sy-vline
WA_REXCESIBI_S_STR-DSCNTMAX sy-vline
WA_REXCESIBI_S_STR-SELINDEX sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.