ABAP Select data from SAP table BAPISDBUSI 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 BAPISDBUSI 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 BAPISDBUSI. 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 BAPISDBUSI 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_BAPISDBUSI TYPE STANDARD TABLE OF BAPISDBUSI, WA_BAPISDBUSI TYPE BAPISDBUSI, 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: <BAPISDBUSI> TYPE BAPISDBUSI. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPISDBUSI. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPISDBUSI INTO TABLE IT_BAPISDBUSI. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPISDBUSI * INTO TABLE @DATA(IT_BAPISDBUSI2). *--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_BAPISDBUSI INDEX 1 INTO DATA(WA_BAPISDBUSI2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPISDBUSI ASSIGNING <BAPISDBUSI>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPISDBUSI>-OPERATION = 1.
<BAPISDBUSI>-SD_DOC = 1.
<BAPISDBUSI>-ITM_NUMBER = 1.
<BAPISDBUSI>-PRICE_GRP = 1.
<BAPISDBUSI>-CUST_GROUP = 1.
ENDLOOP. LOOP AT IT_BAPISDBUSI INTO WA_BAPISDBUSI. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPISDBUSI-SALES_DIST, sy-vline,
WA_BAPISDBUSI-PRICE_LIST, sy-vline,
WA_BAPISDBUSI-INCOTERMS1, sy-vline,
WA_BAPISDBUSI-INCOTERMS2, sy-vline,
WA_BAPISDBUSI-ORDCOMBIND, sy-vline,
WA_BAPISDBUSI-BILL_SCHED, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPISDBUSI 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_BAPISDBUSI 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_BAPISDBUSI INTO WA_BAPISDBUSI. *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 SD_DOC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPISDBUSI-SD_DOC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-SD_DOC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATEFI CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATEFI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATEFI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field FISC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_BAPISDBUSI-FISC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-FISC_YEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATEST CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATEST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATEST.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PROMOTION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPISDBUSI-PROMOTION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-PROMOTION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FINDOCPROC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPISDBUSI-FINDOCPROC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-FINDOCPROC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field POITMNOS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPISDBUSI-POITMNOS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-POITMNOS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATECO CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATECO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATECO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATELC CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATELC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATELC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATELC_V CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATELC_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATELC_V.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCH_RATE_FI_V CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCH_RATE_FI_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCH_RATE_FI_V.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATEST_V CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATEST_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATEST_V.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field EXCHRATECO_V CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPISDBUSI-EXCHRATECO_V IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-EXCHRATECO_V.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN5, internal->external for field TRANS_MAT CALL FUNCTION 'CONVERSION_EXIT_MATN5_OUTPUT' EXPORTING input = WA_BAPISDBUSI-TRANS_MAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-TRANS_MAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNL, internal->external for field TRANS_MAT_EXTERNAL CALL FUNCTION 'CONVERSION_EXIT_MATNL_OUTPUT' EXPORTING input = WA_BAPISDBUSI-TRANS_MAT_EXTERNAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-TRANS_MAT_EXTERNAL.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATNW, internal->external for field TRANS_MAT_VERSION CALL FUNCTION 'CONVERSION_EXIT_MATNW_OUTPUT' EXPORTING input = WA_BAPISDBUSI-TRANS_MAT_VERSION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-TRANS_MAT_VERSION.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field TRANS_MAT_LONG CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_BAPISDBUSI-TRANS_MAT_LONG IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPISDBUSI-TRANS_MAT_LONG.
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_BAPISDBUSI_STR,
OPERATION TYPE STRING,
SD_DOC TYPE STRING,
ITM_NUMBER TYPE STRING,
PRICE_GRP TYPE STRING,
CUST_GROUP TYPE STRING,
SALES_DIST TYPE STRING,
PRICE_LIST TYPE STRING,
INCOTERMS1 TYPE STRING,
INCOTERMS2 TYPE STRING,
ORDCOMBIND TYPE STRING,
BILL_SCHED TYPE STRING,
INVO_SCHED TYPE STRING,
MN_INVOICE TYPE STRING,
EXCHRATEFI TYPE STRING,
ADD_VAL_DY TYPE STRING,
FIX_VAL_DY TYPE STRING,
PMNTTRMS TYPE STRING,
PAYMETHODE TYPE STRING,
ACCNT_ASGN TYPE STRING,
EXCHG_RATE TYPE STRING,
PRICE_DATE TYPE STRING,
BILL_DATE TYPE STRING,
SERV_DATE TYPE STRING,
FISC_YEAR TYPE STRING,
POSTPERIOD TYPE STRING,
EXCHRATEST TYPE STRING,
DUNN_KEY TYPE STRING,
DUNN_BLOCK TYPE STRING,
BILL_PLAN TYPE STRING,
PROMOTION TYPE STRING,
PAY_GUARAN TYPE STRING,
FINDOCPROC TYPE STRING,
J_1AFITP_D TYPE STRING,
REAS_0_VAT TYPE STRING,
REGION TYPE STRING,
ACTIVICODE TYPE STRING,
DISTRIBTYP TYPE STRING,
TAX_CLASS TYPE STRING,
DEPART_NO TYPE STRING,
REC_POINT TYPE STRING,
PURCH_NO_C TYPE STRING,
PURCH_DATE TYPE STRING,
PO_METHOD TYPE STRING,
REF_1 TYPE STRING,
PURCH_NO_S TYPE STRING,
PO_DAT_S TYPE STRING,
PO_METH_S TYPE STRING,
REF_1_S TYPE STRING,
POITMNOS TYPE STRING,
TRANS_DATE TYPE STRING,
TRANSDATE TYPE STRING,
CUSTCONGR1 TYPE STRING,
CUSTCONGR2 TYPE STRING,
CUSTCONGR3 TYPE STRING,
CUSTCONGR4 TYPE STRING,
CUSTCONGR5 TYPE STRING,
VALCONTCUR TYPE STRING,
ISOVALCONT TYPE STRING,
EXCHRATECO TYPE STRING,
CURRENCKEY TYPE STRING,
ISOCURRKEY TYPE STRING,
EXCHRATELC TYPE STRING,
CEPRPERCEN TYPE STRING,
INFLAT_IDX TYPE STRING,
BASDATEIDX TYPE STRING,
CUST_PO_NO TYPE STRING,
DLV_TIME TYPE STRING,
DLI_PROFIL TYPE STRING,
CALC_MOTIVE TYPE STRING,
BILL_FORM TYPE STRING,
REVENUETYP TYPE STRING,
BEGDEMAPER TYPE STRING,
EXCHRATELC_V TYPE STRING,
EXCH_RATE_FI_V TYPE STRING,
EXCHG_RATE_V TYPE STRING,
EXCHRATEST_V TYPE STRING,
EXCHRATECO_V TYPE STRING,
DELIV_TYPE TYPE STRING,
TRANS_CAT TYPE STRING,
TRANS_MAT TYPE STRING,
SPEC_PROC TYPE STRING,
PRODCAT TYPE STRING,
FUNC_AREA TYPE STRING,
POD_PROC TYPE STRING,
CAMPAIGN TYPE STRING,
FKK_CONACCT TYPE STRING,
FUNC_AREA_LONG TYPE STRING,
FKK_CONACCT_GUID TYPE STRING,
TRANS_MAT_EXTERNAL TYPE STRING,
TRANS_MAT_GUID TYPE STRING,
TRANS_MAT_VERSION TYPE STRING,
SEPA_MANDATE_ID TYPE STRING,
INCOTERMSV TYPE STRING,
INCOTERMS2L TYPE STRING,
INCOTERMS3L TYPE STRING,
TRANS_MAT_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPISDBUSI_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_BAPISDBUSI_STR-OPERATION sy-vline
WA_BAPISDBUSI_STR-SD_DOC sy-vline
WA_BAPISDBUSI_STR-ITM_NUMBER sy-vline
WA_BAPISDBUSI_STR-PRICE_GRP sy-vline
WA_BAPISDBUSI_STR-CUST_GROUP sy-vline
WA_BAPISDBUSI_STR-SALES_DIST sy-vline
WA_BAPISDBUSI_STR-PRICE_LIST sy-vline
WA_BAPISDBUSI_STR-INCOTERMS1 sy-vline
WA_BAPISDBUSI_STR-INCOTERMS2 sy-vline
WA_BAPISDBUSI_STR-ORDCOMBIND sy-vline
WA_BAPISDBUSI_STR-BILL_SCHED sy-vline
WA_BAPISDBUSI_STR-INVO_SCHED sy-vline
WA_BAPISDBUSI_STR-MN_INVOICE sy-vline
WA_BAPISDBUSI_STR-EXCHRATEFI sy-vline
WA_BAPISDBUSI_STR-ADD_VAL_DY sy-vline
WA_BAPISDBUSI_STR-FIX_VAL_DY sy-vline
WA_BAPISDBUSI_STR-PMNTTRMS sy-vline
WA_BAPISDBUSI_STR-PAYMETHODE sy-vline
WA_BAPISDBUSI_STR-ACCNT_ASGN sy-vline
WA_BAPISDBUSI_STR-EXCHG_RATE sy-vline
WA_BAPISDBUSI_STR-PRICE_DATE sy-vline
WA_BAPISDBUSI_STR-BILL_DATE sy-vline
WA_BAPISDBUSI_STR-SERV_DATE sy-vline
WA_BAPISDBUSI_STR-FISC_YEAR sy-vline
WA_BAPISDBUSI_STR-POSTPERIOD sy-vline
WA_BAPISDBUSI_STR-EXCHRATEST sy-vline
WA_BAPISDBUSI_STR-DUNN_KEY sy-vline
WA_BAPISDBUSI_STR-DUNN_BLOCK sy-vline
WA_BAPISDBUSI_STR-BILL_PLAN sy-vline
WA_BAPISDBUSI_STR-PROMOTION sy-vline
WA_BAPISDBUSI_STR-PAY_GUARAN sy-vline
WA_BAPISDBUSI_STR-FINDOCPROC sy-vline
WA_BAPISDBUSI_STR-J_1AFITP_D sy-vline
WA_BAPISDBUSI_STR-REAS_0_VAT sy-vline
WA_BAPISDBUSI_STR-REGION sy-vline
WA_BAPISDBUSI_STR-ACTIVICODE sy-vline
WA_BAPISDBUSI_STR-DISTRIBTYP sy-vline
WA_BAPISDBUSI_STR-TAX_CLASS sy-vline
WA_BAPISDBUSI_STR-DEPART_NO sy-vline
WA_BAPISDBUSI_STR-REC_POINT sy-vline
WA_BAPISDBUSI_STR-PURCH_NO_C sy-vline
WA_BAPISDBUSI_STR-PURCH_DATE sy-vline
WA_BAPISDBUSI_STR-PO_METHOD sy-vline
WA_BAPISDBUSI_STR-REF_1 sy-vline
WA_BAPISDBUSI_STR-PURCH_NO_S sy-vline
WA_BAPISDBUSI_STR-PO_DAT_S sy-vline
WA_BAPISDBUSI_STR-PO_METH_S sy-vline
WA_BAPISDBUSI_STR-REF_1_S sy-vline
WA_BAPISDBUSI_STR-POITMNOS sy-vline
WA_BAPISDBUSI_STR-TRANS_DATE sy-vline
WA_BAPISDBUSI_STR-TRANSDATE sy-vline
WA_BAPISDBUSI_STR-CUSTCONGR1 sy-vline
WA_BAPISDBUSI_STR-CUSTCONGR2 sy-vline
WA_BAPISDBUSI_STR-CUSTCONGR3 sy-vline
WA_BAPISDBUSI_STR-CUSTCONGR4 sy-vline
WA_BAPISDBUSI_STR-CUSTCONGR5 sy-vline
WA_BAPISDBUSI_STR-VALCONTCUR sy-vline
WA_BAPISDBUSI_STR-ISOVALCONT sy-vline
WA_BAPISDBUSI_STR-EXCHRATECO sy-vline
WA_BAPISDBUSI_STR-CURRENCKEY sy-vline
WA_BAPISDBUSI_STR-ISOCURRKEY sy-vline
WA_BAPISDBUSI_STR-EXCHRATELC sy-vline
WA_BAPISDBUSI_STR-CEPRPERCEN sy-vline
WA_BAPISDBUSI_STR-INFLAT_IDX sy-vline
WA_BAPISDBUSI_STR-BASDATEIDX sy-vline
WA_BAPISDBUSI_STR-CUST_PO_NO sy-vline
WA_BAPISDBUSI_STR-DLV_TIME sy-vline
WA_BAPISDBUSI_STR-DLI_PROFIL sy-vline
WA_BAPISDBUSI_STR-CALC_MOTIVE sy-vline
WA_BAPISDBUSI_STR-BILL_FORM sy-vline
WA_BAPISDBUSI_STR-REVENUETYP sy-vline
WA_BAPISDBUSI_STR-BEGDEMAPER sy-vline
WA_BAPISDBUSI_STR-EXCHRATELC_V sy-vline
WA_BAPISDBUSI_STR-EXCH_RATE_FI_V sy-vline
WA_BAPISDBUSI_STR-EXCHG_RATE_V sy-vline
WA_BAPISDBUSI_STR-EXCHRATEST_V sy-vline
WA_BAPISDBUSI_STR-EXCHRATECO_V sy-vline
WA_BAPISDBUSI_STR-DELIV_TYPE sy-vline
WA_BAPISDBUSI_STR-TRANS_CAT sy-vline
WA_BAPISDBUSI_STR-TRANS_MAT sy-vline
WA_BAPISDBUSI_STR-SPEC_PROC sy-vline
WA_BAPISDBUSI_STR-PRODCAT sy-vline
WA_BAPISDBUSI_STR-FUNC_AREA sy-vline
WA_BAPISDBUSI_STR-POD_PROC sy-vline
WA_BAPISDBUSI_STR-CAMPAIGN sy-vline
WA_BAPISDBUSI_STR-FKK_CONACCT sy-vline
WA_BAPISDBUSI_STR-FUNC_AREA_LONG sy-vline
WA_BAPISDBUSI_STR-FKK_CONACCT_GUID sy-vline
WA_BAPISDBUSI_STR-TRANS_MAT_EXTERNAL sy-vline
WA_BAPISDBUSI_STR-TRANS_MAT_GUID sy-vline
WA_BAPISDBUSI_STR-TRANS_MAT_VERSION sy-vline
WA_BAPISDBUSI_STR-SEPA_MANDATE_ID sy-vline
WA_BAPISDBUSI_STR-INCOTERMSV sy-vline
WA_BAPISDBUSI_STR-INCOTERMS2L sy-vline
WA_BAPISDBUSI_STR-INCOTERMS3L sy-vline
WA_BAPISDBUSI_STR-TRANS_MAT_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.