ABAP Select data from SAP table FKKINVDOC_I_PRNT 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 FKKINVDOC_I_PRNT 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 FKKINVDOC_I_PRNT. 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 FKKINVDOC_I_PRNT 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_FKKINVDOC_I_PRNT TYPE STANDARD TABLE OF FKKINVDOC_I_PRNT,
      WA_FKKINVDOC_I_PRNT TYPE FKKINVDOC_I_PRNT,
      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: <FKKINVDOC_I_PRNT> TYPE FKKINVDOC_I_PRNT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FKKINVDOC_I_PRNT
*  INTO TABLE @DATA(IT_FKKINVDOC_I_PRNT2).
*--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_FKKINVDOC_I_PRNT INDEX 1 INTO DATA(WA_FKKINVDOC_I_PRNT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FKKINVDOC_I_PRNT ASSIGNING <FKKINVDOC_I_PRNT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FKKINVDOC_I_PRNT>-MANDT = 1.
<FKKINVDOC_I_PRNT>-INVDOCNO = 1.
<FKKINVDOC_I_PRNT>-INVDOCITEM = 1.
<FKKINVDOC_I_PRNT>-ITEMTYPE = 1.
<FKKINVDOC_I_PRNT>-BUKRS = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FKKINVDOC_I_PRNT-SPART, sy-vline,
WA_FKKINVDOC_I_PRNT-VTREF, sy-vline,
WA_FKKINVDOC_I_PRNT-VTPOS, sy-vline,
WA_FKKINVDOC_I_PRNT-SUBAP, sy-vline,
WA_FKKINVDOC_I_PRNT-GPART_A, sy-vline,
WA_FKKINVDOC_I_PRNT-VKONT_A, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FKKINVDOC_I_PRNT 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_FKKINVDOC_I_PRNT 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_FKKINVDOC_I_PRNT INTO WA_FKKINVDOC_I_PRNT. *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 VTREF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKINVDOC_I_PRNT-VTREF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKINVDOC_I_PRNT-VTREF.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FKKINVDOC_I_PRNT-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKINVDOC_I_PRNT-MEINS.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field SRCDOCITEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKINVDOC_I_PRNT-SRCDOCITEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKINVDOC_I_PRNT-SRCDOCITEM.
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_FKKINVDOC_I_PRNT_STR,
MANDT TYPE STRING,
INVDOCNO TYPE STRING,
INVDOCITEM TYPE STRING,
ITEMTYPE TYPE STRING,
BUKRS TYPE STRING,
SPART TYPE STRING,
VTREF TYPE STRING,
VTPOS TYPE STRING,
SUBAP TYPE STRING,
GPART_A TYPE STRING,
VKONT_A TYPE STRING,
GPVKT_A_CAT TYPE STRING,
HVORG TYPE STRING,
TVORG TYPE STRING,
ITEM_SIMULATED TYPE STRING,
REVERSALITEM TYPE STRING,
CORRCAT TYPE STRING,
TOTALREL TYPE STRING,
POSTREL TYPE STRING,
NOT_BPREL TYPE STRING,
PRINTREL TYPE STRING,
PRINT_SUBSTITUTE TYPE STRING,
WAERS TYPE STRING,
BETRW TYPE STRING,
SRCDOC_CURR TYPE STRING,
SRCDOC_AMT TYPE STRING,
CURRC_GROUP TYPE STRING,
KOFIZ TYPE STRING,
BUPLA TYPE STRING,
GSBER TYPE STRING,
TAX_INCLUDED TYPE STRING,
TAX_DET_TYPE TYPE STRING,
TAXGR TYPE STRING,
STRKZ TYPE STRING,
MWSKZ TYPE STRING,
ERMWSKZ TYPE STRING,
TXJCD TYPE STRING,
KTOSL TYPE STRING,
KSCHL TYPE STRING,
TAX_PERC TYPE STRING,
TAX_COUNTRY TYPE STRING,
TXDAT TYPE STRING,
SBASW TYPE STRING,
SBETW TYPE STRING,
STTAX TYPE STRING,
QSSKZ TYPE STRING,
XANZA TYPE STRING,
STAKZ TYPE STRING,
OFFSET_CAT TYPE STRING,
OFFSET_PROC TYPE STRING,
OFFSET_ACTION TYPE STRING,
OFFSET_INVGR TYPE STRING,
DEFREV_STAT TYPE STRING,
RAREL TYPE STRING,
RA_INVGR TYPE STRING,
SERVICE_TYPE TYPE STRING,
BILLAC_TYPE TYPE STRING,
PREPAID TYPE STRING,
MEINS TYPE STRING,
MENGE TYPE STRING,
FAEDN TYPE STRING,
FAEDS TYPE STRING,
SKTPZ TYPE STRING,
XSTUND TYPE STRING,
DATE_FROM TYPE STRING,
DATE_TO TYPE STRING,
CADOCTYPE TYPE STRING,
OPBEL TYPE STRING,
PSGRP TYPE STRING,
INVGR TYPE STRING,
AUGBL TYPE STRING,
AUGBW TYPE STRING,
ITEM_CRMET TYPE STRING,
INV_FUNCTION TYPE STRING,
SRCDOCCAT TYPE STRING,
SRCDOCNO TYPE STRING,
SRCITEMCAT TYPE STRING,
SRCDOCITEM TYPE STRING,
DISCKEY TYPE STRING,
DISCKEY_VERSNO TYPE STRING,
DUMMY_INVDOC_I_INCL_EEW_PS TYPE STRING,END OF T_EKKO_STR. DATA: WA_FKKINVDOC_I_PRNT_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_FKKINVDOC_I_PRNT_STR-MANDT sy-vline
WA_FKKINVDOC_I_PRNT_STR-INVDOCNO sy-vline
WA_FKKINVDOC_I_PRNT_STR-INVDOCITEM sy-vline
WA_FKKINVDOC_I_PRNT_STR-ITEMTYPE sy-vline
WA_FKKINVDOC_I_PRNT_STR-BUKRS sy-vline
WA_FKKINVDOC_I_PRNT_STR-SPART sy-vline
WA_FKKINVDOC_I_PRNT_STR-VTREF sy-vline
WA_FKKINVDOC_I_PRNT_STR-VTPOS sy-vline
WA_FKKINVDOC_I_PRNT_STR-SUBAP sy-vline
WA_FKKINVDOC_I_PRNT_STR-GPART_A sy-vline
WA_FKKINVDOC_I_PRNT_STR-VKONT_A sy-vline
WA_FKKINVDOC_I_PRNT_STR-GPVKT_A_CAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-HVORG sy-vline
WA_FKKINVDOC_I_PRNT_STR-TVORG sy-vline
WA_FKKINVDOC_I_PRNT_STR-ITEM_SIMULATED sy-vline
WA_FKKINVDOC_I_PRNT_STR-REVERSALITEM sy-vline
WA_FKKINVDOC_I_PRNT_STR-CORRCAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-TOTALREL sy-vline
WA_FKKINVDOC_I_PRNT_STR-POSTREL sy-vline
WA_FKKINVDOC_I_PRNT_STR-NOT_BPREL sy-vline
WA_FKKINVDOC_I_PRNT_STR-PRINTREL sy-vline
WA_FKKINVDOC_I_PRNT_STR-PRINT_SUBSTITUTE sy-vline
WA_FKKINVDOC_I_PRNT_STR-WAERS sy-vline
WA_FKKINVDOC_I_PRNT_STR-BETRW sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCDOC_CURR sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCDOC_AMT sy-vline
WA_FKKINVDOC_I_PRNT_STR-CURRC_GROUP sy-vline
WA_FKKINVDOC_I_PRNT_STR-KOFIZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-BUPLA sy-vline
WA_FKKINVDOC_I_PRNT_STR-GSBER sy-vline
WA_FKKINVDOC_I_PRNT_STR-TAX_INCLUDED sy-vline
WA_FKKINVDOC_I_PRNT_STR-TAX_DET_TYPE sy-vline
WA_FKKINVDOC_I_PRNT_STR-TAXGR sy-vline
WA_FKKINVDOC_I_PRNT_STR-STRKZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-MWSKZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-ERMWSKZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-TXJCD sy-vline
WA_FKKINVDOC_I_PRNT_STR-KTOSL sy-vline
WA_FKKINVDOC_I_PRNT_STR-KSCHL sy-vline
WA_FKKINVDOC_I_PRNT_STR-TAX_PERC sy-vline
WA_FKKINVDOC_I_PRNT_STR-TAX_COUNTRY sy-vline
WA_FKKINVDOC_I_PRNT_STR-TXDAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-SBASW sy-vline
WA_FKKINVDOC_I_PRNT_STR-SBETW sy-vline
WA_FKKINVDOC_I_PRNT_STR-STTAX sy-vline
WA_FKKINVDOC_I_PRNT_STR-QSSKZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-XANZA sy-vline
WA_FKKINVDOC_I_PRNT_STR-STAKZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-OFFSET_CAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-OFFSET_PROC sy-vline
WA_FKKINVDOC_I_PRNT_STR-OFFSET_ACTION sy-vline
WA_FKKINVDOC_I_PRNT_STR-OFFSET_INVGR sy-vline
WA_FKKINVDOC_I_PRNT_STR-DEFREV_STAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-RAREL sy-vline
WA_FKKINVDOC_I_PRNT_STR-RA_INVGR sy-vline
WA_FKKINVDOC_I_PRNT_STR-SERVICE_TYPE sy-vline
WA_FKKINVDOC_I_PRNT_STR-BILLAC_TYPE sy-vline
WA_FKKINVDOC_I_PRNT_STR-PREPAID sy-vline
WA_FKKINVDOC_I_PRNT_STR-MEINS sy-vline
WA_FKKINVDOC_I_PRNT_STR-MENGE sy-vline
WA_FKKINVDOC_I_PRNT_STR-FAEDN sy-vline
WA_FKKINVDOC_I_PRNT_STR-FAEDS sy-vline
WA_FKKINVDOC_I_PRNT_STR-SKTPZ sy-vline
WA_FKKINVDOC_I_PRNT_STR-XSTUND sy-vline
WA_FKKINVDOC_I_PRNT_STR-DATE_FROM sy-vline
WA_FKKINVDOC_I_PRNT_STR-DATE_TO sy-vline
WA_FKKINVDOC_I_PRNT_STR-CADOCTYPE sy-vline
WA_FKKINVDOC_I_PRNT_STR-OPBEL sy-vline
WA_FKKINVDOC_I_PRNT_STR-PSGRP sy-vline
WA_FKKINVDOC_I_PRNT_STR-INVGR sy-vline
WA_FKKINVDOC_I_PRNT_STR-AUGBL sy-vline
WA_FKKINVDOC_I_PRNT_STR-AUGBW sy-vline
WA_FKKINVDOC_I_PRNT_STR-ITEM_CRMET sy-vline
WA_FKKINVDOC_I_PRNT_STR-INV_FUNCTION sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCDOCCAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCDOCNO sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCITEMCAT sy-vline
WA_FKKINVDOC_I_PRNT_STR-SRCDOCITEM sy-vline
WA_FKKINVDOC_I_PRNT_STR-DISCKEY sy-vline
WA_FKKINVDOC_I_PRNT_STR-DISCKEY_VERSNO sy-vline
WA_FKKINVDOC_I_PRNT_STR-DUMMY_INVDOC_I_INCL_EEW_PS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.