ABAP Select data from SAP table VSLHPTKOND 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 VSLHPTKOND 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 VSLHPTKOND. 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 VSLHPTKOND 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_VSLHPTKOND TYPE STANDARD TABLE OF VSLHPTKOND, WA_VSLHPTKOND TYPE VSLHPTKOND, 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: <VSLHPTKOND> TYPE VSLHPTKOND. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VSLHPTKOND. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VSLHPTKOND INTO TABLE IT_VSLHPTKOND. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VSLHPTKOND * INTO TABLE @DATA(IT_VSLHPTKOND2). *--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_VSLHPTKOND INDEX 1 INTO DATA(WA_VSLHPTKOND2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VSLHPTKOND ASSIGNING <VSLHPTKOND>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VSLHPTKOND>-MANDT = 1.
<VSLHPTKOND>-BUKRS = 1.
<VSLHPTKOND>-RGATT = 1.
<VSLHPTKOND>-RFHA = 1.
<VSLHPTKOND>-RFHAZU = 1.
ENDLOOP. LOOP AT IT_VSLHPTKOND INTO WA_VSLHPTKOND. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VSLHPTKOND-RKONDGR, sy-vline,
WA_VSLHPTKOND-RKOND, sy-vline,
WA_VSLHPTKOND-DGUEL_KP, sy-vline,
WA_VSLHPTKOND-NSTUFE, sy-vline,
WA_VSLHPTKOND-CRUSER, sy-vline,
WA_VSLHPTKOND-DCRDAT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VSLHPTKOND 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_VSLHPTKOND 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_VSLHPTKOND INTO WA_VSLHPTKOND. *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 RGATT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VSLHPTKOND-RGATT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VSLHPTKOND-RGATT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RFHA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VSLHPTKOND-RFHA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VSLHPTKOND-RFHA.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_OF_MEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_VSLHPTKOND-UNIT_OF_MEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VSLHPTKOND-UNIT_OF_MEASURE.
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_VSLHPTKOND_STR,
MANDT TYPE STRING,
BUKRS TYPE STRING,
RGATT TYPE STRING,
RFHA TYPE STRING,
RFHAZU TYPE STRING,
RKONDGR TYPE STRING,
RKOND TYPE STRING,
DGUEL_KP TYPE STRING,
NSTUFE TYPE STRING,
CRUSER TYPE STRING,
DCRDAT TYPE STRING,
TCRTIM TYPE STRING,
UPUSER TYPE STRING,
DUPDAT TYPE STRING,
TUPTIM TYPE STRING,
SALTKOND TYPE STRING,
SZINSANP TYPE STRING,
JNULLKON TYPE STRING,
SKOART TYPE STRING,
SSIGN TYPE STRING,
SBKKLAS TYPE STRING,
SBKTYP TYPE STRING,
PKOND TYPE STRING,
BKOND TYPE STRING,
SWHRKOND TYPE STRING,
SBASIS TYPE STRING,
BBASIS TYPE STRING,
SZBMETH TYPE STRING,
SKALIDWT TYPE STRING,
SINCL TYPE STRING,
SZSREF TYPE STRING,
SFORMREF TYPE STRING,
SVARNAME TYPE STRING,
AMMRHY TYPE STRING,
ATTRHY TYPE STRING,
DVALUT TYPE STRING,
SVULT TYPE STRING,
SVWERK TYPE STRING,
SVMETH TYPE STRING,
AVGSTAGE TYPE STRING,
DFAELL TYPE STRING,
SFULT TYPE STRING,
SFWERK TYPE STRING,
SFMETH TYPE STRING,
AFGSTAGE TYPE STRING,
SDWERK TYPE STRING,
DZFEST TYPE STRING,
AZGSTAGE TYPE STRING,
DZSREF TYPE STRING,
SKALID TYPE STRING,
SKALID2 TYPE STRING,
RANTYP TYPE STRING,
SHERKUNFT TYPE STRING,
SRHYTHM TYPE STRING,
SBERFIMA TYPE STRING,
SZWERK TYPE STRING,
RHANDPL TYPE STRING,
SKURSART TYPE STRING,
SFVMETH TYPE STRING,
SERBTERM TYPE STRING,
SFRANZ TYPE STRING,
SEXCLGUEL TYPE STRING,
JSOFVERR TYPE STRING,
JEXPOZINS TYPE STRING,
SKALID3 TYPE STRING,
PPAYMENT TYPE STRING,
SZEITANT TYPE STRING,
PKOND1STPER TYPE STRING,
SREFDISC TYPE STRING,
SDISCOUNT TYPE STRING,
BROUNDUNIT TYPE STRING,
SROUND TYPE STRING,
AMMRHYZV TYPE STRING,
FACILITYLINE TYPE STRING,
BGUEL_KP TYPE STRING,
SULTGUEL TYPE STRING,
BBASISUNIT TYPE STRING,
RKONDREF TYPE STRING,
STTLM_FREQ TYPE STRING,
STTLM_FREQ_UNIT TYPE STRING,
PAYDAT_OFFS_UNIT TYPE STRING,
COMMON_PRICING TYPE STRING,
FIXING_DATE_RULE TYPE STRING,
WEEKDAY_NUMBER TYPE STRING,
WEEKDAY TYPE STRING,
AVERAGE_FREQ TYPE STRING,
QUAN TYPE STRING,
UNIT_OF_MEASURE TYPE STRING,
QUAN_RELATED_TO TYPE STRING,
REFERENCE TYPE STRING,
FX_TRANSLATION TYPE STRING,
EXCH_RATE_TYPE TYPE STRING,
CPCC_FLAG TYPE STRING,
JPROZR TYPE STRING,
SFINCL TYPE STRING,
JBMONAT TYPE STRING,
BUGRENZ TYPE STRING,
BOGRENZ TYPE STRING,
SSTAFF TYPE STRING,
LOGIC_RKOND TYPE STRING,
SKALID4 TYPE STRING,
SKALID5 TYPE STRING,
SROUNDFACTOR TYPE STRING,
ROUNDDECFACTOR TYPE STRING,
JEXPOINTFACTOR TYPE STRING,
SROUNDBASEFACTOR TYPE STRING,
ROUNDDECBASEFACTOR TYPE STRING,
SSEQUENCE TYPE STRING,
SROUNDRATEFACTOR TYPE STRING,
ROUNDDECRATEFACTOR TYPE STRING,
ADGSTAGE TYPE STRING,
JAVGCAP TYPE STRING,
PAVGCAP TYPE STRING,
JAVGFLOOR TYPE STRING,
PAVGFLOOR TYPE STRING,
PAVGSPREAD TYPE STRING,
SROUNDAVGINTEREST TYPE STRING,
ROUNDDECAVGINTEREST TYPE STRING,
SAVGWEIGHT TYPE STRING,
SFACTORRESET TYPE STRING,
JUGRENZ TYPE STRING,
JOGRENZ TYPE STRING,
INDEX_INTERPOLATE TYPE STRING,
PRICEINDEX_APPLY TYPE STRING,
INDEX_BASE_VALUE TYPE STRING,
INDEX_BASE_DATE TYPE STRING,
INDEX_FIX_DATE_HIGH TYPE STRING,
INDEX_FIX_DATE_LOW TYPE STRING,
INDEX_ADJ_DATE_RELATION TYPE STRING,
PRICEINDEX_RKONDREF TYPE STRING,
SROUNDDAYFRACTION TYPE STRING,
ROUNDDECDAYFRACTION TYPE STRING,
PRICEINDEX_COMPOUND_FREQUENCY TYPE STRING,
INDEX_FIX_DATE_DATESHIFT TYPE STRING,
INDEX_FIX_DATE_SHIFTDAYS TYPE STRING,
ARHYTM TYPE STRING,
SRHYTM TYPE STRING,
XKOART TYPE STRING,
XGUELT TYPE STRING,
XVALUT TYPE STRING,
XFAELL TYPE STRING,
XBKOND TYPE STRING,
XZBMETH TYPE STRING,
XKALIDWT TYPE STRING,
XRHYTHM TYPE STRING,
XVWERK TYPE STRING,
XFWERK TYPE STRING,
SBWGFI TYPE STRING,
SBWGAEND TYPE STRING,
SZINSKAP TYPE STRING,
SFRANZE TYPE STRING,
XRHYTM TYPE STRING,
SSELECTED TYPE STRING,
SZBMETH_FD TYPE STRING,
PKOND_FIX TYPE STRING,
BKOND_FIX TYPE STRING,END OF T_EKKO_STR. DATA: WA_VSLHPTKOND_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_VSLHPTKOND_STR-MANDT sy-vline
WA_VSLHPTKOND_STR-BUKRS sy-vline
WA_VSLHPTKOND_STR-RGATT sy-vline
WA_VSLHPTKOND_STR-RFHA sy-vline
WA_VSLHPTKOND_STR-RFHAZU sy-vline
WA_VSLHPTKOND_STR-RKONDGR sy-vline
WA_VSLHPTKOND_STR-RKOND sy-vline
WA_VSLHPTKOND_STR-DGUEL_KP sy-vline
WA_VSLHPTKOND_STR-NSTUFE sy-vline
WA_VSLHPTKOND_STR-CRUSER sy-vline
WA_VSLHPTKOND_STR-DCRDAT sy-vline
WA_VSLHPTKOND_STR-TCRTIM sy-vline
WA_VSLHPTKOND_STR-UPUSER sy-vline
WA_VSLHPTKOND_STR-DUPDAT sy-vline
WA_VSLHPTKOND_STR-TUPTIM sy-vline
WA_VSLHPTKOND_STR-SALTKOND sy-vline
WA_VSLHPTKOND_STR-SZINSANP sy-vline
WA_VSLHPTKOND_STR-JNULLKON sy-vline
WA_VSLHPTKOND_STR-SKOART sy-vline
WA_VSLHPTKOND_STR-SSIGN sy-vline
WA_VSLHPTKOND_STR-SBKKLAS sy-vline
WA_VSLHPTKOND_STR-SBKTYP sy-vline
WA_VSLHPTKOND_STR-PKOND sy-vline
WA_VSLHPTKOND_STR-BKOND sy-vline
WA_VSLHPTKOND_STR-SWHRKOND sy-vline
WA_VSLHPTKOND_STR-SBASIS sy-vline
WA_VSLHPTKOND_STR-BBASIS sy-vline
WA_VSLHPTKOND_STR-SZBMETH sy-vline
WA_VSLHPTKOND_STR-SKALIDWT sy-vline
WA_VSLHPTKOND_STR-SINCL sy-vline
WA_VSLHPTKOND_STR-SZSREF sy-vline
WA_VSLHPTKOND_STR-SFORMREF sy-vline
WA_VSLHPTKOND_STR-SVARNAME sy-vline
WA_VSLHPTKOND_STR-AMMRHY sy-vline
WA_VSLHPTKOND_STR-ATTRHY sy-vline
WA_VSLHPTKOND_STR-DVALUT sy-vline
WA_VSLHPTKOND_STR-SVULT sy-vline
WA_VSLHPTKOND_STR-SVWERK sy-vline
WA_VSLHPTKOND_STR-SVMETH sy-vline
WA_VSLHPTKOND_STR-AVGSTAGE sy-vline
WA_VSLHPTKOND_STR-DFAELL sy-vline
WA_VSLHPTKOND_STR-SFULT sy-vline
WA_VSLHPTKOND_STR-SFWERK sy-vline
WA_VSLHPTKOND_STR-SFMETH sy-vline
WA_VSLHPTKOND_STR-AFGSTAGE sy-vline
WA_VSLHPTKOND_STR-SDWERK sy-vline
WA_VSLHPTKOND_STR-DZFEST sy-vline
WA_VSLHPTKOND_STR-AZGSTAGE sy-vline
WA_VSLHPTKOND_STR-DZSREF sy-vline
WA_VSLHPTKOND_STR-SKALID sy-vline
WA_VSLHPTKOND_STR-SKALID2 sy-vline
WA_VSLHPTKOND_STR-RANTYP sy-vline
WA_VSLHPTKOND_STR-SHERKUNFT sy-vline
WA_VSLHPTKOND_STR-SRHYTHM sy-vline
WA_VSLHPTKOND_STR-SBERFIMA sy-vline
WA_VSLHPTKOND_STR-SZWERK sy-vline
WA_VSLHPTKOND_STR-RHANDPL sy-vline
WA_VSLHPTKOND_STR-SKURSART sy-vline
WA_VSLHPTKOND_STR-SFVMETH sy-vline
WA_VSLHPTKOND_STR-SERBTERM sy-vline
WA_VSLHPTKOND_STR-SFRANZ sy-vline
WA_VSLHPTKOND_STR-SEXCLGUEL sy-vline
WA_VSLHPTKOND_STR-JSOFVERR sy-vline
WA_VSLHPTKOND_STR-JEXPOZINS sy-vline
WA_VSLHPTKOND_STR-SKALID3 sy-vline
WA_VSLHPTKOND_STR-PPAYMENT sy-vline
WA_VSLHPTKOND_STR-SZEITANT sy-vline
WA_VSLHPTKOND_STR-PKOND1STPER sy-vline
WA_VSLHPTKOND_STR-SREFDISC sy-vline
WA_VSLHPTKOND_STR-SDISCOUNT sy-vline
WA_VSLHPTKOND_STR-BROUNDUNIT sy-vline
WA_VSLHPTKOND_STR-SROUND sy-vline
WA_VSLHPTKOND_STR-AMMRHYZV sy-vline
WA_VSLHPTKOND_STR-FACILITYLINE sy-vline
WA_VSLHPTKOND_STR-BGUEL_KP sy-vline
WA_VSLHPTKOND_STR-SULTGUEL sy-vline
WA_VSLHPTKOND_STR-BBASISUNIT sy-vline
WA_VSLHPTKOND_STR-RKONDREF sy-vline
WA_VSLHPTKOND_STR-STTLM_FREQ sy-vline
WA_VSLHPTKOND_STR-STTLM_FREQ_UNIT sy-vline
WA_VSLHPTKOND_STR-PAYDAT_OFFS_UNIT sy-vline
WA_VSLHPTKOND_STR-COMMON_PRICING sy-vline
WA_VSLHPTKOND_STR-FIXING_DATE_RULE sy-vline
WA_VSLHPTKOND_STR-WEEKDAY_NUMBER sy-vline
WA_VSLHPTKOND_STR-WEEKDAY sy-vline
WA_VSLHPTKOND_STR-AVERAGE_FREQ sy-vline
WA_VSLHPTKOND_STR-QUAN sy-vline
WA_VSLHPTKOND_STR-UNIT_OF_MEASURE sy-vline
WA_VSLHPTKOND_STR-QUAN_RELATED_TO sy-vline
WA_VSLHPTKOND_STR-REFERENCE sy-vline
WA_VSLHPTKOND_STR-FX_TRANSLATION sy-vline
WA_VSLHPTKOND_STR-EXCH_RATE_TYPE sy-vline
WA_VSLHPTKOND_STR-CPCC_FLAG sy-vline
WA_VSLHPTKOND_STR-JPROZR sy-vline
WA_VSLHPTKOND_STR-SFINCL sy-vline
WA_VSLHPTKOND_STR-JBMONAT sy-vline
WA_VSLHPTKOND_STR-BUGRENZ sy-vline
WA_VSLHPTKOND_STR-BOGRENZ sy-vline
WA_VSLHPTKOND_STR-SSTAFF sy-vline
WA_VSLHPTKOND_STR-LOGIC_RKOND sy-vline
WA_VSLHPTKOND_STR-SKALID4 sy-vline
WA_VSLHPTKOND_STR-SKALID5 sy-vline
WA_VSLHPTKOND_STR-SROUNDFACTOR sy-vline
WA_VSLHPTKOND_STR-ROUNDDECFACTOR sy-vline
WA_VSLHPTKOND_STR-JEXPOINTFACTOR sy-vline
WA_VSLHPTKOND_STR-SROUNDBASEFACTOR sy-vline
WA_VSLHPTKOND_STR-ROUNDDECBASEFACTOR sy-vline
WA_VSLHPTKOND_STR-SSEQUENCE sy-vline
WA_VSLHPTKOND_STR-SROUNDRATEFACTOR sy-vline
WA_VSLHPTKOND_STR-ROUNDDECRATEFACTOR sy-vline
WA_VSLHPTKOND_STR-ADGSTAGE sy-vline
WA_VSLHPTKOND_STR-JAVGCAP sy-vline
WA_VSLHPTKOND_STR-PAVGCAP sy-vline
WA_VSLHPTKOND_STR-JAVGFLOOR sy-vline
WA_VSLHPTKOND_STR-PAVGFLOOR sy-vline
WA_VSLHPTKOND_STR-PAVGSPREAD sy-vline
WA_VSLHPTKOND_STR-SROUNDAVGINTEREST sy-vline
WA_VSLHPTKOND_STR-ROUNDDECAVGINTEREST sy-vline
WA_VSLHPTKOND_STR-SAVGWEIGHT sy-vline
WA_VSLHPTKOND_STR-SFACTORRESET sy-vline
WA_VSLHPTKOND_STR-JUGRENZ sy-vline
WA_VSLHPTKOND_STR-JOGRENZ sy-vline
WA_VSLHPTKOND_STR-INDEX_INTERPOLATE sy-vline
WA_VSLHPTKOND_STR-PRICEINDEX_APPLY sy-vline
WA_VSLHPTKOND_STR-INDEX_BASE_VALUE sy-vline
WA_VSLHPTKOND_STR-INDEX_BASE_DATE sy-vline
WA_VSLHPTKOND_STR-INDEX_FIX_DATE_HIGH sy-vline
WA_VSLHPTKOND_STR-INDEX_FIX_DATE_LOW sy-vline
WA_VSLHPTKOND_STR-INDEX_ADJ_DATE_RELATION sy-vline
WA_VSLHPTKOND_STR-PRICEINDEX_RKONDREF sy-vline
WA_VSLHPTKOND_STR-SROUNDDAYFRACTION sy-vline
WA_VSLHPTKOND_STR-ROUNDDECDAYFRACTION sy-vline
WA_VSLHPTKOND_STR-PRICEINDEX_COMPOUND_FREQUENCY sy-vline
WA_VSLHPTKOND_STR-INDEX_FIX_DATE_DATESHIFT sy-vline
WA_VSLHPTKOND_STR-INDEX_FIX_DATE_SHIFTDAYS sy-vline
WA_VSLHPTKOND_STR-ARHYTM sy-vline
WA_VSLHPTKOND_STR-SRHYTM sy-vline
WA_VSLHPTKOND_STR-XKOART sy-vline
WA_VSLHPTKOND_STR-XGUELT sy-vline
WA_VSLHPTKOND_STR-XVALUT sy-vline
WA_VSLHPTKOND_STR-XFAELL sy-vline
WA_VSLHPTKOND_STR-XBKOND sy-vline
WA_VSLHPTKOND_STR-XZBMETH sy-vline
WA_VSLHPTKOND_STR-XKALIDWT sy-vline
WA_VSLHPTKOND_STR-XRHYTHM sy-vline
WA_VSLHPTKOND_STR-XVWERK sy-vline
WA_VSLHPTKOND_STR-XFWERK sy-vline
WA_VSLHPTKOND_STR-SBWGFI sy-vline
WA_VSLHPTKOND_STR-SBWGAEND sy-vline
WA_VSLHPTKOND_STR-SZINSKAP sy-vline
WA_VSLHPTKOND_STR-SFRANZE sy-vline
WA_VSLHPTKOND_STR-XRHYTM sy-vline
WA_VSLHPTKOND_STR-SSELECTED sy-vline
WA_VSLHPTKOND_STR-SZBMETH_FD sy-vline
WA_VSLHPTKOND_STR-PKOND_FIX sy-vline
WA_VSLHPTKOND_STR-BKOND_FIX sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.