ABAP Select data from SAP table FIRU_S_PP_INVOICE_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 FIRU_S_PP_INVOICE_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 FIRU_S_PP_INVOICE_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 FIRU_S_PP_INVOICE_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_FIRU_S_PP_INVOICE_HEADER TYPE STANDARD TABLE OF FIRU_S_PP_INVOICE_HEADER, WA_FIRU_S_PP_INVOICE_HEADER TYPE FIRU_S_PP_INVOICE_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: <FIRU_S_PP_INVOICE_HEADER> TYPE FIRU_S_PP_INVOICE_HEADER. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FIRU_S_PP_INVOICE_HEADER. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FIRU_S_PP_INVOICE_HEADER INTO TABLE IT_FIRU_S_PP_INVOICE_HEADER. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FIRU_S_PP_INVOICE_HEADER * INTO TABLE @DATA(IT_FIRU_S_PP_INVOICE_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_FIRU_S_PP_INVOICE_HEADER INDEX 1 INTO DATA(WA_FIRU_S_PP_INVOICE_HEADER2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FIRU_S_PP_INVOICE_HEADER ASSIGNING <FIRU_S_PP_INVOICE_HEADER>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FIRU_S_PP_INVOICE_HEADER>-BILLING_DOCUMENT = 1.
<FIRU_S_PP_INVOICE_HEADER>-BILLING_DATE = 1.
<FIRU_S_PP_INVOICE_HEADER>-BUKRS = 1.
<FIRU_S_PP_INVOICE_HEADER>-BELNR = 1.
<FIRU_S_PP_INVOICE_HEADER>-GJAHR = 1.
ENDLOOP. LOOP AT IT_FIRU_S_PP_INVOICE_HEADER INTO WA_FIRU_S_PP_INVOICE_HEADER. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FIRU_S_PP_INVOICE_HEADER-CONTRACT_NUMBER, sy-vline,
WA_FIRU_S_PP_INVOICE_HEADER-CONTRACT_DATE, sy-vline,
WA_FIRU_S_PP_INVOICE_HEADER-RECIPIENT_BANK_NAME, sy-vline,
WA_FIRU_S_PP_INVOICE_HEADER-RECIPIENT_BANK_BIK, sy-vline,
WA_FIRU_S_PP_INVOICE_HEADER-RECIPIENT_BANK_ACCOUNT, sy-vline,
WA_FIRU_S_PP_INVOICE_HEADER-RECIPIENT_INN, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FIRU_S_PP_INVOICE_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_FIRU_S_PP_INVOICE_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_FIRU_S_PP_INVOICE_HEADER INTO WA_FIRU_S_PP_INVOICE_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 BILLING_DOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-BILLING_DOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-BILLING_DOCUMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field BELNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-BELNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-BELNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-GJAHR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field NET_AMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-NET_AMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-NET_AMOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field VAT10_AMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-VAT10_AMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-VAT10_AMOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field VAT18_AMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-VAT18_AMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-VAT18_AMOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AU132, internal->external for field TOTAL_AMOUNT CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_FIRU_S_PP_INVOICE_HEADER-TOTAL_AMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FIRU_S_PP_INVOICE_HEADER-TOTAL_AMOUNT.
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_FIRU_S_PP_INVOICE_HEADER_STR,
BILLING_DOCUMENT TYPE STRING,
BILLING_DATE TYPE STRING,
BUKRS TYPE STRING,
BELNR TYPE STRING,
GJAHR TYPE STRING,
CONTRACT_NUMBER TYPE STRING,
CONTRACT_DATE TYPE STRING,
RECIPIENT_BANK_NAME TYPE STRING,
RECIPIENT_BANK_BIK TYPE STRING,
RECIPIENT_BANK_ACCOUNT TYPE STRING,
RECIPIENT_INN TYPE STRING,
RECIPIENT_KPP TYPE STRING,
RECIPIENT_NAME TYPE STRING,
RECIPIENT_ACCOUNT TYPE STRING,
SELLER_NAME TYPE STRING,
CONSIGNOR_NAME TYPE STRING,
BUYER_NAME TYPE STRING,
CONSIGNEE_NAME TYPE STRING,
CURRENCY_NAME TYPE STRING,
NET_AMOUNT TYPE STRING,
VAT10_AMOUNT TYPE STRING,
VAT18_AMOUNT TYPE STRING,
TOTAL_AMOUNT TYPE STRING,
DOC_CURRENCY TYPE STRING,
TOTAL_AMOUNT_TEXT TYPE STRING,
TERMS TYPE STRING,
CEO_NAME TYPE STRING,
CHIEFACC_NAME TYPE STRING,
RESP_POSITION TYPE STRING,
RESP_NAME TYPE STRING,
TEXT1 TYPE STRING,
TEXT2 TYPE STRING,
TEXT3 TYPE STRING,
TEXT4 TYPE STRING,END OF T_EKKO_STR. DATA: WA_FIRU_S_PP_INVOICE_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_FIRU_S_PP_INVOICE_HEADER_STR-BILLING_DOCUMENT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-BILLING_DATE sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-BUKRS sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-BELNR sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-GJAHR sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CONTRACT_NUMBER sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CONTRACT_DATE sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_BANK_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_BANK_BIK sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_BANK_ACCOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_INN sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_KPP sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RECIPIENT_ACCOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-SELLER_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CONSIGNOR_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-BUYER_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CONSIGNEE_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CURRENCY_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-NET_AMOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-VAT10_AMOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-VAT18_AMOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TOTAL_AMOUNT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-DOC_CURRENCY sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TOTAL_AMOUNT_TEXT sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TERMS sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CEO_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-CHIEFACC_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RESP_POSITION sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-RESP_NAME sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TEXT1 sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TEXT2 sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TEXT3 sy-vline
WA_FIRU_S_PP_INVOICE_HEADER_STR-TEXT4 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.