ABAP Select data from SAP table VVZZKOPO 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 VVZZKOPO 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 VVZZKOPO. 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 VVZZKOPO 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_VVZZKOPO TYPE STANDARD TABLE OF VVZZKOPO, WA_VVZZKOPO TYPE VVZZKOPO, 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: <VVZZKOPO> TYPE VVZZKOPO. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_VVZZKOPO. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM VVZZKOPO INTO TABLE IT_VVZZKOPO. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM VVZZKOPO * INTO TABLE @DATA(IT_VVZZKOPO2). *--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_VVZZKOPO INDEX 1 INTO DATA(WA_VVZZKOPO2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_VVZZKOPO ASSIGNING <VVZZKOPO>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<VVZZKOPO>-MANDT = 1.
<VVZZKOPO>-BUKRS = 1.
<VVZZKOPO>-SANLF = 1.
<VVZZKOPO>-RKEY1 = 1.
<VVZZKOPO>-RKEY2 = 1.
ENDLOOP. LOOP AT IT_VVZZKOPO INTO WA_VVZZKOPO. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_VVZZKOPO-RKEY3, sy-vline,
WA_VVZZKOPO-DGUEL_KK, sy-vline,
WA_VVZZKOPO-NLFD_ANG, sy-vline,
WA_VVZZKOPO-SKOART, sy-vline,
WA_VVZZKOPO-DGUEL_KP, sy-vline,
WA_VVZZKOPO-NSTUFE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_VVZZKOPO 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_VVZZKOPO 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_VVZZKOPO INTO WA_VVZZKOPO. *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 KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VVZZKOPO-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VVZZKOPO-KUNNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SPARTNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VVZZKOPO-SPARTNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VVZZKOPO-SPARTNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field KURS1 CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_VVZZKOPO-KURS1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VVZZKOPO-KURS1.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VVZZKOPO-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VVZZKOPO-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_VVZZKOPO-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_VVZZKOPO-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_VVZZKOPO_STR,
MANDT TYPE STRING,
BUKRS TYPE STRING,
SANLF TYPE STRING,
RKEY1 TYPE STRING,
RKEY2 TYPE STRING,
RKEY3 TYPE STRING,
DGUEL_KK TYPE STRING,
NLFD_ANG TYPE STRING,
SKOART TYPE STRING,
DGUEL_KP TYPE STRING,
NSTUFE TYPE STRING,
XKOARTM TYPE STRING,
SSTATI TYPE STRING,
PKOND TYPE STRING,
BKOND TYPE STRING,
SWHRKOND TYPE STRING,
SBASIS TYPE STRING,
SZSREF TYPE STRING,
SZSREFVZ TYPE STRING,
PFLUCT TYPE STRING,
AMMRHY TYPE STRING,
ATTRHY TYPE STRING,
SZAWS TYPE STRING,
RDIVNR TYPE STRING,
JNULLKON TYPE STRING,
MWSKZ TYPE STRING,
JBMONAT TYPE STRING,
DVALUT TYPE STRING,
DFAELL TYPE STRING,
KUNNR TYPE STRING,
ZLSCH TYPE STRING,
BVTYP TYPE STRING,
MABER TYPE STRING,
SPARTNR TYPE STRING,
RKONT TYPE STRING,
SVULT TYPE STRING,
SFULT TYPE STRING,
SVKALRI TYPE STRING,
SFKALRI TYPE STRING,
AVGSTAGE TYPE STRING,
AFGSTAGE TYPE STRING,
SVKALZUS TYPE STRING,
SFKALZUS TYPE STRING,
SKALID TYPE STRING,
SZBMETH TYPE STRING,
JSOFVERR TYPE STRING,
DALLGEM TYPE STRING,
SZEGEN TYPE STRING,
SBUST TYPE STRING,
SKOPO TYPE STRING,
SALTKOND TYPE STRING,
SZINSANP TYPE STRING,
SINCL TYPE STRING,
SFORMREF TYPE STRING,
SVARNAME TYPE STRING,
SVWERK TYPE STRING,
SVMETH TYPE STRING,
SFWERK TYPE STRING,
SFMETH TYPE STRING,
DPKOND TYPE STRING,
AZGSTAGE TYPE STRING,
SZKALRI TYPE STRING,
DZSREF TYPE STRING,
SKALID2 TYPE STRING,
SKALID3 TYPE STRING,
SKALID4 TYPE STRING,
SKALID5 TYPE STRING,
JGESUCHT TYPE STRING,
KURS1 TYPE STRING,
BBASIS TYPE STRING,
SZWERK TYPE STRING,
SFINCL TYPE STRING,
SRUNDVORF TYPE STRING,
SZWKEY TYPE STRING,
SFVMETH TYPE STRING,
SDWERK TYPE STRING,
SBERECH TYPE STRING,
JPROZR TYPE STRING,
SZEITANT TYPE STRING,
SFANT TYPE STRING,
SFRANZ TYPE STRING,
SKOAREF TYPE STRING,
SBEWSOLL TYPE STRING,
SBEWHABEN TYPE STRING,
SBEWZITI TYPE STRING,
AUSWAHL TYPE STRING,
SBERFIMA TYPE STRING,
JMUSS TYPE STRING,
NFOLGE TYPE STRING,
NHIER TYPE STRING,
KBKOND TYPE STRING,
SBASFIX TYPE STRING,
MANSP TYPE STRING,
ZAHLS TYPE STRING,
SZADRI TYPE STRING,
SZART TYPE STRING,
BKONDQM TYPE STRING,
SFLART TYPE STRING,
JAREA TYPE STRING,
PAY_DATA_C TYPE STRING,
AVGSTAGEVZ TYPE STRING,
AFGSTAGEVZ TYPE STRING,
TXJCD TYPE STRING,
LIFNR TYPE STRING,
JEXPOZINS TYPE STRING,
KOSTL TYPE STRING,
GFZLSCH TYPE STRING,
ZLSPR TYPE STRING,
SROUND TYPE STRING,
SKALIDWT TYPE STRING,
BMWST TYPE STRING,
XCROSS TYPE STRING,
PKOND2 TYPE STRING,
FACTOR_TYPE TYPE STRING,
SROUNDFACTOR TYPE STRING,
ROUNDDECFACTOR TYPE STRING,
JEXPOINTFACTOR TYPE STRING,
SROUNDBASEFACTOR TYPE STRING,
ROUNDDECBASEFACTOR TYPE STRING,
SROUNDRATEFACTOR TYPE STRING,
ROUNDDECRATEFACTOR 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,
ADGSTAGE TYPE STRING,
A_PAYDAY TYPE STRING,
RCO TYPE STRING,
BROUNDUNIT TYPE STRING,
MNDID TYPE STRING,
BBASISUNIT TYPE STRING,
PPAYMENT TYPE STRING,
AMMRHYZV TYPE STRING,
RBO TYPE STRING,
STECH_COND TYPE STRING,
SEXCLGUEL TYPE STRING,
SULTGUEL TYPE STRING,
A_AMTMIN TYPE STRING,
A_AMTMAX TYPE STRING,
SSCHMETH TYPE STRING,
BAUDAMNT TYPE STRING,
JAUSBL TYPE STRING,
GPDAYS TYPE STRING,
IND_IOAGP TYPE STRING,
DISBRATE TYPE STRING,END OF T_EKKO_STR. DATA: WA_VVZZKOPO_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_VVZZKOPO_STR-MANDT sy-vline
WA_VVZZKOPO_STR-BUKRS sy-vline
WA_VVZZKOPO_STR-SANLF sy-vline
WA_VVZZKOPO_STR-RKEY1 sy-vline
WA_VVZZKOPO_STR-RKEY2 sy-vline
WA_VVZZKOPO_STR-RKEY3 sy-vline
WA_VVZZKOPO_STR-DGUEL_KK sy-vline
WA_VVZZKOPO_STR-NLFD_ANG sy-vline
WA_VVZZKOPO_STR-SKOART sy-vline
WA_VVZZKOPO_STR-DGUEL_KP sy-vline
WA_VVZZKOPO_STR-NSTUFE sy-vline
WA_VVZZKOPO_STR-XKOARTM sy-vline
WA_VVZZKOPO_STR-SSTATI sy-vline
WA_VVZZKOPO_STR-PKOND sy-vline
WA_VVZZKOPO_STR-BKOND sy-vline
WA_VVZZKOPO_STR-SWHRKOND sy-vline
WA_VVZZKOPO_STR-SBASIS sy-vline
WA_VVZZKOPO_STR-SZSREF sy-vline
WA_VVZZKOPO_STR-SZSREFVZ sy-vline
WA_VVZZKOPO_STR-PFLUCT sy-vline
WA_VVZZKOPO_STR-AMMRHY sy-vline
WA_VVZZKOPO_STR-ATTRHY sy-vline
WA_VVZZKOPO_STR-SZAWS sy-vline
WA_VVZZKOPO_STR-RDIVNR sy-vline
WA_VVZZKOPO_STR-JNULLKON sy-vline
WA_VVZZKOPO_STR-MWSKZ sy-vline
WA_VVZZKOPO_STR-JBMONAT sy-vline
WA_VVZZKOPO_STR-DVALUT sy-vline
WA_VVZZKOPO_STR-DFAELL sy-vline
WA_VVZZKOPO_STR-KUNNR sy-vline
WA_VVZZKOPO_STR-ZLSCH sy-vline
WA_VVZZKOPO_STR-BVTYP sy-vline
WA_VVZZKOPO_STR-MABER sy-vline
WA_VVZZKOPO_STR-SPARTNR sy-vline
WA_VVZZKOPO_STR-RKONT sy-vline
WA_VVZZKOPO_STR-SVULT sy-vline
WA_VVZZKOPO_STR-SFULT sy-vline
WA_VVZZKOPO_STR-SVKALRI sy-vline
WA_VVZZKOPO_STR-SFKALRI sy-vline
WA_VVZZKOPO_STR-AVGSTAGE sy-vline
WA_VVZZKOPO_STR-AFGSTAGE sy-vline
WA_VVZZKOPO_STR-SVKALZUS sy-vline
WA_VVZZKOPO_STR-SFKALZUS sy-vline
WA_VVZZKOPO_STR-SKALID sy-vline
WA_VVZZKOPO_STR-SZBMETH sy-vline
WA_VVZZKOPO_STR-JSOFVERR sy-vline
WA_VVZZKOPO_STR-DALLGEM sy-vline
WA_VVZZKOPO_STR-SZEGEN sy-vline
WA_VVZZKOPO_STR-SBUST sy-vline
WA_VVZZKOPO_STR-SKOPO sy-vline
WA_VVZZKOPO_STR-SALTKOND sy-vline
WA_VVZZKOPO_STR-SZINSANP sy-vline
WA_VVZZKOPO_STR-SINCL sy-vline
WA_VVZZKOPO_STR-SFORMREF sy-vline
WA_VVZZKOPO_STR-SVARNAME sy-vline
WA_VVZZKOPO_STR-SVWERK sy-vline
WA_VVZZKOPO_STR-SVMETH sy-vline
WA_VVZZKOPO_STR-SFWERK sy-vline
WA_VVZZKOPO_STR-SFMETH sy-vline
WA_VVZZKOPO_STR-DPKOND sy-vline
WA_VVZZKOPO_STR-AZGSTAGE sy-vline
WA_VVZZKOPO_STR-SZKALRI sy-vline
WA_VVZZKOPO_STR-DZSREF sy-vline
WA_VVZZKOPO_STR-SKALID2 sy-vline
WA_VVZZKOPO_STR-SKALID3 sy-vline
WA_VVZZKOPO_STR-SKALID4 sy-vline
WA_VVZZKOPO_STR-SKALID5 sy-vline
WA_VVZZKOPO_STR-JGESUCHT sy-vline
WA_VVZZKOPO_STR-KURS1 sy-vline
WA_VVZZKOPO_STR-BBASIS sy-vline
WA_VVZZKOPO_STR-SZWERK sy-vline
WA_VVZZKOPO_STR-SFINCL sy-vline
WA_VVZZKOPO_STR-SRUNDVORF sy-vline
WA_VVZZKOPO_STR-SZWKEY sy-vline
WA_VVZZKOPO_STR-SFVMETH sy-vline
WA_VVZZKOPO_STR-SDWERK sy-vline
WA_VVZZKOPO_STR-SBERECH sy-vline
WA_VVZZKOPO_STR-JPROZR sy-vline
WA_VVZZKOPO_STR-SZEITANT sy-vline
WA_VVZZKOPO_STR-SFANT sy-vline
WA_VVZZKOPO_STR-SFRANZ sy-vline
WA_VVZZKOPO_STR-SKOAREF sy-vline
WA_VVZZKOPO_STR-SBEWSOLL sy-vline
WA_VVZZKOPO_STR-SBEWHABEN sy-vline
WA_VVZZKOPO_STR-SBEWZITI sy-vline
WA_VVZZKOPO_STR-AUSWAHL sy-vline
WA_VVZZKOPO_STR-SBERFIMA sy-vline
WA_VVZZKOPO_STR-JMUSS sy-vline
WA_VVZZKOPO_STR-NFOLGE sy-vline
WA_VVZZKOPO_STR-NHIER sy-vline
WA_VVZZKOPO_STR-KBKOND sy-vline
WA_VVZZKOPO_STR-SBASFIX sy-vline
WA_VVZZKOPO_STR-MANSP sy-vline
WA_VVZZKOPO_STR-ZAHLS sy-vline
WA_VVZZKOPO_STR-SZADRI sy-vline
WA_VVZZKOPO_STR-SZART sy-vline
WA_VVZZKOPO_STR-BKONDQM sy-vline
WA_VVZZKOPO_STR-SFLART sy-vline
WA_VVZZKOPO_STR-JAREA sy-vline
WA_VVZZKOPO_STR-PAY_DATA_C sy-vline
WA_VVZZKOPO_STR-AVGSTAGEVZ sy-vline
WA_VVZZKOPO_STR-AFGSTAGEVZ sy-vline
WA_VVZZKOPO_STR-TXJCD sy-vline
WA_VVZZKOPO_STR-LIFNR sy-vline
WA_VVZZKOPO_STR-JEXPOZINS sy-vline
WA_VVZZKOPO_STR-KOSTL sy-vline
WA_VVZZKOPO_STR-GFZLSCH sy-vline
WA_VVZZKOPO_STR-ZLSPR sy-vline
WA_VVZZKOPO_STR-SROUND sy-vline
WA_VVZZKOPO_STR-SKALIDWT sy-vline
WA_VVZZKOPO_STR-BMWST sy-vline
WA_VVZZKOPO_STR-XCROSS sy-vline
WA_VVZZKOPO_STR-PKOND2 sy-vline
WA_VVZZKOPO_STR-FACTOR_TYPE sy-vline
WA_VVZZKOPO_STR-SROUNDFACTOR sy-vline
WA_VVZZKOPO_STR-ROUNDDECFACTOR sy-vline
WA_VVZZKOPO_STR-JEXPOINTFACTOR sy-vline
WA_VVZZKOPO_STR-SROUNDBASEFACTOR sy-vline
WA_VVZZKOPO_STR-ROUNDDECBASEFACTOR sy-vline
WA_VVZZKOPO_STR-SROUNDRATEFACTOR sy-vline
WA_VVZZKOPO_STR-ROUNDDECRATEFACTOR sy-vline
WA_VVZZKOPO_STR-JAVGCAP sy-vline
WA_VVZZKOPO_STR-PAVGCAP sy-vline
WA_VVZZKOPO_STR-JAVGFLOOR sy-vline
WA_VVZZKOPO_STR-PAVGFLOOR sy-vline
WA_VVZZKOPO_STR-PAVGSPREAD sy-vline
WA_VVZZKOPO_STR-SROUNDAVGINTEREST sy-vline
WA_VVZZKOPO_STR-ROUNDDECAVGINTEREST sy-vline
WA_VVZZKOPO_STR-SAVGWEIGHT sy-vline
WA_VVZZKOPO_STR-SFACTORRESET sy-vline
WA_VVZZKOPO_STR-ADGSTAGE sy-vline
WA_VVZZKOPO_STR-A_PAYDAY sy-vline
WA_VVZZKOPO_STR-RCO sy-vline
WA_VVZZKOPO_STR-BROUNDUNIT sy-vline
WA_VVZZKOPO_STR-MNDID sy-vline
WA_VVZZKOPO_STR-BBASISUNIT sy-vline
WA_VVZZKOPO_STR-PPAYMENT sy-vline
WA_VVZZKOPO_STR-AMMRHYZV sy-vline
WA_VVZZKOPO_STR-RBO sy-vline
WA_VVZZKOPO_STR-STECH_COND sy-vline
WA_VVZZKOPO_STR-SEXCLGUEL sy-vline
WA_VVZZKOPO_STR-SULTGUEL sy-vline
WA_VVZZKOPO_STR-A_AMTMIN sy-vline
WA_VVZZKOPO_STR-A_AMTMAX sy-vline
WA_VVZZKOPO_STR-SSCHMETH sy-vline
WA_VVZZKOPO_STR-BAUDAMNT sy-vline
WA_VVZZKOPO_STR-JAUSBL sy-vline
WA_VVZZKOPO_STR-GPDAYS sy-vline
WA_VVZZKOPO_STR-IND_IOAGP sy-vline
WA_VVZZKOPO_STR-DISBRATE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.