ABAP Select data from SAP table BAPI_INCINV_COMPLAIN_HEADER 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 BAPI_INCINV_COMPLAIN_HEADER 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 BAPI_INCINV_COMPLAIN_HEADER. 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 BAPI_INCINV_COMPLAIN_HEADER 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_BAPI_INCINV_COMPLAIN_HEADER TYPE STANDARD TABLE OF BAPI_INCINV_COMPLAIN_HEADER,
      WA_BAPI_INCINV_COMPLAIN_HEADER TYPE BAPI_INCINV_COMPLAIN_HEADER,
      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: <BAPI_INCINV_COMPLAIN_HEADER> TYPE BAPI_INCINV_COMPLAIN_HEADER.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI_INCINV_COMPLAIN_HEADER
*  INTO TABLE @DATA(IT_BAPI_INCINV_COMPLAIN_HEADER2).
*--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_BAPI_INCINV_COMPLAIN_HEADER INDEX 1 INTO DATA(WA_BAPI_INCINV_COMPLAIN_HEADER2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI_INCINV_COMPLAIN_HEADER ASSIGNING <BAPI_INCINV_COMPLAIN_HEADER>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_INCINV_COMPLAIN_HEADER>-INV_DOC_NO = 1.
<BAPI_INCINV_COMPLAIN_HEADER>-FISC_YEAR = 1.
<BAPI_INCINV_COMPLAIN_HEADER>-INVOICE_IND = 1.
<BAPI_INCINV_COMPLAIN_HEADER>-DOC_DATE = 1.
<BAPI_INCINV_COMPLAIN_HEADER>-PSTNG_DATE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI_INCINV_COMPLAIN_HEADER-FIRSTNAME, sy-vline,
WA_BAPI_INCINV_COMPLAIN_HEADER-LASTNAME, sy-vline,
WA_BAPI_INCINV_COMPLAIN_HEADER-TITLE_ACA1, sy-vline,
WA_BAPI_INCINV_COMPLAIN_HEADER-TEL1_NUMBR, sy-vline,
WA_BAPI_INCINV_COMPLAIN_HEADER-TEL1_EXT, sy-vline,
WA_BAPI_INCINV_COMPLAIN_HEADER-FAX_NUMBER, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_INCINV_COMPLAIN_HEADER 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_BAPI_INCINV_COMPLAIN_HEADER 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_BAPI_INCINV_COMPLAIN_HEADER INTO WA_BAPI_INCINV_COMPLAIN_HEADER. *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 INV_DOC_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_INCINV_COMPLAIN_HEADER-INV_DOC_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_INCINV_COMPLAIN_HEADER-INV_DOC_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit GJAHR, internal->external for field FISC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_BAPI_INCINV_COMPLAIN_HEADER-FISC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_INCINV_COMPLAIN_HEADER-FISC_YEAR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit SXIDN, internal->external for field E_MAIL CALL FUNCTION 'CONVERSION_EXIT_SXIDN_OUTPUT' EXPORTING input = WA_BAPI_INCINV_COMPLAIN_HEADER-E_MAIL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_INCINV_COMPLAIN_HEADER-E_MAIL.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit GJAHR, internal->external for field REVERSAL_DOC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_BAPI_INCINV_COMPLAIN_HEADER-REVERSAL_DOC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_INCINV_COMPLAIN_HEADER-REVERSAL_DOC_YEAR.
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_BAPI_INCINV_COMPLAIN_HEADER_STR,
INV_DOC_NO TYPE STRING,
FISC_YEAR TYPE STRING,
INVOICE_IND TYPE STRING,
DOC_DATE TYPE STRING,
PSTNG_DATE TYPE STRING,
FIRSTNAME TYPE STRING,
LASTNAME TYPE STRING,
TITLE_ACA1 TYPE STRING,
TEL1_NUMBR TYPE STRING,
TEL1_EXT TYPE STRING,
FAX_NUMBER TYPE STRING,
FAX_EXTENS TYPE STRING,
E_MAIL TYPE STRING,
VAT_REG_NO TYPE STRING,
REF_DOC_NO TYPE STRING,
REF_DOC_NO_LONG TYPE STRING,
VENDOR_NO TYPE STRING,
ACT_AT_VEN TYPE STRING,
CURRENCY TYPE STRING,
CURRENCY_ISO TYPE STRING,
GROSS_AMNT TYPE STRING,
HEADER_TXT TYPE STRING,
AUTINVRED_IND TYPE STRING,
AUTINVRED TYPE STRING,
TAXINVRED TYPE STRING,
VEND_ERROR TYPE STRING,
TAX_ERROR TYPE STRING,
ITEM_TEXT TYPE STRING,
REVERSAL_IND TYPE STRING,
REVERSAL_DOC TYPE STRING,
REVERSAL_DOC_YEAR TYPE STRING,
REPEAT_IND TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_INCINV_COMPLAIN_HEADER_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_BAPI_INCINV_COMPLAIN_HEADER_STR-INV_DOC_NO sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-FISC_YEAR sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-INVOICE_IND sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-DOC_DATE sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-PSTNG_DATE sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-FIRSTNAME sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-LASTNAME sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-TITLE_ACA1 sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-TEL1_NUMBR sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-TEL1_EXT sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-FAX_NUMBER sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-FAX_EXTENS sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-E_MAIL sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-VAT_REG_NO sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REF_DOC_NO sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REF_DOC_NO_LONG sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-VENDOR_NO sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-ACT_AT_VEN sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-CURRENCY sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-CURRENCY_ISO sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-GROSS_AMNT sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-HEADER_TXT sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-AUTINVRED_IND sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-AUTINVRED sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-TAXINVRED sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-VEND_ERROR sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-TAX_ERROR sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-ITEM_TEXT sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REVERSAL_IND sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REVERSAL_DOC sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REVERSAL_DOC_YEAR sy-vline
WA_BAPI_INCINV_COMPLAIN_HEADER_STR-REPEAT_IND sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.