ABAP Select data from SAP table HRCUSCL_T11_EMPLOYEE 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_T11_EMPLOYEE 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_T11_EMPLOYEE. 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_T11_EMPLOYEE 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_T11_EMPLOYEE TYPE STANDARD TABLE OF HRCUSCL_T11_EMPLOYEE,
      WA_HRCUSCL_T11_EMPLOYEE TYPE HRCUSCL_T11_EMPLOYEE,
      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_T11_EMPLOYEE> TYPE HRCUSCL_T11_EMPLOYEE.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM HRCUSCL_T11_EMPLOYEE
*  INTO TABLE @DATA(IT_HRCUSCL_T11_EMPLOYEE2).
*--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_T11_EMPLOYEE INDEX 1 INTO DATA(WA_HRCUSCL_T11_EMPLOYEE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_HRCUSCL_T11_EMPLOYEE ASSIGNING <HRCUSCL_T11_EMPLOYEE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<HRCUSCL_T11_EMPLOYEE>-CONTROLLER = 1.
<HRCUSCL_T11_EMPLOYEE>-AVERAGE_WEEKLY_GROSS = 1.
<HRCUSCL_T11_EMPLOYEE>-BIRTH_DATE_YYYYMMDD = 1.
<HRCUSCL_T11_EMPLOYEE>-CRSVD0 = 1.
<HRCUSCL_T11_EMPLOYEE>-CRSVD1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_HRCUSCL_T11_EMPLOYEE-CALCULATED_LOCAL_TAX_IN, sy-vline,
WA_HRCUSCL_T11_EMPLOYEE-CALCULATED_PERIOD_GROSS, sy-vline,
WA_HRCUSCL_T11_EMPLOYEE-CHECK_DATE_YYYYMMDD, sy-vline,
WA_HRCUSCL_T11_EMPLOYEE-COMPANY_CODE, sy-vline,
WA_HRCUSCL_T11_EMPLOYEE-COMPANY_PLAN, sy-vline,
WA_HRCUSCL_T11_EMPLOYEE-CONTRIBUTION_ALLOCATION, sy-vline.
ENDLOOP. *Add any further fields from structure WA_HRCUSCL_T11_EMPLOYEE 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_T11_EMPLOYEE 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_T11_EMPLOYEE INTO WA_HRCUSCL_T11_EMPLOYEE. *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_T11_EMPLOYEE_STR,
CONTROLLER TYPE STRING,
AVERAGE_WEEKLY_GROSS TYPE STRING,
BIRTH_DATE_YYYYMMDD TYPE STRING,
CRSVD0 TYPE STRING,
CRSVD1 TYPE STRING,
CALCULATED_LOCAL_TAX_IN 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,
DRSVD2 TYPE STRING,
DRSVD3 TYPE STRING,
DRSVD4 TYPE STRING,
DRSVD5 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,
EXEMPT_MILITARY_LOCATION 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,
RRSVD2 TYPE STRING,
RRSVD3 TYPE STRING,
RRSVD4 TYPE STRING,
RRSVD5 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,
UNEMPLOYED_DAYS TYPE STRING,
VACATION_HOURS TYPE STRING,
WAGE_PROCESS_CODE TYPE STRING,
YTD_PAY_PERIODS TYPE STRING,END OF T_EKKO_STR. DATA: WA_HRCUSCL_T11_EMPLOYEE_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_T11_EMPLOYEE_STR-CONTROLLER sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-AVERAGE_WEEKLY_GROSS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-BIRTH_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CRSVD0 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CRSVD1 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CALCULATED_LOCAL_TAX_IN sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CALCULATED_PERIOD_GROSS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CHECK_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-COMPANY_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-COMPANY_PLAN sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-CONTRIBUTION_ALLOCATION sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD0 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD1 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD2 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD3 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD4 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DRSVD5 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DATE_OF_DEATH_YYYYMMDD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-DISBURSEMENT_DATE_YYYYMMDD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EMPLOYEE_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EMPLOYEE_NAME sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EMPLOYEE_STATUS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EMPLOYEE_TYPE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EMPLOYMENT_TYPE_IND sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-ESTD_ANNUAL_GROSS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-ESTD_SPOUSAL_INCOME sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-EXEMPT_MILITARY_LOCATION sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-FINAL_PAYCHECK_NET_AMOUNT sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-FOREIGN_EARNED_INCOME sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-FORMULA_EFFECTIVE_DATE_YYYYMMD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-GARNISHMENT_GROUP sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-GARNISHMENTS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-GROSS_UP_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-GROSS_WAGES sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-GROUP_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-HRSVD0 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-HRSVD1 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-MESSAGE_LEVEL sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-NET_WAGES sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-NUMBER_OF_GARNISHMENTS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-NUMBER_OF_TAX_ENTRIES sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PAY_FREQUENCY sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PAYMENT_TYPE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PRINCIPAL_STATE_OF_EMPLOYMENT sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PROCESS_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PROCESS_GARNISHMENTS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-PRORATION_FREQ sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-QUALIFYING_DAYS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD0 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD1 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD2 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD3 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD4 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RRSVD5 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RECIPROCAL_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-RESIDENT_STATE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-ROLLOVER_ELIGIBLE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-ROLLOVER_MONTHS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-SRSVD0 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-SRSVD1 sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-STAT_EE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-STD_HOURS_IN_PAY_PERIOD sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-TAXES sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-UNEMPLOYED_DAYS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-VACATION_HOURS sy-vline
WA_HRCUSCL_T11_EMPLOYEE_STR-WAGE_PROCESS_CODE sy-vline
WA_HRCUSCL_T11_EMPLOYEE_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.