ABAP Select data from SAP table /PRA/T9_TAXTXN 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 /PRA/T9_TAXTXN 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 /PRA/T9_TAXTXN. 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 /PRA/T9_TAXTXN 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_/PRA/T9_TAXTXN TYPE STANDARD TABLE OF /PRA/T9_TAXTXN,
      WA_/PRA/T9_TAXTXN TYPE /PRA/T9_TAXTXN,
      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: </PRA/T9_TAXTXN> TYPE /PRA/T9_TAXTXN.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PRA/T9_TAXTXN
  INTO TABLE IT_/PRA/T9_TAXTXN.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PRA/T9_TAXTXN
*  INTO TABLE @DATA(IT_/PRA/T9_TAXTXN2).
*--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_/PRA/T9_TAXTXN INDEX 1 INTO DATA(WA_/PRA/T9_TAXTXN2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PRA/T9_TAXTXN ASSIGNING </PRA/T9_TAXTXN>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PRA/T9_TAXTXN>-MANDT = 1.
</PRA/T9_TAXTXN>-BUKRS = 1.
</PRA/T9_TAXTXN>-SALES_DT = 1.
</PRA/T9_TAXTXN>-PDCD = 1.
</PRA/T9_TAXTXN>-WL_NO = 1.
ENDLOOP.

LOOP AT IT_/PRA/T9_TAXTXN INTO WA_/PRA/T9_TAXTXN.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PRA/T9_TAXTXN-WC_NO, sy-vline,
WA_/PRA/T9_TAXTXN-MP_NO, sy-vline,
WA_/PRA/T9_TAXTXN-VNAME, sy-vline,
WA_/PRA/T9_TAXTXN-DOI_NO, sy-vline,
WA_/PRA/T9_TAXTXN-DN_NO, sy-vline,
WA_/PRA/T9_TAXTXN-CT_NO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PRA/T9_TAXTXN 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_/PRA/T9_TAXTXN 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_/PRA/T9_TAXTXN INTO WA_/PRA/T9_TAXTXN. *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 WL_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PRA/T9_TAXTXN-WL_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PRA/T9_TAXTXN-WL_NO.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

*Conversion exit CUNIT, internal->external for field UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/PRA/T9_TAXTXN-UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PRA/T9_TAXTXN-UOM.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit TSTPS, internal->external for field CHANGE_TIMESTAMP CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_/PRA/T9_TAXTXN-CHANGE_TIMESTAMP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PRA/T9_TAXTXN-CHANGE_TIMESTAMP.
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_/PRA/T9_TAXTXN_STR,
MANDT TYPE STRING,
BUKRS TYPE STRING,
SALES_DT TYPE STRING,
PDCD TYPE STRING,
WL_NO TYPE STRING,
WC_NO TYPE STRING,
MP_NO TYPE STRING,
VNAME TYPE STRING,
DOI_NO TYPE STRING,
DN_NO TYPE STRING,
CT_NO TYPE STRING,
VL_TYPE_CD TYPE STRING,
TAX_CLS TYPE STRING,
REV_BOOK_ADJ_IND TYPE STRING,
UNIT_VNAME TYPE STRING,
PROD_PURC_IND TYPE STRING,
OTHER_NO TYPE STRING,
VL_TAX_RAT TYPE STRING,
VAL_TAX_RAT TYPE STRING,
PAY_FL TYPE STRING,
RPT_FL TYPE STRING,
UOM TYPE STRING,
DOC_NO TYPE STRING,
DOC_YEAR TYPE STRING,
OPTION1 TYPE STRING,
OPTION2 TYPE STRING,
OPTION3 TYPE STRING,
INTERFACE_FL TYPE STRING,
OOS_FL TYPE STRING,
GROSS_VOL TYPE STRING,
WET_LESS_RESIDUE TYPE STRING,
EXEMPT_VOL TYPE STRING,
TAX_VOL TYPE STRING,
GROSS_VAL TYPE STRING,
EXEMPT_VAL TYPE STRING,
MKT_COST TYPE STRING,
FIXED_MKT_COST TYPE STRING,
MKT_COST_REIMB TYPE STRING,
TAX_VAL TYPE STRING,
SV_TAX_AMT TYPE STRING,
RF_TAX_AMT TYPE STRING,
INTEREST TYPE STRING,
RPT_COMPANY_NO TYPE STRING,
REVENUE_ACCT_NO TYPE STRING,
MASTER_LEVEL TYPE STRING,
LEASE_NO TYPE STRING,
PARISH TYPE STRING,
PLANT_ID TYPE STRING,
REPORTING_NAME TYPE STRING,
MULTI_PARISH TYPE STRING,
FIELD_ID TYPE STRING,
PROD_CD TYPE STRING,
OPERATED_FL TYPE STRING,
OTHER_CD TYPE STRING,
KIND_CD TYPE STRING,
TAX_RATE_CD TYPE STRING,
DEEP_OR_HORIZ_WL TYPE STRING,
REJ_SUSP_IND TYPE STRING,
REJ_CD TYPE STRING,
REFERENCE_RUN_ID TYPE STRING,
TAXPAYER_CD TYPE STRING,
CHANGE_USER TYPE STRING,
CHANGE_TIMESTAMP TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PRA/T9_TAXTXN_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_/PRA/T9_TAXTXN_STR-MANDT sy-vline
WA_/PRA/T9_TAXTXN_STR-BUKRS sy-vline
WA_/PRA/T9_TAXTXN_STR-SALES_DT sy-vline
WA_/PRA/T9_TAXTXN_STR-PDCD sy-vline
WA_/PRA/T9_TAXTXN_STR-WL_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-WC_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-MP_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-VNAME sy-vline
WA_/PRA/T9_TAXTXN_STR-DOI_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-DN_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-CT_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-VL_TYPE_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-TAX_CLS sy-vline
WA_/PRA/T9_TAXTXN_STR-REV_BOOK_ADJ_IND sy-vline
WA_/PRA/T9_TAXTXN_STR-UNIT_VNAME sy-vline
WA_/PRA/T9_TAXTXN_STR-PROD_PURC_IND sy-vline
WA_/PRA/T9_TAXTXN_STR-OTHER_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-VL_TAX_RAT sy-vline
WA_/PRA/T9_TAXTXN_STR-VAL_TAX_RAT sy-vline
WA_/PRA/T9_TAXTXN_STR-PAY_FL sy-vline
WA_/PRA/T9_TAXTXN_STR-RPT_FL sy-vline
WA_/PRA/T9_TAXTXN_STR-UOM sy-vline
WA_/PRA/T9_TAXTXN_STR-DOC_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-DOC_YEAR sy-vline
WA_/PRA/T9_TAXTXN_STR-OPTION1 sy-vline
WA_/PRA/T9_TAXTXN_STR-OPTION2 sy-vline
WA_/PRA/T9_TAXTXN_STR-OPTION3 sy-vline
WA_/PRA/T9_TAXTXN_STR-INTERFACE_FL sy-vline
WA_/PRA/T9_TAXTXN_STR-OOS_FL sy-vline
WA_/PRA/T9_TAXTXN_STR-GROSS_VOL sy-vline
WA_/PRA/T9_TAXTXN_STR-WET_LESS_RESIDUE sy-vline
WA_/PRA/T9_TAXTXN_STR-EXEMPT_VOL sy-vline
WA_/PRA/T9_TAXTXN_STR-TAX_VOL sy-vline
WA_/PRA/T9_TAXTXN_STR-GROSS_VAL sy-vline
WA_/PRA/T9_TAXTXN_STR-EXEMPT_VAL sy-vline
WA_/PRA/T9_TAXTXN_STR-MKT_COST sy-vline
WA_/PRA/T9_TAXTXN_STR-FIXED_MKT_COST sy-vline
WA_/PRA/T9_TAXTXN_STR-MKT_COST_REIMB sy-vline
WA_/PRA/T9_TAXTXN_STR-TAX_VAL sy-vline
WA_/PRA/T9_TAXTXN_STR-SV_TAX_AMT sy-vline
WA_/PRA/T9_TAXTXN_STR-RF_TAX_AMT sy-vline
WA_/PRA/T9_TAXTXN_STR-INTEREST sy-vline
WA_/PRA/T9_TAXTXN_STR-RPT_COMPANY_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-REVENUE_ACCT_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-MASTER_LEVEL sy-vline
WA_/PRA/T9_TAXTXN_STR-LEASE_NO sy-vline
WA_/PRA/T9_TAXTXN_STR-PARISH sy-vline
WA_/PRA/T9_TAXTXN_STR-PLANT_ID sy-vline
WA_/PRA/T9_TAXTXN_STR-REPORTING_NAME sy-vline
WA_/PRA/T9_TAXTXN_STR-MULTI_PARISH sy-vline
WA_/PRA/T9_TAXTXN_STR-FIELD_ID sy-vline
WA_/PRA/T9_TAXTXN_STR-PROD_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-OPERATED_FL sy-vline
WA_/PRA/T9_TAXTXN_STR-OTHER_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-KIND_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-TAX_RATE_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-DEEP_OR_HORIZ_WL sy-vline
WA_/PRA/T9_TAXTXN_STR-REJ_SUSP_IND sy-vline
WA_/PRA/T9_TAXTXN_STR-REJ_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-REFERENCE_RUN_ID sy-vline
WA_/PRA/T9_TAXTXN_STR-TAXPAYER_CD sy-vline
WA_/PRA/T9_TAXTXN_STR-CHANGE_USER sy-vline
WA_/PRA/T9_TAXTXN_STR-CHANGE_TIMESTAMP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.