ABAP Select data from SAP table BAPI_CTRACPSOBJECT_ACCOUNTI 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_CTRACPSOBJECT_ACCOUNTI 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_CTRACPSOBJECT_ACCOUNTI. 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_CTRACPSOBJECT_ACCOUNTI 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_CTRACPSOBJECT_ACCOUNTI TYPE STANDARD TABLE OF BAPI_CTRACPSOBJECT_ACCOUNTI, WA_BAPI_CTRACPSOBJECT_ACCOUNTI TYPE BAPI_CTRACPSOBJECT_ACCOUNTI, 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_CTRACPSOBJECT_ACCOUNTI> TYPE BAPI_CTRACPSOBJECT_ACCOUNTI. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPI_CTRACPSOBJECT_ACCOUNTI. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPI_CTRACPSOBJECT_ACCOUNTI INTO TABLE IT_BAPI_CTRACPSOBJECT_ACCOUNTI. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPI_CTRACPSOBJECT_ACCOUNTI * INTO TABLE @DATA(IT_BAPI_CTRACPSOBJECT_ACCOUNTI2). *--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_CTRACPSOBJECT_ACCOUNTI INDEX 1 INTO DATA(WA_BAPI_CTRACPSOBJECT_ACCOUNTI2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPI_CTRACPSOBJECT_ACCOUNTI ASSIGNING <BAPI_CTRACPSOBJECT_ACCOUNTI>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI_CTRACPSOBJECT_ACCOUNTI>-PSLEGACYOBJECT = 1.
<BAPI_CTRACPSOBJECT_ACCOUNTI>-PSOBJECT_PAY_ACT = 1.
<BAPI_CTRACPSOBJECT_ACCOUNTI>-ADDR_NO = 1.
<BAPI_CTRACPSOBJECT_ACCOUNTI>-ALTER_PAYER = 1.
<BAPI_CTRACPSOBJECT_ACCOUNTI>-ADDR_ALT_PAYER = 1.
ENDLOOP. LOOP AT IT_BAPI_CTRACPSOBJECT_ACCOUNTI INTO WA_BAPI_CTRACPSOBJECT_ACCOUNTI. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPI_CTRACPSOBJECT_ACCOUNTI-METHOD_INC, sy-vline,
WA_BAPI_CTRACPSOBJECT_ACCOUNTI-BANK_INC, sy-vline,
WA_BAPI_CTRACPSOBJECT_ACCOUNTI-CCARD_INC, sy-vline,
WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALTER_PAYEE, sy-vline,
WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_PAYEE, sy-vline,
WA_BAPI_CTRACPSOBJECT_ACCOUNTI-METHOD_OUTG, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI_CTRACPSOBJECT_ACCOUNTI 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_CTRACPSOBJECT_ACCOUNTI 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_CTRACPSOBJECT_ACCOUNTI INTO WA_BAPI_CTRACPSOBJECT_ACCOUNTI. *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 ADDR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_NO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ALTER_PAYER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALTER_PAYER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALTER_PAYER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ADDR_ALT_PAYER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_PAYER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_PAYER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ALTER_PAYEE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALTER_PAYEE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALTER_PAYEE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ADDR_ALT_PAYEE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_PAYEE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_PAYEE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ALT_CORR_RECIPIENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALT_CORR_RECIPIENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ALT_CORR_RECIPIENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CORR_FIRST_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-CORR_FIRST_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-CORR_FIRST_YEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field CORR_LAST_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-CORR_LAST_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-CORR_LAST_YEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COLLPERSON CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-COLLPERSON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-COLLPERSON.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ADDR_ALT_CORR_RECIPIENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_CORR_RECIPIENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI_CTRACPSOBJECT_ACCOUNTI-ADDR_ALT_CORR_RECIPIENT.
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_CTRACPSOBJECT_ACCOUNTI_STR,
PSLEGACYOBJECT TYPE STRING,
PSOBJECT_PAY_ACT TYPE STRING,
ADDR_NO TYPE STRING,
ALTER_PAYER TYPE STRING,
ADDR_ALT_PAYER TYPE STRING,
METHOD_INC TYPE STRING,
BANK_INC TYPE STRING,
CCARD_INC TYPE STRING,
ALTER_PAYEE TYPE STRING,
ADDR_ALT_PAYEE TYPE STRING,
METHOD_OUTG TYPE STRING,
BANK_OUTG TYPE STRING,
CCARD_OUTG TYPE STRING,
PSOBJECT_CORR_ACT TYPE STRING,
ALT_CORR_RECIPIENT TYPE STRING,
CORR_ACTIVITY_KEY TYPE STRING,
CORR_VARIANT TYPE STRING,
SEPERATE_INVOICE TYPE STRING,
INVOICE_TYPE TYPE STRING,
CORR_STATUS TYPE STRING,
CORR_PERIOD TYPE STRING,
CORR_OFFSET_DAYS TYPE STRING,
CORR_OFFSET_MONTHS TYPE STRING,
CORR_DUNN_VARIANT TYPE STRING,
CORR_FIRST_PERIOD TYPE STRING,
CORR_FIRST_YEAR TYPE STRING,
CORR_LAST_PERIOD TYPE STRING,
CORR_LAST_YEAR TYPE STRING,
OBSOLETEFLAG TYPE STRING,
ACCOUNT_DETERMINATION_ID TYPE STRING,
OWN_BANK_ACCOUNT TYPE STRING,
DIRECT_DEBIT_AMOUNT TYPE STRING,
DIRECT_DEBIT_CURRENCY TYPE STRING,
DIRECT_DEBIT_CURRENCY_ISO TYPE STRING,
DIRECT_DEBIT_MONTHS TYPE STRING,
DIRECT_DEBIT_ROLLING TYPE STRING,
COLLGROUP TYPE STRING,
COLLSTRAT TYPE STRING,
COLLPERSON TYPE STRING,
CORR_INDIVIDUAL TYPE STRING,
XREMINDER TYPE STRING,
SEPA_MANDATE_ID TYPE STRING,
ARCHIVINGFLAG TYPE STRING,
ADDR_ALT_CORR_RECIPIENT TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI_CTRACPSOBJECT_ACCOUNTI_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_CTRACPSOBJECT_ACCOUNTI_STR-PSLEGACYOBJECT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-PSOBJECT_PAY_ACT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ADDR_NO sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ALTER_PAYER sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ADDR_ALT_PAYER sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-METHOD_INC sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-BANK_INC sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CCARD_INC sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ALTER_PAYEE sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ADDR_ALT_PAYEE sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-METHOD_OUTG sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-BANK_OUTG sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CCARD_OUTG sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-PSOBJECT_CORR_ACT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ALT_CORR_RECIPIENT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_ACTIVITY_KEY sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_VARIANT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-SEPERATE_INVOICE sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-INVOICE_TYPE sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_STATUS sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_PERIOD sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_OFFSET_DAYS sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_OFFSET_MONTHS sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_DUNN_VARIANT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_FIRST_PERIOD sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_FIRST_YEAR sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_LAST_PERIOD sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_LAST_YEAR sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-OBSOLETEFLAG sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ACCOUNT_DETERMINATION_ID sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-OWN_BANK_ACCOUNT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-DIRECT_DEBIT_AMOUNT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-DIRECT_DEBIT_CURRENCY sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-DIRECT_DEBIT_CURRENCY_ISO sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-DIRECT_DEBIT_MONTHS sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-DIRECT_DEBIT_ROLLING sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-COLLGROUP sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-COLLSTRAT sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-COLLPERSON sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-CORR_INDIVIDUAL sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-XREMINDER sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-SEPA_MANDATE_ID sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ARCHIVINGFLAG sy-vline
WA_BAPI_CTRACPSOBJECT_ACCOUNTI_STR-ADDR_ALT_CORR_RECIPIENT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.