ABAP Select data from SAP table HRMS_BIW_PY_REC1_NEW 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 HRMS_BIW_PY_REC1_NEW 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 HRMS_BIW_PY_REC1_NEW. 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 HRMS_BIW_PY_REC1_NEW 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_HRMS_BIW_PY_REC1_NEW TYPE STANDARD TABLE OF HRMS_BIW_PY_REC1_NEW,
      WA_HRMS_BIW_PY_REC1_NEW TYPE HRMS_BIW_PY_REC1_NEW,
      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: <HRMS_BIW_PY_REC1_NEW> TYPE HRMS_BIW_PY_REC1_NEW.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM HRMS_BIW_PY_REC1_NEW
*  INTO TABLE @DATA(IT_HRMS_BIW_PY_REC1_NEW2).
*--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_HRMS_BIW_PY_REC1_NEW INDEX 1 INTO DATA(WA_HRMS_BIW_PY_REC1_NEW2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_HRMS_BIW_PY_REC1_NEW ASSIGNING <HRMS_BIW_PY_REC1_NEW>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<HRMS_BIW_PY_REC1_NEW>-PYPER = 1.
<HRMS_BIW_PY_REC1_NEW>-PERNR = 1.
<HRMS_BIW_PY_REC1_NEW>-PERSONID_EXT = 1.
<HRMS_BIW_PY_REC1_NEW>-GRPVL = 1.
<HRMS_BIW_PY_REC1_NEW>-MAIN_PERNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_HRMS_BIW_PY_REC1_NEW-MOLGA, sy-vline,
WA_HRMS_BIW_PY_REC1_NEW-LGART, sy-vline,
WA_HRMS_BIW_PY_REC1_NEW-ORG_UNIT_WP, sy-vline,
WA_HRMS_BIW_PY_REC1_NEW-JOB_WP, sy-vline,
WA_HRMS_BIW_PY_REC1_NEW-POSITION_WP, sy-vline,
WA_HRMS_BIW_PY_REC1_NEW-PERS_AREA_WP, sy-vline.
ENDLOOP. *Add any further fields from structure WA_HRMS_BIW_PY_REC1_NEW 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_HRMS_BIW_PY_REC1_NEW 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_HRMS_BIW_PY_REC1_NEW INTO WA_HRMS_BIW_PY_REC1_NEW. *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 PIDEX, internal->external for field PERSONID_EXT CALL FUNCTION 'CONVERSION_EXIT_PIDEX_OUTPUT' EXPORTING input = WA_HRMS_BIW_PY_REC1_NEW-PERSONID_EXT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_HRMS_BIW_PY_REC1_NEW-PERSONID_EXT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit ABPSP, internal->external for field POSNR CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_HRMS_BIW_PY_REC1_NEW-POSNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_HRMS_BIW_PY_REC1_NEW-POSNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit FMCIL, internal->external for field FIPEX CALL FUNCTION 'CONVERSION_EXIT_FMCIL_OUTPUT' EXPORTING input = WA_HRMS_BIW_PY_REC1_NEW-FIPEX IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_HRMS_BIW_PY_REC1_NEW-FIPEX.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ALPHA, internal->external for field KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_HRMS_BIW_PY_REC1_NEW-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_HRMS_BIW_PY_REC1_NEW-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_HRMS_BIW_PY_REC1_NEW_STR,
PYPER TYPE STRING,
PERNR TYPE STRING,
PERSONID_EXT TYPE STRING,
GRPVL TYPE STRING,
MAIN_PERNR TYPE STRING,
MOLGA TYPE STRING,
LGART TYPE STRING,
ORG_UNIT_WP TYPE STRING,
JOB_WP TYPE STRING,
POSITION_WP TYPE STRING,
PERS_AREA_WP TYPE STRING,
PERS_SUBAREA_WP TYPE STRING,
EMPL_GROUP_WP TYPE STRING,
EMPL_SUBGROUP_WP TYPE STRING,
CO_AREA_WP TYPE STRING,
COSTCENTER_WP TYPE STRING,
COMP_CODE_WP TYPE STRING,
BUS_AREA_WP TYPE STRING,
TIME_STATUS_WP TYPE STRING,
FM_AREA_WP TYPE STRING,
FUND_WP TYPE STRING,
FUNC_AREA_WP TYPE STRING,
GRANT_NBR_WP TYPE STRING,
FISTL_WP TYPE STRING,
BUDGET_PD_WP TYPE STRING,
ANZHL TYPE STRING,
BETRG TYPE STRING,
WAERS TYPE STRING,
APZNR TYPE STRING,
CNTR1 TYPE STRING,
CNTR2 TYPE STRING,
CNTR3 TYPE STRING,
C1ZNR TYPE STRING,
EG_ACCDET TYPE STRING,
EG_MO_FIX TYPE STRING,
V0TYP TYPE STRING,
V0ZNR TYPE STRING,
SEQNR TYPE STRING,
FPPER TYPE STRING,
INPER TYPE STRING,
FPBEG TYPE STRING,
FPEND TYPE STRING,
SRTZA TYPE STRING,
ABKRS TYPE STRING,
VOID TYPE STRING,
JUPER TYPE STRING,
PAYTY TYPE STRING,
RUNDT TYPE STRING,
PAYDT TYPE STRING,
PAYID TYPE STRING,
BONDT TYPE STRING,
IPERM TYPE STRING,
OCRSN TYPE STRING,
KOKRS_C1 TYPE STRING,
GSBER_C1 TYPE STRING,
KOSTL_C1 TYPE STRING,
BUKRS_C1 TYPE STRING,
NPLNR_C1 TYPE STRING,
AUFNR_C1 TYPE STRING,
EXBEL_C1 TYPE STRING,
POSNR TYPE STRING,
FIPEX TYPE STRING,
FIKRS_FUND TYPE STRING,
GEBER TYPE STRING,
FISTL TYPE STRING,
PROZT TYPE STRING,
FDSEQNO TYPE STRING,
C0SEQNO TYPE STRING,
AUSART_FUND TYPE STRING,
IPEND TYPE STRING,
WP_BEGDA TYPE STRING,
WP_ENDDA TYPE STRING,
SEGMENT TYPE STRING,
BUKRS TYPE STRING,
GSBER TYPE STRING,
KOKRS TYPE STRING,
KOSTL TYPE STRING,
REUSE1 TYPE STRING,
REUSE2 TYPE STRING,
REUSE3 TYPE STRING,
REUSE4 TYPE STRING,
REUSE5 TYPE STRING,END OF T_EKKO_STR. DATA: WA_HRMS_BIW_PY_REC1_NEW_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_HRMS_BIW_PY_REC1_NEW_STR-PYPER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PERNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PERSONID_EXT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-GRPVL sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-MAIN_PERNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-MOLGA sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-LGART sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-ORG_UNIT_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-JOB_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-POSITION_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PERS_AREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PERS_SUBAREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-EMPL_GROUP_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-EMPL_SUBGROUP_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-CO_AREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-COSTCENTER_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-COMP_CODE_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BUS_AREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-TIME_STATUS_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FM_AREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FUND_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FUNC_AREA_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-GRANT_NBR_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FISTL_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BUDGET_PD_WP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-ANZHL sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BETRG sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-WAERS sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-APZNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-CNTR1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-CNTR2 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-CNTR3 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-C1ZNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-EG_ACCDET sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-EG_MO_FIX sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-V0TYP sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-V0ZNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-SEQNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FPPER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-INPER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FPBEG sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FPEND sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-SRTZA sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-ABKRS sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-VOID sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-JUPER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PAYTY sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-RUNDT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PAYDT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PAYID sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BONDT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-IPERM sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-OCRSN sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-KOKRS_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-GSBER_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-KOSTL_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BUKRS_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-NPLNR_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-AUFNR_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-EXBEL_C1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-POSNR sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FIPEX sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FIKRS_FUND sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-GEBER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FISTL sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-PROZT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-FDSEQNO sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-C0SEQNO sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-AUSART_FUND sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-IPEND sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-WP_BEGDA sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-WP_ENDDA sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-SEGMENT sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-BUKRS sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-GSBER sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-KOKRS sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-KOSTL sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-REUSE1 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-REUSE2 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-REUSE3 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-REUSE4 sy-vline
WA_HRMS_BIW_PY_REC1_NEW_STR-REUSE5 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.