ABAP Select data from SAP table HRDEPBSVASENS_LOG_P14N91_QOTB 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 HRDEPBSVASENS_LOG_P14N91_QOTB 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 HRDEPBSVASENS_LOG_P14N91_QOTB. 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 HRDEPBSVASENS_LOG_P14N91_QOTB 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_HRDEPBSVASENS_LOG_P14N91_QOTB TYPE STANDARD TABLE OF HRDEPBSVASENS_LOG_P14N91_QOTB,
      WA_HRDEPBSVASENS_LOG_P14N91_QOTB TYPE HRDEPBSVASENS_LOG_P14N91_QOTB,
      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: <HRDEPBSVASENS_LOG_P14N91_QOTB> TYPE HRDEPBSVASENS_LOG_P14N91_QOTB.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM HRDEPBSVASENS_LOG_P14N91_QOTB
*  INTO TABLE @DATA(IT_HRDEPBSVASENS_LOG_P14N91_QOTB2).
*--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_HRDEPBSVASENS_LOG_P14N91_QOTB INDEX 1 INTO DATA(WA_HRDEPBSVASENS_LOG_P14N91_QOTB2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_HRDEPBSVASENS_LOG_P14N91_QOTB ASSIGNING <HRDEPBSVASENS_LOG_P14N91_QOTB>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<HRDEPBSVASENS_LOG_P14N91_QOTB>-QOL_RDET = 1.
<HRDEPBSVASENS_LOG_P14N91_QOTB>-IST_AUSBILDUNG = 1.
<HRDEPBSVASENS_LOG_P14N91_QOTB>-IST_ZURECHNUNG = 1.
<HRDEPBSVASENS_LOG_P14N91_QOTB>-CALYYF97 = 1.
<HRDEPBSVASENS_LOG_P14N91_QOTB>-CALMMF97 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_HRDEPBSVASENS_LOG_P14N91_QOTB-CALDDF97, sy-vline,
WA_HRDEPBSVASENS_LOG_P14N91_QOTB-QOL_REAS, sy-vline,
WA_HRDEPBSVASENS_LOG_P14N91_QOTB-QOL_1ST_F97, sy-vline,
WA_HRDEPBSVASENS_LOG_P14N91_QOTB-QOL_CGL_NUMER, sy-vline,
WA_HRDEPBSVASENS_LOG_P14N91_QOTB-JAHRERYD, sy-vline,
WA_HRDEPBSVASENS_LOG_P14N91_QOTB-TAGERYD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_HRDEPBSVASENS_LOG_P14N91_QOTB 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_HRDEPBSVASENS_LOG_P14N91_QOTB 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_HRDEPBSVASENS_LOG_P14N91_QOTB INTO WA_HRDEPBSVASENS_LOG_P14N91_QOTB. *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_HRDEPBSVASENS_LOG_P14N91_QOTB_STR,
QOL_RDET TYPE STRING,
IST_AUSBILDUNG TYPE STRING,
IST_ZURECHNUNG TYPE STRING,
CALYYF97 TYPE STRING,
CALMMF97 TYPE STRING,
CALDDF97 TYPE STRING,
QOL_REAS TYPE STRING,
QOL_1ST_F97 TYPE STRING,
QOL_CGL_NUMER TYPE STRING,
JAHRERYD TYPE STRING,
TAGERYD TYPE STRING,
CVDDY TYPE STRING,
CVYDY TYPE STRING,
QOL_CGL_DENOM TYPE STRING,
JAHRERYD TYPE STRING,
TAGERYD TYPE STRING,
CVDDY TYPE STRING,
CVYDY TYPE STRING,
QOA_RDET TYPE STRING,
IST_AUSBILDUNG TYPE STRING,
QOA_KIND TYPE STRING,
QOA_MIND_DET TYPE STRING,
QOA_MIND TYPE STRING,
CALYY TYPE STRING,
CALMM TYPE STRING,
CALDD TYPE STRING,
QOA_CGL_NUMER TYPE STRING,
JAHRERYD TYPE STRING,
TAGERYD TYPE STRING,
CVDDY TYPE STRING,
CVYDY TYPE STRING,
QOA_CGL_DENOM TYPE STRING,
JAHRERYD TYPE STRING,
TAGERYD TYPE STRING,
CVDDY TYPE STRING,
CVYDY TYPE STRING,END OF T_EKKO_STR. DATA: WA_HRDEPBSVASENS_LOG_P14N91_QOTB_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_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOL_RDET sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-IST_AUSBILDUNG sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-IST_ZURECHNUNG sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALYYF97 sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALMMF97 sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALDDF97 sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOL_REAS sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOL_1ST_F97 sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOL_CGL_NUMER sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-JAHRERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-TAGERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVDDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVYDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOL_CGL_DENOM sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-JAHRERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-TAGERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVDDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVYDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_RDET sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-IST_AUSBILDUNG sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_KIND sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_MIND_DET sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_MIND sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALYY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALMM sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CALDD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_CGL_NUMER sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-JAHRERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-TAGERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVDDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVYDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-QOA_CGL_DENOM sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-JAHRERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-TAGERYD sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVDDY sy-vline
WA_HRDEPBSVASENS_LOG_P14N91_QOTB_STR-CVYDY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.