ABAP Select data from SAP table RFUMS4_TAX_ITEM 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 RFUMS4_TAX_ITEM 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 RFUMS4_TAX_ITEM. 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 RFUMS4_TAX_ITEM 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_RFUMS4_TAX_ITEM TYPE STANDARD TABLE OF RFUMS4_TAX_ITEM,
      WA_RFUMS4_TAX_ITEM TYPE RFUMS4_TAX_ITEM,
      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: <RFUMS4_TAX_ITEM> TYPE RFUMS4_TAX_ITEM.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RFUMS4_TAX_ITEM
*  INTO TABLE @DATA(IT_RFUMS4_TAX_ITEM2).
*--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_RFUMS4_TAX_ITEM INDEX 1 INTO DATA(WA_RFUMS4_TAX_ITEM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RFUMS4_TAX_ITEM ASSIGNING <RFUMS4_TAX_ITEM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RFUMS4_TAX_ITEM>-UMKRS = 1.
<RFUMS4_TAX_ITEM>-UMSNR = 1.
<RFUMS4_TAX_ITEM>-UKADRNR = 1.
<RFUMS4_TAX_ITEM>-FAADR = 1.
<RFUMS4_TAX_ITEM>-FNAME1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RFUMS4_TAX_ITEM-FNAME2, sy-vline,
WA_RFUMS4_TAX_ITEM-FNAME3, sy-vline,
WA_RFUMS4_TAX_ITEM-FNAME4, sy-vline,
WA_RFUMS4_TAX_ITEM-FSTRAS, sy-vline,
WA_RFUMS4_TAX_ITEM-FPFACH, sy-vline,
WA_RFUMS4_TAX_ITEM-FSTRS2, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RFUMS4_TAX_ITEM 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_RFUMS4_TAX_ITEM 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_RFUMS4_TAX_ITEM INTO WA_RFUMS4_TAX_ITEM. *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 UKADRNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RFUMS4_TAX_ITEM-UKADRNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFUMS4_TAX_ITEM-UKADRNR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit GJAHR, internal->external for field DECL_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_RFUMS4_TAX_ITEM-DECL_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFUMS4_TAX_ITEM-DECL_YEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit AU132, internal->external for field AMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_RFUMS4_TAX_ITEM-AMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RFUMS4_TAX_ITEM-AMOUNT.
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_RFUMS4_TAX_ITEM_STR,
UMKRS TYPE STRING,
UMSNR TYPE STRING,
UKADRNR TYPE STRING,
FAADR TYPE STRING,
FNAME1 TYPE STRING,
FNAME2 TYPE STRING,
FNAME3 TYPE STRING,
FNAME4 TYPE STRING,
FSTRAS TYPE STRING,
FPFACH TYPE STRING,
FSTRS2 TYPE STRING,
FHAUSN TYPE STRING,
FPSTLZ TYPE STRING,
FORT01 TYPE STRING,
FEMAIL TYPE STRING,
BUKRS TYPE STRING,
ADRNR TYPE STRING,
NAME1 TYPE STRING,
NAME2 TYPE STRING,
NAME3 TYPE STRING,
NAME4 TYPE STRING,
STRAS TYPE STRING,
PFACH TYPE STRING,
STRS2 TYPE STRING,
HAUSN TYPE STRING,
PSTLZ TYPE STRING,
ORT01 TYPE STRING,
TELF TYPE STRING,
STCEG TYPE STRING,
TXJCD TYPE STRING,
PERIV TYPE STRING,
CEMAIL TYPE STRING,
SWNAME TYPE STRING,
SWVENDOR TYPE STRING,
SWVERSION TYPE STRING,
SWREVISION TYPE STRING,
SWCONTACT TYPE STRING,
SWTELF TYPE STRING,
SWEMAIL TYPE STRING,
FILEREF TYPE STRING,
CREATDAT TYPE STRING,
LANGUAGE TYPE STRING,
AUTHCODE TYPE STRING,
DECL_YEAR TYPE STRING,
DECL_MONTH TYPE STRING,
DECL_TYPE TYPE STRING,
TAX_GROUP TYPE STRING,
AMOUNT TYPE STRING,
CURRENCY TYPE STRING,
CHOICE1 TYPE STRING,
CHOICE2 TYPE STRING,END OF T_EKKO_STR. DATA: WA_RFUMS4_TAX_ITEM_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_RFUMS4_TAX_ITEM_STR-UMKRS sy-vline
WA_RFUMS4_TAX_ITEM_STR-UMSNR sy-vline
WA_RFUMS4_TAX_ITEM_STR-UKADRNR sy-vline
WA_RFUMS4_TAX_ITEM_STR-FAADR sy-vline
WA_RFUMS4_TAX_ITEM_STR-FNAME1 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FNAME2 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FNAME3 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FNAME4 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FSTRAS sy-vline
WA_RFUMS4_TAX_ITEM_STR-FPFACH sy-vline
WA_RFUMS4_TAX_ITEM_STR-FSTRS2 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FHAUSN sy-vline
WA_RFUMS4_TAX_ITEM_STR-FPSTLZ sy-vline
WA_RFUMS4_TAX_ITEM_STR-FORT01 sy-vline
WA_RFUMS4_TAX_ITEM_STR-FEMAIL sy-vline
WA_RFUMS4_TAX_ITEM_STR-BUKRS sy-vline
WA_RFUMS4_TAX_ITEM_STR-ADRNR sy-vline
WA_RFUMS4_TAX_ITEM_STR-NAME1 sy-vline
WA_RFUMS4_TAX_ITEM_STR-NAME2 sy-vline
WA_RFUMS4_TAX_ITEM_STR-NAME3 sy-vline
WA_RFUMS4_TAX_ITEM_STR-NAME4 sy-vline
WA_RFUMS4_TAX_ITEM_STR-STRAS sy-vline
WA_RFUMS4_TAX_ITEM_STR-PFACH sy-vline
WA_RFUMS4_TAX_ITEM_STR-STRS2 sy-vline
WA_RFUMS4_TAX_ITEM_STR-HAUSN sy-vline
WA_RFUMS4_TAX_ITEM_STR-PSTLZ sy-vline
WA_RFUMS4_TAX_ITEM_STR-ORT01 sy-vline
WA_RFUMS4_TAX_ITEM_STR-TELF sy-vline
WA_RFUMS4_TAX_ITEM_STR-STCEG sy-vline
WA_RFUMS4_TAX_ITEM_STR-TXJCD sy-vline
WA_RFUMS4_TAX_ITEM_STR-PERIV sy-vline
WA_RFUMS4_TAX_ITEM_STR-CEMAIL sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWNAME sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWVENDOR sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWVERSION sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWREVISION sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWCONTACT sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWTELF sy-vline
WA_RFUMS4_TAX_ITEM_STR-SWEMAIL sy-vline
WA_RFUMS4_TAX_ITEM_STR-FILEREF sy-vline
WA_RFUMS4_TAX_ITEM_STR-CREATDAT sy-vline
WA_RFUMS4_TAX_ITEM_STR-LANGUAGE sy-vline
WA_RFUMS4_TAX_ITEM_STR-AUTHCODE sy-vline
WA_RFUMS4_TAX_ITEM_STR-DECL_YEAR sy-vline
WA_RFUMS4_TAX_ITEM_STR-DECL_MONTH sy-vline
WA_RFUMS4_TAX_ITEM_STR-DECL_TYPE sy-vline
WA_RFUMS4_TAX_ITEM_STR-TAX_GROUP sy-vline
WA_RFUMS4_TAX_ITEM_STR-AMOUNT sy-vline
WA_RFUMS4_TAX_ITEM_STR-CURRENCY sy-vline
WA_RFUMS4_TAX_ITEM_STR-CHOICE1 sy-vline
WA_RFUMS4_TAX_ITEM_STR-CHOICE2 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.