ABAP Select data from SAP table TIVBPVENDORGEN 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 TIVBPVENDORGEN 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 TIVBPVENDORGEN. 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 TIVBPVENDORGEN 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_TIVBPVENDORGEN TYPE STANDARD TABLE OF TIVBPVENDORGEN,
      WA_TIVBPVENDORGEN TYPE TIVBPVENDORGEN,
      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: <TIVBPVENDORGEN> TYPE TIVBPVENDORGEN.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TIVBPVENDORGEN
*  INTO TABLE @DATA(IT_TIVBPVENDORGEN2).
*--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_TIVBPVENDORGEN INDEX 1 INTO DATA(WA_TIVBPVENDORGEN2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TIVBPVENDORGEN ASSIGNING <TIVBPVENDORGEN>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TIVBPVENDORGEN>-MANDT = 1.
<TIVBPVENDORGEN>-APPL = 1.
<TIVBPVENDORGEN>-ANRED = 1.
<TIVBPVENDORGEN>-BAHNS = 1.
<TIVBPVENDORGEN>-BBBNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TIVBPVENDORGEN-BBSNR, sy-vline,
WA_TIVBPVENDORGEN-BEGRU, sy-vline,
WA_TIVBPVENDORGEN-BRSCH, sy-vline,
WA_TIVBPVENDORGEN-BUBKZ, sy-vline,
WA_TIVBPVENDORGEN-DATLT, sy-vline,
WA_TIVBPVENDORGEN-DTAMS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TIVBPVENDORGEN 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_TIVBPVENDORGEN 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_TIVBPVENDORGEN INTO WA_TIVBPVENDORGEN. *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_TIVBPVENDORGEN-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-KUNNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field LNRZA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TIVBPVENDORGEN-LNRZA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-LNRZA.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field SPRAS CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_TIVBPVENDORGEN-SPRAS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-SPRAS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VBUND CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TIVBPVENDORGEN-VBUND IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-VBUND.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field FISKN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TIVBPVENDORGEN-FISKN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-FISKN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field FISKU CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TIVBPVENDORGEN-FISKU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TIVBPVENDORGEN-FISKU.
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_TIVBPVENDORGEN_STR,
MANDT TYPE STRING,
APPL TYPE STRING,
ANRED TYPE STRING,
BAHNS TYPE STRING,
BBBNR TYPE STRING,
BBSNR TYPE STRING,
BEGRU TYPE STRING,
BRSCH TYPE STRING,
BUBKZ TYPE STRING,
DATLT TYPE STRING,
DTAMS TYPE STRING,
DTAWS TYPE STRING,
ERDAT TYPE STRING,
ERNAM TYPE STRING,
ESRNR TYPE STRING,
KONZS TYPE STRING,
KTOKK TYPE STRING,
KUNNR TYPE STRING,
LNRZA TYPE STRING,
LOEVM TYPE STRING,
SPERR TYPE STRING,
SPERM TYPE STRING,
SPRAS TYPE STRING,
STCD1 TYPE STRING,
STCD2 TYPE STRING,
STKZA TYPE STRING,
STKZU TYPE STRING,
TELBX TYPE STRING,
TELF1 TYPE STRING,
TELF2 TYPE STRING,
TELFX TYPE STRING,
TELTX TYPE STRING,
TELX1 TYPE STRING,
XCPDK TYPE STRING,
XZEMP TYPE STRING,
VBUND TYPE STRING,
FISKN TYPE STRING,
STCEG TYPE STRING,
STKZN TYPE STRING,
SPERQ TYPE STRING,
GBORT TYPE STRING,
GBDAT TYPE STRING,
SEXKZ TYPE STRING,
KRAUS TYPE STRING,
REVDB TYPE STRING,
QSSYS TYPE STRING,
KTOCK TYPE STRING,
PFORT TYPE STRING,
WERKS TYPE STRING,
LTSNA TYPE STRING,
WERKR TYPE STRING,
PLKAL TYPE STRING,
DUEFL TYPE STRING,
TXJCD TYPE STRING,
SPERZ TYPE STRING,
SCACD TYPE STRING,
SFRGR TYPE STRING,
LZONE TYPE STRING,
XLFZA TYPE STRING,
DLGRP TYPE STRING,
FITYP TYPE STRING,
STCDT TYPE STRING,
REGSS TYPE STRING,
ACTSS TYPE STRING,
STCD3 TYPE STRING,
STCD4 TYPE STRING,
IPISP TYPE STRING,
TAXBS TYPE STRING,
PROFS TYPE STRING,
STGDL TYPE STRING,
EMNFR TYPE STRING,
LFURL TYPE STRING,
J_1KFREPRE TYPE STRING,
J_1KFTBUS TYPE STRING,
J_1KFTIND TYPE STRING,
CONFS TYPE STRING,
UPDAT TYPE STRING,
UPTIM TYPE STRING,
NODEL TYPE STRING,
QSSYSDAT TYPE STRING,
PODKZB TYPE STRING,
FISKU TYPE STRING,
STENR TYPE STRING,END OF T_EKKO_STR. DATA: WA_TIVBPVENDORGEN_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_TIVBPVENDORGEN_STR-MANDT sy-vline
WA_TIVBPVENDORGEN_STR-APPL sy-vline
WA_TIVBPVENDORGEN_STR-ANRED sy-vline
WA_TIVBPVENDORGEN_STR-BAHNS sy-vline
WA_TIVBPVENDORGEN_STR-BBBNR sy-vline
WA_TIVBPVENDORGEN_STR-BBSNR sy-vline
WA_TIVBPVENDORGEN_STR-BEGRU sy-vline
WA_TIVBPVENDORGEN_STR-BRSCH sy-vline
WA_TIVBPVENDORGEN_STR-BUBKZ sy-vline
WA_TIVBPVENDORGEN_STR-DATLT sy-vline
WA_TIVBPVENDORGEN_STR-DTAMS sy-vline
WA_TIVBPVENDORGEN_STR-DTAWS sy-vline
WA_TIVBPVENDORGEN_STR-ERDAT sy-vline
WA_TIVBPVENDORGEN_STR-ERNAM sy-vline
WA_TIVBPVENDORGEN_STR-ESRNR sy-vline
WA_TIVBPVENDORGEN_STR-KONZS sy-vline
WA_TIVBPVENDORGEN_STR-KTOKK sy-vline
WA_TIVBPVENDORGEN_STR-KUNNR sy-vline
WA_TIVBPVENDORGEN_STR-LNRZA sy-vline
WA_TIVBPVENDORGEN_STR-LOEVM sy-vline
WA_TIVBPVENDORGEN_STR-SPERR sy-vline
WA_TIVBPVENDORGEN_STR-SPERM sy-vline
WA_TIVBPVENDORGEN_STR-SPRAS sy-vline
WA_TIVBPVENDORGEN_STR-STCD1 sy-vline
WA_TIVBPVENDORGEN_STR-STCD2 sy-vline
WA_TIVBPVENDORGEN_STR-STKZA sy-vline
WA_TIVBPVENDORGEN_STR-STKZU sy-vline
WA_TIVBPVENDORGEN_STR-TELBX sy-vline
WA_TIVBPVENDORGEN_STR-TELF1 sy-vline
WA_TIVBPVENDORGEN_STR-TELF2 sy-vline
WA_TIVBPVENDORGEN_STR-TELFX sy-vline
WA_TIVBPVENDORGEN_STR-TELTX sy-vline
WA_TIVBPVENDORGEN_STR-TELX1 sy-vline
WA_TIVBPVENDORGEN_STR-XCPDK sy-vline
WA_TIVBPVENDORGEN_STR-XZEMP sy-vline
WA_TIVBPVENDORGEN_STR-VBUND sy-vline
WA_TIVBPVENDORGEN_STR-FISKN sy-vline
WA_TIVBPVENDORGEN_STR-STCEG sy-vline
WA_TIVBPVENDORGEN_STR-STKZN sy-vline
WA_TIVBPVENDORGEN_STR-SPERQ sy-vline
WA_TIVBPVENDORGEN_STR-GBORT sy-vline
WA_TIVBPVENDORGEN_STR-GBDAT sy-vline
WA_TIVBPVENDORGEN_STR-SEXKZ sy-vline
WA_TIVBPVENDORGEN_STR-KRAUS sy-vline
WA_TIVBPVENDORGEN_STR-REVDB sy-vline
WA_TIVBPVENDORGEN_STR-QSSYS sy-vline
WA_TIVBPVENDORGEN_STR-KTOCK sy-vline
WA_TIVBPVENDORGEN_STR-PFORT sy-vline
WA_TIVBPVENDORGEN_STR-WERKS sy-vline
WA_TIVBPVENDORGEN_STR-LTSNA sy-vline
WA_TIVBPVENDORGEN_STR-WERKR sy-vline
WA_TIVBPVENDORGEN_STR-PLKAL sy-vline
WA_TIVBPVENDORGEN_STR-DUEFL sy-vline
WA_TIVBPVENDORGEN_STR-TXJCD sy-vline
WA_TIVBPVENDORGEN_STR-SPERZ sy-vline
WA_TIVBPVENDORGEN_STR-SCACD sy-vline
WA_TIVBPVENDORGEN_STR-SFRGR sy-vline
WA_TIVBPVENDORGEN_STR-LZONE sy-vline
WA_TIVBPVENDORGEN_STR-XLFZA sy-vline
WA_TIVBPVENDORGEN_STR-DLGRP sy-vline
WA_TIVBPVENDORGEN_STR-FITYP sy-vline
WA_TIVBPVENDORGEN_STR-STCDT sy-vline
WA_TIVBPVENDORGEN_STR-REGSS sy-vline
WA_TIVBPVENDORGEN_STR-ACTSS sy-vline
WA_TIVBPVENDORGEN_STR-STCD3 sy-vline
WA_TIVBPVENDORGEN_STR-STCD4 sy-vline
WA_TIVBPVENDORGEN_STR-IPISP sy-vline
WA_TIVBPVENDORGEN_STR-TAXBS sy-vline
WA_TIVBPVENDORGEN_STR-PROFS sy-vline
WA_TIVBPVENDORGEN_STR-STGDL sy-vline
WA_TIVBPVENDORGEN_STR-EMNFR sy-vline
WA_TIVBPVENDORGEN_STR-LFURL sy-vline
WA_TIVBPVENDORGEN_STR-J_1KFREPRE sy-vline
WA_TIVBPVENDORGEN_STR-J_1KFTBUS sy-vline
WA_TIVBPVENDORGEN_STR-J_1KFTIND sy-vline
WA_TIVBPVENDORGEN_STR-CONFS sy-vline
WA_TIVBPVENDORGEN_STR-UPDAT sy-vline
WA_TIVBPVENDORGEN_STR-UPTIM sy-vline
WA_TIVBPVENDORGEN_STR-NODEL sy-vline
WA_TIVBPVENDORGEN_STR-QSSYSDAT sy-vline
WA_TIVBPVENDORGEN_STR-PODKZB sy-vline
WA_TIVBPVENDORGEN_STR-FISKU sy-vline
WA_TIVBPVENDORGEN_STR-STENR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.