ABAP Select data from SAP table FEBEP_RFC 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 FEBEP_RFC 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 FEBEP_RFC. 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 FEBEP_RFC 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_FEBEP_RFC TYPE STANDARD TABLE OF FEBEP_RFC, WA_FEBEP_RFC TYPE FEBEP_RFC, 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: <FEBEP_RFC> TYPE FEBEP_RFC. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FEBEP_RFC. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FEBEP_RFC INTO TABLE IT_FEBEP_RFC. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FEBEP_RFC * INTO TABLE @DATA(IT_FEBEP_RFC2). *--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_FEBEP_RFC INDEX 1 INTO DATA(WA_FEBEP_RFC2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FEBEP_RFC ASSIGNING <FEBEP_RFC>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FEBEP_RFC>-KUKEY = 1.
<FEBEP_RFC>-ESNUM = 1.
<FEBEP_RFC>-EPERL = 1.
<FEBEP_RFC>-VB1OK = 1.
<FEBEP_RFC>-VB2BA = 1.
ENDLOOP. LOOP AT IT_FEBEP_RFC INTO WA_FEBEP_RFC. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FEBEP_RFC-VB2OK, sy-vline,
WA_FEBEP_RFC-PIPRE, sy-vline,
WA_FEBEP_RFC-GRPNR, sy-vline,
WA_FEBEP_RFC-ESTAT, sy-vline,
WA_FEBEP_RFC-BELNR, sy-vline,
WA_FEBEP_RFC-GJAHR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FEBEP_RFC 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_FEBEP_RFC 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_FEBEP_RFC INTO WA_FEBEP_RFC. *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 BELNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-BELNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-BELNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FEBEP_RFC-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-GJAHR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-PRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-PRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VERTN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-VERTN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-VERTN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field NBBLN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-NBBLN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-NBBLN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AK1BL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-AK1BL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-AK1BL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AKBLN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-AKBLN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-AKBLN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KNRZA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-KNRZA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-KNRZA.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AVKON CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-AVKON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-AVKON.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field KURSF CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_FEBEP_RFC-KURSF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-KURSF.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SDOC2 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-SDOC2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-SDOC2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SVKON CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FEBEP_RFC-SVKON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FEBEP_RFC-SVKON.
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_FEBEP_RFC_STR,
KUKEY TYPE STRING,
ESNUM TYPE STRING,
EPERL TYPE STRING,
VB1OK TYPE STRING,
VB2BA TYPE STRING,
VB2OK TYPE STRING,
PIPRE TYPE STRING,
GRPNR TYPE STRING,
ESTAT TYPE STRING,
BELNR TYPE STRING,
GJAHR TYPE STRING,
BVDAT TYPE STRING,
BUDAT TYPE STRING,
VALUT TYPE STRING,
BUTIM TYPE STRING,
VOZEI TYPE STRING,
KWAER TYPE STRING,
KWBTR TYPE STRING,
SPESK TYPE STRING,
FWAER TYPE STRING,
FWBTR TYPE STRING,
SPESF TYPE STRING,
VORGC TYPE STRING,
TEXTS TYPE STRING,
VGEXT TYPE STRING,
VGMAN TYPE STRING,
VGINT TYPE STRING,
VGDEF TYPE STRING,
KFMOD TYPE STRING,
VGSAP TYPE STRING,
BUTXT TYPE STRING,
ANZSP TYPE STRING,
XBLNR TYPE STRING,
ZUONR TYPE STRING,
PABKS TYPE STRING,
PABLZ TYPE STRING,
PASWI TYPE STRING,
PAKTO TYPE STRING,
PARTN TYPE STRING,
BUSAB TYPE STRING,
KOSTL TYPE STRING,
GSBER TYPE STRING,
PRCTR TYPE STRING,
VERTN TYPE STRING,
VERTT TYPE STRING,
PNOTA TYPE STRING,
CHECT TYPE STRING,
STAVV TYPE STRING,
TXTVV TYPE STRING,
EPVOZ TYPE STRING,
INFO1 TYPE STRING,
INFO2 TYPE STRING,
AVSID TYPE STRING,
INTAG TYPE STRING,
NBBLN TYPE STRING,
AK1BL TYPE STRING,
AKBLN TYPE STRING,
KNRZA TYPE STRING,
AVKOA TYPE STRING,
AVKON TYPE STRING,
BATCH TYPE STRING,
ITMNR TYPE STRING,
KURSF TYPE STRING,
SGTXT TYPE STRING,
JPDAT TYPE STRING,
POSAG TYPE STRING,
SDOC2 TYPE STRING,
VGREF TYPE STRING,
XBENR TYPE STRING,
XBTYP TYPE STRING,
ARRSK TYPE STRING,
PFORM TYPE STRING,
KIDNO TYPE STRING,
KKREF TYPE STRING,
KKRF2 TYPE STRING,
MANSP TYPE STRING,
FNAM1 TYPE STRING,
FVAL1 TYPE STRING,
FKOA1 TYPE STRING,
FNAM2 TYPE STRING,
FVAL2 TYPE STRING,
FKOA2 TYPE STRING,
FNAM3 TYPE STRING,
FVAL3 TYPE STRING,
FKOA3 TYPE STRING,
IDENR TYPE STRING,
B1APP TYPE STRING,
B1ERR TYPE STRING,
B1STD TYPE STRING,
B1DOC TYPE STRING,
B1TYP TYPE STRING,
B2APP TYPE STRING,
B2ERR TYPE STRING,
B2STD TYPE STRING,
B2DOC TYPE STRING,
B2TYP TYPE STRING,
PIBAN TYPE STRING,
N2PCH TYPE STRING,
SVBUK TYPE STRING,
SVKOA TYPE STRING,
SVKON TYPE STRING,
SVAVS TYPE STRING,
REPRO TYPE STRING,
TRNID TYPE STRING,END OF T_EKKO_STR. DATA: WA_FEBEP_RFC_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_FEBEP_RFC_STR-KUKEY sy-vline
WA_FEBEP_RFC_STR-ESNUM sy-vline
WA_FEBEP_RFC_STR-EPERL sy-vline
WA_FEBEP_RFC_STR-VB1OK sy-vline
WA_FEBEP_RFC_STR-VB2BA sy-vline
WA_FEBEP_RFC_STR-VB2OK sy-vline
WA_FEBEP_RFC_STR-PIPRE sy-vline
WA_FEBEP_RFC_STR-GRPNR sy-vline
WA_FEBEP_RFC_STR-ESTAT sy-vline
WA_FEBEP_RFC_STR-BELNR sy-vline
WA_FEBEP_RFC_STR-GJAHR sy-vline
WA_FEBEP_RFC_STR-BVDAT sy-vline
WA_FEBEP_RFC_STR-BUDAT sy-vline
WA_FEBEP_RFC_STR-VALUT sy-vline
WA_FEBEP_RFC_STR-BUTIM sy-vline
WA_FEBEP_RFC_STR-VOZEI sy-vline
WA_FEBEP_RFC_STR-KWAER sy-vline
WA_FEBEP_RFC_STR-KWBTR sy-vline
WA_FEBEP_RFC_STR-SPESK sy-vline
WA_FEBEP_RFC_STR-FWAER sy-vline
WA_FEBEP_RFC_STR-FWBTR sy-vline
WA_FEBEP_RFC_STR-SPESF sy-vline
WA_FEBEP_RFC_STR-VORGC sy-vline
WA_FEBEP_RFC_STR-TEXTS sy-vline
WA_FEBEP_RFC_STR-VGEXT sy-vline
WA_FEBEP_RFC_STR-VGMAN sy-vline
WA_FEBEP_RFC_STR-VGINT sy-vline
WA_FEBEP_RFC_STR-VGDEF sy-vline
WA_FEBEP_RFC_STR-KFMOD sy-vline
WA_FEBEP_RFC_STR-VGSAP sy-vline
WA_FEBEP_RFC_STR-BUTXT sy-vline
WA_FEBEP_RFC_STR-ANZSP sy-vline
WA_FEBEP_RFC_STR-XBLNR sy-vline
WA_FEBEP_RFC_STR-ZUONR sy-vline
WA_FEBEP_RFC_STR-PABKS sy-vline
WA_FEBEP_RFC_STR-PABLZ sy-vline
WA_FEBEP_RFC_STR-PASWI sy-vline
WA_FEBEP_RFC_STR-PAKTO sy-vline
WA_FEBEP_RFC_STR-PARTN sy-vline
WA_FEBEP_RFC_STR-BUSAB sy-vline
WA_FEBEP_RFC_STR-KOSTL sy-vline
WA_FEBEP_RFC_STR-GSBER sy-vline
WA_FEBEP_RFC_STR-PRCTR sy-vline
WA_FEBEP_RFC_STR-VERTN sy-vline
WA_FEBEP_RFC_STR-VERTT sy-vline
WA_FEBEP_RFC_STR-PNOTA sy-vline
WA_FEBEP_RFC_STR-CHECT sy-vline
WA_FEBEP_RFC_STR-STAVV sy-vline
WA_FEBEP_RFC_STR-TXTVV sy-vline
WA_FEBEP_RFC_STR-EPVOZ sy-vline
WA_FEBEP_RFC_STR-INFO1 sy-vline
WA_FEBEP_RFC_STR-INFO2 sy-vline
WA_FEBEP_RFC_STR-AVSID sy-vline
WA_FEBEP_RFC_STR-INTAG sy-vline
WA_FEBEP_RFC_STR-NBBLN sy-vline
WA_FEBEP_RFC_STR-AK1BL sy-vline
WA_FEBEP_RFC_STR-AKBLN sy-vline
WA_FEBEP_RFC_STR-KNRZA sy-vline
WA_FEBEP_RFC_STR-AVKOA sy-vline
WA_FEBEP_RFC_STR-AVKON sy-vline
WA_FEBEP_RFC_STR-BATCH sy-vline
WA_FEBEP_RFC_STR-ITMNR sy-vline
WA_FEBEP_RFC_STR-KURSF sy-vline
WA_FEBEP_RFC_STR-SGTXT sy-vline
WA_FEBEP_RFC_STR-JPDAT sy-vline
WA_FEBEP_RFC_STR-POSAG sy-vline
WA_FEBEP_RFC_STR-SDOC2 sy-vline
WA_FEBEP_RFC_STR-VGREF sy-vline
WA_FEBEP_RFC_STR-XBENR sy-vline
WA_FEBEP_RFC_STR-XBTYP sy-vline
WA_FEBEP_RFC_STR-ARRSK sy-vline
WA_FEBEP_RFC_STR-PFORM sy-vline
WA_FEBEP_RFC_STR-KIDNO sy-vline
WA_FEBEP_RFC_STR-KKREF sy-vline
WA_FEBEP_RFC_STR-KKRF2 sy-vline
WA_FEBEP_RFC_STR-MANSP sy-vline
WA_FEBEP_RFC_STR-FNAM1 sy-vline
WA_FEBEP_RFC_STR-FVAL1 sy-vline
WA_FEBEP_RFC_STR-FKOA1 sy-vline
WA_FEBEP_RFC_STR-FNAM2 sy-vline
WA_FEBEP_RFC_STR-FVAL2 sy-vline
WA_FEBEP_RFC_STR-FKOA2 sy-vline
WA_FEBEP_RFC_STR-FNAM3 sy-vline
WA_FEBEP_RFC_STR-FVAL3 sy-vline
WA_FEBEP_RFC_STR-FKOA3 sy-vline
WA_FEBEP_RFC_STR-IDENR sy-vline
WA_FEBEP_RFC_STR-B1APP sy-vline
WA_FEBEP_RFC_STR-B1ERR sy-vline
WA_FEBEP_RFC_STR-B1STD sy-vline
WA_FEBEP_RFC_STR-B1DOC sy-vline
WA_FEBEP_RFC_STR-B1TYP sy-vline
WA_FEBEP_RFC_STR-B2APP sy-vline
WA_FEBEP_RFC_STR-B2ERR sy-vline
WA_FEBEP_RFC_STR-B2STD sy-vline
WA_FEBEP_RFC_STR-B2DOC sy-vline
WA_FEBEP_RFC_STR-B2TYP sy-vline
WA_FEBEP_RFC_STR-PIBAN sy-vline
WA_FEBEP_RFC_STR-N2PCH sy-vline
WA_FEBEP_RFC_STR-SVBUK sy-vline
WA_FEBEP_RFC_STR-SVKOA sy-vline
WA_FEBEP_RFC_STR-SVKON sy-vline
WA_FEBEP_RFC_STR-SVAVS sy-vline
WA_FEBEP_RFC_STR-REPRO sy-vline
WA_FEBEP_RFC_STR-TRNID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.