ABAP Select data from SAP table HRCUSCL_T10_TAX_CALC_RESPONSE 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 HRCUSCL_T10_TAX_CALC_RESPONSE 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 HRCUSCL_T10_TAX_CALC_RESPONSE. 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 HRCUSCL_T10_TAX_CALC_RESPONSE 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_HRCUSCL_T10_TAX_CALC_RESPONSE TYPE STANDARD TABLE OF HRCUSCL_T10_TAX_CALC_RESPONSE, WA_HRCUSCL_T10_TAX_CALC_RESPONSE TYPE HRCUSCL_T10_TAX_CALC_RESPONSE, 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: <HRCUSCL_T10_TAX_CALC_RESPONSE> TYPE HRCUSCL_T10_TAX_CALC_RESPONSE. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_HRCUSCL_T10_TAX_CALC_RESPONSE. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM HRCUSCL_T10_TAX_CALC_RESPONSE INTO TABLE IT_HRCUSCL_T10_TAX_CALC_RESPONSE. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM HRCUSCL_T10_TAX_CALC_RESPONSE * INTO TABLE @DATA(IT_HRCUSCL_T10_TAX_CALC_RESPONSE2). *--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_HRCUSCL_T10_TAX_CALC_RESPONSE INDEX 1 INTO DATA(WA_HRCUSCL_T10_TAX_CALC_RESPONSE2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_HRCUSCL_T10_TAX_CALC_RESPONSE ASSIGNING <HRCUSCL_T10_TAX_CALC_RESPONSE>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<HRCUSCL_T10_TAX_CALC_RESPONSE>-CONTROLLER = 1.
<HRCUSCL_T10_TAX_CALC_RESPONSE>-BASE = 1.
<HRCUSCL_T10_TAX_CALC_RESPONSE>-CONTROLLER = 1.
<HRCUSCL_T10_TAX_CALC_RESPONSE>-MESSAGES = 1.
<HRCUSCL_T10_TAX_CALC_RESPONSE>-EMPLOYEE = 1.
ENDLOOP. LOOP AT IT_HRCUSCL_T10_TAX_CALC_RESPONSE INTO WA_HRCUSCL_T10_TAX_CALC_RESPONSE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_HRCUSCL_T10_TAX_CALC_RESPONSE-CONTROLLER, sy-vline,
WA_HRCUSCL_T10_TAX_CALC_RESPONSE-BIRTH_DATE_YYYYMMDD, sy-vline,
WA_HRCUSCL_T10_TAX_CALC_RESPONSE-CRSVD0, sy-vline,
WA_HRCUSCL_T10_TAX_CALC_RESPONSE-CRSVD1, sy-vline,
WA_HRCUSCL_T10_TAX_CALC_RESPONSE-CALCULATED_PERIOD_GROSS, sy-vline,
WA_HRCUSCL_T10_TAX_CALC_RESPONSE-CHECK_DATE_YYYYMMDD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_HRCUSCL_T10_TAX_CALC_RESPONSE 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_HRCUSCL_T10_TAX_CALC_RESPONSE 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_HRCUSCL_T10_TAX_CALC_RESPONSE INTO WA_HRCUSCL_T10_TAX_CALC_RESPONSE. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_HRCUSCL_T10_TAX_CALC_RESPONSE_STR,
CONTROLLER TYPE STRING,
BASE TYPE STRING,
CONTROLLER TYPE STRING,
MESSAGES TYPE STRING,
EMPLOYEE TYPE STRING,
CONTROLLER TYPE STRING,
BIRTH_DATE_YYYYMMDD TYPE STRING,
CRSVD0 TYPE STRING,
CRSVD1 TYPE STRING,
CALCULATED_PERIOD_GROSS TYPE STRING,
CHECK_DATE_YYYYMMDD TYPE STRING,
COMPANY_CODE TYPE STRING,
COMPANY_PLAN TYPE STRING,
CONTRIBUTION_ALLOCATION TYPE STRING,
DRSVD0 TYPE STRING,
DRSVD1 TYPE STRING,
DATE_OF_DEATH_YYYYMMDD TYPE STRING,
DISBURSEMENT_DATE_YYYYMMDD TYPE STRING,
EMPLOYEE_CODE TYPE STRING,
EMPLOYEE_NAME TYPE STRING,
EMPLOYEE_STATUS TYPE STRING,
EMPLOYEE_TYPE TYPE STRING,
EMPLOYMENT_TYPE_IND TYPE STRING,
ESTD_ANNUAL_GROSS TYPE STRING,
ESTD_SPOUSAL_INCOME TYPE STRING,
FINAL_PAYCHECK_NET_AMOUNT TYPE STRING,
FOREIGN_EARNED_INCOME TYPE STRING,
FORMULA_EFFECTIVE_DATE_YYYYMMD TYPE STRING,
GARNISHMENT_GROUP TYPE STRING,
GARNISHMENTS TYPE STRING,
GROSS_UP_CODE TYPE STRING,
GROSS_WAGES TYPE STRING,
GROUP_CODE TYPE STRING,
HRSVD0 TYPE STRING,
HRSVD1 TYPE STRING,
MESSAGE_LEVEL TYPE STRING,
NET_WAGES TYPE STRING,
NUMBER_OF_GARNISHMENTS TYPE STRING,
NUMBER_OF_TAX_ENTRIES TYPE STRING,
PAY_FREQUENCY TYPE STRING,
PAYMENT_TYPE TYPE STRING,
PRINCIPAL_STATE_OF_EMPLOYMENT TYPE STRING,
PROCESS_CODE TYPE STRING,
PROCESS_GARNISHMENTS TYPE STRING,
PRORATION_FREQ TYPE STRING,
QUALIFYING_DAYS TYPE STRING,
RRSVD0 TYPE STRING,
RRSVD1 TYPE STRING,
RECIPROCAL_CODE TYPE STRING,
RESIDENT_STATE TYPE STRING,
ROLLOVER_ELIGIBLE TYPE STRING,
ROLLOVER_MONTHS TYPE STRING,
SRSVD0 TYPE STRING,
SRSVD1 TYPE STRING,
STAT_EE TYPE STRING,
STD_HOURS_IN_PAY_PERIOD TYPE STRING,
TAXES TYPE STRING,
VACATION_HOURS TYPE STRING,
WAGE_PROCESS_CODE TYPE STRING,
YTD_PAY_PERIODS TYPE STRING,END OF T_EKKO_STR. DATA: WA_HRCUSCL_T10_TAX_CALC_RESPONSE_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_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CONTROLLER sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-BASE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CONTROLLER sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-MESSAGES sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYEE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CONTROLLER sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-BIRTH_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CRSVD0 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CRSVD1 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CALCULATED_PERIOD_GROSS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CHECK_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-COMPANY_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-COMPANY_PLAN sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-CONTRIBUTION_ALLOCATION sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-DRSVD0 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-DRSVD1 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-DATE_OF_DEATH_YYYYMMDD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-DISBURSEMENT_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYEE_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYEE_NAME sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYEE_STATUS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYEE_TYPE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-EMPLOYMENT_TYPE_IND sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-ESTD_ANNUAL_GROSS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-ESTD_SPOUSAL_INCOME sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-FINAL_PAYCHECK_NET_AMOUNT sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-FOREIGN_EARNED_INCOME sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-FORMULA_EFFECTIVE_DATE_YYYYMMD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-GARNISHMENT_GROUP sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-GARNISHMENTS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-GROSS_UP_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-GROSS_WAGES sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-GROUP_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-HRSVD0 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-HRSVD1 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-MESSAGE_LEVEL sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-NET_WAGES sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-NUMBER_OF_GARNISHMENTS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-NUMBER_OF_TAX_ENTRIES sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PAY_FREQUENCY sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PAYMENT_TYPE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PRINCIPAL_STATE_OF_EMPLOYMENT sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PROCESS_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PROCESS_GARNISHMENTS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-PRORATION_FREQ sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-QUALIFYING_DAYS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-RRSVD0 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-RRSVD1 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-RECIPROCAL_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-RESIDENT_STATE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-ROLLOVER_ELIGIBLE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-ROLLOVER_MONTHS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-SRSVD0 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-SRSVD1 sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-STAT_EE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-STD_HOURS_IN_PAY_PERIOD sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-TAXES sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-VACATION_HOURS sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-WAGE_PROCESS_CODE sy-vline
WA_HRCUSCL_T10_TAX_CALC_RESPONSE_STR-YTD_PAY_PERIODS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.