ABAP Select data from SAP table HRPAYDETM_KTRUECKST_OUT 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 HRPAYDETM_KTRUECKST_OUT 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 HRPAYDETM_KTRUECKST_OUT. 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 HRPAYDETM_KTRUECKST_OUT 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_HRPAYDETM_KTRUECKST_OUT TYPE STANDARD TABLE OF HRPAYDETM_KTRUECKST_OUT,
      WA_HRPAYDETM_KTRUECKST_OUT TYPE HRPAYDETM_KTRUECKST_OUT,
      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: <HRPAYDETM_KTRUECKST_OUT> TYPE HRPAYDETM_KTRUECKST_OUT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM HRPAYDETM_KTRUECKST_OUT
*  INTO TABLE @DATA(IT_HRPAYDETM_KTRUECKST_OUT2).
*--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_HRPAYDETM_KTRUECKST_OUT INDEX 1 INTO DATA(WA_HRPAYDETM_KTRUECKST_OUT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_HRPAYDETM_KTRUECKST_OUT ASSIGNING <HRPAYDETM_KTRUECKST_OUT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<HRPAYDETM_KTRUECKST_OUT>-DETAIL = 1.
<HRPAYDETM_KTRUECKST_OUT>-KOKRS = 1.
<HRPAYDETM_KTRUECKST_OUT>-KOKRS_TXT = 1.
<HRPAYDETM_KTRUECKST_OUT>-KOSTL = 1.
<HRPAYDETM_KTRUECKST_OUT>-KOSTL_TXT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_HRPAYDETM_KTRUECKST_OUT-BUKRS, sy-vline,
WA_HRPAYDETM_KTRUECKST_OUT-BUKRS_TXT, sy-vline,
WA_HRPAYDETM_KTRUECKST_OUT-SACHA, sy-vline,
WA_HRPAYDETM_KTRUECKST_OUT-SACHA_TXT, sy-vline,
WA_HRPAYDETM_KTRUECKST_OUT-SACHP, sy-vline,
WA_HRPAYDETM_KTRUECKST_OUT-SACHP_TXT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_HRPAYDETM_KTRUECKST_OUT 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_HRPAYDETM_KTRUECKST_OUT 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_HRPAYDETM_KTRUECKST_OUT INTO WA_HRPAYDETM_KTRUECKST_OUT. *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 KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_HRPAYDETM_KTRUECKST_OUT-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_HRPAYDETM_KTRUECKST_OUT-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_HRPAYDETM_KTRUECKST_OUT_STR,
DETAIL TYPE STRING,
KOKRS TYPE STRING,
KOKRS_TXT TYPE STRING,
KOSTL TYPE STRING,
KOSTL_TXT TYPE STRING,
BUKRS TYPE STRING,
BUKRS_TXT TYPE STRING,
SACHA TYPE STRING,
SACHA_TXT TYPE STRING,
SACHP TYPE STRING,
SACHP_TXT TYPE STRING,
PERNR TYPE STRING,
ENAME TYPE STRING,
JUPER TYPE STRING,
WERKS TYPE STRING,
WERKS_TXT TYPE STRING,
BTRTL TYPE STRING,
BTRTL_TXT TYPE STRING,
PERSG TYPE STRING,
PERSG_TXT TYPE STRING,
PERSK TYPE STRING,
PERSK_TXT TYPE STRING,
QUOUN TYPE STRING,
UNTEXT TYPE STRING,
ENTITLE TYPE STRING,
REST TYPE STRING,
ENTIREDU TYPE STRING,
RESTREDU TYPE STRING,
NKPUN TYPE STRING,
RSPUN TYPE STRING,
BWTOT TYPE STRING,
NKTOT TYPE STRING,
RSTOT TYPE STRING,
AZDPP TYPE STRING,
AZHPP TYPE STRING,
NKPRZ TYPE STRING,END OF T_EKKO_STR. DATA: WA_HRPAYDETM_KTRUECKST_OUT_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_HRPAYDETM_KTRUECKST_OUT_STR-DETAIL sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-KOKRS sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-KOKRS_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-KOSTL sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-KOSTL_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-BUKRS sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-BUKRS_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-SACHA sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-SACHA_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-SACHP sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-SACHP_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-PERNR sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-ENAME sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-JUPER sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-WERKS sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-WERKS_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-BTRTL sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-BTRTL_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-PERSG sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-PERSG_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-PERSK sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-PERSK_TXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-QUOUN sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-UNTEXT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-ENTITLE sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-REST sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-ENTIREDU sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-RESTREDU sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-NKPUN sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-RSPUN sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-BWTOT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-NKTOT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-RSTOT sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-AZDPP sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-AZHPP sy-vline
WA_HRPAYDETM_KTRUECKST_OUT_STR-NKPRZ sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.