ABAP Select data from SAP table RJBTKVR 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 RJBTKVR 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 RJBTKVR. 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 RJBTKVR 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_RJBTKVR TYPE STANDARD TABLE OF RJBTKVR, WA_RJBTKVR TYPE RJBTKVR, 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: <RJBTKVR> TYPE RJBTKVR. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_RJBTKVR. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM RJBTKVR INTO TABLE IT_RJBTKVR. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM RJBTKVR * INTO TABLE @DATA(IT_RJBTKVR2). *--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_RJBTKVR INDEX 1 INTO DATA(WA_RJBTKVR2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_RJBTKVR ASSIGNING <RJBTKVR>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<RJBTKVR>-MANDT = 1.
<RJBTKVR>-RKALRG = 1.
<RJBTKVR>-SGSART = 1.
<RJBTKVR>-SKALRT = 1.
<RJBTKVR>-SAKPAS = 1.
ENDLOOP. LOOP AT IT_RJBTKVR INTO WA_RJBTKVR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_RJBTKVR-SBILRL, sy-vline,
WA_RJBTKVR-SZSTRM, sy-vline,
WA_RJBTKVR-SDSVOL, sy-vline,
WA_RJBTKVR-SZINKO, sy-vline,
WA_RJBTKVR-SZINBE, sy-vline,
WA_RJBTKVR-SOPPBE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RJBTKVR 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_RJBTKVR 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_RJBTKVR INTO WA_RJBTKVR. *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_RJBTKVR_STR,
MANDT TYPE STRING,
RKALRG TYPE STRING,
SGSART TYPE STRING,
SKALRT TYPE STRING,
SAKPAS TYPE STRING,
SBILRL TYPE STRING,
SZSTRM TYPE STRING,
SDSVOL TYPE STRING,
SZINKO TYPE STRING,
SZINBE TYPE STRING,
SOPPBE TYPE STRING,
SOPPZS TYPE STRING,
NOZZTE TYPE STRING,
XOZZTE TYPE STRING,
NOZDSP TYPE STRING,
BSTRA TYPE STRING,
SRUECK TYPE STRING,
SSALBL TYPE STRING,
SEZDUR TYPE STRING,
SWATRA TYPE STRING,
SMINRK TYPE STRING,
SMBWPR TYPE STRING,
SBWVOL TYPE STRING,
SABRKA TYPE STRING,
SMARBW TYPE STRING,
SWTBBW TYPE STRING,
SKNVOL TYPE STRING,
SMKVOL TYPE STRING,
SOPVOL TYPE STRING,
SOPKOS TYPE STRING,
SKVBER TYPE STRING,
SGLDKR TYPE STRING,
SRKUGV TYPE STRING,
SSKUGV TYPE STRING,
SANLF TYPE STRING,
SERTRZ TYPE STRING,
SHKOBE TYPE STRING,
SDISAB TYPE STRING,
RKURSA TYPE STRING,
RKURST TYPE STRING,
RKURSG TYPE STRING,
RKURSB TYPE STRING,
SZKART TYPE STRING,
SZKAT1 TYPE STRING,
SZKAT2 TYPE STRING,
SLEIST TYPE STRING,
RUKRST TYPE STRING,
SOPPSU TYPE STRING,
BEINWE TYPE STRING,
SOPPKD TYPE STRING,
RVOLAG TYPE STRING,
RVOLAB TYPE STRING,
SFEVER TYPE STRING,
SEFFZS TYPE STRING,
SOPPBH TYPE STRING,
SOPPZH TYPE STRING,
NOZZTH TYPE STRING,
XOZZTH TYPE STRING,
NOZDSH TYPE STRING,
SPRPAY TYPE STRING,
SDURAT TYPE STRING,
SOPPER TYPE STRING,
AUSWT TYPE STRING,
SRKUGVB TYPE STRING,
SUXAL1 TYPE STRING,
SUXAL2 TYPE STRING,
SUXAL3 TYPE STRING,
SUXAL4 TYPE STRING,
RHANDPL TYPE STRING,
SNOMOZ TYPE STRING,
SKUGVS TYPE STRING,
SOPBAS TYPE STRING,
SSPRDS TYPE STRING,
SEGEPBW TYPE STRING,
SEGEPBE TYPE STRING,
ORIGIN TYPE STRING,
INTINV_ENABLED TYPE STRING,
INTINV_YILDCRVTP TYPE STRING,
INTINV_TRMNRUNTS TYPE STRING,
INTINV_TRMUNIT TYPE STRING,
INTINV_INTRPLT TYPE STRING,
INTINV_INCLINTCO TYPE STRING,
PERIOD_COMM_INTR TYPE STRING,
XTEXT TYPE STRING,END OF T_EKKO_STR. DATA: WA_RJBTKVR_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_RJBTKVR_STR-MANDT sy-vline
WA_RJBTKVR_STR-RKALRG sy-vline
WA_RJBTKVR_STR-SGSART sy-vline
WA_RJBTKVR_STR-SKALRT sy-vline
WA_RJBTKVR_STR-SAKPAS sy-vline
WA_RJBTKVR_STR-SBILRL sy-vline
WA_RJBTKVR_STR-SZSTRM sy-vline
WA_RJBTKVR_STR-SDSVOL sy-vline
WA_RJBTKVR_STR-SZINKO sy-vline
WA_RJBTKVR_STR-SZINBE sy-vline
WA_RJBTKVR_STR-SOPPBE sy-vline
WA_RJBTKVR_STR-SOPPZS sy-vline
WA_RJBTKVR_STR-NOZZTE sy-vline
WA_RJBTKVR_STR-XOZZTE sy-vline
WA_RJBTKVR_STR-NOZDSP sy-vline
WA_RJBTKVR_STR-BSTRA sy-vline
WA_RJBTKVR_STR-SRUECK sy-vline
WA_RJBTKVR_STR-SSALBL sy-vline
WA_RJBTKVR_STR-SEZDUR sy-vline
WA_RJBTKVR_STR-SWATRA sy-vline
WA_RJBTKVR_STR-SMINRK sy-vline
WA_RJBTKVR_STR-SMBWPR sy-vline
WA_RJBTKVR_STR-SBWVOL sy-vline
WA_RJBTKVR_STR-SABRKA sy-vline
WA_RJBTKVR_STR-SMARBW sy-vline
WA_RJBTKVR_STR-SWTBBW sy-vline
WA_RJBTKVR_STR-SKNVOL sy-vline
WA_RJBTKVR_STR-SMKVOL sy-vline
WA_RJBTKVR_STR-SOPVOL sy-vline
WA_RJBTKVR_STR-SOPKOS sy-vline
WA_RJBTKVR_STR-SKVBER sy-vline
WA_RJBTKVR_STR-SGLDKR sy-vline
WA_RJBTKVR_STR-SRKUGV sy-vline
WA_RJBTKVR_STR-SSKUGV sy-vline
WA_RJBTKVR_STR-SANLF sy-vline
WA_RJBTKVR_STR-SERTRZ sy-vline
WA_RJBTKVR_STR-SHKOBE sy-vline
WA_RJBTKVR_STR-SDISAB sy-vline
WA_RJBTKVR_STR-RKURSA sy-vline
WA_RJBTKVR_STR-RKURST sy-vline
WA_RJBTKVR_STR-RKURSG sy-vline
WA_RJBTKVR_STR-RKURSB sy-vline
WA_RJBTKVR_STR-SZKART sy-vline
WA_RJBTKVR_STR-SZKAT1 sy-vline
WA_RJBTKVR_STR-SZKAT2 sy-vline
WA_RJBTKVR_STR-SLEIST sy-vline
WA_RJBTKVR_STR-RUKRST sy-vline
WA_RJBTKVR_STR-SOPPSU sy-vline
WA_RJBTKVR_STR-BEINWE sy-vline
WA_RJBTKVR_STR-SOPPKD sy-vline
WA_RJBTKVR_STR-RVOLAG sy-vline
WA_RJBTKVR_STR-RVOLAB sy-vline
WA_RJBTKVR_STR-SFEVER sy-vline
WA_RJBTKVR_STR-SEFFZS sy-vline
WA_RJBTKVR_STR-SOPPBH sy-vline
WA_RJBTKVR_STR-SOPPZH sy-vline
WA_RJBTKVR_STR-NOZZTH sy-vline
WA_RJBTKVR_STR-XOZZTH sy-vline
WA_RJBTKVR_STR-NOZDSH sy-vline
WA_RJBTKVR_STR-SPRPAY sy-vline
WA_RJBTKVR_STR-SDURAT sy-vline
WA_RJBTKVR_STR-SOPPER sy-vline
WA_RJBTKVR_STR-AUSWT sy-vline
WA_RJBTKVR_STR-SRKUGVB sy-vline
WA_RJBTKVR_STR-SUXAL1 sy-vline
WA_RJBTKVR_STR-SUXAL2 sy-vline
WA_RJBTKVR_STR-SUXAL3 sy-vline
WA_RJBTKVR_STR-SUXAL4 sy-vline
WA_RJBTKVR_STR-RHANDPL sy-vline
WA_RJBTKVR_STR-SNOMOZ sy-vline
WA_RJBTKVR_STR-SKUGVS sy-vline
WA_RJBTKVR_STR-SOPBAS sy-vline
WA_RJBTKVR_STR-SSPRDS sy-vline
WA_RJBTKVR_STR-SEGEPBW sy-vline
WA_RJBTKVR_STR-SEGEPBE sy-vline
WA_RJBTKVR_STR-ORIGIN sy-vline
WA_RJBTKVR_STR-INTINV_ENABLED sy-vline
WA_RJBTKVR_STR-INTINV_YILDCRVTP sy-vline
WA_RJBTKVR_STR-INTINV_TRMNRUNTS sy-vline
WA_RJBTKVR_STR-INTINV_TRMUNIT sy-vline
WA_RJBTKVR_STR-INTINV_INTRPLT sy-vline
WA_RJBTKVR_STR-INTINV_INCLINTCO sy-vline
WA_RJBTKVR_STR-PERIOD_COMM_INTR sy-vline
WA_RJBTKVR_STR-XTEXT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.