ABAP Select data from SAP table RFVIMAFCKOPO 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 RFVIMAFCKOPO 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 RFVIMAFCKOPO. 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 RFVIMAFCKOPO 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_RFVIMAFCKOPO TYPE STANDARD TABLE OF RFVIMAFCKOPO,
      WA_RFVIMAFCKOPO TYPE RFVIMAFCKOPO,
      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: <RFVIMAFCKOPO> TYPE RFVIMAFCKOPO.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RFVIMAFCKOPO
*  INTO TABLE @DATA(IT_RFVIMAFCKOPO2).
*--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_RFVIMAFCKOPO INDEX 1 INTO DATA(WA_RFVIMAFCKOPO2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RFVIMAFCKOPO ASSIGNING <RFVIMAFCKOPO>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RFVIMAFCKOPO>-XVERSION = 1.
<RFVIMAFCKOPO>-SBUKRS = 1.
<RFVIMAFCKOPO>-SRECNNR = 1.
<RFVIMAFCKOPO>-SSKOART = 1.
<RFVIMAFCKOPO>-DGUELAB = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RFVIMAFCKOPO-MANDT, sy-vline,
WA_RFVIMAFCKOPO-BUKRS, sy-vline,
WA_RFVIMAFCKOPO-SANLF, sy-vline,
WA_RFVIMAFCKOPO-RKEY1, sy-vline,
WA_RFVIMAFCKOPO-RKEY2, sy-vline,
WA_RFVIMAFCKOPO-RKEY3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RFVIMAFCKOPO 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_RFVIMAFCKOPO 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_RFVIMAFCKOPO INTO WA_RFVIMAFCKOPO. *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 KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RFVIMAFCKOPO-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFVIMAFCKOPO-KUNNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SPARTNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RFVIMAFCKOPO-SPARTNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFVIMAFCKOPO-SPARTNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit EXCRT, internal->external for field KURS1 CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_RFVIMAFCKOPO-KURS1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFVIMAFCKOPO-KURS1.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RFVIMAFCKOPO-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFVIMAFCKOPO-LIFNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RFVIMAFCKOPO-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFVIMAFCKOPO-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_RFVIMAFCKOPO_STR,
XVERSION TYPE STRING,
SBUKRS TYPE STRING,
SRECNNR TYPE STRING,
SSKOART TYPE STRING,
DGUELAB TYPE STRING,
MANDT TYPE STRING,
BUKRS TYPE STRING,
SANLF TYPE STRING,
RKEY1 TYPE STRING,
RKEY2 TYPE STRING,
RKEY3 TYPE STRING,
DGUEL_KK TYPE STRING,
NLFD_ANG TYPE STRING,
SKOART TYPE STRING,
DGUEL_KP TYPE STRING,
NSTUFE TYPE STRING,
SSTATI TYPE STRING,
PKOND TYPE STRING,
BKOND TYPE STRING,
SWHRKOND TYPE STRING,
SBASIS TYPE STRING,
SZSREF TYPE STRING,
SZSREFVZ TYPE STRING,
PFLUCT TYPE STRING,
AMMRHY TYPE STRING,
ATTRHY TYPE STRING,
SZAWS TYPE STRING,
RDIVNR TYPE STRING,
JNULLKON TYPE STRING,
MWSKZ TYPE STRING,
JBMONAT TYPE STRING,
DVALUT TYPE STRING,
DFAELL TYPE STRING,
KUNNR TYPE STRING,
ZLSCH TYPE STRING,
BVTYP TYPE STRING,
MABER TYPE STRING,
SPARTNR TYPE STRING,
RKONT TYPE STRING,
SVULT TYPE STRING,
SFULT TYPE STRING,
SVKALRI TYPE STRING,
SFKALRI TYPE STRING,
AVGSTAGE TYPE STRING,
AFGSTAGE TYPE STRING,
SVKALZUS TYPE STRING,
SFKALZUS TYPE STRING,
SKALID TYPE STRING,
SZBMETH TYPE STRING,
JSOFVERR TYPE STRING,
DALLGEM TYPE STRING,
SZEGEN TYPE STRING,
SBUST TYPE STRING,
SKOPO TYPE STRING,
SALTKOND TYPE STRING,
SZINSANP TYPE STRING,
SINCL TYPE STRING,
SFORMREF TYPE STRING,
SVARNAME TYPE STRING,
SVWERK TYPE STRING,
SVMETH TYPE STRING,
SFWERK TYPE STRING,
SFMETH TYPE STRING,
DPKOND TYPE STRING,
AZGSTAGE TYPE STRING,
SZKALRI TYPE STRING,
DZSREF TYPE STRING,
SKALID2 TYPE STRING,
SKALID3 TYPE STRING,
SKALID4 TYPE STRING,
SKALID5 TYPE STRING,
JGESUCHT TYPE STRING,
KURS1 TYPE STRING,
BBASIS TYPE STRING,
SZWERK TYPE STRING,
SFINCL TYPE STRING,
SRUNDVORF TYPE STRING,
SZWKEY TYPE STRING,
SFVMETH TYPE STRING,
SDWERK TYPE STRING,
SBERECH TYPE STRING,
JPROZR TYPE STRING,
SZEITANT TYPE STRING,
SFANT TYPE STRING,
SFRANZ TYPE STRING,
KBKOND TYPE STRING,
SBASFIX TYPE STRING,
MANSP TYPE STRING,
ZAHLS TYPE STRING,
BKONDQM TYPE STRING,
JAREA TYPE STRING,
SFLART TYPE STRING,
TXJCD TYPE STRING,
AVGSTAGEVZ TYPE STRING,
AFGSTAGEVZ TYPE STRING,
LIFNR TYPE STRING,
JEXPOZINS TYPE STRING,
KOSTL TYPE STRING,
GFZLSCH TYPE STRING,
ZLSPR TYPE STRING,
SROUND TYPE STRING,
SKALIDWT TYPE STRING,
BMWST TYPE STRING,
XCROSS TYPE STRING,
PPAYMENT TYPE STRING,
AMMRHYZV TYPE STRING,
PKOND2 TYPE STRING,
FACTOR_TYPE TYPE STRING,
SROUNDFACTOR TYPE STRING,
ROUNDDECFACTOR TYPE STRING,
JEXPOINTFACTOR TYPE STRING,
SROUNDBASEFACTOR TYPE STRING,
ROUNDDECBASEFACTOR TYPE STRING,
SROUNDRATEFACTOR TYPE STRING,
ROUNDDECRATEFACTOR TYPE STRING,
JAVGCAP TYPE STRING,
PAVGCAP TYPE STRING,
JAVGFLOOR TYPE STRING,
PAVGFLOOR TYPE STRING,
PAVGSPREAD TYPE STRING,
SROUNDAVGINTEREST TYPE STRING,
ROUNDDECAVGINTEREST TYPE STRING,
SAVGWEIGHT TYPE STRING,
SFACTORRESET TYPE STRING,
ADGSTAGE TYPE STRING,
MNDID TYPE STRING,
RBO TYPE STRING,
STECH_COND TYPE STRING,
SEXCLGUEL TYPE STRING,
SULTGUEL TYPE STRING,
A_AMTMIN TYPE STRING,
A_AMTMAX TYPE STRING,
SSCHMETH TYPE STRING,
BAUDAMNT TYPE STRING,
A_PAYDAY TYPE STRING,
RCO TYPE STRING,
BROUNDUNIT TYPE STRING,
BBASISUNIT TYPE STRING,
GPDAYS TYPE STRING,
IND_IOAGP TYPE STRING,
DISBRATE TYPE STRING,END OF T_EKKO_STR. DATA: WA_RFVIMAFCKOPO_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_RFVIMAFCKOPO_STR-XVERSION sy-vline
WA_RFVIMAFCKOPO_STR-SBUKRS sy-vline
WA_RFVIMAFCKOPO_STR-SRECNNR sy-vline
WA_RFVIMAFCKOPO_STR-SSKOART sy-vline
WA_RFVIMAFCKOPO_STR-DGUELAB sy-vline
WA_RFVIMAFCKOPO_STR-MANDT sy-vline
WA_RFVIMAFCKOPO_STR-BUKRS sy-vline
WA_RFVIMAFCKOPO_STR-SANLF sy-vline
WA_RFVIMAFCKOPO_STR-RKEY1 sy-vline
WA_RFVIMAFCKOPO_STR-RKEY2 sy-vline
WA_RFVIMAFCKOPO_STR-RKEY3 sy-vline
WA_RFVIMAFCKOPO_STR-DGUEL_KK sy-vline
WA_RFVIMAFCKOPO_STR-NLFD_ANG sy-vline
WA_RFVIMAFCKOPO_STR-SKOART sy-vline
WA_RFVIMAFCKOPO_STR-DGUEL_KP sy-vline
WA_RFVIMAFCKOPO_STR-NSTUFE sy-vline
WA_RFVIMAFCKOPO_STR-SSTATI sy-vline
WA_RFVIMAFCKOPO_STR-PKOND sy-vline
WA_RFVIMAFCKOPO_STR-BKOND sy-vline
WA_RFVIMAFCKOPO_STR-SWHRKOND sy-vline
WA_RFVIMAFCKOPO_STR-SBASIS sy-vline
WA_RFVIMAFCKOPO_STR-SZSREF sy-vline
WA_RFVIMAFCKOPO_STR-SZSREFVZ sy-vline
WA_RFVIMAFCKOPO_STR-PFLUCT sy-vline
WA_RFVIMAFCKOPO_STR-AMMRHY sy-vline
WA_RFVIMAFCKOPO_STR-ATTRHY sy-vline
WA_RFVIMAFCKOPO_STR-SZAWS sy-vline
WA_RFVIMAFCKOPO_STR-RDIVNR sy-vline
WA_RFVIMAFCKOPO_STR-JNULLKON sy-vline
WA_RFVIMAFCKOPO_STR-MWSKZ sy-vline
WA_RFVIMAFCKOPO_STR-JBMONAT sy-vline
WA_RFVIMAFCKOPO_STR-DVALUT sy-vline
WA_RFVIMAFCKOPO_STR-DFAELL sy-vline
WA_RFVIMAFCKOPO_STR-KUNNR sy-vline
WA_RFVIMAFCKOPO_STR-ZLSCH sy-vline
WA_RFVIMAFCKOPO_STR-BVTYP sy-vline
WA_RFVIMAFCKOPO_STR-MABER sy-vline
WA_RFVIMAFCKOPO_STR-SPARTNR sy-vline
WA_RFVIMAFCKOPO_STR-RKONT sy-vline
WA_RFVIMAFCKOPO_STR-SVULT sy-vline
WA_RFVIMAFCKOPO_STR-SFULT sy-vline
WA_RFVIMAFCKOPO_STR-SVKALRI sy-vline
WA_RFVIMAFCKOPO_STR-SFKALRI sy-vline
WA_RFVIMAFCKOPO_STR-AVGSTAGE sy-vline
WA_RFVIMAFCKOPO_STR-AFGSTAGE sy-vline
WA_RFVIMAFCKOPO_STR-SVKALZUS sy-vline
WA_RFVIMAFCKOPO_STR-SFKALZUS sy-vline
WA_RFVIMAFCKOPO_STR-SKALID sy-vline
WA_RFVIMAFCKOPO_STR-SZBMETH sy-vline
WA_RFVIMAFCKOPO_STR-JSOFVERR sy-vline
WA_RFVIMAFCKOPO_STR-DALLGEM sy-vline
WA_RFVIMAFCKOPO_STR-SZEGEN sy-vline
WA_RFVIMAFCKOPO_STR-SBUST sy-vline
WA_RFVIMAFCKOPO_STR-SKOPO sy-vline
WA_RFVIMAFCKOPO_STR-SALTKOND sy-vline
WA_RFVIMAFCKOPO_STR-SZINSANP sy-vline
WA_RFVIMAFCKOPO_STR-SINCL sy-vline
WA_RFVIMAFCKOPO_STR-SFORMREF sy-vline
WA_RFVIMAFCKOPO_STR-SVARNAME sy-vline
WA_RFVIMAFCKOPO_STR-SVWERK sy-vline
WA_RFVIMAFCKOPO_STR-SVMETH sy-vline
WA_RFVIMAFCKOPO_STR-SFWERK sy-vline
WA_RFVIMAFCKOPO_STR-SFMETH sy-vline
WA_RFVIMAFCKOPO_STR-DPKOND sy-vline
WA_RFVIMAFCKOPO_STR-AZGSTAGE sy-vline
WA_RFVIMAFCKOPO_STR-SZKALRI sy-vline
WA_RFVIMAFCKOPO_STR-DZSREF sy-vline
WA_RFVIMAFCKOPO_STR-SKALID2 sy-vline
WA_RFVIMAFCKOPO_STR-SKALID3 sy-vline
WA_RFVIMAFCKOPO_STR-SKALID4 sy-vline
WA_RFVIMAFCKOPO_STR-SKALID5 sy-vline
WA_RFVIMAFCKOPO_STR-JGESUCHT sy-vline
WA_RFVIMAFCKOPO_STR-KURS1 sy-vline
WA_RFVIMAFCKOPO_STR-BBASIS sy-vline
WA_RFVIMAFCKOPO_STR-SZWERK sy-vline
WA_RFVIMAFCKOPO_STR-SFINCL sy-vline
WA_RFVIMAFCKOPO_STR-SRUNDVORF sy-vline
WA_RFVIMAFCKOPO_STR-SZWKEY sy-vline
WA_RFVIMAFCKOPO_STR-SFVMETH sy-vline
WA_RFVIMAFCKOPO_STR-SDWERK sy-vline
WA_RFVIMAFCKOPO_STR-SBERECH sy-vline
WA_RFVIMAFCKOPO_STR-JPROZR sy-vline
WA_RFVIMAFCKOPO_STR-SZEITANT sy-vline
WA_RFVIMAFCKOPO_STR-SFANT sy-vline
WA_RFVIMAFCKOPO_STR-SFRANZ sy-vline
WA_RFVIMAFCKOPO_STR-KBKOND sy-vline
WA_RFVIMAFCKOPO_STR-SBASFIX sy-vline
WA_RFVIMAFCKOPO_STR-MANSP sy-vline
WA_RFVIMAFCKOPO_STR-ZAHLS sy-vline
WA_RFVIMAFCKOPO_STR-BKONDQM sy-vline
WA_RFVIMAFCKOPO_STR-JAREA sy-vline
WA_RFVIMAFCKOPO_STR-SFLART sy-vline
WA_RFVIMAFCKOPO_STR-TXJCD sy-vline
WA_RFVIMAFCKOPO_STR-AVGSTAGEVZ sy-vline
WA_RFVIMAFCKOPO_STR-AFGSTAGEVZ sy-vline
WA_RFVIMAFCKOPO_STR-LIFNR sy-vline
WA_RFVIMAFCKOPO_STR-JEXPOZINS sy-vline
WA_RFVIMAFCKOPO_STR-KOSTL sy-vline
WA_RFVIMAFCKOPO_STR-GFZLSCH sy-vline
WA_RFVIMAFCKOPO_STR-ZLSPR sy-vline
WA_RFVIMAFCKOPO_STR-SROUND sy-vline
WA_RFVIMAFCKOPO_STR-SKALIDWT sy-vline
WA_RFVIMAFCKOPO_STR-BMWST sy-vline
WA_RFVIMAFCKOPO_STR-XCROSS sy-vline
WA_RFVIMAFCKOPO_STR-PPAYMENT sy-vline
WA_RFVIMAFCKOPO_STR-AMMRHYZV sy-vline
WA_RFVIMAFCKOPO_STR-PKOND2 sy-vline
WA_RFVIMAFCKOPO_STR-FACTOR_TYPE sy-vline
WA_RFVIMAFCKOPO_STR-SROUNDFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-ROUNDDECFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-JEXPOINTFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-SROUNDBASEFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-ROUNDDECBASEFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-SROUNDRATEFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-ROUNDDECRATEFACTOR sy-vline
WA_RFVIMAFCKOPO_STR-JAVGCAP sy-vline
WA_RFVIMAFCKOPO_STR-PAVGCAP sy-vline
WA_RFVIMAFCKOPO_STR-JAVGFLOOR sy-vline
WA_RFVIMAFCKOPO_STR-PAVGFLOOR sy-vline
WA_RFVIMAFCKOPO_STR-PAVGSPREAD sy-vline
WA_RFVIMAFCKOPO_STR-SROUNDAVGINTEREST sy-vline
WA_RFVIMAFCKOPO_STR-ROUNDDECAVGINTEREST sy-vline
WA_RFVIMAFCKOPO_STR-SAVGWEIGHT sy-vline
WA_RFVIMAFCKOPO_STR-SFACTORRESET sy-vline
WA_RFVIMAFCKOPO_STR-ADGSTAGE sy-vline
WA_RFVIMAFCKOPO_STR-MNDID sy-vline
WA_RFVIMAFCKOPO_STR-RBO sy-vline
WA_RFVIMAFCKOPO_STR-STECH_COND sy-vline
WA_RFVIMAFCKOPO_STR-SEXCLGUEL sy-vline
WA_RFVIMAFCKOPO_STR-SULTGUEL sy-vline
WA_RFVIMAFCKOPO_STR-A_AMTMIN sy-vline
WA_RFVIMAFCKOPO_STR-A_AMTMAX sy-vline
WA_RFVIMAFCKOPO_STR-SSCHMETH sy-vline
WA_RFVIMAFCKOPO_STR-BAUDAMNT sy-vline
WA_RFVIMAFCKOPO_STR-A_PAYDAY sy-vline
WA_RFVIMAFCKOPO_STR-RCO sy-vline
WA_RFVIMAFCKOPO_STR-BROUNDUNIT sy-vline
WA_RFVIMAFCKOPO_STR-BBASISUNIT sy-vline
WA_RFVIMAFCKOPO_STR-GPDAYS sy-vline
WA_RFVIMAFCKOPO_STR-IND_IOAGP sy-vline
WA_RFVIMAFCKOPO_STR-DISBRATE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.