ABAP Select data from SAP table FKKINV033 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 FKKINV033 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 FKKINV033. 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 FKKINV033 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_FKKINV033 TYPE STANDARD TABLE OF FKKINV033,
      WA_FKKINV033 TYPE FKKINV033,
      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: <FKKINV033> TYPE FKKINV033.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FKKINV033
*  INTO TABLE @DATA(IT_FKKINV0332).
*--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_FKKINV033 INDEX 1 INTO DATA(WA_FKKINV0332).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FKKINV033 ASSIGNING <FKKINV033>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FKKINV033>-DOCTYPE_INV = 1.
<FKKINV033>-DOCTYPE_REV = 1.
<FKKINV033>-DOCTYPE_SIM = 1.
<FKKINV033>-DOCTYPE_OUT = 1.
<FKKINV033>-BLART_REV = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FKKINV033-DOCTYPE_BILL_EXT, sy-vline,
WA_FKKINV033-DOCTYPE_BILL, sy-vline,
WA_FKKINV033-DOCTYPE_SIMBILL, sy-vline,
WA_FKKINV033-PA2640_POS_ID1, sy-vline,
WA_FKKINV033-PA2640_POS_ID2, sy-vline,
WA_FKKINV033-PA2640_POS_ID3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FKKINV033 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_FKKINV033 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_FKKINV033 INTO WA_FKKINV033. *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 HKONT_VJ CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKINV033-HKONT_VJ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKINV033-HKONT_VJ.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ALPHA, internal->external for field HKONT_NOT_BPREL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FKKINV033-HKONT_NOT_BPREL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FKKINV033-HKONT_NOT_BPREL.
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_FKKINV033_STR,
DOCTYPE_INV TYPE STRING,
DOCTYPE_REV TYPE STRING,
DOCTYPE_SIM TYPE STRING,
DOCTYPE_OUT TYPE STRING,
BLART_REV TYPE STRING,
DOCTYPE_BILL_EXT TYPE STRING,
DOCTYPE_BILL TYPE STRING,
DOCTYPE_SIMBILL TYPE STRING,
PA2640_POS_ID1 TYPE STRING,
PA2640_POS_ID2 TYPE STRING,
PA2640_POS_ID3 TYPE STRING,
PA2640_POS_ID4 TYPE STRING,
PA2640_POS_ID5 TYPE STRING,
PA2640_POS_ID6 TYPE STRING,
PA2640_POS_ID7 TYPE STRING,
TAX_ID TYPE STRING,
SUB_TAX_ID TYPE STRING,
HVORG_BILL TYPE STRING,
TVORG_BILL TYPE STRING,
HVORG_BPITEM TYPE STRING,
TVORGS_BPITEM TYPE STRING,
TVORGH_BPITEM TYPE STRING,
HVORG_OFFSET TYPE STRING,
TVORG_OFFSET TYPE STRING,
CHGNO TYPE STRING,
BI_SUB_TRANS_DEBIT TYPE STRING,
BI_SUB_TRANS_CREDIT TYPE STRING,
FORM_DIALOG_ID TYPE STRING,
BLART_2612 TYPE STRING,
STAKZ_2620 TYPE STRING,
AUGRS_2622 TYPE STRING,
PAYMET TYPE STRING,
TOTAL_AMT_SIGN TYPE STRING,
PAYFORM_GEN TYPE STRING,
PYREF_GEN TYPE STRING,
SELRULE_2618 TYPE STRING,
SELRULE_2620 TYPE STRING,
SELRULE_2622 TYPE STRING,
SELRULE_2630 TYPE STRING,
SELRULE_2635 TYPE STRING,
SELRULE_2625 TYPE STRING,
SELRULE_2628 TYPE STRING,
ACTRULE_2628 TYPE STRING,
DIFFDAYS_2618 TYPE STRING,
DIFFDAYS_2620 TYPE STRING,
DIFFDAYS_2625 TYPE STRING,
DIFFDAYS_2630 TYPE STRING,
DIFFDAYS_2635 TYPE STRING,
TOTALREL_2617 TYPE STRING,
TOTALREL_2620 TYPE STRING,
TOTALREL_2630 TYPE STRING,
REVSTAT_2630 TYPE STRING,
DEBCRED_SIGN TYPE STRING,
INV_ACTIT_2627 TYPE STRING,
DIFFDAYS_2627 TYPE STRING,
FIXDUED_2627 TYPE STRING,
SRCDOCTYPE_2627 TYPE STRING,
SRCDOCTYPE_INVBI TYPE STRING,
XSUBINV_CR_2637 TYPE STRING,
SRCDOCTYPE_2637 TYPE STRING,
DIFFDAYS_2637 TYPE STRING,
RETURN_SEC_2623 TYPE STRING,
TOTALREL_2623 TYPE STRING,
SELRULE_2623 TYPE STRING,
CFCVALNO TYPE STRING,
PRLINV_CAT_2638 TYPE STRING,
XPRLINV_CR_2638 TYPE STRING,
CREATE_CFCCASE TYPE STRING,
PRLINV_PRINT TYPE STRING,
DIFFDAYS_2638 TYPE STRING,
PA2643_POS_ID1 TYPE STRING,
PA2643_POS_ID2 TYPE STRING,
PA2643_POS_ID3 TYPE STRING,
SCHEDULE_RULE_REV TYPE STRING,
CYCLE_TRIG_CR_2607 TYPE STRING,
SRCDOCTYPE_2607 TYPE STRING,
INV_NOZERO_2607 TYPE STRING,
NRRANGE_INV TYPE STRING,
NRRANGE_BILL TYPE STRING,
SENDCTRL_DIA TYPE STRING,
XTAX_NOTIF_CR_2737 TYPE STRING,
TRANS_CRDEB_2632 TYPE STRING,
HVORG_2632 TYPE STRING,
TVORG_2632 TYPE STRING,
SELRULE_2632 TYPE STRING,
DIFFDAYS_2632 TYPE STRING,
TOTALREL_2632 TYPE STRING,
HKONT_VJ TYPE STRING,
HKONT_VVJ TYPE STRING,
HVORG_2651 TYPE STRING,
TVORG_2651 TYPE STRING,
HKONT_NOT_BPREL TYPE STRING,END OF T_EKKO_STR. DATA: WA_FKKINV033_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_FKKINV033_STR-DOCTYPE_INV sy-vline
WA_FKKINV033_STR-DOCTYPE_REV sy-vline
WA_FKKINV033_STR-DOCTYPE_SIM sy-vline
WA_FKKINV033_STR-DOCTYPE_OUT sy-vline
WA_FKKINV033_STR-BLART_REV sy-vline
WA_FKKINV033_STR-DOCTYPE_BILL_EXT sy-vline
WA_FKKINV033_STR-DOCTYPE_BILL sy-vline
WA_FKKINV033_STR-DOCTYPE_SIMBILL sy-vline
WA_FKKINV033_STR-PA2640_POS_ID1 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID2 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID3 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID4 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID5 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID6 sy-vline
WA_FKKINV033_STR-PA2640_POS_ID7 sy-vline
WA_FKKINV033_STR-TAX_ID sy-vline
WA_FKKINV033_STR-SUB_TAX_ID sy-vline
WA_FKKINV033_STR-HVORG_BILL sy-vline
WA_FKKINV033_STR-TVORG_BILL sy-vline
WA_FKKINV033_STR-HVORG_BPITEM sy-vline
WA_FKKINV033_STR-TVORGS_BPITEM sy-vline
WA_FKKINV033_STR-TVORGH_BPITEM sy-vline
WA_FKKINV033_STR-HVORG_OFFSET sy-vline
WA_FKKINV033_STR-TVORG_OFFSET sy-vline
WA_FKKINV033_STR-CHGNO sy-vline
WA_FKKINV033_STR-BI_SUB_TRANS_DEBIT sy-vline
WA_FKKINV033_STR-BI_SUB_TRANS_CREDIT sy-vline
WA_FKKINV033_STR-FORM_DIALOG_ID sy-vline
WA_FKKINV033_STR-BLART_2612 sy-vline
WA_FKKINV033_STR-STAKZ_2620 sy-vline
WA_FKKINV033_STR-AUGRS_2622 sy-vline
WA_FKKINV033_STR-PAYMET sy-vline
WA_FKKINV033_STR-TOTAL_AMT_SIGN sy-vline
WA_FKKINV033_STR-PAYFORM_GEN sy-vline
WA_FKKINV033_STR-PYREF_GEN sy-vline
WA_FKKINV033_STR-SELRULE_2618 sy-vline
WA_FKKINV033_STR-SELRULE_2620 sy-vline
WA_FKKINV033_STR-SELRULE_2622 sy-vline
WA_FKKINV033_STR-SELRULE_2630 sy-vline
WA_FKKINV033_STR-SELRULE_2635 sy-vline
WA_FKKINV033_STR-SELRULE_2625 sy-vline
WA_FKKINV033_STR-SELRULE_2628 sy-vline
WA_FKKINV033_STR-ACTRULE_2628 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2618 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2620 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2625 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2630 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2635 sy-vline
WA_FKKINV033_STR-TOTALREL_2617 sy-vline
WA_FKKINV033_STR-TOTALREL_2620 sy-vline
WA_FKKINV033_STR-TOTALREL_2630 sy-vline
WA_FKKINV033_STR-REVSTAT_2630 sy-vline
WA_FKKINV033_STR-DEBCRED_SIGN sy-vline
WA_FKKINV033_STR-INV_ACTIT_2627 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2627 sy-vline
WA_FKKINV033_STR-FIXDUED_2627 sy-vline
WA_FKKINV033_STR-SRCDOCTYPE_2627 sy-vline
WA_FKKINV033_STR-SRCDOCTYPE_INVBI sy-vline
WA_FKKINV033_STR-XSUBINV_CR_2637 sy-vline
WA_FKKINV033_STR-SRCDOCTYPE_2637 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2637 sy-vline
WA_FKKINV033_STR-RETURN_SEC_2623 sy-vline
WA_FKKINV033_STR-TOTALREL_2623 sy-vline
WA_FKKINV033_STR-SELRULE_2623 sy-vline
WA_FKKINV033_STR-CFCVALNO sy-vline
WA_FKKINV033_STR-PRLINV_CAT_2638 sy-vline
WA_FKKINV033_STR-XPRLINV_CR_2638 sy-vline
WA_FKKINV033_STR-CREATE_CFCCASE sy-vline
WA_FKKINV033_STR-PRLINV_PRINT sy-vline
WA_FKKINV033_STR-DIFFDAYS_2638 sy-vline
WA_FKKINV033_STR-PA2643_POS_ID1 sy-vline
WA_FKKINV033_STR-PA2643_POS_ID2 sy-vline
WA_FKKINV033_STR-PA2643_POS_ID3 sy-vline
WA_FKKINV033_STR-SCHEDULE_RULE_REV sy-vline
WA_FKKINV033_STR-CYCLE_TRIG_CR_2607 sy-vline
WA_FKKINV033_STR-SRCDOCTYPE_2607 sy-vline
WA_FKKINV033_STR-INV_NOZERO_2607 sy-vline
WA_FKKINV033_STR-NRRANGE_INV sy-vline
WA_FKKINV033_STR-NRRANGE_BILL sy-vline
WA_FKKINV033_STR-SENDCTRL_DIA sy-vline
WA_FKKINV033_STR-XTAX_NOTIF_CR_2737 sy-vline
WA_FKKINV033_STR-TRANS_CRDEB_2632 sy-vline
WA_FKKINV033_STR-HVORG_2632 sy-vline
WA_FKKINV033_STR-TVORG_2632 sy-vline
WA_FKKINV033_STR-SELRULE_2632 sy-vline
WA_FKKINV033_STR-DIFFDAYS_2632 sy-vline
WA_FKKINV033_STR-TOTALREL_2632 sy-vline
WA_FKKINV033_STR-HKONT_VJ sy-vline
WA_FKKINV033_STR-HKONT_VVJ sy-vline
WA_FKKINV033_STR-HVORG_2651 sy-vline
WA_FKKINV033_STR-TVORG_2651 sy-vline
WA_FKKINV033_STR-HKONT_NOT_BPREL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.