ABAP Select data from SAP table BAPIREQUEST_ITEM_IN 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 BAPIREQUEST_ITEM_IN 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 BAPIREQUEST_ITEM_IN. 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 BAPIREQUEST_ITEM_IN 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_BAPIREQUEST_ITEM_IN TYPE STANDARD TABLE OF BAPIREQUEST_ITEM_IN, WA_BAPIREQUEST_ITEM_IN TYPE BAPIREQUEST_ITEM_IN, 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: <BAPIREQUEST_ITEM_IN> TYPE BAPIREQUEST_ITEM_IN. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_BAPIREQUEST_ITEM_IN. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM BAPIREQUEST_ITEM_IN INTO TABLE IT_BAPIREQUEST_ITEM_IN. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM BAPIREQUEST_ITEM_IN * INTO TABLE @DATA(IT_BAPIREQUEST_ITEM_IN2). *--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_BAPIREQUEST_ITEM_IN INDEX 1 INTO DATA(WA_BAPIREQUEST_ITEM_IN2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_BAPIREQUEST_ITEM_IN ASSIGNING <BAPIREQUEST_ITEM_IN>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPIREQUEST_ITEM_IN>-EXECUTION_PERIOD = 1.
<BAPIREQUEST_ITEM_IN>-LINE_NUMBER = 1.
<BAPIREQUEST_ITEM_IN>-BUSP_COMP_CODE = 1.
<BAPIREQUEST_ITEM_IN>-BUSPARTNER = 1.
<BAPIREQUEST_ITEM_IN>-CONT_ACCT = 1.
ENDLOOP. LOOP AT IT_BAPIREQUEST_ITEM_IN INTO WA_BAPIREQUEST_ITEM_IN. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_BAPIREQUEST_ITEM_IN-CONTRACT, sy-vline,
WA_BAPIREQUEST_ITEM_IN-APPL_AREA, sy-vline,
WA_BAPIREQUEST_ITEM_IN-MAIN_TRANS, sy-vline,
WA_BAPIREQUEST_ITEM_IN-SUB_TRANS, sy-vline,
WA_BAPIREQUEST_ITEM_IN-AMOUNT, sy-vline,
WA_BAPIREQUEST_ITEM_IN-NET_DATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPIREQUEST_ITEM_IN 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_BAPIREQUEST_ITEM_IN 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_BAPIREQUEST_ITEM_IN INTO WA_BAPIREQUEST_ITEM_IN. *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 BUSPARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-BUSPARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-BUSPARTNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONT_ACCT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-CONT_ACCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-CONT_ACCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CONTRACT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-CONTRACT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-CONTRACT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field TRAN_RATE CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-TRAN_RATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-TRAN_RATE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-PARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-PARTNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FINAL_RECIPIENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-FINAL_RECIPIENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-FINAL_RECIPIENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field GL_ACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-GL_ACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-GL_ACCOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PROFIT_CTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-PROFIT_CTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-PROFIT_CTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COSTCENTER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-COSTCENTER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-COSTCENTER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ORDERID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-ORDERID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-ORDERID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SALES_ORD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-SALES_ORD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-SALES_ORD.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ABPSP, internal->external for field WBS_ELEM CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-WBS_ELEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-WBS_ELEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PLAN_GRP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPIREQUEST_ITEM_IN-PLAN_GRP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPIREQUEST_ITEM_IN-PLAN_GRP.
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_BAPIREQUEST_ITEM_IN_STR,
EXECUTION_PERIOD TYPE STRING,
LINE_NUMBER TYPE STRING,
BUSP_COMP_CODE TYPE STRING,
BUSPARTNER TYPE STRING,
CONT_ACCT TYPE STRING,
CONTRACT TYPE STRING,
APPL_AREA TYPE STRING,
MAIN_TRANS TYPE STRING,
SUB_TRANS TYPE STRING,
AMOUNT TYPE STRING,
NET_DATE TYPE STRING,
VALID_TO TYPE STRING,
BUS_AREA TYPE STRING,
DIVISION TYPE STRING,
ITEM_TEXT TYPE STRING,
TAX_CODE TYPE STRING,
DISC_DUE TYPE STRING,
DISC_DAYS TYPE STRING,
DISC_RATE TYPE STRING,
AMOUNT_LOC_CURR TYPE STRING,
TRAN_RATE TYPE STRING,
PMNT_METH TYPE STRING,
DUNN_PROC TYPE STRING,
INT_KEY TYPE STRING,
PARTNER TYPE STRING,
BK_DETAILS TYPE STRING,
CRD_DETAILS TYPE STRING,
FINAL_RECIPIENT TYPE STRING,
PERIOD_KEY TYPE STRING,
CALC_PERLO TYPE STRING,
CALC_PERHI TYPE STRING,
GLA_COMP_CODE TYPE STRING,
GL_ACCOUNT TYPE STRING,
PROFIT_CTR TYPE STRING,
COSTCENTER TYPE STRING,
ORDERID TYPE STRING,
SALES_ORD TYPE STRING,
S_ORD_ITEM TYPE STRING,
SCHED_LINE TYPE STRING,
WBS_ELEM TYPE STRING,
PROFIT_SEGM_NO TYPE STRING,
PROFIT_SEGM_HIST TYPE STRING,
TAXJURCODE TYPE STRING,
PLAN_GRP TYPE STRING,
PLAN_LEVEL TYPE STRING,
CM_EX_DAYS TYPE STRING,
CLASS_KEY TYPE STRING,
SUB_APPLICATION TYPE STRING,
GROUPING TYPE STRING,
SEPA_MANDATE_ID TYPE STRING,
PNCTR TYPE STRING,
TAX_AMOUNT TYPE STRING,
TAX_MANUAL TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPIREQUEST_ITEM_IN_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_BAPIREQUEST_ITEM_IN_STR-EXECUTION_PERIOD sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-LINE_NUMBER sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-BUSP_COMP_CODE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-BUSPARTNER sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CONT_ACCT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CONTRACT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-APPL_AREA sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-MAIN_TRANS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-SUB_TRANS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-AMOUNT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-NET_DATE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-VALID_TO sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-BUS_AREA sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-DIVISION sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-ITEM_TEXT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-TAX_CODE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-DISC_DUE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-DISC_DAYS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-DISC_RATE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-AMOUNT_LOC_CURR sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-TRAN_RATE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PMNT_METH sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-DUNN_PROC sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-INT_KEY sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PARTNER sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-BK_DETAILS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CRD_DETAILS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-FINAL_RECIPIENT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PERIOD_KEY sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CALC_PERLO sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CALC_PERHI sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-GLA_COMP_CODE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-GL_ACCOUNT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PROFIT_CTR sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-COSTCENTER sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-ORDERID sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-SALES_ORD sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-S_ORD_ITEM sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-SCHED_LINE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-WBS_ELEM sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PROFIT_SEGM_NO sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PROFIT_SEGM_HIST sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-TAXJURCODE sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PLAN_GRP sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PLAN_LEVEL sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CM_EX_DAYS sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-CLASS_KEY sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-SUB_APPLICATION sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-GROUPING sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-SEPA_MANDATE_ID sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-PNCTR sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-TAX_AMOUNT sy-vline
WA_BAPIREQUEST_ITEM_IN_STR-TAX_MANUAL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.